): void;
onContextMenuVisibleChange?(visible: boolean): void;
}
diff --git a/packages/mlz-admin/src/tree/index.less b/packages/mlz-admin/src/tree/index.less
old mode 100644
new mode 100755
diff --git a/packages/mlz-adminer/package-lock.json b/packages/mlz-adminer/package-lock.json
new file mode 100755
index 00000000..c0ac0c81
--- /dev/null
+++ b/packages/mlz-adminer/package-lock.json
@@ -0,0 +1,156 @@
+{
+ "name": "@mlz/adminer",
+ "version": "1.0.0",
+ "lockfileVersion": 1,
+ "requires": true,
+ "dependencies": {
+ "history": {
+ "version": "4.10.1",
+ "resolved": "https://registry.npmjs.org/history/-/history-4.10.1.tgz",
+ "integrity": "sha512-36nwAD620w12kuzPAsyINPWJqlNbij+hpK1k9XRloDtym8mxzGYl2c17LnV6IAGB2Dmg4tEa7G7DlawS0+qjew==",
+ "requires": {
+ "@babel/runtime": "^7.1.2",
+ "loose-envify": "^1.2.0",
+ "resolve-pathname": "^3.0.0",
+ "tiny-invariant": "^1.0.2",
+ "tiny-warning": "^1.0.0",
+ "value-equal": "^1.0.1"
+ },
+ "dependencies": {
+ "@babel/runtime": {
+ "version": "7.14.6",
+ "resolved": "https://registry.npmjs.org/@babel/runtime/-/runtime-7.14.6.tgz",
+ "integrity": "sha512-/PCB2uJ7oM44tz8YhC4Z/6PeOKXp4K588f+5M3clr1M4zbqztlo0XEfJ2LEzj/FgwfgGcIdl8n7YYjTCI0BYwg==",
+ "requires": {
+ "regenerator-runtime": "^0.13.4"
+ }
+ }
+ }
+ },
+ "hoist-non-react-statics": {
+ "version": "3.3.2",
+ "resolved": "https://registry.npmjs.org/hoist-non-react-statics/-/hoist-non-react-statics-3.3.2.tgz",
+ "integrity": "sha512-/gGivxi8JPKWNm/W0jSmzcMPpfpPLc3dY/6GxhX2hQ9iGj3aDfklV4ET7NjKpSinLpJ5vafa9iiGIEZg10SfBw==",
+ "requires": {
+ "react-is": "^16.7.0"
+ }
+ },
+ "isarray": {
+ "version": "0.0.1",
+ "resolved": "https://registry.npmjs.org/isarray/-/isarray-0.0.1.tgz",
+ "integrity": "sha1-ihis/Kmo9Bd+Cav8YDiTmwXR7t8="
+ },
+ "js-tokens": {
+ "version": "4.0.0",
+ "resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-4.0.0.tgz",
+ "integrity": "sha512-RdJUflcE3cUzKiMqQgsCu06FPu9UdIJO0beYbPhHN4k6apgJtifcoCtT9bcxOpYBtpD2kCM6Sbzg4CausW/PKQ=="
+ },
+ "loose-envify": {
+ "version": "1.4.0",
+ "resolved": "https://registry.npmjs.org/loose-envify/-/loose-envify-1.4.0.tgz",
+ "integrity": "sha512-lyuxPGr/Wfhrlem2CL/UcnUc1zcqKAImBDzukY7Y5F/yQiNdko6+fRLevlw1HgMySw7f611UIY408EtxRSoK3Q==",
+ "requires": {
+ "js-tokens": "^3.0.0 || ^4.0.0"
+ }
+ },
+ "mini-create-react-context": {
+ "version": "0.4.1",
+ "resolved": "https://registry.npmjs.org/mini-create-react-context/-/mini-create-react-context-0.4.1.tgz",
+ "integrity": "sha512-YWCYEmd5CQeHGSAKrYvXgmzzkrvssZcuuQDDeqkT+PziKGMgE+0MCCtcKbROzocGBG1meBLl2FotlRwf4gAzbQ==",
+ "requires": {
+ "@babel/runtime": "^7.12.1",
+ "tiny-warning": "^1.0.3"
+ },
+ "dependencies": {
+ "@babel/runtime": {
+ "version": "7.14.6",
+ "resolved": "https://registry.npmjs.org/@babel/runtime/-/runtime-7.14.6.tgz",
+ "integrity": "sha512-/PCB2uJ7oM44tz8YhC4Z/6PeOKXp4K588f+5M3clr1M4zbqztlo0XEfJ2LEzj/FgwfgGcIdl8n7YYjTCI0BYwg==",
+ "requires": {
+ "regenerator-runtime": "^0.13.4"
+ }
+ }
+ }
+ },
+ "object-assign": {
+ "version": "4.1.1",
+ "resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz",
+ "integrity": "sha1-IQmtx5ZYh8/AXLvUQsrIv7s2CGM="
+ },
+ "path-to-regexp": {
+ "version": "1.8.0",
+ "resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-1.8.0.tgz",
+ "integrity": "sha512-n43JRhlUKUAlibEJhPeir1ncUID16QnEjNpwzNdO3Lm4ywrBpBZ5oLD0I6br9evr1Y9JTqwRtAh7JLoOzAQdVA==",
+ "requires": {
+ "isarray": "0.0.1"
+ }
+ },
+ "prop-types": {
+ "version": "15.7.2",
+ "resolved": "https://registry.npmjs.org/prop-types/-/prop-types-15.7.2.tgz",
+ "integrity": "sha512-8QQikdH7//R2vurIJSutZ1smHYTcLpRWEOlHnzcWHmBYrOGUysKwSsrC89BCiFj3CbrfJ/nXFdJepOVrY1GCHQ==",
+ "requires": {
+ "loose-envify": "^1.4.0",
+ "object-assign": "^4.1.1",
+ "react-is": "^16.8.1"
+ }
+ },
+ "react-is": {
+ "version": "16.13.1",
+ "resolved": "https://registry.npmjs.org/react-is/-/react-is-16.13.1.tgz",
+ "integrity": "sha512-24e6ynE2H+OKt4kqsOvNd8kBpV65zoxbA4BVsEOB3ARVWQki/DHzaUoC5KuON/BiccDaCCTZBuOcfZs70kR8bQ=="
+ },
+ "react-router": {
+ "version": "5.2.0",
+ "resolved": "https://registry.npmjs.org/react-router/-/react-router-5.2.0.tgz",
+ "integrity": "sha512-smz1DUuFHRKdcJC0jobGo8cVbhO3x50tCL4icacOlcwDOEQPq4TMqwx3sY1TP+DvtTgz4nm3thuo7A+BK2U0Dw==",
+ "requires": {
+ "@babel/runtime": "^7.1.2",
+ "history": "^4.9.0",
+ "hoist-non-react-statics": "^3.1.0",
+ "loose-envify": "^1.3.1",
+ "mini-create-react-context": "^0.4.0",
+ "path-to-regexp": "^1.7.0",
+ "prop-types": "^15.6.2",
+ "react-is": "^16.6.0",
+ "tiny-invariant": "^1.0.2",
+ "tiny-warning": "^1.0.0"
+ },
+ "dependencies": {
+ "@babel/runtime": {
+ "version": "7.14.6",
+ "resolved": "https://registry.npmjs.org/@babel/runtime/-/runtime-7.14.6.tgz",
+ "integrity": "sha512-/PCB2uJ7oM44tz8YhC4Z/6PeOKXp4K588f+5M3clr1M4zbqztlo0XEfJ2LEzj/FgwfgGcIdl8n7YYjTCI0BYwg==",
+ "requires": {
+ "regenerator-runtime": "^0.13.4"
+ }
+ }
+ }
+ },
+ "regenerator-runtime": {
+ "version": "0.13.7",
+ "resolved": "https://registry.npmjs.org/regenerator-runtime/-/regenerator-runtime-0.13.7.tgz",
+ "integrity": "sha512-a54FxoJDIr27pgf7IgeQGxmqUNYrcV338lf/6gH456HZ/PhX+5BcwHXG9ajESmwe6WRO0tAzRUrRmNONWgkrew=="
+ },
+ "resolve-pathname": {
+ "version": "3.0.0",
+ "resolved": "https://registry.npmjs.org/resolve-pathname/-/resolve-pathname-3.0.0.tgz",
+ "integrity": "sha512-C7rARubxI8bXFNB/hqcp/4iUeIXJhJZvFPFPiSPRnhU5UPxzMFIl+2E6yY6c4k9giDJAhtV+enfA+G89N6Csng=="
+ },
+ "tiny-invariant": {
+ "version": "1.1.0",
+ "resolved": "https://registry.npmjs.org/tiny-invariant/-/tiny-invariant-1.1.0.tgz",
+ "integrity": "sha512-ytxQvrb1cPc9WBEI/HSeYYoGD0kWnGEOR8RY6KomWLBVhqz0RgTwVO9dLrGz7dC+nN9llyI7OKAgRq8Vq4ZBSw=="
+ },
+ "tiny-warning": {
+ "version": "1.0.3",
+ "resolved": "https://registry.npmjs.org/tiny-warning/-/tiny-warning-1.0.3.tgz",
+ "integrity": "sha512-lBN9zLN/oAf68o3zNXYrdCt1kP8WsiGW8Oo2ka41b2IM5JL/S1CTyX1rW0mb/zSuJun0ZUrDxx4sqvYS2FWzPA=="
+ },
+ "value-equal": {
+ "version": "1.0.1",
+ "resolved": "https://registry.npmjs.org/value-equal/-/value-equal-1.0.1.tgz",
+ "integrity": "sha512-NOJ6JZCAWr0zlxZt+xqCHNTEKOsrks2HQd4MqhP1qy4z1SkbEP467eNx6TgDKXMvUOb+OENfJCZwM+16n7fRfw=="
+ }
+ }
+}
diff --git a/packages/mlz-adminer/package.json b/packages/mlz-adminer/package.json
index 7001b173..497b68bc 100755
--- a/packages/mlz-adminer/package.json
+++ b/packages/mlz-adminer/package.json
@@ -1,6 +1,6 @@
{
"name": "@mlz/adminer",
- "version": "0.10.0",
+ "version": "1.0.0",
"description": "@mlz/admin配套的交互和业务代码库",
"license": "MPL2",
"keywords": [
@@ -19,12 +19,13 @@
"dependencies": {
"@babel/runtime": "^7.10.2",
"@mlz/admin": "^0.8.5",
- "react": "^16.14.0",
- "react-dom": "^16.14.0",
+ "react": "^17.0.2",
+ "react-dom": "^17.0.2",
+ "react-router": "^5.2.0",
"umi-request": "^1.3.5"
},
"peerDependencies": {
- "@mlz/admin": ">=0.8.5",
+ "@mlz/admin": ">=0.9.2",
"umi-request": ">=1.3.5"
},
"devDependencies": {
@@ -47,4 +48,4 @@
"registry": "https://registry.npmjs.org/"
},
"gitHead": "2fed11fc4cc30fd18219c3ddf5aea7ca5e778143"
-}
\ No newline at end of file
+}
diff --git a/packages/mlz-adminer/src/shared/basic-class/index.ts b/packages/mlz-adminer/src/shared/basic-class/index.ts
old mode 100644
new mode 100755
diff --git a/packages/mlz-adminer/src/shared/basic-request-hook/index.tsx b/packages/mlz-adminer/src/shared/basic-request-hook/index.tsx
old mode 100644
new mode 100755
index 3c5e93cc..aba7ff06
--- a/packages/mlz-adminer/src/shared/basic-request-hook/index.tsx
+++ b/packages/mlz-adminer/src/shared/basic-request-hook/index.tsx
@@ -53,7 +53,12 @@ const useBasicRequest = , R>(fetchPromise:
//
const devResult = { loading, run, data: response, abort, setResponse, toggleLoading };
- return isCompiled ? { loading, run, ...(!manual && { data: response, abort }) } : devResult;
+
+ type TDevResult = typeof devResult;
+ type TCompiledBundleType = { loading: boolean; run: Function; data: R; abort: Function };
+
+ const returnedValue = (isCompiled ? ({ loading, run, ...(!manual && { data: response, abort }) } as TCompiledBundleType) : devResult) as TDevResult;
+ return returnedValue;
};
export default useBasicRequest;
diff --git a/packages/mlz-adminer/src/shared/basic-request-hook/index.type.ts b/packages/mlz-adminer/src/shared/basic-request-hook/index.type.ts
old mode 100644
new mode 100755
diff --git a/packages/mlz-adminer/src/shared/index.tsx b/packages/mlz-adminer/src/shared/index.tsx
old mode 100644
new mode 100755
diff --git a/packages/mlz-adminer/src/shared/service/index.ts b/packages/mlz-adminer/src/shared/service/index.ts
index c0a686d6..1dcacd40 100755
--- a/packages/mlz-adminer/src/shared/service/index.ts
+++ b/packages/mlz-adminer/src/shared/service/index.ts
@@ -44,7 +44,7 @@ export type IHttpObject = Record {
- $http[method] = async (url: URL['href'], opts?: Partial) => {
+ $http[method] = async (url: URL['href'], opts?: Partial): Promise => {
const { host = config[env]?.['hosts']?.['open-service'], data, params, ...rests } = opts || {};
return umiRequest[method](`${host}/${url.replace(/^\//g, '')}`, {
data,
diff --git a/packages/mlz-adminer/src/shared/utils/index.ts b/packages/mlz-adminer/src/shared/utils/index.ts
old mode 100644
new mode 100755
diff --git a/packages/mlz-adminer/src/use-auth-guard/accessories/auth-menu.tsx b/packages/mlz-adminer/src/use-auth-guard/accessories/auth-menu.tsx
new file mode 100755
index 00000000..34c7bb26
--- /dev/null
+++ b/packages/mlz-adminer/src/use-auth-guard/accessories/auth-menu.tsx
@@ -0,0 +1,14 @@
+import React, { createContext, useContext } from 'react';
+import useAuthGuard from '..';
+
+const InnerAuthMenu = (props: any) => {
+ console.log(props, 'InnerAuthMenu');
+ return 1234
;
+};
+
+const AuthMenu = (props?: any) => {
+ const { AuthGuard } = useAuthGuard();
+ return {(info) => };
+};
+
+export default AuthMenu;
diff --git a/packages/mlz-adminer/src/use-auth-guard/accessories/auth-resource.tsx b/packages/mlz-adminer/src/use-auth-guard/accessories/auth-resource.tsx
new file mode 100755
index 00000000..fed2aaa1
--- /dev/null
+++ b/packages/mlz-adminer/src/use-auth-guard/accessories/auth-resource.tsx
@@ -0,0 +1,7 @@
+import React, { createContext, useContext } from 'react';
+
+const AuthResource = (props?: any) => {
+ return resources
;
+};
+
+export default AuthResource;
diff --git a/packages/mlz-adminer/src/use-auth-guard/controller.ts b/packages/mlz-adminer/src/use-auth-guard/controller.ts
new file mode 100755
index 00000000..bfa59471
--- /dev/null
+++ b/packages/mlz-adminer/src/use-auth-guard/controller.ts
@@ -0,0 +1,37 @@
+import $http, { paramsDiverter } from '../shared/service';
+import config, { isCompiled, env, mockHost, redirectMiddleService, OpenServiceHOST } from '../shared/service/constant';
+import { TMenuResponse, TResourceResponse, IAuthRequestParams } from './index.type';
+
+const { timeout = 5000 } = config?.[env] || {};
+
+// 获取菜单列表
+export const getMenus = (params?: IAuthRequestParams): Promise => {
+ const { host } = params || {};
+ const DECODE_PHONE_MOCK_URL = `${mockHost}/menus`;
+ const logoutURL = isCompiled ? `${host || OpenServiceHOST}/decode/phone_number` : redirectMiddleService;
+ const requestUrl = new URL(logoutURL);
+
+ return >$http.post(requestUrl.pathname, {
+ timeout,
+ ...paramsDiverter(params || {}, {
+ data: { url: `${DECODE_PHONE_MOCK_URL}` },
+ }),
+ host: host || `https://${requestUrl.host}`,
+ });
+};
+
+// 获取资源列表
+export const getResources = (params?: IAuthRequestParams): Promise => {
+ const { host } = params || {};
+ const DECODE_PHONE_MOCK_URL = `${mockHost}/resources`;
+ const logoutURL = isCompiled ? `${OpenServiceHOST}/decode/phone_number` : redirectMiddleService;
+ const requestUrl = new URL(logoutURL);
+
+ return >$http.post(requestUrl.pathname, {
+ timeout,
+ ...paramsDiverter(params || {}, {
+ data: { url: `${DECODE_PHONE_MOCK_URL}` },
+ }),
+ host: host || `https://${requestUrl.host}`,
+ });
+};
diff --git a/packages/mlz-adminer/src/use-auth-guard/index.tsx b/packages/mlz-adminer/src/use-auth-guard/index.tsx
new file mode 100755
index 00000000..005ad6e0
--- /dev/null
+++ b/packages/mlz-adminer/src/use-auth-guard/index.tsx
@@ -0,0 +1,66 @@
+import React, { createContext, useContext, useMemo } from 'react';
+import useBasicRequest from '../shared/basic-request-hook';
+import { useAuthGuardOptions, TMenuListItem, TResourceListItem, IAuthGuardProps } from './index.type';
+import AuthMenu from './accessories/auth-menu';
+import AuthResource from './accessories/auth-resource';
+import { default as Auth } from './model';
+
+/**
+ * 创建context
+ */
+export const Context = createContext<{ menus: TMenuListItem[]; resources: TResourceListItem[]; routes: any[] }>({
+ menus: [],
+ resources: [],
+ routes: [],
+});
+
+//
+const useAuthGuard = (options?: useAuthGuardOptions, deps?: any[]) => {
+ const context = useContext(Context);
+
+ const { data: menus = [{ menu_code: '/a/b' }, { menu_code: '/c/d' }] } = useBasicRequest(Auth.create().getMenus, { deps, ...options });
+ const { data: resources = [] } = useBasicRequest(Auth.create().getResources, { deps, ...options });
+
+ /**
+ * 需求:
+ * 1.根据menus分配前端动态路由,没有的不允许访问。
+ * 2.根据resources对应的resource_url,在status为YES的情况下,也要成为生成路由的素材。
+ * 3.
+ */
+ const routes = [
+ ...menus.map(($m) => $m.menu_code),
+ ...resources.map(($r) => {
+ if ($r.status === 'YES') {
+ return $r.resource_url;
+ } else {
+ return undefined;
+ }
+ }),
+ ].filter((rt) => rt);
+
+ const AuthGuard = useMemo(() => {
+ const contextPayload = {
+ menus,
+ resources,
+ routes,
+ };
+ return (props: IAuthGuardProps) => {
+ const { children } = props;
+ return (
+ <>{children(contextPayload)}>
+
+ // 权限系统目前来看,可以视为一个常量,用于派生
+ // 对应的menus或resources,所以不需要context后续更改
+ //
+ //
+ // {() => children(contextPayload)}
+ //
+ );
+ };
+ }, []);
+
+ return { menus, resources, routes, AuthGuard, _Context: Context };
+};
+
+export { AuthMenu, AuthResource };
+export default useAuthGuard;
diff --git a/packages/mlz-adminer/src/use-auth-guard/index.type.ts b/packages/mlz-adminer/src/use-auth-guard/index.type.ts
new file mode 100755
index 00000000..63ac7220
--- /dev/null
+++ b/packages/mlz-adminer/src/use-auth-guard/index.type.ts
@@ -0,0 +1,47 @@
+import React from 'react';
+
+export type TContact = {
+ id: string;
+ name: string;
+};
+
+export type TMenuListItem = {
+ menu_code: string;
+ menu_id: number;
+ menu_name: string;
+ order_number: number;
+ parent_id: number;
+};
+
+export interface TMenuResponse extends Response {
+ readonly appid: number;
+ readonly app_name: string;
+ readonly authorizationContact: TContact;
+ readonly menu_list: TMenuListItem[];
+}
+
+export type TResourceListItem = {
+ description: string;
+ resourceId: number;
+ resource_code: string;
+ resource_name: string;
+ resource_url: string;
+ status: 'YES' | 'NO';
+};
+
+export interface TResourceResponse extends Response {
+ readonly app_id: number;
+ readonly app_name: string;
+ readonly menu_id: number;
+ readonly resources: TResourceListItem[];
+}
+
+export interface useAuthGuardOptions {}
+
+export interface IAuthRequestParams {
+ host?: string;
+}
+
+export interface IAuthGuardProps {
+ children: (...args: any) => React.ReactElement;
+}
diff --git a/packages/mlz-adminer/src/use-auth-guard/model.ts b/packages/mlz-adminer/src/use-auth-guard/model.ts
new file mode 100755
index 00000000..d8356d0b
--- /dev/null
+++ b/packages/mlz-adminer/src/use-auth-guard/model.ts
@@ -0,0 +1,24 @@
+import { getMenus, getResources } from './controller';
+import { TMenuListItem, TResourceListItem } from './index.type';
+
+export default class Auth {
+ readonly menus: TMenuListItem[] = [];
+
+ readonly resources: TResourceListItem[] = [];
+
+ static create = () => {
+ return new Auth();
+ };
+
+ getMenus = async () => {
+ const menus = await getMenus();
+ return menus;
+ };
+
+ getResources = async () => {
+ const resources = await getResources();
+ return resources;
+ };
+
+ genRouters = () => {};
+}
diff --git a/packages/mlz-adminer/src/use-staff-logout/__tests__/index.test.tsx b/packages/mlz-adminer/src/use-staff-logout/__tests__/index.test.tsx
old mode 100644
new mode 100755
diff --git a/packages/mlz-adminer/src/use-staff-logout/controller.ts b/packages/mlz-adminer/src/use-staff-logout/controller.ts
old mode 100644
new mode 100755
diff --git a/packages/mlz-adminer/src/use-staff-logout/index.type.ts b/packages/mlz-adminer/src/use-staff-logout/index.type.ts
old mode 100644
new mode 100755
diff --git a/packages/mlz-adminer/src/use-staff-logout/model.ts b/packages/mlz-adminer/src/use-staff-logout/model.ts
old mode 100644
new mode 100755
diff --git a/scripts/common/genAdminerExports.js b/scripts/common/genAdminerExports.js
index 650bd94e..fb08d5c2 100755
--- a/scripts/common/genAdminerExports.js
+++ b/scripts/common/genAdminerExports.js
@@ -7,7 +7,7 @@ const genAdminerExports = () =>
genExports(ADMINER_SRC_PATH, {
donotCamelizes: [],
donotCompiles: ['service'],
- extraContents: [],
+ extraContents: [`export { AuthMenu } from './use-auth-guard';`, ` export { AuthResource } from './use-auth-guard';`],
});
module.exports = genAdminerExports;
diff --git a/scripts/common/genVersion.js b/scripts/common/genVersion.js
index feae99c4..27308694 100755
--- a/scripts/common/genVersion.js
+++ b/scripts/common/genVersion.js
@@ -1,6 +1,6 @@
#!/usr/bin/env node
-const pkg = require('../../package.json');
+const { version } = require('../../lerna.json');
const antdVersion = require('../../node_modules/antd/package.json').version;
-module.exports = (opt = {}) => `export const version = '${pkg.version}';\n\r
+module.exports = (opt = {}) => `export const version = '${version}';\n\r
export const AntdVersion = '${opt.antdVersion || antdVersion}';`;