123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200 |
- //app.js
- const ald = require('./utils/ald-stat.js')
- import WxAuthor from './utils/WxAuthor'
- require('./utils/push_sdk.js')
- App({
- onLaunch: function () {
- // if (__devtoolsConfig.network.request.indexOf('https://plog.xiaoshentui.com') !== -1) {
- // wx.showModal({
- // title: '小神推提示',
- // content: '配置成功,请进行下一步',
- // })
- // } else {
- // wx.showModal({
- // title: '小神推提示',
- // content: '配置失败,请核查',
- // })
- // }
-
- // 用户版本更新
- if (wx.canIUse("getUpdateManager")) {
- let updateManager = wx.getUpdateManager();
- updateManager.onCheckForUpdate((res) => {
- // 请求完新版本信息的回调
- console.log(res.hasUpdate);
- })
- updateManager.onUpdateReady(() => {
- wx.showModal({
- title: '更新提示',
- content: '新版本已经准备好,是否重启应用?',
- success: (res) => {
- if (res.confirm) {
- // 新的版本已经下载好,调用 applyUpdate 应用新版本并重启
- updateManager.applyUpdate();
- } else if (res.cancel) {
- return false;
- }
- }
- })
- })
- updateManager.onUpdateFailed(() => {
- // 新的版本下载失败
- wx.hideLoading();
- wx.showModal({
- title: '升级失败',
- content: '新版本下载失败,请检查网络!',
- showCancel: false
- });
- });
- }
- // 登录
- let self = this;
- this.mWxAuthor = new WxAuthor(self, true)
- const dirs = ['addAddress', 'address', 'myhome', 'confirmOrder', 'confirmVOrder',
- 'order_tabs', 'orderPaySn', 'person', 'postageDetail', 'postageManage', 'shopCart'
- ];
- let pages = new Set()
- dirs.forEach(dir => {
- let page = `/pages/${dir}/${dir}`
- pages.add(page)
- });
- this.globalData.authPages = pages
- },
- globalData: {
- fMinistart: false,
- userId: {
- openid: '',
- unionid: '',
- timeStamp: 0
- },
- userInfo: null,
- defaultAddress: null,
- fcodeErr: '',
- backLogin: false,
- arrayTree: [],
- fromSource: '',
- channel: '欧耶商城',
- record: null,
- card_type: '',
- authPages: null,
- mWxAuthor: null,
- member_id: 0,
- hasmobile: false,
- relay_id: 0,
- channel_num: 0
- },
- setFromSource(fromSource) {
- this.globalData.fromSource = fromSource
- },
- checkDefaultAddress(address) {
- this.globalData.defaultAddress = address
- },
- clearAddress() {
- this.globalData.defaultAddress = null
- },
- setArrayTree(tree) {
- this.globalData.arrayTree = tree
- },
- setCardType(card_type) {
- this.globalData.card_type = card_type
- },
- showToast(title, icon, duration) {
- wx.showToast({
- icon: icon || 'none',
- title,
- duration: 2000 || duration
- })
- },
- trim(str) {
- str = str.replace(/\s+/g, "")
- return str
- },
- checkCurrentRecord(record) {
- this.globalData.record = record
- },
- clearRecord() {
- this.globalData.record = null
- },
- navigateto(page) {
- if (!this.globalData.userInfo) {
- this.globalData.authPages.forEach(prefix => {
- if (page.indexOf(prefix) == 0) {
- wx.navigateTo({
- url: '/pages/auth/auth',
- })
- return;
- }
- });
- }
- wx.navigateTo({
- url: page,
- })
- },
- switchtab(page) {
- if (!this.globalData.userInfo) {
- this.globalData.authPages.forEach(prefix => {
- if (page.indexOf(prefix) == 0) {
- wx.navigateTo({
- url: '/pages/auth/auth',
- })
- return;
- }
- });
- }
- wx.switchTab({
- url: page,
- })
- },
- getValueByKey(key = '', data = []) {
- if (!data.length) return {}
- return data.filter(val => val.card_type === key)[0] || {}
- },
- relogin() {
- this.mWxAuthor.init(true);
- },
- cardShareInfo() {
- console.log('index cardShareInfo')
- let userid = this.globalData.member_id
- let imageUrl = '/image/xyzshare.png'
- let share_path = `/pages/index/index?relay_id=${userid}`
- console.log('share path:', share_path)
- let title = '我正在充值,麻烦帮我授权一下,100元能省5元哦!拜托拜托~'
- return {
- title: title,
- path: share_path,
- imageUrl: imageUrl,
- }
- },
- isNullObject(obj) {
- return (Object.keys(obj).length === 0);
- },
- writePhotosAlbum(callback) {
- wx.showLoading({
- title: '加载中'
- });
- wx.getSetting({
- success(res) {
- if (!res.authSetting['scope.writePhotosAlbum']) {
- wx.authorize({
- scope: 'scope.writePhotosAlbum',
- success() {
- wx.hideLoading();
- if (callback) callback();
- }
- })
- }
- else {
- wx.hideLoading();
- if (callback) callback();
- }
- }
- })
- },
- })
|