import Vue from 'vue' import App from './App' import store from './store' let { config } = require('./common/util.js'); Vue.config.productionTip = false App.mpType = 'app' Vue.prototype.$store = store import { mapState, mapMutations, mapActions } from 'vuex'; Vue.mixin({ data() { return { // api: api //引入api文件 // wsBaseUrl menuinfo: { top: 0, height: 0 }, privacyShow: 0, privacyContractName: '', privacyed: 0, p: '', } }, computed: { ...mapState(['hasLogin', 'userInfo', 'shop', 'geoinfo', 'redirctCurCate']), authorize() { return code => { if (`${this.userInfo.role_id}`.indexOf('1') > -1) { return true; } let arrCode = code.split(','); return arrCode.filter(item => { return `${this.userInfo.role_id || ''}`.indexOf(item) != -1 }).length; } } }, methods: { ...mapMutations(['login', 'setShop', 'setGeoInfo', 'setUserInfo', 'setRedirctCurCate']), ...mapActions(['doLogin', 'getUser']), setTabBarPath(path) { // if (typeof this.$mp.page.getTabBar === 'function' && // this.$mp.page.getTabBar()) { // this.$mp.page.getTabBar().setData({ // selectedPath: path // }) // } }, meShowLoading(opt) { uni.showLoading({ title: '加载中', ...opt }) }, goToDetail(e) { let item = e.currentTarget.dataset.item; let type = item.type; // type=1是商品组,type=2是商品详情,type=3是文章详情,type_id就是商品组id、商品id、文章id switch(type) { case '-1': if(item.option == 2) { uni.switchTab({ url: `/${item.link}` }) } else { uni.navigateTo({ url: `/${item.link}` }) } break; case '1': { uni.navigateTo({ url: `/pages/dinghuo/goods_group/goods_group?id=${item.type_id}` }) } break; case '2': { uni.navigateTo({ url: `/pages/dinghuo/goods_detail/goods_detail?id=${item.type_id}` }) } break; case '3': uni.navigateTo({ url: `/pages/dinghuo/goods_detail/redirector?id=${item.type_id}` }) break; case '5': this.setRedirctCurCate(item.type_id) uni.switchTab({ url: `/pages/app/shop/shop` }) break; default: uni.navigateTo({ url: `/pages/assets/webview/webview?link=${item.link}` }) break; } }, goBack() { if (getCurrentPages().length == 1) { uni.reLaunch({ url: '/pages/app/index/index' }) } else { uni.navigateBack({}) } }, formatPath(url) { return `${config.path}${url}&json=1&version=${config.version}&t=${this.userInfo.t}` }, reqByuser: function(options) { if(!this.p) { let p = uni.getStorageSync('place') this.p = p; if(!this.p) { uni.showToast({ icon: 'error', title: '缺少身份码' }) return } } if (this.userInfo.t) { options.data = { ...options.data, ...config.data, p: this.p, t: this.userInfo.t }; if(options.data.env) { options.data.env = 3; } options.url = `${config.path}${options.url}`; uni.request(options) } else { uni.navigateTo({ url:'/pages/login/login' }) uni.hideLoading() return Promise.reject('未登录') } }, req: function(options) { if(!this.p) { let p = uni.getStorageSync('place') console.log(p) this.p = p; if(!this.p) { uni.showToast({ icon: 'error', title: '缺少身份码' }) return } } options.data = { ...options.data, ...config.data, p: this.p, }; if(options.data.env) { options.data.env = 3; } if(options.url.indexOf('http') !== 0) { options.url = `${config.path}${options.url}`; } uni.request(options) }, upload: function(options) { options.formData = { ...options.formData, ...config.data, json: 0 }; options.url = `${config.path}${options.url}`; uni.uploadFile(options) }, refreshCartNum() { if (this.userInfo.t && this.$mp.page.route.indexOf('pages/app') > -1) { this.reqByuser({ url: "src/sell/order/?l=cart.getNum", method: "GET", data: { }, success: (d) => { if (d.data.status == 1) { if (d.data.data.total > 0) { uni.setTabBarBadge({ index: 2, text: `${d.data.data.total}` }) } else { uni.removeTabBarBadge({ index: 2 }) } } else { uni.showToast({ icon: "error", title: d.data.msg }) } }, }); } }, handleAgreePrivacyAuthorization() { this.privacyShow = 0 this.resolvePrivacyAuthorization({ buttonId: 'agree-btn', event: 'agree' }) }, openPricacy() { wx.openPrivacyContract({ success: () => {}, // 打开成功 fail: () => {}, // 打开失败 complete: () => {} }) }, loadUserInfo() { return new Promise((resolve, reject) => { this.reqByuser({ url: '?l=user.info', data: {}, success: res => { if(res.data.status == 1) { this.user = res.data.data.user; this.setUserInfo({...this.user, ...this.userInfo}) resolve({user: {...this.user, ...this.userInfo}, order:res.data.data.order}) }else { uni.showToast({ icon: 'error', title: res.data.msg }) reject(res.data.msg) } } }) }) }, }, onLoad(options) { if(options.p) { this.p = options.p; uni.setStorageSync('place', this.p) } // let menuinfo = uni.getMenuButtonBoundingClientRect(); // this.menuinfo = menuinfo; // this.refreshCartNum() // if(wx.onNeedPrivacyAuthorization) { // console.log('onNeedPrivacyAuthorization') // wx.onNeedPrivacyAuthorization((resolve, eventInfo) => { // console.log('触发本次事件的接口是:' + eventInfo.referrer, eventInfo) // // 需要用户同意隐私授权时 // // 弹出开发者自定义的隐私授权弹窗 // this.privacyShow = 1 // // this.privacyContractName = res.privacyContractName // this.resolvePrivacyAuthorization = resolve // }) // } // wx.requirePrivacyAuthorize({ // success: () => { // // 用户同意授权 // // 继续小程序逻辑 // }, // fail: () => {}, // 用户拒绝授权 // complete: () => {} // }) } }) const app = new Vue({ store, ...App }) app.$mount()