123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137 |
- import Vue from 'vue';
- import App from './App';
- //token前缀
- Vue.prototype.$preToken='Bearer';
- //更新提示红点
- Vue.prototype.$needUpdate = true;
- // 引入全局存储
- 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 $mWebsocketConfig from '@/config/websocket.config.js';
- import $mSettingConfig from '@/config/setting.config.js';
- // 引入全局方法
- import {
- http
- } from '@/utils/request';
- import $mGraceChecker from '@/utils/graceChecker';
- import $mHelper from '@/utils/helper';
- import $mRouter from '@/utils/router';
- import { getTabBarBadge } from '@/api/login.js'
- // import $mWebsocket from '@/utils/websocket';
- // 全局组件
- import rfImage from '@/components/oa-image/oa-image';
- import rfEmpty from '@/components/oa-empty';
- import rfLoading from '@/components/oa-loading';
- import rfLoadProgress from '@/components/oa-load-progress/oa-load-progress';
- import rfParser from '@/components/oa-parser';
- import rfBackTop from '@/components/oa-back-top';
- import rfTag from '@/components/oa-tag';
- import rfNavDetail from '@/components/oa-nav-detail';
- import cuCustom from '@/components/cu-custom';
- // 网络状态监听
- uni.getNetworkType({
- success: res => {
- store.dispatch('networkStateChange', res.networkType);
- }
- });
- uni.onNetworkStatusChange(function(res) {
- store.dispatch('networkStateChange', res.networkType);
- });
- // 挂载全局自定义方法
- Vue.prototype.$mStore = store;
- 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.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);
- if (process.env.NODE_ENV === 'production') {
- Vue.config.productionTip = false;
- }
- // 路由导航
- $mRouter.beforeEach((navType, to) => {
- var mRoutesConfig = $mRoutesConfig;
- var requiresAuth = false;
- 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;
- }
- // 过滤需要权限的页面
- for (var routeCfg in mRoutesConfig) {
- if (to.route === mRoutesConfig[routeCfg].path) {
- requiresAuth = false;
- }
- }
- if (requiresAuth) {
- if (store.getters.hasLogin) {
- // 已经登录
- uni[navType]({
- url: to.route
- });
- } else {
- uni.navigateTo({
- url: "/pages/public/login"
- });
- }
- } else {
- uni[navType]({
- url: to.route
- });
- }
- });
- App.mpType = 'app';
- Vue.mixin({
- computed: {
- themeColor: {
- get() {
- return store.getters.themeColor;
- },
- set(val) {
- store.state.themeColor = val;
- }
- }
- }
- });
- Vue.prototype.getTabBarBadge=getTabBarBadge;
- 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,
- store: store
- });
- app.$mount();
|