Commit d39bbbc2 by 姜雷

修改api挂载方式

parent 7a9830f4
......@@ -13,16 +13,18 @@ import { formatRouteLink } from '@/utils/route';
import storeModule from './storeModule';
import mixinModule from './mixins';
const createSystem = ({ routers, routeFilter }) => {
class SystemShell {
constructor() {
this.createBaseFetch = createBaseFetch;
this.fetch = createBaseFetch(
const fetch = createBaseFetch(
{
timeout: 10000,
},
store
);
);
const createSystem = ({ routers, routeFilter }) => {
class SystemShell {
constructor() {
this.createBaseFetch = createBaseFetch;
this.fetch = fetch;
this.initSystem();
}
......@@ -68,4 +70,8 @@ const createSystem = ({ routers, routeFilter }) => {
return systemShell;
};
export default createSystem;
export default {
createBaseFetch,
Api: fetch,
createSystem,
};
import createSystem from './lib/main';
import System from './lib/main';
console.log(System);
let allAasyncRouterMap = [
...customerManage.default,
......@@ -6,12 +8,8 @@ let allAasyncRouterMap = [
...systemManage.default,
];
let app = createSystem({
let app = System.createSystem({
routers: allAasyncRouterMap,
// routeFilter: allRoute => {
// let filterRoute = allRoute.find(menu => menu.menuCode == '0001');
// return filterRoute ? [filterRoute] : [];
// },
});
app.mount();
import router, { asyncRouterMap } from './router';
import store from './store';
import NProgress from 'nprogress'; // Progress 进度条
import 'nprogress/nprogress.css'; // Progress 进度条样式
import { getToken } from '@/utils/auth'; // 验权
import { getAuthRoute } from './utils/route';
let allAasyncRouterMap = [
...customerManage.default,
...baseManage.default,
...systemManage.default,
];
NProgress.configure({ showSpinner: false }); // NProgress Configuration
const whiteList = process.env.VUE_APP_WHITE_LIST.split(','); // 不重定向白名单
const getRouteAdd = () => {
let allRoute = store.getters.asyncRoutes;
let asyncRouters = getAuthRoute(allAasyncRouterMap, allRoute);
router.addRoutes(asyncRouters); // 动态添加可访问路由表
router.addRoutes(asyncRouterMap);
};
router.beforeEach((to, from, next) => {
NProgress.start(); // 进度条Progress
if (getToken()) {
if (to.path === '/login') {
next({ path: '/' });
NProgress.done();
} else {
if (store.getters.isRouteDone) {
next(); //
} else {
let addRoute = store.getters.asyncRoutes;
if (addRoute && addRoute.length) {
getRouteAdd();
store.dispatch('GenerateRoutes');
next({ ...to, replace: true });
} else {
store
.dispatch('TokenLogin', {
data: { token: getToken() },
})
.then(() => {
getRouteAdd();
store.dispatch('GenerateRoutes');
next({ ...to, replace: true });
})
.catch(err => {
console.log(err);
store.dispatch('FedLogOut').then(() => {
next({ path: '/login' });
});
});
}
}
}
} else {
if (whiteList.indexOf(to.path) !== -1) {
next();
} else {
next('/login');
NProgress.done();
}
}
});
router.afterEach(() => {
NProgress.done(); // 结束Progress
});
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment