App.vue 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. <script>
  2. import request from '/common/request.js';
  3. export default {
  4. onLaunch: function() {
  5. // #ifdef APP-PLUS || APP-PLUS-NVUE
  6. const ua = uni.getSystemInfoSync().platform;
  7. if (/ios/i.test(ua)) {
  8. // 苹果
  9. } else {
  10. this.checkVersion();
  11. }
  12. // #endif
  13. },
  14. onShow: function() {
  15. console.log('App Show');
  16. },
  17. onHide: function() {
  18. console.log('App Hide');
  19. },
  20. data() {
  21. return { fastOrderTimer: {} };
  22. },
  23. mounted() {
  24. uni.$on('startPlayVoiceBroadcast', (res) => {
  25. clearInterval(this.fastOrderTimer);
  26. if (res) {
  27. this.startPlayVoiceBroadcast();
  28. }
  29. });
  30. },
  31. methods: {
  32. startPlayVoiceBroadcast() {
  33. const _this = this;
  34. this.fastOrderTimer = setInterval(function() {
  35. _this.getFastOrderNum();
  36. }, 3000);
  37. },
  38. getFastOrderNum() {
  39. request({
  40. url: '/api/jsOrder/getSeizeOrder',
  41. data: {},
  42. success: (res) => {
  43. console.log('抢单订单数量', res);
  44. if (res.data.data?.fast_number) {
  45. uni.setTabBarBadge({ index: 3, text: res.data.data?.fast_number + '' });
  46. }
  47. if (!res.data.data?.count) {
  48. // 没有认证
  49. console.log('结束');
  50. uni.removeTabBarBadge({ index: 3 });
  51. clearInterval(this.fastOrderTimer);
  52. }
  53. },
  54. fail: () => {},
  55. complete: () => {}
  56. });
  57. },
  58. // #ifdef APP-PLUS || APP-PLUS-NVUE
  59. // app更新检测
  60. checkVersion() {
  61. // 获取应用版本号
  62. let version = plus.runtime.version;
  63. //检测当前平台,如果是安卓则启动安卓更新
  64. uni.getSystemInfo({
  65. success: res => {
  66. this.updateHandler(res.platform, version);
  67. }
  68. })
  69. },
  70. // 更新操作
  71. updateHandler(platform, version) {
  72. let data = {
  73. platform: platform,
  74. version: version
  75. }
  76. let _this = this;
  77. request({
  78. url: '/api/getdow',
  79. data: { data },
  80. success: res => {
  81. console.log('版本检测', res)
  82. if (res.data.data.version_num) {
  83. const info = res.data.data.version_num;
  84. var downUrl = res.data.data.url
  85. let version_num_d = info.split('.').join('');
  86. let version_d = version.split('.').join('');
  87. if (info !== '' && version_num_d > version_d) {
  88. uni.showModal({
  89. //提醒用户更新
  90. title: '更新提示',
  91. content: `发现新版本,是否更新`,
  92. success: (res) => {
  93. if (res.confirm) {
  94. if (platform == 'android') {
  95. plus.runtime.openURL(downUrl)
  96. } else if (platform == 'ios') {
  97. const appleId = 1628804508; //app对应的appleId
  98. plus.runtime.launchApplication({
  99. action: `itms-apps://itunes.apple.com/cn/app/id${appleId}?mt=8`
  100. },
  101. function(e) {
  102. console.log(
  103. 'Open system default browser failed:' +
  104. e.message);
  105. }
  106. );
  107. }
  108. } else {
  109. // plus.runtime.quit();
  110. }
  111. }
  112. });
  113. }
  114. }
  115. },
  116. fail: () => {},
  117. complete: () => {
  118. // uni.hideLoading();
  119. }
  120. });
  121. }
  122. // #endif
  123. }
  124. };
  125. </script>
  126. <style>
  127. /*每个页面公共css */
  128. </style>