app.js 4.5 KB

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