@yysports/tools 0.0.10 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,41 +0,0 @@
1
- export type LocalRouteItemType = {
2
- access?: string;
3
- name?: string;
4
- parentPath?: string;
5
- path?: string;
6
- routes?: LocalRouteItemType[];
7
- };
8
- export type AuthMenuItemType = {
9
- logAction: any;
10
- name: string;
11
- meta?: {
12
- title: string;
13
- };
14
- permission?: string;
15
- children?: AuthMenuItemType[];
16
- path?: string;
17
- builtIn?: boolean;
18
- };
19
- export type MenuNameMapType = {
20
- [key: string]: string;
21
- };
22
- export interface CurrentUserConfig {
23
- getAuth?: () => Promise<any>;
24
- menuBuild?: () => Promise<AuthMenuItemType[]>;
25
- menuNameMap: MenuNameMapType;
26
- routes: LocalRouteItemType[];
27
- }
28
- export interface CurrentUserInfo {
29
- userName: string;
30
- department: string;
31
- email: string;
32
- enabled: boolean;
33
- gender: string;
34
- isAdmin: boolean;
35
- jobs: string[];
36
- nickName: string;
37
- phone: string;
38
- status: number;
39
- roles: string[];
40
- accessPage: string[];
41
- }
@@ -1 +0,0 @@
1
- export {};
@@ -1,13 +0,0 @@
1
- import { AuthMenuItemType, CurrentUserConfig, CurrentUserInfo, LocalRouteItemType, MenuNameMapType } from '../interfaces/currentUser.interface';
2
- export default class CurrentUser {
3
- static profile: CurrentUserInfo | null;
4
- static pathMap: {
5
- [routeStr: string]: string[];
6
- };
7
- static authMap: {
8
- [authStr: string]: string;
9
- };
10
- static formatAuthMenu(authMenuData: AuthMenuItemType[]): void;
11
- static formatLocalMenu(routes: LocalRouteItemType[], menuNameMap: MenuNameMapType, roles: string[]): string[];
12
- static init({ getAuth, menuBuild, menuNameMap, routes, }: CurrentUserConfig): Promise<CurrentUserInfo>;
13
- }
@@ -1,109 +0,0 @@
1
- var __defProp = Object.defineProperty;
2
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
- var __getOwnPropNames = Object.getOwnPropertyNames;
4
- var __hasOwnProp = Object.prototype.hasOwnProperty;
5
- var __export = (target, all) => {
6
- for (var name in all)
7
- __defProp(target, name, { get: all[name], enumerable: true });
8
- };
9
- var __copyProps = (to, from, except, desc) => {
10
- if (from && typeof from === "object" || typeof from === "function") {
11
- for (let key of __getOwnPropNames(from))
12
- if (!__hasOwnProp.call(to, key) && key !== except)
13
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
- }
15
- return to;
16
- };
17
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
-
19
- // src/CurrentUser/index.tsx
20
- var CurrentUser_exports = {};
21
- __export(CurrentUser_exports, {
22
- default: () => CurrentUser
23
- });
24
- module.exports = __toCommonJS(CurrentUser_exports);
25
- var CurrentUser = class {
26
- // 格式化权限按钮操作日志
27
- static formatAuthMenu(authMenuData) {
28
- const ergodicAuthMenu = (amd) => {
29
- amd.forEach((menu) => {
30
- const { permission, name, logAction, children } = menu;
31
- if (permission && logAction) {
32
- this.authMap[permission] = logAction || name;
33
- }
34
- if (Array.isArray(children) && children.length > 0) {
35
- ergodicAuthMenu(children);
36
- }
37
- });
38
- };
39
- ergodicAuthMenu(authMenuData);
40
- }
41
- // 格式化本地菜单权限数据
42
- static formatLocalMenu(routes, menuNameMap, roles) {
43
- const isAdmin = roles.includes("admin");
44
- const accessPage = [];
45
- const ergodicLocalMenu = (rs, parentMenu) => {
46
- rs.forEach((route) => {
47
- const { path, access, name, routes: routes2 } = route;
48
- const nameArr = [...(parentMenu == null ? void 0 : parentMenu.name) || []];
49
- const moduleArr = [...(parentMenu == null ? void 0 : parentMenu.module) || []];
50
- if (access && (isAdmin || roles.includes(access))) {
51
- accessPage.push(access);
52
- }
53
- if (name) {
54
- nameArr.push(name);
55
- const menuKey = ["menu", ...nameArr].join(".");
56
- moduleArr.push(menuNameMap[menuKey]);
57
- }
58
- if (path) {
59
- this.pathMap[path] = [...moduleArr];
60
- }
61
- if (routes2) {
62
- ergodicLocalMenu(routes2, {
63
- path,
64
- name: nameArr,
65
- module: moduleArr
66
- });
67
- }
68
- });
69
- };
70
- ergodicLocalMenu(routes);
71
- return accessPage;
72
- }
73
- static async init({
74
- getAuth,
75
- menuBuild,
76
- menuNameMap,
77
- routes
78
- }) {
79
- const [authInfo = {}, menuData = []] = await Promise.all(
80
- [
81
- getAuth,
82
- // 获取用户权限
83
- menuBuild
84
- // 获取权限中心配置的菜单及按钮
85
- ].map((v) => {
86
- if (v) {
87
- return v();
88
- } else {
89
- return Promise.resolve();
90
- }
91
- })
92
- );
93
- const { user = {}, roles = [] } = authInfo || {};
94
- const accessPage = this.formatLocalMenu(routes, menuNameMap, roles);
95
- this.formatAuthMenu(menuData);
96
- this.profile = {
97
- ...user,
98
- roles,
99
- accessPage
100
- };
101
- return this.profile;
102
- }
103
- };
104
- // 当前用户信息
105
- CurrentUser.profile = null;
106
- // 路径信息映射
107
- CurrentUser.pathMap = {};
108
- // 权限信息映射
109
- CurrentUser.authMap = {};
@@ -1,41 +0,0 @@
1
- export type LocalRouteItemType = {
2
- access?: string;
3
- name?: string;
4
- parentPath?: string;
5
- path?: string;
6
- routes?: LocalRouteItemType[];
7
- };
8
- export type AuthMenuItemType = {
9
- logAction: any;
10
- name: string;
11
- meta?: {
12
- title: string;
13
- };
14
- permission?: string;
15
- children?: AuthMenuItemType[];
16
- path?: string;
17
- builtIn?: boolean;
18
- };
19
- export type MenuNameMapType = {
20
- [key: string]: string;
21
- };
22
- export interface CurrentUserConfig {
23
- getAuth?: () => Promise<any>;
24
- menuBuild?: () => Promise<AuthMenuItemType[]>;
25
- menuNameMap: MenuNameMapType;
26
- routes: LocalRouteItemType[];
27
- }
28
- export interface CurrentUserInfo {
29
- userName: string;
30
- department: string;
31
- email: string;
32
- enabled: boolean;
33
- gender: string;
34
- isAdmin: boolean;
35
- jobs: string[];
36
- nickName: string;
37
- phone: string;
38
- status: number;
39
- roles: string[];
40
- accessPage: string[];
41
- }
@@ -1,17 +0,0 @@
1
- var __defProp = Object.defineProperty;
2
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
- var __getOwnPropNames = Object.getOwnPropertyNames;
4
- var __hasOwnProp = Object.prototype.hasOwnProperty;
5
- var __copyProps = (to, from, except, desc) => {
6
- if (from && typeof from === "object" || typeof from === "function") {
7
- for (let key of __getOwnPropNames(from))
8
- if (!__hasOwnProp.call(to, key) && key !== except)
9
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
10
- }
11
- return to;
12
- };
13
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
14
-
15
- // src/interfaces/currentUser.interface.ts
16
- var currentUser_interface_exports = {};
17
- module.exports = __toCommonJS(currentUser_interface_exports);