app.js 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. //app.js
  2. const ald = require('./utils/ald-stat.js')
  3. import WxAuthor from './utils/WxAuthor'
  4. require('./utils/push_sdk.js')
  5. App({
  6. onLaunch: function () {
  7. // if (__devtoolsConfig.network.request.indexOf('https://plog.xiaoshentui.com') !== -1) {
  8. // wx.showModal({
  9. // title: '小神推提示',
  10. // content: '配置成功,请进行下一步',
  11. // })
  12. // } else {
  13. // wx.showModal({
  14. // title: '小神推提示',
  15. // content: '配置失败,请核查',
  16. // })
  17. // }
  18. // 用户版本更新
  19. if (wx.canIUse("getUpdateManager")) {
  20. let updateManager = wx.getUpdateManager();
  21. updateManager.onCheckForUpdate((res) => {
  22. // 请求完新版本信息的回调
  23. console.log(res.hasUpdate);
  24. })
  25. updateManager.onUpdateReady(() => {
  26. wx.showModal({
  27. title: '更新提示',
  28. content: '新版本已经准备好,是否重启应用?',
  29. success: (res) => {
  30. if (res.confirm) {
  31. // 新的版本已经下载好,调用 applyUpdate 应用新版本并重启
  32. updateManager.applyUpdate();
  33. } else if (res.cancel) {
  34. return false;
  35. }
  36. }
  37. })
  38. })
  39. updateManager.onUpdateFailed(() => {
  40. // 新的版本下载失败
  41. wx.hideLoading();
  42. wx.showModal({
  43. title: '升级失败',
  44. content: '新版本下载失败,请检查网络!',
  45. showCancel: false
  46. });
  47. });
  48. }
  49. // 登录
  50. let self = this;
  51. this.mWxAuthor = new WxAuthor(self, true)
  52. const dirs = ['addAddress', 'address', 'myhome', 'confirmOrder', 'confirmVOrder',
  53. 'order_tabs', 'orderPaySn', 'person', 'postageDetail', 'postageManage', 'shopCart'
  54. ];
  55. let pages = new Set()
  56. dirs.forEach(dir => {
  57. let page = `/pages/${dir}/${dir}`
  58. pages.add(page)
  59. });
  60. this.globalData.authPages = pages
  61. },
  62. globalData: {
  63. fMinistart: false,
  64. userId: {
  65. openid: '',
  66. unionid: '',
  67. timeStamp: 0
  68. },
  69. userInfo: null,
  70. defaultAddress: null,
  71. fcodeErr: '',
  72. backLogin: false,
  73. arrayTree: [],
  74. fromSource: '',
  75. channel: '欧耶商城',
  76. record: null,
  77. card_type: '',
  78. authPages: null,
  79. mWxAuthor: null,
  80. member_id: 0,
  81. hasmobile: false,
  82. relay_id: 0,
  83. channel_num: 0
  84. },
  85. setFromSource(fromSource) {
  86. this.globalData.fromSource = fromSource
  87. },
  88. checkDefaultAddress(address) {
  89. this.globalData.defaultAddress = address
  90. },
  91. clearAddress() {
  92. this.globalData.defaultAddress = null
  93. },
  94. setArrayTree(tree) {
  95. this.globalData.arrayTree = tree
  96. },
  97. setCardType(card_type) {
  98. this.globalData.card_type = card_type
  99. },
  100. showToast(title, icon, duration) {
  101. wx.showToast({
  102. icon: icon || 'none',
  103. title,
  104. duration: 2000 || duration
  105. })
  106. },
  107. trim(str) {
  108. str = str.replace(/\s+/g, "")
  109. return str
  110. },
  111. checkCurrentRecord(record) {
  112. this.globalData.record = record
  113. },
  114. clearRecord() {
  115. this.globalData.record = null
  116. },
  117. navigateto(page) {
  118. if (!this.globalData.userInfo) {
  119. this.globalData.authPages.forEach(prefix => {
  120. if (page.indexOf(prefix) == 0) {
  121. wx.navigateTo({
  122. url: '/pages/auth/auth',
  123. })
  124. return;
  125. }
  126. });
  127. }
  128. wx.navigateTo({
  129. url: page,
  130. })
  131. },
  132. switchtab(page) {
  133. if (!this.globalData.userInfo) {
  134. this.globalData.authPages.forEach(prefix => {
  135. if (page.indexOf(prefix) == 0) {
  136. wx.navigateTo({
  137. url: '/pages/auth/auth',
  138. })
  139. return;
  140. }
  141. });
  142. }
  143. wx.switchTab({
  144. url: page,
  145. })
  146. },
  147. getValueByKey(key = '', data = []) {
  148. if (!data.length) return {}
  149. return data.filter(val => val.card_type === key)[0] || {}
  150. },
  151. relogin() {
  152. this.mWxAuthor.init(true);
  153. },
  154. cardShareInfo() {
  155. console.log('index cardShareInfo')
  156. let userid = this.globalData.member_id
  157. let imageUrl = '/image/xyzshare.png'
  158. let share_path = `/pages/index/index?relay_id=${userid}`
  159. console.log('share path:', share_path)
  160. let title = '我正在充值,麻烦帮我授权一下,100元能省5元哦!拜托拜托~'
  161. return {
  162. title: title,
  163. path: share_path,
  164. imageUrl: imageUrl,
  165. }
  166. },
  167. isNullObject(obj) {
  168. return (Object.keys(obj).length === 0);
  169. },
  170. writePhotosAlbum(callback) {
  171. wx.showLoading({
  172. title: '加载中'
  173. });
  174. wx.getSetting({
  175. success(res) {
  176. if (!res.authSetting['scope.writePhotosAlbum']) {
  177. wx.authorize({
  178. scope: 'scope.writePhotosAlbum',
  179. success() {
  180. wx.hideLoading();
  181. if (callback) callback();
  182. }
  183. })
  184. }
  185. else {
  186. wx.hideLoading();
  187. if (callback) callback();
  188. }
  189. }
  190. })
  191. },
  192. })