App.vue 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. <script>
  2. import request from '/common/request.js';
  3. export default {
  4. onLaunch: function () {
  5. console.log('App Launch');
  6. // #ifdef APP-PLUS || APP-PLUS-NVUE
  7. this.checkVersion();
  8. // #endif
  9. },
  10. onShow: function () {
  11. console.log('App Show');
  12. },
  13. onHide: function () {
  14. console.log('App Hide');
  15. },
  16. data() {
  17. return { orderTimer: {}, fastOrderTimer: {}, receiveOrderTimer: {} };
  18. },
  19. mounted() {
  20. // this.playVoiceBroadcast();
  21. // this.getFastOrderNum();
  22. this.startPlayVoiceBroadcast();
  23. uni.$on('startPlayVoiceBroadcast', (res) => {
  24. clearInterval(this.orderTimer);
  25. if (res) {
  26. this.startPlayVoiceBroadcast();
  27. }
  28. });
  29. uni.$on('receiveOrdernum', (res) => {
  30. clearInterval(this.receiveOrderTimer);
  31. res && this.receiveOrdernum();
  32. });
  33. uni.$on('fastOrderNum', (res) => {
  34. clearInterval(this.fastOrderTimer);
  35. res && this.fastOrderNum();
  36. });
  37. },
  38. methods: {
  39. // #ifdef APP-PLUS || APP-PLUS-NVUE
  40. // app更新检测
  41. checkVersion() {
  42. // 获取应用版本号
  43. let version = plus.runtime.version;
  44. //检测当前平台,如果是安卓则启动安卓更新
  45. uni.getSystemInfo({
  46. success: (res) => {
  47. this.updateHandler(res.platform, version);
  48. }
  49. });
  50. },
  51. // 更新操作
  52. updateHandler(platform, version) {
  53. let data = {
  54. platform: platform,
  55. version: version
  56. };
  57. let _this = this;
  58. request({
  59. url: '/api/getdow',
  60. data: { data },
  61. success: (res) => {
  62. if (res.data.data.version_num1) {
  63. const info = res.data.data.version_num1;
  64. var urlxz = res.data.data.url;
  65. let version_num_d = info.split('.').join('');
  66. let version_d = version.split('.').join('');
  67. if (info !== '' && version_num_d > version_d) {
  68. uni.showModal({
  69. //提醒用户更新
  70. title: '更新提示',
  71. content: `发现新版本,是否更新`,
  72. success: (res) => {
  73. if (res.confirm) {
  74. if (platform == 'android'){
  75. plus.runtime.openURL('https://dd.niusenyun.com/dow/嘀咚点到师傅端.apk');
  76. }
  77. else if (platform == 'ios') {
  78. const appleId = 1629163610; //app对应的appleId
  79. plus.runtime.launchApplication(
  80. {
  81. action: `itms-apps://itunes.apple.com/cn/app/id${appleId}?mt=8`
  82. },
  83. function (e) {
  84. console.log('Open system default browser failed:' + e.message);
  85. }
  86. );
  87. }
  88. } else {
  89. // plus.runtime.quit();
  90. }
  91. }
  92. });
  93. }
  94. }
  95. },
  96. fail: () => {},
  97. complete: () => {
  98. // uni.hideLoading();
  99. }
  100. });
  101. },
  102. // #endif
  103. // 可接单数量
  104. receiveOrdernum() {
  105. const _this = this;
  106. this.receiveOrderTimer = setInterval(function () {
  107. _this.getOrderNum();
  108. }, 3000);
  109. },
  110. startPlayVoiceBroadcast() {
  111. const _this = this;
  112. this.orderTimer = setInterval(function () {
  113. _this.playVoiceBroadcast();
  114. }, 3000);
  115. },
  116. fastOrderNum() {
  117. const _this = this;
  118. this.fastOrderTimer = setInterval(function () {
  119. _this.getFastOrderNum();
  120. }, 3000);
  121. },
  122. playVoiceBroadcast() {
  123. request({
  124. url: '/api/userjs/play',
  125. data: {},
  126. success: (res) => {
  127. console.log('订单播报', res);
  128. if (res.data.code == 1) {
  129. const innerAudioContext = uni.createInnerAudioContext();
  130. innerAudioContext.autoplay = true;
  131. innerAudioContext.src = '/static/voice/order_new.mp3';
  132. innerAudioContext.onPlay(() => {});
  133. console.log('订单播报', res);
  134. } else if (res.data.code == 10001) {
  135. clearInterval(this.orderTimer);
  136. }
  137. },
  138. fail: () => {},
  139. complete: () => {}
  140. });
  141. request({
  142. url: '/api/userjs/cancelplay',
  143. data: {},
  144. success: (res) => {
  145. if (res.data.code == 1) {
  146. console.log('取消订单播报', res);
  147. const innerAudioContext = uni.createInnerAudioContext();
  148. innerAudioContext.autoplay = true;
  149. innerAudioContext.src = '/static/voice/order_cancel.mp3';
  150. innerAudioContext.onPlay(() => {});
  151. }
  152. },
  153. fail: () => {},
  154. complete: () => {}
  155. });
  156. // that.jiaobiao();
  157. //that.tishi()
  158. // uni.$on("sxqd", function (data) {
  159. // that.jiaobiao();
  160. // });
  161. },
  162. getFastOrderNum() {
  163. request({
  164. url: '/api/userjs/getJsOrdernum',
  165. data: {},
  166. success: (res) => {
  167. console.log('抢单订单数量', res);
  168. if (res.data.code == 0) {
  169. clearInterval(this.fastOrderTimer);
  170. }
  171. if (res.data.data > 0) {
  172. uni.setTabBarBadge({ index: 2, text: res.data.data + '' });
  173. } else {
  174. // 没有认证
  175. uni.removeTabBarBadge({ index: 2 });
  176. }
  177. },
  178. fail: () => {},
  179. complete: () => {}
  180. });
  181. },
  182. getOrderNum() {
  183. request({
  184. url: '/api/userjs/getOrdernum',
  185. data: {},
  186. success: (res) => {
  187. console.log('可接单数量', res);
  188. if (res.data.code == 0) {
  189. clearInterval(this.receiveOrderTimer);
  190. }
  191. if (res.data.data > 0) {
  192. uni.setTabBarBadge({ index: 3, text: res.data.data + '' });
  193. } else {
  194. // 没有认证
  195. uni.removeTabBarBadge({ index: 3 });
  196. }
  197. },
  198. fail: () => {},
  199. complete: () => {}
  200. });
  201. }
  202. }
  203. };
  204. </script>
  205. <style>
  206. /*每个页面公共css */
  207. </style>