utils.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. export function cardType(index, card) {
  2. let type = index
  3. switch (card.status) {
  4. case 1:
  5. type = 5
  6. break
  7. case 2:
  8. type = 4
  9. break
  10. }
  11. return type
  12. }
  13. export function navigateTo(url, query) {
  14. console.log('进入页面跳转事件')
  15. if (query && Object.keys(query).length != 0) {
  16. url += '?'
  17. for (let i in query) {
  18. url += i
  19. url += '='
  20. url += query[i]
  21. url += '&'
  22. }
  23. }
  24. console.log(url, 'url')
  25. wx.navigateTo({
  26. url: url,
  27. })
  28. }
  29. export function redirectTo(url, query) {
  30. console.log('进入页面跳转事件')
  31. if (query && Object.keys(query).length != 0) {
  32. url += '?'
  33. for (let i in query) {
  34. url += i
  35. url += '='
  36. url += query[i]
  37. url += '&'
  38. }
  39. }
  40. console.log(url, 'url')
  41. wx.redirectTo({
  42. url: url,
  43. })
  44. }
  45. // 回显数据字典
  46. export function selectDictLabel(datas, value) {
  47. var actions = []
  48. Object.keys(datas).some(key => {
  49. if (datas[key].value == '' + value) {
  50. actions.push(datas[key].label)
  51. return true
  52. }
  53. })
  54. return actions.join('')
  55. }
  56. // 时间戳转时分秒
  57. export const formatSeconds = value => {
  58. if (value === 0 || value < 1000) return '00:00:00'
  59. var timestamp = parseInt(value) / 1000 // 毫秒转秒
  60. // 小时取余数
  61. const remainder = timestamp % 3600
  62. // 时、分、秒
  63. let hour, minute, second
  64. if (remainder === 0) {
  65. // 整除 小时
  66. hour = parseInt(timestamp / 3600)
  67. } else {
  68. hour = parseInt(timestamp / 3600)
  69. let remainderMinute = remainder % 60
  70. if (remainderMinute === 0) {
  71. // 整除 分钟
  72. minute = parseInt(remainder / 60)
  73. } else {
  74. minute = parseInt(remainder / 60)
  75. second = parseInt(remainderMinute)
  76. }
  77. }
  78. let text = ''
  79. if (hour > 0) {
  80. if (hour < 10) {
  81. text += '0'
  82. }
  83. text += hour + ':'
  84. } else {
  85. text += '00' + ':'
  86. }
  87. if (minute > 0) {
  88. if (minute < 10) {
  89. text += '0'
  90. }
  91. text += minute + ':'
  92. } else {
  93. text += '00' + ':'
  94. }
  95. if (second > 0) {
  96. if (second < 10) {
  97. text += '0'
  98. }
  99. text += second
  100. } else {
  101. text += '00'
  102. }
  103. return text
  104. }