utils.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. import {
  2. BrowseRecordAdd
  3. } from '@/api/applist.js'
  4. import sha256 from 'crypto-js/sha256'
  5. //防抖函数
  6. export function debounce(func, fnThis, wait) {
  7. var timer;
  8. return () => {
  9. timer && clearTimeout(timer);
  10. timer = setTimeout(() => {
  11. func.call(fnThis)
  12. timer = null
  13. }, wait);
  14. };
  15. }
  16. //节流函数
  17. export function debounce1(func, fnThis, wait) {
  18. var timer;
  19. return () => {
  20. clearTimeout(timer);
  21. timer = setTimeout(func.bind(fnThis), wait);
  22. };
  23. }
  24. let goMiniAppFlag = false
  25. //跳转小程序
  26. export function goMiniApp(data, item) {
  27. if (goMiniAppFlag) return
  28. goMiniAppFlag = true
  29. let myData = JSON.parse(data)
  30. wx.navigateToMiniProgram({
  31. ...myData,
  32. success: (res) => {
  33. // 打开成功
  34. goMiniAppFlag = false
  35. item && BrowseRecordAdd(item.id)
  36. },
  37. fail: () => {
  38. goMiniAppFlag = false
  39. }
  40. })
  41. }
  42. //跳转页面
  43. export function goPage(url, type) {
  44. if (type == 'reLaunch') {
  45. uni.reLaunch({
  46. url
  47. });
  48. return
  49. }
  50. if (type == 'redirectTo') {
  51. uni.redirectTo({
  52. url
  53. });
  54. return
  55. }
  56. uni.navigateTo({
  57. url
  58. });
  59. }
  60. //根据类型跳转
  61. export function clickJumpType(item) {
  62. if (item.jumpUrlType == 'goMiniApp') {
  63. goMiniApp(item.jumpUrl)
  64. }
  65. if (item.jumpUrlType == 'goPage') {
  66. goPage(item.jumpUrl)
  67. }
  68. if (item.jumpUrlType == 'goWebView') {
  69. goPage(`/pages/webview/webview?src=${item.jumpUrl}`)
  70. }
  71. }
  72. function base64_encode(str) {
  73. var c1, c2, c3;
  74. var base64EncodeChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
  75. var i = 0,
  76. len = str.length,
  77. string = '';
  78. while (i < len) {
  79. c1 = str.charCodeAt(i++) & 0xff;
  80. if (i == len) {
  81. string += base64EncodeChars.charAt(c1 >> 2);
  82. string += base64EncodeChars.charAt((c1 & 0x3) << 4);
  83. string += "==";
  84. break;
  85. }
  86. c2 = str.charCodeAt(i++);
  87. if (i == len) {
  88. string += base64EncodeChars.charAt(c1 >> 2);
  89. string += base64EncodeChars.charAt(((c1 & 0x3) << 4) | ((c2 & 0xF0) >> 4));
  90. string += base64EncodeChars.charAt((c2 & 0xF) << 2);
  91. string += "=";
  92. break;
  93. }
  94. c3 = str.charCodeAt(i++);
  95. string += base64EncodeChars.charAt(c1 >> 2);
  96. string += base64EncodeChars.charAt(((c1 & 0x3) << 4) | ((c2 & 0xF0) >> 4));
  97. string += base64EncodeChars.charAt(((c2 & 0xF) << 2) | ((c3 & 0xC0) >> 6));
  98. string += base64EncodeChars.charAt(c3 & 0x3F)
  99. }
  100. return string
  101. }
  102. //微信支付调起支付
  103. export function wxPay(data) {
  104. wx.requestPayment({
  105. ...data
  106. })
  107. }
  108. //返回星期几
  109. export function getUTCDay(date) {
  110. let UTCDay = new Date(date).getUTCDay()
  111. switch (UTCDay) {
  112. case 0:
  113. return '周天';
  114. case 1:
  115. return '周一';
  116. case 2:
  117. return '周二';
  118. case 3:
  119. return '周三';
  120. case 4:
  121. return '周四';
  122. case 5:
  123. return '周五';
  124. case 6:
  125. return '周六';
  126. }
  127. }
  128. //返回今天明天后天周几
  129. export function getDay(date) {
  130. let UTCDay = new Date(date).getUTCDay()
  131. let jetLag = new Date(date).getTime() - new Date().getTime()
  132. let dayDif = jetLag / (1000 * 60 * 60 * 24)
  133. if (dayDif < 2) {
  134. if (dayDif < 0) {
  135. return '今天'
  136. }
  137. if (dayDif < 1) {
  138. return '明天'
  139. }
  140. if (dayDif < 2) {
  141. return '后天'
  142. }
  143. }
  144. switch (UTCDay) {
  145. case 0:
  146. return '周天';
  147. case 1:
  148. return '周一';
  149. case 2:
  150. return '周二';
  151. case 3:
  152. return '周三';
  153. case 4:
  154. return '周四';
  155. case 5:
  156. return '周五';
  157. case 6:
  158. return '周六';
  159. }
  160. }