123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111 |
- //app.js
- import WxAuthor from './utils/WxAuthor'
- App({
- onLaunch: function() {
- let self = this;
- // 登录
- this.mWxAuthor = new WxAuthor(self)
- 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: {
- userId: {
- openid: '',
- unionid: ''
- },
- userInfo: null,
- defaultAddress: null,
- fcodeErr: '',
- backLogin: false,
- arrayTree: [],
- fromSource: '',
- channel: '欧耶商城',
- record: null,
- card_type: '',
- authPages: null,
- mWxAuthor:null,
- member_id:0,
- relay_id: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)
- {
- this.globalData.authPages.forEach(prefix => {
- if(page.indexOf(prefix) == 0) {
- if(!this.globalData.userInfo) {
- wx.navigateTo({
- url: '/pages/auth/auth',
- })
- return;
- }
- }
- });
-
- wx.navigateTo({
- url: page,
- })
- },
- switchtab(page) {
- this.globalData.authPages.forEach(prefix => {
- if(page.indexOf(prefix) == 0) {
- if(!this.globalData.userInfo) {
- 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();
- }
- })
|