app.js 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293
  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. share_title:'',
  85. share_image:''
  86. },
  87. setFromSource(fromSource) {
  88. this.globalData.fromSource = fromSource
  89. },
  90. checkDefaultAddress(address) {
  91. this.globalData.defaultAddress = address
  92. },
  93. clearAddress() {
  94. this.globalData.defaultAddress = null
  95. },
  96. setArrayTree(tree) {
  97. this.globalData.arrayTree = tree
  98. },
  99. setCardType(card_type) {
  100. this.globalData.card_type = card_type
  101. },
  102. showToast(title, icon, duration) {
  103. wx.showToast({
  104. icon: icon || 'none',
  105. title,
  106. duration: 2000 || duration
  107. })
  108. },
  109. trim(str) {
  110. str = str.replace(/\s+/g, "")
  111. return str
  112. },
  113. checkCurrentRecord(record) {
  114. this.globalData.record = record
  115. },
  116. clearRecord() {
  117. this.globalData.record = null
  118. },
  119. navigateback() {
  120. if (getCurrentPages().length <= 1) {
  121. wx.reLaunch({ url: "/pages/home/home" })
  122. }
  123. else {
  124. wx.navigateBack()
  125. }
  126. },
  127. navigateto(page) {
  128. if (!this.globalData.userInfo) {
  129. this.globalData.authPages.forEach(prefix => {
  130. if (page.indexOf(prefix) == 0) {
  131. wx.navigateTo({
  132. url: '/pages/auth/auth',
  133. })
  134. return;
  135. }
  136. });
  137. }
  138. wx.navigateTo({
  139. url: page,
  140. })
  141. },
  142. switchtab(page) {
  143. if (!this.globalData.userInfo) {
  144. this.globalData.authPages.forEach(prefix => {
  145. if (page.indexOf(prefix) == 0) {
  146. wx.navigateTo({
  147. url: '/pages/auth/auth',
  148. })
  149. return;
  150. }
  151. });
  152. }
  153. wx.switchTab({
  154. url: page,
  155. })
  156. },
  157. getValueByKey(key = '', data = []) {
  158. if (!data.length) return {}
  159. return data.filter(val => val.card_type === key)[0] || {}
  160. },
  161. relogin() {
  162. this.mWxAuthor.init(true);
  163. },
  164. cardShareInfo() {
  165. console.log('index cardShareInfo')
  166. let userid = this.globalData.member_id
  167. let imageUrl = this.globalData.share_image ? this.globalData.share_image : '/image/xyzshare.png'
  168. let share_path = `/pages/index/index?relay_id=${userid}`
  169. console.log('share path:', share_path)
  170. let def = '我正在充值,麻烦帮我授权一下,100元能省5元哦!拜托拜托~'
  171. let title = this.globalData.share_title ? this.globalData.share_title : def
  172. console.log('share_title', title, this.globalData.share_title, 'share_image', imageUrl, this.globalData.share_image)
  173. return {
  174. title: title,
  175. path: share_path,
  176. imageUrl: imageUrl,
  177. }
  178. },
  179. isNullObject(obj) {
  180. return (Object.keys(obj).length === 0);
  181. },
  182. writePhotosAlbum(callback) {
  183. wx.showLoading({
  184. title: '加载中'
  185. });
  186. wx.getSetting({
  187. success(res) {
  188. if (!res.authSetting['scope.writePhotosAlbum']) {
  189. wx.authorize({
  190. scope: 'scope.writePhotosAlbum',
  191. success() {
  192. wx.hideLoading();
  193. if (callback) callback();
  194. }
  195. })
  196. }
  197. else {
  198. wx.hideLoading();
  199. if (callback) callback();
  200. }
  201. }
  202. })
  203. },
  204. randint(low, high) {
  205. let result = low + Math.round(Math.random() * (high - low));
  206. return result;
  207. },
  208. getUrl() {
  209. let len = getCurrentPages().length
  210. if (len < 1) return ''
  211. let currentPage = getCurrentPages()[len - 1]
  212. let params = ''
  213. if (currentPage.options) {
  214. for (let k in currentPage.options) {
  215. params = params + k + '=' + currentPage.options[k] + '&'
  216. }
  217. params = params.slice(0, params.length - 1)
  218. }
  219. let current_url = "/" + currentPage['route']
  220. if (params) {
  221. current_url = current_url + '?' + params
  222. }
  223. return current_url
  224. },
  225. genMsgs() {
  226. let length = 200;
  227. let numset = new Set();
  228. for (let index = 0; index < length; index++) {
  229. let num = this.randint(0, 9999);
  230. numset.add(num);
  231. }
  232. let dis_phone = [5, 10, 15, 20, 25];
  233. let dis_oil = [5, 10, 25, 30, 45, 50];
  234. let msgs = new Array();
  235. let nums = Array.from(numset)
  236. for (let index in nums) {
  237. let num = nums[index];
  238. let str = '' + num;
  239. if (str.length == 3) {
  240. str = '0' + str;
  241. }
  242. else if (str.length == 2) {
  243. str = '00' + str;
  244. }
  245. else if (str.length == 1) {
  246. str = '000' + str;
  247. }
  248. else if (str.length == 4) {
  249. str = str;
  250. }
  251. else {
  252. continue;
  253. }
  254. let stype = '';
  255. let discount = 0;
  256. let type = this.randint(0, 1);
  257. if (type == 0) {
  258. stype = "油卡充值";
  259. let dis = this.randint(0, dis_oil.length - 1);
  260. discount = dis_oil[dis];
  261. }
  262. else {
  263. stype = "话费充值";
  264. let dis = this.randint(0, dis_phone.length - 1);
  265. discount = dis_phone[dis];
  266. }
  267. msgs.push({ phone: str, type: stype, discount: discount });
  268. }
  269. return msgs;
  270. },
  271. showLoading() {
  272. wx.showLoading({
  273. title: '加载中'
  274. });
  275. },
  276. hideLoading() {
  277. wx.hideLoading();
  278. }
  279. })