@kkt/plugin-pro-access
TypeScript icon, indicating that this package has built-in type declarations

1.1.5 • Public • Published

权限配置

权限控制,开启 access 配置, 则src目录下自动生成 access 文件。可以在业务中根据路径来定制需求。

参数

export interface AccessPluginProps {
  /** 是否开启权限 */
  access?: string;
}

roles

当路由配置roles参数,在页面中可以直接获取roles用于页面模块校验权限。

// config/routes.json
const routes = [
  // ....
  {
    path: '/demo',
    element: '@/pages/demo',
    roles: ['admin', 'users']
  }
]

// page
const Page = (props) => {
  const { roles = [] } = props;

  return <div />
}
export default Page;

access.ts

页面跳转拦截,思路来源于vue-routerbeforeEach

// src/access.ts
/**
 * @path: 当前页面地址
 * @return 返回true则通过,返回路由则表示跳转
 */
const beforeEach = (path: string) => {
  return new Promise((resolve, reject) => {
    const isAuth = false;
    if (isAuth) {
      resolve(true);
    } else {
      // 如果当前无权限则跳转到 login 页面
      resolve('/login')
    }
  })
};

export default beforeEach;

kktp配置文件

// .kktprc.ts
export default {
  access: true
}

Contributors

License

Licensed under the MIT License.

Package Sidebar

Install

npm i @kkt/plugin-pro-access

Weekly Downloads

1

Version

1.1.5

License

MIT

Unpacked Size

19 kB

Total Files

22

Last publish

Collaborators

  • uiwjs
  • wcjiang