@pisell/core 0.0.2
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.
- package/README.md +1 -0
- package/es/app/app.d.ts +101 -0
- package/es/app/app.js +177 -0
- package/es/app/const.d.ts +4 -0
- package/es/app/const.js +6 -0
- package/es/app/index.d.ts +14 -0
- package/es/app/index.js +52 -0
- package/es/applicationManager/application.d.ts +197 -0
- package/es/applicationManager/application.js +469 -0
- package/es/applicationManager/index.d.ts +19 -0
- package/es/applicationManager/index.js +206 -0
- package/es/aws/index.d.ts +16 -0
- package/es/aws/index.js +76 -0
- package/es/cmd/const.d.ts +11 -0
- package/es/cmd/const.js +13 -0
- package/es/cmd/index.d.ts +13 -0
- package/es/cmd/index.js +91 -0
- package/es/cmd/type.d.ts +5 -0
- package/es/cmd/type.js +1 -0
- package/es/communicationManager/index.d.ts +59 -0
- package/es/communicationManager/index.js +174 -0
- package/es/config.d.ts +3 -0
- package/es/config.js +14 -0
- package/es/cookie/index.d.ts +13 -0
- package/es/cookie/index.js +47 -0
- package/es/css/global.less +73 -0
- package/es/css/index.less +31 -0
- package/es/css/variables.css +84 -0
- package/es/data/index.d.ts +8 -0
- package/es/data/index.js +16 -0
- package/es/history/config.d.ts +24 -0
- package/es/history/config.js +43 -0
- package/es/history/index.d.ts +26 -0
- package/es/history/index.js +80 -0
- package/es/history/type.d.ts +2 -0
- package/es/history/type.js +1 -0
- package/es/hooks/index.d.ts +12 -0
- package/es/hooks/index.js +13 -0
- package/es/hooks/useDelayedValue/index.d.ts +2 -0
- package/es/hooks/useDelayedValue/index.js +26 -0
- package/es/hooks/useDispatch/index.d.ts +2 -0
- package/es/hooks/useDispatch/index.js +2 -0
- package/es/hooks/useLowCode/index.d.ts +13 -0
- package/es/hooks/useLowCode/index.js +74 -0
- package/es/hooks/useStore/index.d.ts +6 -0
- package/es/hooks/useStore/index.js +11 -0
- package/es/index.d.ts +8 -0
- package/es/index.js +10 -0
- package/es/indexDB/index.d.ts +296 -0
- package/es/indexDB/index.js +1619 -0
- package/es/locales/en.d.ts +3 -0
- package/es/locales/en.js +5 -0
- package/es/locales/index.d.ts +39 -0
- package/es/locales/index.js +199 -0
- package/es/locales/original.d.ts +3 -0
- package/es/locales/original.js +7 -0
- package/es/locales/type.d.ts +19 -0
- package/es/locales/type.js +1 -0
- package/es/locales/zh-CN.d.ts +3 -0
- package/es/locales/zh-CN.js +5 -0
- package/es/locales/zh-HK.d.ts +3 -0
- package/es/locales/zh-HK.js +5 -0
- package/es/logger/feishu.d.ts +11 -0
- package/es/logger/feishu.js +50 -0
- package/es/logger/index.d.ts +135 -0
- package/es/logger/index.js +870 -0
- package/es/menuManager/hooks.d.ts +17 -0
- package/es/menuManager/hooks.js +136 -0
- package/es/menuManager/index.d.ts +28 -0
- package/es/menuManager/index.js +165 -0
- package/es/models/global.d.ts +32 -0
- package/es/models/global.js +66 -0
- package/es/models/index.d.ts +45 -0
- package/es/models/index.js +65 -0
- package/es/models/type.d.ts +2 -0
- package/es/models/type.js +1 -0
- package/es/plugin/index.d.ts +0 -0
- package/es/plugin/index.js +0 -0
- package/es/pubsub/example.d.ts +5 -0
- package/es/pubsub/example.js +92 -0
- package/es/pubsub/index.d.ts +73 -0
- package/es/pubsub/index.js +166 -0
- package/es/render/index.d.ts +0 -0
- package/es/render/index.js +0 -0
- package/es/request/cache.d.ts +46 -0
- package/es/request/cache.js +372 -0
- package/es/request/cancelToken.d.ts +38 -0
- package/es/request/cancelToken.js +59 -0
- package/es/request/config.d.ts +3 -0
- package/es/request/config.js +63 -0
- package/es/request/constants.d.ts +2 -0
- package/es/request/constants.js +6 -0
- package/es/request/index.d.ts +24 -0
- package/es/request/index.js +267 -0
- package/es/request/pisell2Request.d.ts +6 -0
- package/es/request/pisell2Request.js +62 -0
- package/es/request/type.d.ts +57 -0
- package/es/request/type.js +10 -0
- package/es/request/utils.d.ts +46 -0
- package/es/request/utils.js +147 -0
- package/es/routes/config.d.ts +7 -0
- package/es/routes/config.js +17 -0
- package/es/routes/index.d.ts +28 -0
- package/es/routes/index.js +151 -0
- package/es/socket/components/SocketMonitorPage.d.ts +6 -0
- package/es/socket/components/SocketMonitorPage.js +485 -0
- package/es/socket/components/index.d.ts +2 -0
- package/es/socket/components/index.js +2 -0
- package/es/socket/constants.d.ts +33 -0
- package/es/socket/constants.js +39 -0
- package/es/socket/events.d.ts +31 -0
- package/es/socket/events.js +19 -0
- package/es/socket/heartbeat.d.ts +66 -0
- package/es/socket/heartbeat.js +184 -0
- package/es/socket/index.d.ts +61 -0
- package/es/socket/index.js +246 -0
- package/es/socket/monitor.d.ts +169 -0
- package/es/socket/monitor.js +448 -0
- package/es/socket/reconnect.d.ts +61 -0
- package/es/socket/reconnect.js +199 -0
- package/es/socket/socket.d.ts +130 -0
- package/es/socket/socket.js +613 -0
- package/es/socket/types.d.ts +85 -0
- package/es/socket/types.js +35 -0
- package/es/storage/index.d.ts +17 -0
- package/es/storage/index.js +46 -0
- package/es/tasks/index.d.ts +127 -0
- package/es/tasks/index.js +1119 -0
- package/es/tasks/scheduledTasksExample.d.ts +61 -0
- package/es/tasks/scheduledTasksExample.js +351 -0
- package/es/tasks/type.d.ts +100 -0
- package/es/tasks/type.js +1 -0
- package/es/tasks/useTasks.d.ts +5 -0
- package/es/tasks/useTasks.js +25 -0
- package/es/type.d.ts +2 -0
- package/es/type.js +1 -0
- package/es/utils/adaptiveThrottle/index.d.ts +36 -0
- package/es/utils/adaptiveThrottle/index.js +136 -0
- package/es/variables/VariablesProvider.d.ts +7 -0
- package/es/variables/VariablesProvider.js +12 -0
- package/es/variables/config.d.ts +3 -0
- package/es/variables/config.js +16 -0
- package/es/variables/index.d.ts +6 -0
- package/es/variables/index.js +5 -0
- package/es/variables/type.d.ts +2 -0
- package/es/variables/type.js +1 -0
- package/es/website/index.d.ts +6 -0
- package/es/website/index.js +65 -0
- package/lib/app/app.d.ts +101 -0
- package/lib/app/app.js +171 -0
- package/lib/app/const.d.ts +4 -0
- package/lib/app/const.js +33 -0
- package/lib/app/index.d.ts +14 -0
- package/lib/app/index.js +76 -0
- package/lib/applicationManager/application.d.ts +197 -0
- package/lib/applicationManager/application.js +280 -0
- package/lib/applicationManager/index.d.ts +19 -0
- package/lib/applicationManager/index.js +88 -0
- package/lib/aws/index.d.ts +16 -0
- package/lib/aws/index.js +67 -0
- package/lib/cmd/const.d.ts +11 -0
- package/lib/cmd/const.js +39 -0
- package/lib/cmd/index.d.ts +13 -0
- package/lib/cmd/index.js +96 -0
- package/lib/cmd/type.d.ts +5 -0
- package/lib/cmd/type.js +17 -0
- package/lib/communicationManager/index.d.ts +59 -0
- package/lib/communicationManager/index.js +102 -0
- package/lib/config.d.ts +3 -0
- package/lib/config.js +36 -0
- package/lib/cookie/index.d.ts +13 -0
- package/lib/cookie/index.js +62 -0
- package/lib/css/global.less +73 -0
- package/lib/css/index.less +31 -0
- package/lib/css/variables.css +84 -0
- package/lib/data/index.d.ts +8 -0
- package/lib/data/index.js +38 -0
- package/lib/history/config.d.ts +24 -0
- package/lib/history/config.js +41 -0
- package/lib/history/index.d.ts +26 -0
- package/lib/history/index.js +99 -0
- package/lib/history/type.d.ts +2 -0
- package/lib/history/type.js +17 -0
- package/lib/hooks/index.d.ts +12 -0
- package/lib/hooks/index.js +44 -0
- package/lib/hooks/useDelayedValue/index.d.ts +2 -0
- package/lib/hooks/useDelayedValue/index.js +36 -0
- package/lib/hooks/useDispatch/index.d.ts +2 -0
- package/lib/hooks/useDispatch/index.js +26 -0
- package/lib/hooks/useLowCode/index.d.ts +13 -0
- package/lib/hooks/useLowCode/index.js +75 -0
- package/lib/hooks/useStore/index.d.ts +6 -0
- package/lib/hooks/useStore/index.js +33 -0
- package/lib/index.d.ts +8 -0
- package/lib/index.js +58 -0
- package/lib/indexDB/index.d.ts +296 -0
- package/lib/indexDB/index.js +767 -0
- package/lib/locales/en.d.ts +3 -0
- package/lib/locales/en.js +29 -0
- package/lib/locales/index.d.ts +39 -0
- package/lib/locales/index.js +159 -0
- package/lib/locales/original.d.ts +3 -0
- package/lib/locales/original.js +31 -0
- package/lib/locales/type.d.ts +19 -0
- package/lib/locales/type.js +17 -0
- package/lib/locales/zh-CN.d.ts +3 -0
- package/lib/locales/zh-CN.js +29 -0
- package/lib/locales/zh-HK.d.ts +3 -0
- package/lib/locales/zh-HK.js +29 -0
- package/lib/logger/feishu.d.ts +11 -0
- package/lib/logger/feishu.js +52 -0
- package/lib/logger/index.d.ts +135 -0
- package/lib/logger/index.js +476 -0
- package/lib/menuManager/hooks.d.ts +17 -0
- package/lib/menuManager/hooks.js +135 -0
- package/lib/menuManager/index.d.ts +28 -0
- package/lib/menuManager/index.js +125 -0
- package/lib/models/global.d.ts +32 -0
- package/lib/models/global.js +62 -0
- package/lib/models/index.d.ts +45 -0
- package/lib/models/index.js +69 -0
- package/lib/models/type.d.ts +2 -0
- package/lib/models/type.js +17 -0
- package/lib/plugin/index.d.ts +0 -0
- package/lib/plugin/index.js +0 -0
- package/lib/pubsub/example.d.ts +5 -0
- package/lib/pubsub/example.js +61 -0
- package/lib/pubsub/index.d.ts +73 -0
- package/lib/pubsub/index.js +141 -0
- package/lib/render/index.d.ts +0 -0
- package/lib/render/index.js +0 -0
- package/lib/request/cache.d.ts +46 -0
- package/lib/request/cache.js +195 -0
- package/lib/request/cancelToken.d.ts +38 -0
- package/lib/request/cancelToken.js +59 -0
- package/lib/request/config.d.ts +3 -0
- package/lib/request/config.js +69 -0
- package/lib/request/constants.d.ts +2 -0
- package/lib/request/constants.js +34 -0
- package/lib/request/index.d.ts +24 -0
- package/lib/request/index.js +210 -0
- package/lib/request/pisell2Request.d.ts +6 -0
- package/lib/request/pisell2Request.js +75 -0
- package/lib/request/type.d.ts +57 -0
- package/lib/request/type.js +36 -0
- package/lib/request/utils.d.ts +46 -0
- package/lib/request/utils.js +113 -0
- package/lib/routes/config.d.ts +7 -0
- package/lib/routes/config.js +50 -0
- package/lib/routes/index.d.ts +28 -0
- package/lib/routes/index.js +121 -0
- package/lib/socket/components/SocketMonitorPage.d.ts +6 -0
- package/lib/socket/components/SocketMonitorPage.js +340 -0
- package/lib/socket/components/index.d.ts +2 -0
- package/lib/socket/components/index.js +39 -0
- package/lib/socket/constants.d.ts +33 -0
- package/lib/socket/constants.js +62 -0
- package/lib/socket/events.d.ts +31 -0
- package/lib/socket/events.js +44 -0
- package/lib/socket/heartbeat.d.ts +66 -0
- package/lib/socket/heartbeat.js +157 -0
- package/lib/socket/index.d.ts +61 -0
- package/lib/socket/index.js +198 -0
- package/lib/socket/monitor.d.ts +169 -0
- package/lib/socket/monitor.js +350 -0
- package/lib/socket/reconnect.d.ts +61 -0
- package/lib/socket/reconnect.js +157 -0
- package/lib/socket/socket.d.ts +130 -0
- package/lib/socket/socket.js +426 -0
- package/lib/socket/types.d.ts +85 -0
- package/lib/socket/types.js +36 -0
- package/lib/storage/index.d.ts +17 -0
- package/lib/storage/index.js +64 -0
- package/lib/tasks/index.d.ts +127 -0
- package/lib/tasks/index.js +710 -0
- package/lib/tasks/scheduledTasksExample.d.ts +61 -0
- package/lib/tasks/scheduledTasksExample.js +267 -0
- package/lib/tasks/type.d.ts +100 -0
- package/lib/tasks/type.js +17 -0
- package/lib/tasks/useTasks.d.ts +5 -0
- package/lib/tasks/useTasks.js +37 -0
- package/lib/type.d.ts +2 -0
- package/lib/type.js +17 -0
- package/lib/utils/adaptiveThrottle/index.d.ts +36 -0
- package/lib/utils/adaptiveThrottle/index.js +121 -0
- package/lib/variables/VariablesProvider.d.ts +7 -0
- package/lib/variables/VariablesProvider.js +51 -0
- package/lib/variables/config.d.ts +3 -0
- package/lib/variables/config.js +38 -0
- package/lib/variables/index.d.ts +6 -0
- package/lib/variables/index.js +29 -0
- package/lib/variables/type.d.ts +2 -0
- package/lib/variables/type.js +17 -0
- package/lib/website/index.d.ts +6 -0
- package/lib/website/index.js +75 -0
- package/package.json +49 -0
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { MenuItem } from "./index";
|
|
3
|
+
export declare const isHttp: (url: string) => boolean;
|
|
4
|
+
export interface MenuContextType {
|
|
5
|
+
selectedKeys: string[];
|
|
6
|
+
openKeys: string[];
|
|
7
|
+
setOpenKeys: (keys: string[]) => void;
|
|
8
|
+
handleClick: (key: string) => void;
|
|
9
|
+
menuItems: MenuItem[];
|
|
10
|
+
getShowChildren: (children: MenuItem[]) => MenuItem[];
|
|
11
|
+
setMenuItems: (items: MenuItem[]) => void;
|
|
12
|
+
}
|
|
13
|
+
export declare const MenuProvider: React.FC<{
|
|
14
|
+
children: React.ReactNode;
|
|
15
|
+
menus: MenuItem[];
|
|
16
|
+
}>;
|
|
17
|
+
export declare const useMenu: () => MenuContextType;
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
2
|
+
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
3
|
+
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
4
|
+
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
5
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
6
|
+
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
7
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
8
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
9
|
+
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
|
|
10
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
11
|
+
import React, { createContext, useContext, useState, useEffect } from "react";
|
|
12
|
+
import { useApp } from "../app";
|
|
13
|
+
// 是否 http https 前缀
|
|
14
|
+
export var isHttp = function isHttp(url) {
|
|
15
|
+
return /^http(s)?:\/\//.test(url);
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* 处理路由参数的工具函数
|
|
19
|
+
* @param targetPath 目标路径(可能包含动态参数)
|
|
20
|
+
* @param currentPath 当前路径
|
|
21
|
+
* @returns 处理后的实际路径
|
|
22
|
+
*/
|
|
23
|
+
function handleRouteParams(targetPath, currentPath) {
|
|
24
|
+
// 如果目标路径不包含动态参数,直接返回
|
|
25
|
+
if (!targetPath.includes(':')) {
|
|
26
|
+
return targetPath;
|
|
27
|
+
}
|
|
28
|
+
var currentParams = {};
|
|
29
|
+
var pathSegments = currentPath.split('/');
|
|
30
|
+
var targetSegments = targetPath.split('/');
|
|
31
|
+
|
|
32
|
+
// 提取动态参数
|
|
33
|
+
targetSegments.forEach(function (segment, index) {
|
|
34
|
+
if (segment.startsWith(':')) {
|
|
35
|
+
var paramName = segment.slice(1);
|
|
36
|
+
currentParams[paramName] = pathSegments[index] || '';
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
// 替换动态参数
|
|
41
|
+
return targetPath.replace(/:(\w+)/g, function (match, key) {
|
|
42
|
+
var _currentParams$key;
|
|
43
|
+
return ((_currentParams$key = currentParams[key]) === null || _currentParams$key === void 0 ? void 0 : _currentParams$key.toString()) || match;
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
var MenuContext = /*#__PURE__*/createContext(undefined);
|
|
47
|
+
export var MenuProvider = function MenuProvider(_ref) {
|
|
48
|
+
var children = _ref.children,
|
|
49
|
+
menus = _ref.menus;
|
|
50
|
+
var _useApp = useApp(),
|
|
51
|
+
app = _useApp.app;
|
|
52
|
+
var menuManager = app.menuManager;
|
|
53
|
+
var location = app.history.useLocation();
|
|
54
|
+
var _useState = useState([]),
|
|
55
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
56
|
+
selectedKeys = _useState2[0],
|
|
57
|
+
setSelectedKeys = _useState2[1];
|
|
58
|
+
var _useState3 = useState([]),
|
|
59
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
60
|
+
openKeys = _useState4[0],
|
|
61
|
+
setOpenKeys = _useState4[1];
|
|
62
|
+
var _useState5 = useState(menus),
|
|
63
|
+
_useState6 = _slicedToArray(_useState5, 2),
|
|
64
|
+
menuItems = _useState6[0],
|
|
65
|
+
setMenuItems = _useState6[1];
|
|
66
|
+
|
|
67
|
+
// 初始化菜单项
|
|
68
|
+
useEffect(function () {
|
|
69
|
+
app.menuManager.set(menuItems);
|
|
70
|
+
}, [menuItems]);
|
|
71
|
+
|
|
72
|
+
// 根据当前路由更新选中的菜单项和打开的子菜单
|
|
73
|
+
useEffect(function () {
|
|
74
|
+
var pathname = location.pathname;
|
|
75
|
+
// 如果 pathname 为空,则直接返回
|
|
76
|
+
if (!pathname) {
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
var currentMenuItem = menuManager.findMenuItemByPath(menuItems, pathname);
|
|
80
|
+
if (currentMenuItem) {
|
|
81
|
+
setSelectedKeys([currentMenuItem.key]);
|
|
82
|
+
var parent = menuManager.findParent(menuItems, currentMenuItem.key);
|
|
83
|
+
if (parent) {
|
|
84
|
+
var _children = menuManager.getShowChildren(parent.children || []);
|
|
85
|
+
if (_children !== null && _children !== void 0 && _children.length) {
|
|
86
|
+
setOpenKeys(function (prevKeys) {
|
|
87
|
+
return _toConsumableArray(new Set([].concat(_toConsumableArray(prevKeys), [parent.key])));
|
|
88
|
+
});
|
|
89
|
+
} else {
|
|
90
|
+
setSelectedKeys([parent.key]);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}, [location, menuItems]);
|
|
95
|
+
|
|
96
|
+
// 处理菜单项点击
|
|
97
|
+
var handleClick = function handleClick(key) {
|
|
98
|
+
try {
|
|
99
|
+
if (!key) {
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
// 处理外部链接
|
|
103
|
+
if (isHttp(key)) {
|
|
104
|
+
window.open(key, '_blank');
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
// 处理内部路由
|
|
108
|
+
var newPath = handleRouteParams(key, location.pathname);
|
|
109
|
+
if (newPath !== location.pathname) {
|
|
110
|
+
app.history.push(newPath);
|
|
111
|
+
}
|
|
112
|
+
} catch (error) {
|
|
113
|
+
console.error('Menu navigation error:', error);
|
|
114
|
+
}
|
|
115
|
+
};
|
|
116
|
+
return /*#__PURE__*/React.createElement(MenuContext.Provider, {
|
|
117
|
+
value: {
|
|
118
|
+
selectedKeys: selectedKeys,
|
|
119
|
+
openKeys: openKeys,
|
|
120
|
+
setOpenKeys: setOpenKeys,
|
|
121
|
+
handleClick: handleClick,
|
|
122
|
+
menuItems: menuItems,
|
|
123
|
+
getShowChildren: menuManager.getShowChildren,
|
|
124
|
+
setMenuItems: setMenuItems
|
|
125
|
+
}
|
|
126
|
+
}, children);
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
// 自定义hook,用于获取菜单上下文
|
|
130
|
+
export var useMenu = function useMenu() {
|
|
131
|
+
var context = useContext(MenuContext);
|
|
132
|
+
if (context === undefined) {
|
|
133
|
+
throw new Error("useMenu must be used within a MenuProvider");
|
|
134
|
+
}
|
|
135
|
+
return context;
|
|
136
|
+
};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import App from '../app';
|
|
3
|
+
export interface MenuItem {
|
|
4
|
+
key: string;
|
|
5
|
+
label: string;
|
|
6
|
+
path: string;
|
|
7
|
+
children?: MenuItem[];
|
|
8
|
+
icon?: string | React.ReactNode;
|
|
9
|
+
hide?: boolean;
|
|
10
|
+
}
|
|
11
|
+
export declare class MenuManager {
|
|
12
|
+
private menuItems;
|
|
13
|
+
private menuMaps;
|
|
14
|
+
private app;
|
|
15
|
+
useMenu: () => import("./hooks").MenuContextType;
|
|
16
|
+
MenuProvider: React.FC<{
|
|
17
|
+
children: React.ReactNode;
|
|
18
|
+
menus: MenuItem[];
|
|
19
|
+
}>;
|
|
20
|
+
constructor(items: MenuItem[], app: App);
|
|
21
|
+
set(items: MenuItem[]): void;
|
|
22
|
+
getMenus(): MenuItem[];
|
|
23
|
+
getMenuMaps(): void;
|
|
24
|
+
findMenuItemByPath(items: MenuItem[], path: string): MenuItem | null;
|
|
25
|
+
findParent(items: MenuItem[], key: string, parent?: MenuItem | null): MenuItem | null;
|
|
26
|
+
getShowChildren(items: MenuItem[]): MenuItem[];
|
|
27
|
+
findMenuItemByKey(items: MenuItem[], key: string): MenuItem | null;
|
|
28
|
+
}
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
2
|
+
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
|
|
3
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
4
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
5
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
6
|
+
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
|
|
7
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
8
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
9
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
10
|
+
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
11
|
+
import { useMenu, MenuProvider } from "./hooks";
|
|
12
|
+
export var MenuManager = /*#__PURE__*/function () {
|
|
13
|
+
function MenuManager(items, app) {
|
|
14
|
+
_classCallCheck(this, MenuManager);
|
|
15
|
+
_defineProperty(this, "menuItems", []);
|
|
16
|
+
_defineProperty(this, "menuMaps", {});
|
|
17
|
+
_defineProperty(this, "app", void 0);
|
|
18
|
+
_defineProperty(this, "useMenu", useMenu);
|
|
19
|
+
_defineProperty(this, "MenuProvider", MenuProvider);
|
|
20
|
+
this.app = app;
|
|
21
|
+
this.set(items);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// 设置菜单项
|
|
25
|
+
_createClass(MenuManager, [{
|
|
26
|
+
key: "set",
|
|
27
|
+
value: function set(items) {
|
|
28
|
+
this.menuItems = items;
|
|
29
|
+
this.getMenuMaps();
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// 获取菜单项
|
|
33
|
+
}, {
|
|
34
|
+
key: "getMenus",
|
|
35
|
+
value: function getMenus() {
|
|
36
|
+
return this.menuItems;
|
|
37
|
+
}
|
|
38
|
+
}, {
|
|
39
|
+
key: "getMenuMaps",
|
|
40
|
+
value: function getMenuMaps() {
|
|
41
|
+
var maps = {}; // 将菜单项存储在map中,方便后续查找
|
|
42
|
+
var fn = function fn(items) {
|
|
43
|
+
items.forEach(function (item) {
|
|
44
|
+
maps[item.path] = item;
|
|
45
|
+
if (item.children) {
|
|
46
|
+
fn(item.children);
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
};
|
|
50
|
+
fn(this.menuItems);
|
|
51
|
+
this.menuMaps = maps;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// 根据路径查找菜单项
|
|
55
|
+
}, {
|
|
56
|
+
key: "findMenuItemByPath",
|
|
57
|
+
value: function findMenuItemByPath(items, path) {
|
|
58
|
+
// 首先尝试精确匹配
|
|
59
|
+
var menu = this.menuMaps[path];
|
|
60
|
+
if (menu) {
|
|
61
|
+
return menu;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// 提取路径的主要部分(去掉查询参数和hash)
|
|
65
|
+
var getPathname = function getPathname(url) {
|
|
66
|
+
var questionMarkIndex = url.indexOf('?');
|
|
67
|
+
var hashIndex = url.indexOf('#');
|
|
68
|
+
var endIndex = url.length;
|
|
69
|
+
if (questionMarkIndex !== -1 && hashIndex !== -1) {
|
|
70
|
+
endIndex = Math.min(questionMarkIndex, hashIndex);
|
|
71
|
+
} else if (questionMarkIndex !== -1) {
|
|
72
|
+
endIndex = questionMarkIndex;
|
|
73
|
+
} else if (hashIndex !== -1) {
|
|
74
|
+
endIndex = hashIndex;
|
|
75
|
+
}
|
|
76
|
+
return url.substring(0, endIndex);
|
|
77
|
+
};
|
|
78
|
+
var inputPathname = getPathname(path);
|
|
79
|
+
var _iterator = _createForOfIteratorHelper(items),
|
|
80
|
+
_step;
|
|
81
|
+
try {
|
|
82
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
83
|
+
var _item$path;
|
|
84
|
+
var item = _step.value;
|
|
85
|
+
// 特殊处理 /workspaces/:id 类型的路由
|
|
86
|
+
if (item !== null && item !== void 0 && (_item$path = item.path) !== null && _item$path !== void 0 && _item$path.includes('/:') && path.startsWith(item.path.split('/:')[0])) {
|
|
87
|
+
return item;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// 比较路径的主要部分(忽略查询参数)
|
|
91
|
+
var itemPathname = getPathname((item === null || item === void 0 ? void 0 : item.path) || "");
|
|
92
|
+
if (itemPathname === inputPathname) {
|
|
93
|
+
return item;
|
|
94
|
+
}
|
|
95
|
+
if (item.children) {
|
|
96
|
+
var found = this.findMenuItemByPath(item.children, path);
|
|
97
|
+
if (found) return found;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
} catch (err) {
|
|
101
|
+
_iterator.e(err);
|
|
102
|
+
} finally {
|
|
103
|
+
_iterator.f();
|
|
104
|
+
}
|
|
105
|
+
return null;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
// 查找给定key的父级菜单key
|
|
109
|
+
}, {
|
|
110
|
+
key: "findParent",
|
|
111
|
+
value: function findParent(items, key) {
|
|
112
|
+
var parent = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
|
|
113
|
+
var _iterator2 = _createForOfIteratorHelper(items),
|
|
114
|
+
_step2;
|
|
115
|
+
try {
|
|
116
|
+
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
117
|
+
var item = _step2.value;
|
|
118
|
+
if (item.key === key) return parent;
|
|
119
|
+
if (item.children) {
|
|
120
|
+
var found = this.findParent(item.children, key, item);
|
|
121
|
+
if (found) return found;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
} catch (err) {
|
|
125
|
+
_iterator2.e(err);
|
|
126
|
+
} finally {
|
|
127
|
+
_iterator2.f();
|
|
128
|
+
}
|
|
129
|
+
return null;
|
|
130
|
+
}
|
|
131
|
+
}, {
|
|
132
|
+
key: "getShowChildren",
|
|
133
|
+
value: function getShowChildren(items) {
|
|
134
|
+
return items.filter(function (item) {
|
|
135
|
+
return !item.hide;
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
// 根据key查找菜单项
|
|
140
|
+
}, {
|
|
141
|
+
key: "findMenuItemByKey",
|
|
142
|
+
value: function findMenuItemByKey(items, key) {
|
|
143
|
+
var _iterator3 = _createForOfIteratorHelper(items),
|
|
144
|
+
_step3;
|
|
145
|
+
try {
|
|
146
|
+
for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
|
|
147
|
+
var item = _step3.value;
|
|
148
|
+
if (item.key === key) {
|
|
149
|
+
return item;
|
|
150
|
+
}
|
|
151
|
+
if (item.children) {
|
|
152
|
+
var found = this.findMenuItemByKey(item.children, key);
|
|
153
|
+
if (found) return found;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
} catch (err) {
|
|
157
|
+
_iterator3.e(err);
|
|
158
|
+
} finally {
|
|
159
|
+
_iterator3.f();
|
|
160
|
+
}
|
|
161
|
+
return null;
|
|
162
|
+
}
|
|
163
|
+
}]);
|
|
164
|
+
return MenuManager;
|
|
165
|
+
}();
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { Effect, Subscription } from 'dva';
|
|
2
|
+
import { Reducer } from 'redux';
|
|
3
|
+
export interface GlobalModal {
|
|
4
|
+
namespace: 'global';
|
|
5
|
+
state: {
|
|
6
|
+
isLogin: boolean;
|
|
7
|
+
account: any;
|
|
8
|
+
core: any;
|
|
9
|
+
isInstallAPP: boolean;
|
|
10
|
+
app: {
|
|
11
|
+
status: {
|
|
12
|
+
login: boolean;
|
|
13
|
+
storage: boolean;
|
|
14
|
+
network: boolean;
|
|
15
|
+
materials: boolean;
|
|
16
|
+
pisell2: boolean;
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
effects: {
|
|
21
|
+
init: Effect;
|
|
22
|
+
};
|
|
23
|
+
reducers: {
|
|
24
|
+
saveGlobalState: Reducer<any>;
|
|
25
|
+
setInit: Reducer<any>;
|
|
26
|
+
};
|
|
27
|
+
subscriptions: {
|
|
28
|
+
_init: Subscription;
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
declare const modal: GlobalModal;
|
|
32
|
+
export default modal;
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
2
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
3
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
4
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
5
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
6
|
+
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
7
|
+
function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw new Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator.return && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw new Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, catch: function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }
|
|
8
|
+
// @ts-ignore
|
|
9
|
+
|
|
10
|
+
var modal = {
|
|
11
|
+
namespace: 'global',
|
|
12
|
+
state: {
|
|
13
|
+
/* 测试登录逻辑状态 */
|
|
14
|
+
isLogin: false,
|
|
15
|
+
account: null,
|
|
16
|
+
core: null,
|
|
17
|
+
isInstallAPP: false,
|
|
18
|
+
app: {
|
|
19
|
+
status: {
|
|
20
|
+
login: false,
|
|
21
|
+
storage: false,
|
|
22
|
+
network: false,
|
|
23
|
+
materials: false,
|
|
24
|
+
pisell2: false
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
effects: {
|
|
29
|
+
init: function init(_ref, _ref2) {
|
|
30
|
+
var params = _ref.params;
|
|
31
|
+
var put = _ref2.put,
|
|
32
|
+
call = _ref2.call;
|
|
33
|
+
return /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
|
|
34
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
35
|
+
while (1) switch (_context.prev = _context.next) {
|
|
36
|
+
case 0:
|
|
37
|
+
case "end":
|
|
38
|
+
return _context.stop();
|
|
39
|
+
}
|
|
40
|
+
}, _callee);
|
|
41
|
+
})();
|
|
42
|
+
}
|
|
43
|
+
},
|
|
44
|
+
reducers: {
|
|
45
|
+
saveGlobalState: function saveGlobalState(state, _ref3) {
|
|
46
|
+
var params = _ref3.params;
|
|
47
|
+
console.log('params', params);
|
|
48
|
+
return _objectSpread(_objectSpread({}, state), params);
|
|
49
|
+
},
|
|
50
|
+
setInit: function setInit(state, _ref4) {
|
|
51
|
+
var payload = _ref4.payload;
|
|
52
|
+
console.log(payload);
|
|
53
|
+
return _objectSpread(_objectSpread({}, state), {}, {
|
|
54
|
+
isInstallAPP: payload
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
},
|
|
58
|
+
subscriptions: {
|
|
59
|
+
_init: function _init(_ref5) {
|
|
60
|
+
var dispatch = _ref5.dispatch;
|
|
61
|
+
} // dispatch({
|
|
62
|
+
// type: 'init',
|
|
63
|
+
// })
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
export default modal;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import hooks from '../hooks';
|
|
2
|
+
import { Provider as StoreProvider } from "react-redux";
|
|
3
|
+
declare const models: import("./global").GlobalModal[];
|
|
4
|
+
declare type ModalsType = (typeof models[number]);
|
|
5
|
+
export interface Store {
|
|
6
|
+
getDataByModel: typeof getDataByModel;
|
|
7
|
+
useStore: typeof hooks.useStore;
|
|
8
|
+
useDispatch: typeof hooks.useDispatch;
|
|
9
|
+
setDataByModel: typeof setDataByModel;
|
|
10
|
+
dispatch: any;
|
|
11
|
+
getState: any;
|
|
12
|
+
}
|
|
13
|
+
export declare type ModelsNames = ModalsType['namespace'];
|
|
14
|
+
export declare type ModelsState = {
|
|
15
|
+
[K in (ModalsType['namespace'])]: Extract<ModalsType, {
|
|
16
|
+
namespace: K;
|
|
17
|
+
}>['state'];
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* @title: 从store内获取数据
|
|
21
|
+
* @description:
|
|
22
|
+
* @param {string} model
|
|
23
|
+
* @param {string} key
|
|
24
|
+
* @return {*}
|
|
25
|
+
* @Author: zhiwei.Wang
|
|
26
|
+
* @Date: 2024-09-03 11:07
|
|
27
|
+
*/
|
|
28
|
+
declare const getDataByModel: <T extends "global", D extends keyof ModelsState[T]>(model: string, key?: D | undefined) => D extends undefined ? ModelsState[T] : ModelsState[T][D];
|
|
29
|
+
/**
|
|
30
|
+
* @title: 设置数据到store
|
|
31
|
+
* @description:
|
|
32
|
+
* @param {string} model
|
|
33
|
+
* @param {string} key
|
|
34
|
+
* @param {string} value
|
|
35
|
+
* @return {*}
|
|
36
|
+
* @Author: zhiwei.Wang
|
|
37
|
+
* @Date: 2024-09-08 15:17
|
|
38
|
+
*/
|
|
39
|
+
declare const setDataByModel: <T extends "global", D extends keyof ModelsState[T]>(model: string, key: any, value: any) => void;
|
|
40
|
+
declare const _default: {
|
|
41
|
+
getStore: () => Store;
|
|
42
|
+
StoreProvider: typeof StoreProvider;
|
|
43
|
+
setConfig: (models: any[]) => void;
|
|
44
|
+
};
|
|
45
|
+
export default _default;
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
//@ts-ignore
|
|
2
|
+
import { create } from 'dva-core';
|
|
3
|
+
import hooks from "../hooks";
|
|
4
|
+
import global from "./global";
|
|
5
|
+
import { Provider as StoreProvider } from "react-redux";
|
|
6
|
+
var models = [global];
|
|
7
|
+
var app = create();
|
|
8
|
+
models.forEach(function (item) {
|
|
9
|
+
return app.model(item);
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
// 获取_store 实例
|
|
13
|
+
var getStore = function getStore() {
|
|
14
|
+
return app._store;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* @title: 从store内获取数据
|
|
19
|
+
* @description:
|
|
20
|
+
* @param {string} model
|
|
21
|
+
* @param {string} key
|
|
22
|
+
* @return {*}
|
|
23
|
+
* @Author: zhiwei.Wang
|
|
24
|
+
* @Date: 2024-09-03 11:07
|
|
25
|
+
*/
|
|
26
|
+
var getDataByModel = function getDataByModel(model, key) {
|
|
27
|
+
var _getStore$getState;
|
|
28
|
+
var modelData = (_getStore$getState = getStore().getState()) === null || _getStore$getState === void 0 ? void 0 : _getStore$getState[model];
|
|
29
|
+
if (key !== undefined) {
|
|
30
|
+
return modelData === null || modelData === void 0 ? void 0 : modelData[key];
|
|
31
|
+
}
|
|
32
|
+
return modelData;
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* @title: 设置数据到store
|
|
37
|
+
* @description:
|
|
38
|
+
* @param {string} model
|
|
39
|
+
* @param {string} key
|
|
40
|
+
* @param {string} value
|
|
41
|
+
* @return {*}
|
|
42
|
+
* @Author: zhiwei.Wang
|
|
43
|
+
* @Date: 2024-09-08 15:17
|
|
44
|
+
*/
|
|
45
|
+
var setDataByModel = function setDataByModel(model, key, value) {
|
|
46
|
+
getStore().dispatch({
|
|
47
|
+
type: "".concat(model, "/").concat(String(key)),
|
|
48
|
+
payload: value
|
|
49
|
+
});
|
|
50
|
+
};
|
|
51
|
+
var setConfig = function setConfig(models) {
|
|
52
|
+
models.forEach(function (item) {
|
|
53
|
+
return app.model(item);
|
|
54
|
+
});
|
|
55
|
+
app.start();
|
|
56
|
+
getStore().getDataByModel = getDataByModel;
|
|
57
|
+
getStore().setDataByModel = setDataByModel;
|
|
58
|
+
getStore().useStore = hooks.useStore;
|
|
59
|
+
getStore().useDispatch = hooks.useDispatch;
|
|
60
|
+
};
|
|
61
|
+
export default {
|
|
62
|
+
getStore: getStore,
|
|
63
|
+
StoreProvider: StoreProvider,
|
|
64
|
+
setConfig: setConfig
|
|
65
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
File without changes
|
|
File without changes
|