mirror of
https://github.com/WeBankFinTech/fes.js.git
synced 2025-06-30 02:35:08 +08:00
fix: 判断页面权限的path统一从match中拿路由path
This commit is contained in:
parent
2ca3951c3f
commit
01598a08ac
@ -4,10 +4,10 @@
|
||||
对于前端应用来说,权限就是页面、页面元素是否可见。
|
||||
|
||||
### 资源
|
||||
Fes.js 把页面、页面元素统一叫做资源,每个资源都有 `accessId`:
|
||||
- 页面的 `accessId` 默认是页面的路由 `path` 。比如页面 `pages/a.vue` 的路由 `path` 是 `/a`。当页面访问 `/a` 时会渲染当前页面,`/a` 也就是页面的 `accessId`。
|
||||
Fes.js 把页面、页面元素统一叫做资源,用资源 ID 来识别区分他们:
|
||||
- 页面的资源 ID 默认是页面的路由 `path` 。比如页面 `pages/a.vue` 的路由 `path` 是 `/a`。当页面访问 `/a` 时会渲染当前页面,`/a` 也就是页面的 `accessId`。
|
||||
|
||||
- 页面元素的 `accessId` 没有默认值,由我们自定义。
|
||||
- 页面元素的资源 ID 没有默认值,需要自定义。
|
||||
```vue
|
||||
<template>
|
||||
<access :id="accessId"> accessOnepicess1 <input /> </access>
|
||||
|
@ -1,4 +1,5 @@
|
||||
import { plugin, ApplyPluginsType } from '@@/core/coreExports';
|
||||
// eslint-disable-next-line import/extensions
|
||||
import { access, install } from './core';
|
||||
|
||||
export function onRouterCreated({ router }) {
|
||||
@ -9,25 +10,35 @@ export function onRouterCreated({ router }) {
|
||||
initialValue: {}
|
||||
});
|
||||
if (to.matched.length === 0) {
|
||||
if (runtimeConfig.noFoundHandler && typeof runtimeConfig.noFoundHandler === 'function') {
|
||||
if (
|
||||
runtimeConfig.noFoundHandler
|
||||
&& typeof runtimeConfig.noFoundHandler === 'function'
|
||||
) {
|
||||
return runtimeConfig.noFoundHandler({
|
||||
router, to, from, next
|
||||
router,
|
||||
to,
|
||||
from,
|
||||
next
|
||||
});
|
||||
}
|
||||
return next(false);
|
||||
}
|
||||
let path;
|
||||
if (to.matched.length === 1) {
|
||||
path = to.matched[0].path;
|
||||
} else {
|
||||
path = to.path;
|
||||
}
|
||||
const canRoute = await access.hasAccess(path);
|
||||
// path是匹配路由的path,不是页面hash
|
||||
const canRoute = await access.hasAccess(
|
||||
to.matched[to.matched.length - 1].path
|
||||
);
|
||||
if (canRoute) {
|
||||
return next();
|
||||
}
|
||||
if (runtimeConfig.unAccessHandler && typeof runtimeConfig.unAccessHandler === 'function') {
|
||||
if (
|
||||
runtimeConfig.unAccessHandler
|
||||
&& typeof runtimeConfig.unAccessHandler === 'function'
|
||||
) {
|
||||
return runtimeConfig.unAccessHandler({
|
||||
router, to, from, next
|
||||
router,
|
||||
to,
|
||||
from,
|
||||
next
|
||||
});
|
||||
}
|
||||
next(false);
|
||||
|
Loading…
x
Reference in New Issue
Block a user