utils.js 834 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. import {
  2. BrowseRecordAdd
  3. } from '@/api/applist.js'
  4. //防抖函数
  5. export function debounce(func, fnThis, wait) {
  6. var timer;
  7. return () => {
  8. timer && clearTimeout(timer);
  9. timer = setTimeout(() => {
  10. func.call(fnThis)
  11. timer = null
  12. }, wait);
  13. };
  14. }
  15. //节流函数
  16. export function debounce1(func, fnThis, wait) {
  17. var timer;
  18. return () => {
  19. clearTimeout(timer);
  20. timer = setTimeout(func.bind(fnThis), wait);
  21. };
  22. }
  23. let goMiniAppFlag = false
  24. //跳转小程序
  25. export function goMiniApp(data, item) {
  26. if (goMiniAppFlag) return
  27. goMiniAppFlag = true
  28. wx.navigateToMiniProgram({
  29. ...data,
  30. success: (res) => {
  31. // 打开成功
  32. goMiniAppFlag = false
  33. item && BrowseRecordAdd(item.id)
  34. },
  35. fail: () => {
  36. goMiniAppFlag = false
  37. }
  38. })
  39. }
  40. //跳转页面
  41. export function goPage(url) {
  42. uni.navigateTo({
  43. url
  44. });
  45. }