import Vue from 'vue' import store from './store' import App from './App' import uView from '@/uni_modules/uview-ui'; Vue.use(uView); // 下拉 import drawer from "@/components/drawer/drawer.vue" import md5 from "./common/md5.js" import mixin from "common/share.js" import filter from 'common/filter.js' import config from './config/config' // 引入全局uView // import uView from 'uview-ui' // Vue.use(uView); Vue.mixin(mixin) /** * 因工具函数属于公司资产, 所以直接在Vue实例挂载几个常用的函数 * 所有测试用数据均存放于根目录json.js * * css部分使用了App.vue下的全局样式和iconfont图标,有需要图标库的可以留言。 * 示例使用了uni.scss下的变量, 除变量外已尽量移除特有语法,可直接替换为其他预处理器使用 */ const msg = (title, duration=1500, mask=false, icon='none',)=>{ //统一提示方便全局修改 if(Boolean(title) === false){ return; } uni.showToast({ title, duration, mask, icon, }); } const json = type=>{ //模拟异步请求数据 return new Promise(resolve=>{ resolve(Json[type]); }) } const prePage = ()=>{ let pages = getCurrentPages(); let prePage = pages[pages.length - 2]; // #ifdef H5 return prePage; // #endif return prePage.$vm; } const getSign = (str)=>{ return md5(str + "A1B2C3"); } const requst = (opt) => { opt = opt || {}; opt.data = opt.data || null; opt.method = opt.method || 'POST'; opt.header = opt.header || { "Content-Type": "application/x-www-form-urlencoded" }; opt.success = opt.success || function () {}; let url = opt.url let json = getApp().globalData.storeInfo; let baseUrl = getApp().globalData.apiUrl; if (url.indexOf("/api/") == -1) { // 生产环境通过nginx根据校区code路由,本地开发统一用a1(context-path) if (baseUrl.indexOf('127.0.0.1') != -1 || baseUrl.indexOf('localhost') != -1) { url = 'a1' + url } else if (json) { url = json.code + url } } if (url.indexOf('http') != 0) { // 去掉前导斜杠,避免 baseUrl + '/' + url 产生双斜杠 // if (url.charAt(0) == '/') { url = url.substring(1); } // /api/ 前缀的请求走管理平台服务(client-plat:8080),其他走移动端服务(client-app:8081) if (url.indexOf('api/') == 0 && getApp().globalData.platApiUrl) { url = getApp().globalData.platApiUrl + '/' + url; } else { url = baseUrl + '/' + url; } } uni.request({ url: url, data: opt.data, method: opt.method, header: opt.header, dataType: 'json', success: function (res) { if (res && res.data && res.data.rtnBean) { opt.success(res); } else { console.error('响应数据格式异常:', res); uni.showToast({ title: '服务响应异常,请稍后重试', icon: 'none' }); } }, fail: function (err) { console.error('请求失败:', err); uni.showToast({ title: '网络请求失败,请稍后重试', icon: 'none' }); } }) } const moneyConverter = (money)=> { let m = Number(money) / Number(100); return Math.round(m * 100) / 100; } const loginx = (code,storeUserId)=> { uni.get uni.login({ provider: 'weixin', success: (loginRes) => { uni.request({ url: getApp().globalData.apiUrl + '/' + code + '/storeUserLoginApi/login', data: { code: loginRes.code, storeUserId: storeUserId }, method: 'POST', header: { 'content-type': 'application/x-www-form-urlencoded', }, dataType: 'json', success: function (res) { // store.state.hasLogin = true; // store.state.userInfo = res.data.obj; // //缓存用户登陆状态 // uni.setStorage({ // key: 'userInfo', // data: res.data.obj // }) }, fail: function (err) { console.log(err); uni.showLoading({ title: '请稍后重试' }); } }) }, }); } Vue.config.productionTip = false Vue.prototype.$fire = new Vue(); Vue.prototype.requst = requst; Vue.prototype.moneyConverter = moneyConverter; Vue.prototype.loginx = loginx; Vue.prototype.$store = store; Vue.prototype.getSign = getSign; Vue.prototype.$api = {msg, prePage}; Object.keys(filter).forEach(key=>{ Vue.filter(key, filter[key]) }) // 设置全局色号 config/config文件 配置色号 Object.keys(config).forEach(i => { if (i.includes('Color') || i.includes('color')) { Vue.prototype['$' + i] = config[i] } }) Vue.component('drawer', drawer) App.mpType = 'app' const app = new Vue({ ...App }) app.$mount()