utils.js 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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. hour = parseInt(timestamp / 3600);
  66. } else {
  67. hour = parseInt(timestamp / 3600);
  68. let remainderMinute = remainder % 60;
  69. if (remainderMinute === 0) { // 整除 分钟
  70. minute = parseInt(remainder / 60);
  71. } else {
  72. minute = parseInt(remainder / 60);
  73. second = parseInt(remainderMinute);
  74. }
  75. }
  76. let text = '';
  77. if (hour > 0) {
  78. if (hour < 10) {
  79. text += '0';
  80. }
  81. text += hour + ':';
  82. } else {
  83. text += '00' + ':';
  84. }
  85. if (minute > 0) {
  86. if (minute < 10) {
  87. text += '0';
  88. }
  89. text += minute + ':';
  90. } else {
  91. text += '00' + ':';
  92. }
  93. if (second > 0) {
  94. if (second < 10) {
  95. text += '0';
  96. }
  97. text += second;
  98. } else {
  99. text += '00';
  100. }
  101. return text;
  102. }