mirror of
https://github.com/WeBankFinTech/fes.js.git
synced 2025-05-24 07:39:28 +08:00
* docs: 更新文档 * break: plugin-layout优化api * break: 去掉switch配置,改为使用navigation * feat: 重构layout * docs: 升级文档 * feat: 无logo和title时隐藏dom * fix: 修复一些问题 * fix: 配置提示 * fix: build watch copy 路径识别问题 * docs: 文档 Co-authored-by: winixt <haizekuo@gmail.com>
66 lines
2.0 KiB
JavaScript
66 lines
2.0 KiB
JavaScript
// eslint-disable-next-line import/extensions
|
||
import { access as accessApi } from '../plugin-access/core';
|
||
import Exception404 from './views/404.vue';
|
||
import Exception403 from './views/403.vue';
|
||
// eslint-disable-next-line import/extensions
|
||
import getConfig from './helpers/getConfig';
|
||
|
||
if (!accessApi) {
|
||
throw new Error('[plugin-layout]: pLugin-layout depends on plugin-access,please install plugin-access first!');
|
||
}
|
||
|
||
const handle = (type, router) => {
|
||
const accessIds = accessApi.getAccess();
|
||
const path = `/${type}`;
|
||
const name = `Exception${type}`;
|
||
const components = {
|
||
404: Exception404,
|
||
403: Exception403,
|
||
};
|
||
if (!accessIds.includes(path)) {
|
||
accessApi.setAccess(accessIds.concat([path]));
|
||
}
|
||
if (!router.hasRoute(name)) {
|
||
router.addRoute({ path, name, component: components[type] });
|
||
}
|
||
};
|
||
|
||
export const access = (memo) => {
|
||
const runtimeConfig = getConfig();
|
||
return {
|
||
unAccessHandler({ router, to, from, next }) {
|
||
if (runtimeConfig.unAccessHandler && typeof runtimeConfig.unAccessHandler === 'function') {
|
||
return runtimeConfig.unAccessHandler({
|
||
router,
|
||
to,
|
||
from,
|
||
next,
|
||
});
|
||
}
|
||
if (to.path === '/404') {
|
||
handle(404, router);
|
||
return next('/404');
|
||
}
|
||
handle(403, router);
|
||
next('/403');
|
||
},
|
||
noFoundHandler({ router, to, from, next }) {
|
||
if (runtimeConfig.noFoundHandler && typeof runtimeConfig.noFoundHandler === 'function') {
|
||
return runtimeConfig.noFoundHandler({
|
||
router,
|
||
to,
|
||
from,
|
||
next,
|
||
});
|
||
}
|
||
if (to.path === '/403') {
|
||
handle(403, router);
|
||
return next('/403');
|
||
}
|
||
handle(404, router);
|
||
next('/404');
|
||
},
|
||
...memo,
|
||
};
|
||
};
|