import Vue from 'vue' import App from './App' import {appConfig} from './config' import {weixin} from './utils/weixin.js' import {util} from './utils/util.js' import uView from "uview-ui"; Vue.use(uView); Vue.prototype.util = util; Vue.config.productionTip = false Vue.prototype.baseUrl = appConfig.baseUrl Vue.prototype.openidInfoKey = appConfig.openidInfoKey Vue.prototype.arrayCol = (arr, column) => { const res = [] arr.forEach(i => { res.push(i[column]) }) return res } Vue.prototype.alert = msg => { uni.showToast({title: msg, duration: 2000, icon: 'none'}) } Vue.prototype.checkLogin = () => { const userInfo = uni.getStorageSync('userInfo') if (!userInfo || !userInfo.access_token) { uni.navigateTo({ url: '/pages/login/index' }) return false } return true } Vue.prototype.getToken = () => { const userInfo = uni.getStorageSync('userInfo') return userInfo ? userInfo.access_token : '' } Vue.prototype.sendReq = (url, params, cb, method) => { method = method || 'POST' weixin.getOpenidInfo(r => { var info = r.user_info; params.openid = info.openid uni.request({ url: appConfig.baseUrl + url, method: method, data: params, success: r => { if (r.data.status === 0) { uni.showToast({title: r.data.msg, duration: 2000, icon: 'none'}) } else { cb(r.data.data) } } }) }) } Vue.prototype.reqByToken = (url, params, cb, method) => { method = method || 'POST' const userInfo = uni.getStorageSync('userInfo') params.token = userInfo.access_token console.log(url) uni.request({ url: appConfig.baseUrl + url, method: method, data: params, success: r => { if (r.data.status === 1) { cb(r.data.data) } else if (r.data.status === 2) { uni.navigateTo({ url: '/package/pages/login/index' }) return false } else { uni.showToast({title: r.data.msg, duration: 2000, icon: 'none'}) } }, complete(r) { console.log(r) } }) } App.mpType = 'app' const app = new Vue({ ...App }) app.$mount()