watchShakes.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. let times = 0
  2. let lastTime = 0
  3. const getLogInfo = function() {
  4. let num = 0
  5. let info = my.getStorageSync({
  6. key: '__antmove_loginfo',
  7. }).data
  8. if (info === null) { return false }
  9. info = info.pages
  10. info.forEach((v) => {
  11. num += v.logs.length
  12. })
  13. return num
  14. }
  15. function getNewData() {
  16. if (!lastTime) {
  17. lastTime = new Date().getTime()
  18. times = 1
  19. } else {
  20. const thisTime = new Date().getTime()
  21. times += 1
  22. if (thisTime - lastTime > 1000 || times > 3) {
  23. times = 1
  24. }
  25. lastTime = thisTime
  26. }
  27. }
  28. const watchShakes = function() {
  29. const pages = getCurrentPages()
  30. const url = pages[pages.length - 1].route
  31. const logUrl = 'pages/ant-move-runtime-logs/index'
  32. const specificUrl = 'pages/ant-move-runtime-logs/specific/index'
  33. my.watchShake({
  34. success() {
  35. const num = getLogInfo()
  36. const ifWatch = my.getStorageSync({
  37. key: 'ifWatch',
  38. }).data
  39. getNewData()
  40. if (times !== 3 || !ifWatch || url === logUrl || url === specificUrl || !num) {
  41. watchShakes()
  42. return false
  43. }
  44. my.confirm({
  45. title: '温馨提示',
  46. content: `已收集了${num}条问题日志,是否查看? (该弹窗和问题收集页面的代码由Antmove嵌入,上线时请记得去掉)`,
  47. confirmButtonText: '赶紧看看',
  48. cancelButtonText: '暂不需要',
  49. success(res) {
  50. if (res.confirm) {
  51. my.navigateTo({
  52. url: '/pages/ant-move-runtime-logs/index',
  53. })
  54. }
  55. },
  56. complete() {
  57. watchShakes()
  58. },
  59. })
  60. },
  61. })
  62. }
  63. module.exports = watchShakes