watchShakes.js 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. "use strict";
  2. var times = 0;
  3. var lastTime = 0;
  4. var getLogInfo = function getLogInfo() {
  5. var num = 0;
  6. var info = my.getStorageSync({
  7. key: '__antmove_loginfo'
  8. }).data;
  9. if (info === null) {
  10. return false;
  11. }
  12. info = info.pages;
  13. info.forEach(function (v) {
  14. num += v.logs.length;
  15. });
  16. return num;
  17. };
  18. function getNewData() {
  19. if (!lastTime) {
  20. lastTime = new Date().getTime();
  21. times = 1;
  22. } else {
  23. var thisTime = new Date().getTime();
  24. times += 1;
  25. if (thisTime - lastTime > 1000 || times > 3) {
  26. times = 1;
  27. }
  28. lastTime = thisTime;
  29. }
  30. }
  31. var watchShakes = function watchShakes() {
  32. var pages = getCurrentPages();
  33. var url = pages[pages.length - 1].route;
  34. var logUrl = 'pages/ant-move-runtime-logs/index';
  35. var specificUrl = 'pages/ant-move-runtime-logs/specific/index';
  36. my.watchShake({
  37. success: function success() {
  38. var num = getLogInfo();
  39. var ifWatch = my.getStorageSync({
  40. key: 'ifWatch'
  41. }).data;
  42. getNewData();
  43. if (times !== 3 || !ifWatch || url === logUrl || url === specificUrl || !num) {
  44. watchShakes();
  45. return false;
  46. }
  47. my.confirm({
  48. title: '温馨提示',
  49. content: "\u5DF2\u6536\u96C6\u4E86".concat(num, "\u6761\u95EE\u9898\u65E5\u5FD7\uFF0C\u662F\u5426\u67E5\u770B? (\u8BE5\u5F39\u7A97\u548C\u95EE\u9898\u6536\u96C6\u9875\u9762\u7684\u4EE3\u7801\u7531Antmove\u5D4C\u5165\uFF0C\u4E0A\u7EBF\u65F6\u8BF7\u8BB0\u5F97\u53BB\u6389)"),
  50. confirmButtonText: '赶紧看看',
  51. cancelButtonText: '暂不需要',
  52. success: function success(res) {
  53. if (res.confirm) {
  54. my.navigateTo({
  55. url: '/pages/ant-move-runtime-logs/index'
  56. });
  57. }
  58. },
  59. complete: function complete() {
  60. watchShakes();
  61. }
  62. });
  63. }
  64. });
  65. };
  66. module.exports = watchShakes;