diff --git a/packages/fes-plugin-layout/src/index.js b/packages/fes-plugin-layout/src/index.js
index 1870e1e6..a1df5923 100644
--- a/packages/fes-plugin-layout/src/index.js
+++ b/packages/fes-plugin-layout/src/index.js
@@ -50,13 +50,6 @@ export default (api) => {
}`,
});
- api.writeTmpFile({
- path: absFilePath,
- content: Mustache.render(readFileSync(join(__dirname, 'runtime/views/index.tpl'), 'utf-8'), {
- REPLACE_USER_CONFIG: JSON.stringify(userConfig),
- }),
- });
-
api.writeTmpFile({
path: absConfigFilePath,
content: Mustache.render(readFileSync(join(__dirname, 'runtime/helpers/getConfig.tpl'), 'utf-8'), {
@@ -80,14 +73,37 @@ export default (api) => {
},
]);
- // 把BaseLayout插入到路由配置中,作为根路由
- api.modifyRoutes((routes) => [
- {
- path: '/',
- component: winPath(join(api.paths.absTmpPath || '', absFilePath)),
- children: routes,
- },
- ]);
+ // 把 BaseLayout插入到路由配置中,作为根路由
+ // 添加 403 和 404 路由
+ api.modifyRoutes((routes) => {
+ if (!routes.find((item) => item.path === '/403')) {
+ routes.push({
+ path: '/403',
+ name: 'Exception403',
+ component: winPath(join(api.paths.absTmpPath, join(namespace, 'views/403.vue'))),
+ meta: {
+ title: '403',
+ },
+ });
+ }
+ if (!routes.find((item) => item.path === '/404')) {
+ routes.push({
+ path: '/404',
+ name: 'Exception404',
+ component: winPath(join(api.paths.absTmpPath, join(namespace, 'views/404.vue'))),
+ meta: {
+ title: '404',
+ },
+ });
+ }
+ return [
+ {
+ path: '/',
+ component: winPath(join(api.paths.absTmpPath || '', absFilePath)),
+ children: routes,
+ },
+ ];
+ });
api.addConfigType(() => ({
source: name,
diff --git a/packages/fes-plugin-layout/src/runtime/assets/403.png b/packages/fes-plugin-layout/src/runtime/assets/403.png
new file mode 100644
index 00000000..73e54154
Binary files /dev/null and b/packages/fes-plugin-layout/src/runtime/assets/403.png differ
diff --git a/packages/fes-plugin-layout/src/runtime/assets/404.png b/packages/fes-plugin-layout/src/runtime/assets/404.png
new file mode 100644
index 00000000..96944031
Binary files /dev/null and b/packages/fes-plugin-layout/src/runtime/assets/404.png differ
diff --git a/packages/fes-plugin-layout/src/runtime/helpers/fillMenu.js b/packages/fes-plugin-layout/src/runtime/helpers/fillMenu.js
index cbf7da55..366dfa4f 100644
--- a/packages/fes-plugin-layout/src/runtime/helpers/fillMenu.js
+++ b/packages/fes-plugin-layout/src/runtime/helpers/fillMenu.js
@@ -29,27 +29,16 @@ const fillMenuByRoute = (menuConfig, routeConfig, dep = 0) => {
menuConfig.forEach((menu) => {
const pageConfig = {};
if (menu.name) {
- Object.assign(
- pageConfig,
- getMetaByName(routeConfig, menu.name)
- );
+ Object.assign(pageConfig, getMetaByName(routeConfig, menu.name));
}
// menu的配置优先级高,当menu存在配置时,忽略页面的配置
Object.keys(pageConfig).forEach((prop) => {
- if (
- menu[prop] === undefined
- || menu[prop] === null
- || menu[prop] === ''
- ) {
+ if (menu[prop] === undefined || menu[prop] === null || menu[prop] === '') {
menu[prop] = pageConfig[prop];
}
});
if (menu.children && menu.children.length > 0) {
- menu.children = fillMenuByRoute(
- menu.children,
- routeConfig,
- dep
- );
+ menu.children = fillMenuByRoute(menu.children, routeConfig, dep);
}
arr.push(menu);
});
diff --git a/packages/fes-plugin-layout/src/runtime/runtime.js b/packages/fes-plugin-layout/src/runtime/runtime.js
index 2e087953..de9ab180 100644
--- a/packages/fes-plugin-layout/src/runtime/runtime.js
+++ b/packages/fes-plugin-layout/src/runtime/runtime.js
@@ -1,32 +1,16 @@
// 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!');
+ 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();
+ const accessIds = accessApi.getAccess();
+ accessApi.setAccess(accessIds.concat(['/403', '/404']));
return {
unAccessHandler({ router, to, from, next }) {
if (runtimeConfig.unAccessHandler && typeof runtimeConfig.unAccessHandler === 'function') {
@@ -37,11 +21,6 @@ export const access = (memo) => {
next,
});
}
- if (to.path === '/404') {
- handle(404, router);
- return next('/404');
- }
- handle(403, router);
next('/403');
},
noFoundHandler({ router, to, from, next }) {
@@ -53,11 +32,6 @@ export const access = (memo) => {
next,
});
}
- if (to.path === '/403') {
- handle(403, router);
- return next('/403');
- }
- handle(404, router);
next('/404');
},
...memo,
diff --git a/packages/fes-plugin-layout/src/runtime/views/403.vue b/packages/fes-plugin-layout/src/runtime/views/403.vue
index 0da87747..78a2b93c 100644
--- a/packages/fes-plugin-layout/src/runtime/views/403.vue
+++ b/packages/fes-plugin-layout/src/runtime/views/403.vue
@@ -1,241 +1,19 @@
-
-
-
对不起,您没有权限访问此页面。
-
上一页
-
+
-
diff --git a/packages/fes-plugin-layout/src/runtime/views/404.vue b/packages/fes-plugin-layout/src/runtime/views/404.vue
index 470845fc..16fda346 100644
--- a/packages/fes-plugin-layout/src/runtime/views/404.vue
+++ b/packages/fes-plugin-layout/src/runtime/views/404.vue
@@ -1,266 +1,19 @@
-
-
-
对不起,您访问的页面不存在。
-
上一页
-
+
-
diff --git a/packages/fes-plugin-layout/src/runtime/views/BaseLayout.vue b/packages/fes-plugin-layout/src/runtime/views/BaseLayout.vue
index 233aac91..cb9b6fac 100644
--- a/packages/fes-plugin-layout/src/runtime/views/BaseLayout.vue
+++ b/packages/fes-plugin-layout/src/runtime/views/BaseLayout.vue
@@ -27,7 +27,7 @@