import Vue from 'vue'; import App from './App'; // 引入全局存储 import store from '@/store'; // 引入全局配置 import $mAssetsPath from '@/config/assets.config.js'; import $mConfig from '@/config/index.config.js'; import $mRoutesConfig from '@/config/routes.config.js'; import $mFormRule from '@/config/formRule.config.js'; import $mConstDataConfig from '@/config/constData.config.js'; import $mSettingConfig from '@/config/setting.config.js'; // 生产发布 // Vue.prototype.websiteUrl = 'https://8.8.20.112:19001/api/file/pub/'; // Vue.prototype.websiteUrl = 'https://m.geidcp.com/api/file/pub/'; Vue.prototype.websiteUrl = 'https://m.geidcp.com/api/file/pub/'; // Vue.prototype.websiteUrl = 'http://172.16.1.159:9100/api/fileextend/pub/'; // Vue.prototype.websiteUrl = 'http://172.16.1.159:9100/api/file/pub/'; // Vue.prototype.websiteUrl = 'http://192.168.95.118/api/file/pub/'; // Vue.prototype.websiteUrl = 'https://www.geidcp.com/api/file/pub/'; // Vue.prototype.websiteUrlExtend = 'https://8.8.20.112:19001/api/fileextend/pub/'; // Vue.prototype.websiteUrl1 = 'https://8.8.20.112:19001/api/file'; //h5本地调试 // Vue.prototype.websiteUrl = 'http://localhost:8080/api/file/pub/'; // Vue.prototype.websiteUrlExtend = 'http://localhost:8080/api/fileextend/pub/'; // 160手机调试 // Vue.prototype.websiteUrl = 'http://10.0.1.160:7000/file/pub/'; // Vue.prototype.websiteUrlExtend = 'http://10.0.1.160:7000/fileextend/pub/'; //生产发布图片上传地址 Vue.prototype.uploadUrl = 'https://m.geidcp.com/api/meeting/upload/file/'; // Vue.prototype.uploadUrl = 'https://8.8.20.112:19001/api/meeting/upload/file/'; //h5本地图片上传地址 // Vue.prototype.uploadUrl = 'http://localhost:8080/api/meeting/upload/file/'; //160手机图片上传地址 //Vue.prototype.uploadUrl = 'http://10.0.1.160:7000/meeting/upload/file/'; // 引入全局方法 import axios from 'axios' Vue.prototype.$http = axios axios.defaults.baseURL = 'http://localhost:7000' axios.defaults.baseURL = 'http://localhost:7000/api/uc/' import { myRequest } from './api/my-api.js' import commonArray from '@/static/js/common.js' Vue.use(commonArray) // 挂载到全局,让所有的页面都能调用myRequest方法 Vue.prototype.$myRequest = myRequest import $mGraceChecker from '@/utils/graceChecker'; import $mHelper from '@/utils/helper'; import $mRouter from '@/utils/router'; import $mPayment from '@/utils/payment'; // 全局组件 import rfImage from '@/components/rf-image/rf-image'; import rfEmpty from '@/components/rf-empty'; import rfLoading from '@/components/rf-loading'; import rfLoadProgress from '@/components/rf-load-progress/rf-load-progress'; import rfParser from '@/components/rf-parser'; import rfBackTop from '@/components/rf-back-top'; import rfTag from '@/components/rf-tag'; import rfNavDetail from '@/components/rf-nav-detail'; import cuCustom from '@/components/cu-custom'; import rfBackHome from '@/components/rf-back-home'; //全局属性 Vue.prototype.systemInfo = uni.getSystemInfoSync(); // 网络状态监听 uni.getNetworkType({ success: res => { store.dispatch('networkStateChange', res.networkType); } }); // uni.onNetworkStatusChange(function (res) { // store.dispatch('networkStateChange', res.networkType); // }); // 挂载全局自定义方法 Vue.prototype.$mStore = store; import Json from './Json'; //测试用数据 const json = type => { return new Promise(resolve => { setTimeout(() => { resolve(Json[type]); }, 100) }) } const msg = (title, duration = 1500, mask = false, icon = 'none') => { //统一提示方便全局修改 if (Boolean(title) === false) { return; } uni.showToast({ title, duration, mask, icon }); } const prePage = () => { let pages = getCurrentPages(); let prePage = pages[pages.length - 2]; // #ifdef H5 return prePage; // #endif return prePage.$vm; } Vue.prototype.$api = { msg, json, prePage }; // Vue.prototype.$http = http; Vue.prototype.$mConfig = $mConfig; Vue.prototype.$mAssetsPath = $mAssetsPath; Vue.prototype.$mFormRule = $mFormRule; Vue.prototype.$mRoutesConfig = $mRoutesConfig; Vue.prototype.$mConstDataConfig = $mConstDataConfig; Vue.prototype.$mSettingConfig = $mSettingConfig; Vue.prototype.$mGraceChecker = $mGraceChecker; Vue.prototype.$mHelper = $mHelper; Vue.prototype.$mRouter = $mRouter; Vue.prototype.$mPayment = $mPayment; Vue.component('rfImage', rfImage); Vue.component('rfEmpty', rfEmpty); Vue.component('rfLoading', rfLoading); Vue.component('rfLoadProgress', rfLoadProgress); Vue.component('rfParser', rfParser); Vue.component('rfBackTop', rfBackTop); Vue.component('rfTag', rfTag); Vue.component('rfNavDetail', rfNavDetail); Vue.component('cuCustom', cuCustom); Vue.component('rfBackHome', rfBackHome); if (process.env.NODE_ENV === 'production') { Vue.config.productionTip = false; } // 路由导航 $mRouter.beforeEach((navType, to) => { if (to.route === undefined) { throw '路由钩子函数中没有找到to对象,路由信息:' + JSON.stringify(to); } if (to.route === $mRoutesConfig.login.path && store.getters.hasLogin) { uni.reLaunch({ url: $mHelper.objParseUrlAndParam($mRoutesConfig.main.path) }); return; } // 过滤需要权限的页面 if (to.route.requiresAuth) { if (store.getters.hasLogin) { // 已经登录 uni[navType]({ url: $mHelper.objParseUrlAndParam(to.route.path, to.query) }); } else { // 登录成功后的重定向地址和参数 const query = { redirectUrl: to.route.path, ...to.query }; // 没有登录 是否强制登录? if (store.state.forcedLogin) { uni.redirectTo({ url: $mHelper.objParseUrlAndParam($mRoutesConfig.login.path, query) }); } else { uni.navigateTo({ url: $mHelper.objParseUrlAndParam($mRoutesConfig.login.path, query) }); } } } else { uni[navType]({ url: $mHelper.objParseUrlAndParam(to.route, to.query) }); } }); import i18n from './static/js/language/index' Vue.prototype._i18n = i18n import moment from "moment"; Vue.prototype.moment = moment; import uView from "uview-ui"; Vue.use(uView); Vue.prototype.formatDate = function(value, formatString, defaultString) { if (value == null) { return defaultString ? defaultString : ""; } formatString = formatString || 'YYYY-MM-DD'; return moment(value).format(formatString); } Vue.prototype.formatDateAndHouse = function(value, formatString, defaultString) { if (value == null) { return defaultString ? defaultString : ""; } formatString = formatString || 'YYYY-MM-DD HH:mm:ss'; return moment(value).format(formatString, "YYYY-MM-DD HH:mm:ss"); } Vue.prototype.handlePublishTimeDesc = function(curTime, postModified, language) { // 计算两个时间戳 const NewcurTime = moment(curTime).valueOf(); const NewpostModified = moment(postModified).valueOf(); const timeDiff = moment(NewcurTime).diff(moment(NewpostModified)) // 单位换算 var min = 60 * 1000; var hour = min * 60; var day = hour * 24; var week = day * 7; var month = week * 4; var year = month * 12; // 计算发布时间距离当前时间的周、天、时、分 var exceedyear = Math.floor(timeDiff / year); var exceedmonth = Math.floor(timeDiff / month); var exceedWeek = Math.floor(timeDiff / week); var exceedDay = Math.floor(timeDiff / day); var exceedHour = Math.floor(timeDiff / hour); var exceedMin = Math.floor(timeDiff / min); // debugger; // 最后判断时间差到底是属于哪个区间,然后return if (exceedyear < 100 && exceedyear > 0) { return language == 'zh' ? exceedyear + '年前' : exceedyear + ' years ago'; } else { if (exceedmonth < 12 && exceedmonth > 0) { return language == 'zh' ? exceedmonth + '月前' : exceedmonth + ' months ago'; } else { if (exceedWeek < 4 && exceedWeek > 0) { return language == 'zh' ? exceedWeek + '星期前' : exceedWeek + ' weeks ago'; } else { if (exceedDay < 7 && exceedDay > 0) { return language == 'zh' ? exceedDay + '天前' : exceedDay + ' days ago' } else { if (exceedHour < 24 && exceedHour > 0) { return language == 'zh' ? exceedHour + '小时前' : exceedHour + ' hours ago' } else { return language == 'zh' ? exceedMin + '分钟前' : exceedMin + ' minutes ago' } } } } } } App.mpType = 'app'; Vue.mixin({ computed: { themeColor: { get() { return store.getters.themeColor; }, set(val) { store.state.themeColor = val; } } } }); Vue.prototype.moneySymbol = $mConstDataConfig.moneySymbol; Vue.prototype.singleSkuText = $mConstDataConfig.singleSkuText; // 保留小数点后两位 Vue.filter('keepTwoDecimal', value => { return (Math.floor((value || 0) * 100) / 100).toFixed(2); }); const app = new Vue({ ...App, i18n, store: store }); app.$mount();