mirror of
https://github.com/WeBankFinTech/fes.js.git
synced 2025-04-06 03:59:53 +08:00
feat: plugin-access done
This commit is contained in:
parent
60f2cbb1f9
commit
6cbdb70b44
@ -1,18 +1,26 @@
|
|||||||
import { access } from "./core";
|
import { access } from "./core";
|
||||||
|
import { plugin, ApplyPluginsType } from "@@/core/coreExports";
|
||||||
|
|
||||||
|
async function getInitialState() {
|
||||||
|
const appGetInitialState = plugin.applyPlugins({
|
||||||
|
key: "getInitialState",
|
||||||
|
type: ApplyPluginsType.modify,
|
||||||
|
initialValue: {},
|
||||||
|
});
|
||||||
|
return await appGetInitialState;
|
||||||
|
}
|
||||||
|
|
||||||
export function onRouterCreated({ router }) {
|
export function onRouterCreated({ router }) {
|
||||||
router.beforeEach(async (to, from, next) => {
|
router.beforeEach(async (to, from) => {
|
||||||
let path;
|
let path;
|
||||||
if (to.matched.length === 1) {
|
if (to.matched.length === 1) {
|
||||||
path = to.matched[0].path;
|
path = to.matched[0].path;
|
||||||
} else {
|
} else {
|
||||||
path = to.path;
|
path = to.path;
|
||||||
}
|
}
|
||||||
|
// 等待初始化数据
|
||||||
|
await getInitialState();
|
||||||
const canRoute = await access.hasAccess(path);
|
const canRoute = await access.hasAccess(path);
|
||||||
if (canRoute) {
|
return canRoute
|
||||||
next();
|
|
||||||
} else {
|
|
||||||
next(false);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -25,7 +25,9 @@ export default function (api) {
|
|||||||
// 修改路由
|
// 修改路由
|
||||||
'patchRoutes',
|
'patchRoutes',
|
||||||
// 生成router时触发
|
// 生成router时触发
|
||||||
'onRouterCreated'
|
'onRouterCreated',
|
||||||
|
// 初始化数据
|
||||||
|
'getInitialState'
|
||||||
]
|
]
|
||||||
});
|
});
|
||||||
const plugins = await api.applyPlugins({
|
const plugins = await api.applyPlugins({
|
||||||
|
@ -83,9 +83,6 @@ export default (api) => {
|
|||||||
}
|
}
|
||||||
]);
|
]);
|
||||||
|
|
||||||
// 注册 getInitialState 方法
|
|
||||||
api.addRuntimePluginKey(() => 'getInitialState');
|
|
||||||
|
|
||||||
// 注册 initialStateConfig 方法
|
// 注册 initialStateConfig 方法
|
||||||
api.addRuntimePluginKey(() => 'initialStateConfig');
|
api.addRuntimePluginKey(() => 'initialStateConfig');
|
||||||
|
|
||||||
|
@ -23,7 +23,7 @@
|
|||||||
"vue": "^3.0.0"
|
"vue": "^3.0.0"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"vue-router": "^4.0.0-rc.1"
|
"vue-router": "^4.0.1"
|
||||||
},
|
},
|
||||||
"module": "dist/index.esm.js"
|
"module": "dist/index.esm.js"
|
||||||
}
|
}
|
||||||
|
@ -14711,10 +14711,10 @@ vue-loader@^16.0.0-rc.1:
|
|||||||
hash-sum "^2.0.0"
|
hash-sum "^2.0.0"
|
||||||
loader-utils "^2.0.0"
|
loader-utils "^2.0.0"
|
||||||
|
|
||||||
vue-router@^4.0.0-rc.1:
|
vue-router@^4.0.1:
|
||||||
version "4.0.0-rc.1"
|
version "4.0.1"
|
||||||
resolved "https://registry.npmjs.org/vue-router/-/vue-router-4.0.0-rc.1.tgz#42f41315849163a1243886c9aa6d7c14f24fd003"
|
resolved "https://registry.yarnpkg.com/vue-router/-/vue-router-4.0.1.tgz#309240e50524b1e7d4e82e27f0a0fa25fe3d1d71"
|
||||||
integrity sha512-N3SSOIiRFo1/D6EkHGuahUSuyDvFhKizN5zVXkALX7wv0hYYndV49KwzRF5lKsAIt+OlDl7y+sNmwNewb7a4iw==
|
integrity sha512-2C2nRxA2nCusgJyUpvcbd9Bnc9kACp/VLUCK4drXtgeRXHjQliZJcgjjP268vkGvvEKun9jjp8Ic1PpzUgbYKg==
|
||||||
|
|
||||||
vue-types@^3.0.0:
|
vue-types@^3.0.0:
|
||||||
version "3.0.1"
|
version "3.0.1"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user