utils.js 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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. }