harrywan a9dd94506a
refactor: 重构plugin-layout,统一配置
* 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>
2022-06-22 14:25:47 +08:00

66 lines
2.0 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// 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-accessplease 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,
};
};