index.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. import applist from '@/api/modules/applist.js'
  2. import sha256 from 'crypto-js/sha256'
  3. import request from '@/api/request'
  4. import QRCode from 'qrcode'
  5. import dayjs from 'dayjs'
  6. import wxUtils from './modules/wx.js'
  7. import route from './modules/route.js'
  8. dayjs.locale('zh-cn')
  9. let goMiniAppFlag = false
  10. let imagePrefix = ''
  11. setTimeout(()=>{
  12. imagePrefix="https://ct.zzxcx.net/ctjk/mp-wx/"
  13. },500)
  14. const utils = {
  15. dynaImagePrefix(src){
  16. return imagePrefix+src
  17. },
  18. mapToUrlQuery(map) {
  19. let str = ""
  20. if (typeof map !== 'object') {
  21. return false
  22. }
  23. for (const key in map) {
  24. if (Object.hasOwnProperty.call(map, key)) {
  25. str += (key + "=" + map[key])+"&"
  26. }
  27. }
  28. // console.log(str)
  29. return str
  30. },
  31. //生成二维码图片
  32. async qrcodeGenerate(data) {
  33. let qrcodeRes = await QRCode.toString(data, {
  34. margin: 0,
  35. errorCorrectionLevel: 'H'
  36. });
  37. return 'data:image/svg+xml;base64,' + Buffer(qrcodeRes).toString('base64');
  38. },
  39. //引入路由相关函数
  40. route,
  41. //引入微信相关utils
  42. wxUtils,
  43. //引入moment模块
  44. dayjs,
  45. //临时测试接口请求
  46. testReq(data) {
  47. return request(data)
  48. },
  49. //vant通知组件调用函数
  50. Toast(title) {
  51. wx.showToast({
  52. title,
  53. icon: 'none'
  54. })
  55. },
  56. //防抖函数
  57. debounce(func, fnThis, wait) {
  58. var timer;
  59. return () => {
  60. timer && clearTimeout(timer);
  61. timer = setTimeout(() => {
  62. func.call(fnThis)
  63. timer = null
  64. }, wait);
  65. };
  66. },
  67. //节流函数
  68. throttling(func, fnThis, wait) {
  69. var timer;
  70. return () => {
  71. clearTimeout(timer);
  72. timer = setTimeout(func.bind(fnThis), wait);
  73. };
  74. },
  75. //跳转小程序
  76. goMiniApp(data, item) {
  77. if (goMiniAppFlag) return
  78. goMiniAppFlag = true
  79. let myData = JSON.parse(data)
  80. wx.navigateToMiniProgram({
  81. ...myData,
  82. success: (res) => {
  83. // 打开成功
  84. goMiniAppFlag = false
  85. item && applist.BrowseRecordAdd(item.id)
  86. },
  87. fail: () => {
  88. goMiniAppFlag = false
  89. }
  90. })
  91. },
  92. //跳转页面
  93. goPage(url, type, data) {
  94. if (type == 'reLaunch') {
  95. uni.reLaunch({
  96. url
  97. });
  98. return
  99. }
  100. if (type == 'redirectTo') {
  101. uni.redirectTo({
  102. url
  103. });
  104. return
  105. }
  106. uni.navigateTo({
  107. url,
  108. success: function (res) {
  109. // 通过eventChannel向被打开页面传送数据
  110. res.eventChannel.emit('passParameters', data)
  111. }
  112. });
  113. },
  114. //页面接受参数
  115. goPageGetData() {
  116. return new Promise((res) => {
  117. const eventChannel = this.getOpenerEventChannel()
  118. eventChannel.on('passParameters', function (data) {
  119. res(data)
  120. })
  121. })
  122. },
  123. //返回今天明天后天周几
  124. getDay(date) {
  125. let UTCDay = new Date(date).getUTCDay()
  126. let jetLag = new Date(date).getTime() - new Date().getTime()
  127. let dayDif = jetLag / (1000 * 60 * 60 * 24)
  128. if (dayDif < 2) {
  129. if (dayDif < 0) {
  130. return '今天'
  131. }
  132. if (dayDif < 1) {
  133. return '明天'
  134. }
  135. if (dayDif < 2) {
  136. return '后天'
  137. }
  138. }
  139. switch (UTCDay) {
  140. case 0:
  141. return '周天';
  142. case 1:
  143. return '周一';
  144. case 2:
  145. return '周二';
  146. case 3:
  147. return '周三';
  148. case 4:
  149. return '周四';
  150. case 5:
  151. return '周五';
  152. case 6:
  153. return '周六';
  154. }
  155. }
  156. }
  157. export default utils