app.js 4.6 KB

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