App.vue 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. <script>
  2. import siteinfo from './siteinfo.js';
  3. import $http from './utils/http.js'
  4. let q, store_id, table_id, turntable_id, app_id, defInfo = {},merchant_id,
  5. number = 0; //门店id 餐桌id 大转盘id
  6. export default {
  7. onLaunch: function(options) {
  8. uni.hideTabBar();
  9. uni.removeStorageSync('baseUrl');
  10. },
  11. async onShow(options) {
  12. uni.hideTabBar();
  13. this.initSocket();
  14. let query = options.query,
  15. queryCode = null;
  16. if (query && query.share_user_id) {
  17. uni.setStorageSync('share_user_id', query.share_user_id)
  18. }
  19. // #ifdef MP-ALIPAY
  20. // 合伙人邀请
  21. if (query && query.give_user_id) {
  22. let use= {
  23. store_id:query.store_id,
  24. give_user_id:query.give_user_id
  25. }
  26. getApp().globalData.give_user = use
  27. //由于这里是网络请求,可能会在 Page.onLoad 之后才返回
  28. // 所以此处加入 callback 以防止这种情况
  29. if (this.employIdCallback){
  30. }
  31. }
  32. if (query) {
  33. queryCode = query.qrCode || '';
  34. }
  35. // #endif
  36. // #ifdef MP-WEIXIN
  37. queryCode = query.q;
  38. // #endif
  39. //跳转选择地址的时候,返回会走默认门店,阻止默认门店
  40. if (!this.$store.state.prevent && !queryCode) {
  41. return
  42. }
  43. if (queryCode) {
  44. q = decodeURIComponent(queryCode)
  45. if(q.indexOf("?") == -1){
  46. let code;
  47. code = q.split("/smdc/");
  48. code = code[1]?code:q.split("/zhjy/");
  49. await $http.request('yy/empty_code', {
  50. code:code[1]
  51. }).then(res => {
  52. store_id = res.data.store_id;
  53. table_id = res.data.table_id;
  54. merchant_id = '';
  55. })
  56. }else{
  57. store_id = await this.gettParameter(q, 'store_id')
  58. table_id = await this.gettParameter(q, 'table_id')
  59. turntable_id = await this.gettParameter(q, 'id')
  60. merchant_id = await this.gettParameter(q, 'merchant_id')
  61. }
  62. // console.log(merchant_id,q,"merchant_id")
  63. }else {
  64. // #ifdef MP-ALIPAY
  65. defInfo = await my.getExtConfigSync()
  66. // #endif
  67. // #ifdef MP-WEIXIN
  68. defInfo = await wx.getExtConfigSync()
  69. // #endif
  70. store_id = defInfo.store_id;
  71. table_id = defInfo.table_id;
  72. app_id = defInfo.appId;
  73. }
  74. // var store_id=176,table_id=211;
  75. this.$store.commit('SET_STORE_ID', 3)
  76. this.$store.commit('SET_MERCHANT_ID', merchant_id)
  77. this.$store.commit('SET_TABLE_ID', 1)
  78. this.$store.commit('SET_TURNTABLE_ID', turntable_id)
  79. this.$store.commit('SET_APP_ID', app_id)
  80. this.$store.dispatch('getSystemColor', store_id);
  81. this.$store.dispatch('getSystemStup', store_id);
  82. this.$store.dispatch('getOpenid', store_id);
  83. // 更新提示
  84. this.getUpdateManager();
  85. //判断打烊
  86. this.getIsClose()
  87. },
  88. onHide: function() {
  89. getApp().globalData.isApp = true; //清除控制赋能,只赋能一次
  90. },
  91. onUnload() {},
  92. methods: {
  93. getIsClose(options) { // console.log('options', options) $http.request('xcx/system', { store_id: uni.getStorageSync('store_id'), table_id: uni.getStorageSync('table_id'), }).then(res => { // console.log(res) // #ifdef MP-ALIPAY if (res.data.is_alipay == 2) { uni.reLaunch({ url: '/pages/closeInfo/closeInfo' }) } // #endif
  94. // #ifdef MP-WEIXIN if (res.data.is_wechat == 2) { uni.reLaunch({ url: '/pages/closeInfo/closeInfo' }) } // #endif
  95. }) },
  96. //统一发送消息,可以在其他页面调用此方法发送消息
  97. sendSocketMessage: function(msg) {
  98. let that = this
  99. return new Promise((resolve, reject) => {
  100. if (this.globalData.localSocket.readyState === 1) {
  101. uni.sendSocketMessage({
  102. data: msg,
  103. success: function(res) {
  104. resolve(res)
  105. that.globalData.readyReset = 1;
  106. },
  107. fail: function(e) {
  108. reject(e)
  109. }
  110. })
  111. } else {
  112. // console.log('已断开')
  113. that.globalData.readyReset = 2;
  114. }
  115. })
  116. },
  117. storeColor() {
  118. let that = this;
  119. return new Promise((resolve, reject) => {
  120. $http.request('xcx/store_color', {
  121. store_id: store_id,
  122. }, "", "", true).then(res => {
  123. resolve(res)
  124. })
  125. })
  126. },
  127. storeSystem() {
  128. return new Promise((resolve, reject) => {
  129. $http.request('xcx/system', {
  130. store_id: store_id,
  131. table_id: table_id,
  132. }, "", "", true).then(res => {
  133. resolve(res)
  134. $http.request('xcx/template', {
  135. admin_id: res.data.admin_id,
  136. }, "", "", true).then(r => {
  137. if (r.code == '200') {
  138. uni.setStorageSync('balance_subscribe', r.data)
  139. }
  140. })
  141. })
  142. })
  143. },
  144. getUpdateManager: function() {
  145. const updateManager = uni.getUpdateManager(); // 获取更新管理器对象
  146. updateManager.onCheckForUpdate(function(res) {
  147. if (res.hasUpdate) {
  148. updateManager.onUpdateReady(function() {
  149. uni.showModal({
  150. title: '更新提示',
  151. content: '新版本已经准备好,是否重启应用?',
  152. showCancel: false,
  153. success: res => {
  154. if (res.confirm) {
  155. updateManager.applyUpdate();
  156. }
  157. }
  158. })
  159. })
  160. updateManager.onUpdateFailed(function() {
  161. uni.showModal({
  162. title: '提示',
  163. content: '检查到有新版本,但是下载失败,请检查网络设置',
  164. showCancel: false
  165. })
  166. })
  167. }
  168. })
  169. },
  170. gettParameter: function(url, name) {
  171. let val = ''
  172. if (url.indexOf('?' + name + '=') !== -1) {
  173. val = url.split('?' + name + '=')[1].split(/&|#/)[0];
  174. } else if (url.indexOf('&' + name + '=') !== -1) {
  175. val = url.split('&' + name + '=')[1].split(/&|#/)[0];
  176. }
  177. return val
  178. },
  179. },
  180. globalData: {
  181. localSocket: {},
  182. callback: function() {},
  183. closeCallback: function() {},
  184. onSocketOpen: function() {},
  185. URL: siteinfo.siteroot,
  186. isApp: true,
  187. SocketOpen: false,
  188. readyState: 0,
  189. readyReset: 1,
  190. give_user:{
  191. store_id:'',
  192. give_user_id:''
  193. }
  194. }
  195. }
  196. </script>
  197. <style lang="scss">
  198. @import url("/static/css/iconfont.css");
  199. @import url("/static/css/app.css");
  200. </style>