@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.
Files changed (296) hide show
  1. package/README.md +1 -0
  2. package/es/app/app.d.ts +101 -0
  3. package/es/app/app.js +177 -0
  4. package/es/app/const.d.ts +4 -0
  5. package/es/app/const.js +6 -0
  6. package/es/app/index.d.ts +14 -0
  7. package/es/app/index.js +52 -0
  8. package/es/applicationManager/application.d.ts +197 -0
  9. package/es/applicationManager/application.js +469 -0
  10. package/es/applicationManager/index.d.ts +19 -0
  11. package/es/applicationManager/index.js +206 -0
  12. package/es/aws/index.d.ts +16 -0
  13. package/es/aws/index.js +76 -0
  14. package/es/cmd/const.d.ts +11 -0
  15. package/es/cmd/const.js +13 -0
  16. package/es/cmd/index.d.ts +13 -0
  17. package/es/cmd/index.js +91 -0
  18. package/es/cmd/type.d.ts +5 -0
  19. package/es/cmd/type.js +1 -0
  20. package/es/communicationManager/index.d.ts +59 -0
  21. package/es/communicationManager/index.js +174 -0
  22. package/es/config.d.ts +3 -0
  23. package/es/config.js +14 -0
  24. package/es/cookie/index.d.ts +13 -0
  25. package/es/cookie/index.js +47 -0
  26. package/es/css/global.less +73 -0
  27. package/es/css/index.less +31 -0
  28. package/es/css/variables.css +84 -0
  29. package/es/data/index.d.ts +8 -0
  30. package/es/data/index.js +16 -0
  31. package/es/history/config.d.ts +24 -0
  32. package/es/history/config.js +43 -0
  33. package/es/history/index.d.ts +26 -0
  34. package/es/history/index.js +80 -0
  35. package/es/history/type.d.ts +2 -0
  36. package/es/history/type.js +1 -0
  37. package/es/hooks/index.d.ts +12 -0
  38. package/es/hooks/index.js +13 -0
  39. package/es/hooks/useDelayedValue/index.d.ts +2 -0
  40. package/es/hooks/useDelayedValue/index.js +26 -0
  41. package/es/hooks/useDispatch/index.d.ts +2 -0
  42. package/es/hooks/useDispatch/index.js +2 -0
  43. package/es/hooks/useLowCode/index.d.ts +13 -0
  44. package/es/hooks/useLowCode/index.js +74 -0
  45. package/es/hooks/useStore/index.d.ts +6 -0
  46. package/es/hooks/useStore/index.js +11 -0
  47. package/es/index.d.ts +8 -0
  48. package/es/index.js +10 -0
  49. package/es/indexDB/index.d.ts +296 -0
  50. package/es/indexDB/index.js +1619 -0
  51. package/es/locales/en.d.ts +3 -0
  52. package/es/locales/en.js +5 -0
  53. package/es/locales/index.d.ts +39 -0
  54. package/es/locales/index.js +199 -0
  55. package/es/locales/original.d.ts +3 -0
  56. package/es/locales/original.js +7 -0
  57. package/es/locales/type.d.ts +19 -0
  58. package/es/locales/type.js +1 -0
  59. package/es/locales/zh-CN.d.ts +3 -0
  60. package/es/locales/zh-CN.js +5 -0
  61. package/es/locales/zh-HK.d.ts +3 -0
  62. package/es/locales/zh-HK.js +5 -0
  63. package/es/logger/feishu.d.ts +11 -0
  64. package/es/logger/feishu.js +50 -0
  65. package/es/logger/index.d.ts +135 -0
  66. package/es/logger/index.js +870 -0
  67. package/es/menuManager/hooks.d.ts +17 -0
  68. package/es/menuManager/hooks.js +136 -0
  69. package/es/menuManager/index.d.ts +28 -0
  70. package/es/menuManager/index.js +165 -0
  71. package/es/models/global.d.ts +32 -0
  72. package/es/models/global.js +66 -0
  73. package/es/models/index.d.ts +45 -0
  74. package/es/models/index.js +65 -0
  75. package/es/models/type.d.ts +2 -0
  76. package/es/models/type.js +1 -0
  77. package/es/plugin/index.d.ts +0 -0
  78. package/es/plugin/index.js +0 -0
  79. package/es/pubsub/example.d.ts +5 -0
  80. package/es/pubsub/example.js +92 -0
  81. package/es/pubsub/index.d.ts +73 -0
  82. package/es/pubsub/index.js +166 -0
  83. package/es/render/index.d.ts +0 -0
  84. package/es/render/index.js +0 -0
  85. package/es/request/cache.d.ts +46 -0
  86. package/es/request/cache.js +372 -0
  87. package/es/request/cancelToken.d.ts +38 -0
  88. package/es/request/cancelToken.js +59 -0
  89. package/es/request/config.d.ts +3 -0
  90. package/es/request/config.js +63 -0
  91. package/es/request/constants.d.ts +2 -0
  92. package/es/request/constants.js +6 -0
  93. package/es/request/index.d.ts +24 -0
  94. package/es/request/index.js +267 -0
  95. package/es/request/pisell2Request.d.ts +6 -0
  96. package/es/request/pisell2Request.js +62 -0
  97. package/es/request/type.d.ts +57 -0
  98. package/es/request/type.js +10 -0
  99. package/es/request/utils.d.ts +46 -0
  100. package/es/request/utils.js +147 -0
  101. package/es/routes/config.d.ts +7 -0
  102. package/es/routes/config.js +17 -0
  103. package/es/routes/index.d.ts +28 -0
  104. package/es/routes/index.js +151 -0
  105. package/es/socket/components/SocketMonitorPage.d.ts +6 -0
  106. package/es/socket/components/SocketMonitorPage.js +485 -0
  107. package/es/socket/components/index.d.ts +2 -0
  108. package/es/socket/components/index.js +2 -0
  109. package/es/socket/constants.d.ts +33 -0
  110. package/es/socket/constants.js +39 -0
  111. package/es/socket/events.d.ts +31 -0
  112. package/es/socket/events.js +19 -0
  113. package/es/socket/heartbeat.d.ts +66 -0
  114. package/es/socket/heartbeat.js +184 -0
  115. package/es/socket/index.d.ts +61 -0
  116. package/es/socket/index.js +246 -0
  117. package/es/socket/monitor.d.ts +169 -0
  118. package/es/socket/monitor.js +448 -0
  119. package/es/socket/reconnect.d.ts +61 -0
  120. package/es/socket/reconnect.js +199 -0
  121. package/es/socket/socket.d.ts +130 -0
  122. package/es/socket/socket.js +613 -0
  123. package/es/socket/types.d.ts +85 -0
  124. package/es/socket/types.js +35 -0
  125. package/es/storage/index.d.ts +17 -0
  126. package/es/storage/index.js +46 -0
  127. package/es/tasks/index.d.ts +127 -0
  128. package/es/tasks/index.js +1119 -0
  129. package/es/tasks/scheduledTasksExample.d.ts +61 -0
  130. package/es/tasks/scheduledTasksExample.js +351 -0
  131. package/es/tasks/type.d.ts +100 -0
  132. package/es/tasks/type.js +1 -0
  133. package/es/tasks/useTasks.d.ts +5 -0
  134. package/es/tasks/useTasks.js +25 -0
  135. package/es/type.d.ts +2 -0
  136. package/es/type.js +1 -0
  137. package/es/utils/adaptiveThrottle/index.d.ts +36 -0
  138. package/es/utils/adaptiveThrottle/index.js +136 -0
  139. package/es/variables/VariablesProvider.d.ts +7 -0
  140. package/es/variables/VariablesProvider.js +12 -0
  141. package/es/variables/config.d.ts +3 -0
  142. package/es/variables/config.js +16 -0
  143. package/es/variables/index.d.ts +6 -0
  144. package/es/variables/index.js +5 -0
  145. package/es/variables/type.d.ts +2 -0
  146. package/es/variables/type.js +1 -0
  147. package/es/website/index.d.ts +6 -0
  148. package/es/website/index.js +65 -0
  149. package/lib/app/app.d.ts +101 -0
  150. package/lib/app/app.js +171 -0
  151. package/lib/app/const.d.ts +4 -0
  152. package/lib/app/const.js +33 -0
  153. package/lib/app/index.d.ts +14 -0
  154. package/lib/app/index.js +76 -0
  155. package/lib/applicationManager/application.d.ts +197 -0
  156. package/lib/applicationManager/application.js +280 -0
  157. package/lib/applicationManager/index.d.ts +19 -0
  158. package/lib/applicationManager/index.js +88 -0
  159. package/lib/aws/index.d.ts +16 -0
  160. package/lib/aws/index.js +67 -0
  161. package/lib/cmd/const.d.ts +11 -0
  162. package/lib/cmd/const.js +39 -0
  163. package/lib/cmd/index.d.ts +13 -0
  164. package/lib/cmd/index.js +96 -0
  165. package/lib/cmd/type.d.ts +5 -0
  166. package/lib/cmd/type.js +17 -0
  167. package/lib/communicationManager/index.d.ts +59 -0
  168. package/lib/communicationManager/index.js +102 -0
  169. package/lib/config.d.ts +3 -0
  170. package/lib/config.js +36 -0
  171. package/lib/cookie/index.d.ts +13 -0
  172. package/lib/cookie/index.js +62 -0
  173. package/lib/css/global.less +73 -0
  174. package/lib/css/index.less +31 -0
  175. package/lib/css/variables.css +84 -0
  176. package/lib/data/index.d.ts +8 -0
  177. package/lib/data/index.js +38 -0
  178. package/lib/history/config.d.ts +24 -0
  179. package/lib/history/config.js +41 -0
  180. package/lib/history/index.d.ts +26 -0
  181. package/lib/history/index.js +99 -0
  182. package/lib/history/type.d.ts +2 -0
  183. package/lib/history/type.js +17 -0
  184. package/lib/hooks/index.d.ts +12 -0
  185. package/lib/hooks/index.js +44 -0
  186. package/lib/hooks/useDelayedValue/index.d.ts +2 -0
  187. package/lib/hooks/useDelayedValue/index.js +36 -0
  188. package/lib/hooks/useDispatch/index.d.ts +2 -0
  189. package/lib/hooks/useDispatch/index.js +26 -0
  190. package/lib/hooks/useLowCode/index.d.ts +13 -0
  191. package/lib/hooks/useLowCode/index.js +75 -0
  192. package/lib/hooks/useStore/index.d.ts +6 -0
  193. package/lib/hooks/useStore/index.js +33 -0
  194. package/lib/index.d.ts +8 -0
  195. package/lib/index.js +58 -0
  196. package/lib/indexDB/index.d.ts +296 -0
  197. package/lib/indexDB/index.js +767 -0
  198. package/lib/locales/en.d.ts +3 -0
  199. package/lib/locales/en.js +29 -0
  200. package/lib/locales/index.d.ts +39 -0
  201. package/lib/locales/index.js +159 -0
  202. package/lib/locales/original.d.ts +3 -0
  203. package/lib/locales/original.js +31 -0
  204. package/lib/locales/type.d.ts +19 -0
  205. package/lib/locales/type.js +17 -0
  206. package/lib/locales/zh-CN.d.ts +3 -0
  207. package/lib/locales/zh-CN.js +29 -0
  208. package/lib/locales/zh-HK.d.ts +3 -0
  209. package/lib/locales/zh-HK.js +29 -0
  210. package/lib/logger/feishu.d.ts +11 -0
  211. package/lib/logger/feishu.js +52 -0
  212. package/lib/logger/index.d.ts +135 -0
  213. package/lib/logger/index.js +476 -0
  214. package/lib/menuManager/hooks.d.ts +17 -0
  215. package/lib/menuManager/hooks.js +135 -0
  216. package/lib/menuManager/index.d.ts +28 -0
  217. package/lib/menuManager/index.js +125 -0
  218. package/lib/models/global.d.ts +32 -0
  219. package/lib/models/global.js +62 -0
  220. package/lib/models/index.d.ts +45 -0
  221. package/lib/models/index.js +69 -0
  222. package/lib/models/type.d.ts +2 -0
  223. package/lib/models/type.js +17 -0
  224. package/lib/plugin/index.d.ts +0 -0
  225. package/lib/plugin/index.js +0 -0
  226. package/lib/pubsub/example.d.ts +5 -0
  227. package/lib/pubsub/example.js +61 -0
  228. package/lib/pubsub/index.d.ts +73 -0
  229. package/lib/pubsub/index.js +141 -0
  230. package/lib/render/index.d.ts +0 -0
  231. package/lib/render/index.js +0 -0
  232. package/lib/request/cache.d.ts +46 -0
  233. package/lib/request/cache.js +195 -0
  234. package/lib/request/cancelToken.d.ts +38 -0
  235. package/lib/request/cancelToken.js +59 -0
  236. package/lib/request/config.d.ts +3 -0
  237. package/lib/request/config.js +69 -0
  238. package/lib/request/constants.d.ts +2 -0
  239. package/lib/request/constants.js +34 -0
  240. package/lib/request/index.d.ts +24 -0
  241. package/lib/request/index.js +210 -0
  242. package/lib/request/pisell2Request.d.ts +6 -0
  243. package/lib/request/pisell2Request.js +75 -0
  244. package/lib/request/type.d.ts +57 -0
  245. package/lib/request/type.js +36 -0
  246. package/lib/request/utils.d.ts +46 -0
  247. package/lib/request/utils.js +113 -0
  248. package/lib/routes/config.d.ts +7 -0
  249. package/lib/routes/config.js +50 -0
  250. package/lib/routes/index.d.ts +28 -0
  251. package/lib/routes/index.js +121 -0
  252. package/lib/socket/components/SocketMonitorPage.d.ts +6 -0
  253. package/lib/socket/components/SocketMonitorPage.js +340 -0
  254. package/lib/socket/components/index.d.ts +2 -0
  255. package/lib/socket/components/index.js +39 -0
  256. package/lib/socket/constants.d.ts +33 -0
  257. package/lib/socket/constants.js +62 -0
  258. package/lib/socket/events.d.ts +31 -0
  259. package/lib/socket/events.js +44 -0
  260. package/lib/socket/heartbeat.d.ts +66 -0
  261. package/lib/socket/heartbeat.js +157 -0
  262. package/lib/socket/index.d.ts +61 -0
  263. package/lib/socket/index.js +198 -0
  264. package/lib/socket/monitor.d.ts +169 -0
  265. package/lib/socket/monitor.js +350 -0
  266. package/lib/socket/reconnect.d.ts +61 -0
  267. package/lib/socket/reconnect.js +157 -0
  268. package/lib/socket/socket.d.ts +130 -0
  269. package/lib/socket/socket.js +426 -0
  270. package/lib/socket/types.d.ts +85 -0
  271. package/lib/socket/types.js +36 -0
  272. package/lib/storage/index.d.ts +17 -0
  273. package/lib/storage/index.js +64 -0
  274. package/lib/tasks/index.d.ts +127 -0
  275. package/lib/tasks/index.js +710 -0
  276. package/lib/tasks/scheduledTasksExample.d.ts +61 -0
  277. package/lib/tasks/scheduledTasksExample.js +267 -0
  278. package/lib/tasks/type.d.ts +100 -0
  279. package/lib/tasks/type.js +17 -0
  280. package/lib/tasks/useTasks.d.ts +5 -0
  281. package/lib/tasks/useTasks.js +37 -0
  282. package/lib/type.d.ts +2 -0
  283. package/lib/type.js +17 -0
  284. package/lib/utils/adaptiveThrottle/index.d.ts +36 -0
  285. package/lib/utils/adaptiveThrottle/index.js +121 -0
  286. package/lib/variables/VariablesProvider.d.ts +7 -0
  287. package/lib/variables/VariablesProvider.js +51 -0
  288. package/lib/variables/config.d.ts +3 -0
  289. package/lib/variables/config.js +38 -0
  290. package/lib/variables/index.d.ts +6 -0
  291. package/lib/variables/index.js +29 -0
  292. package/lib/variables/type.d.ts +2 -0
  293. package/lib/variables/type.js +17 -0
  294. package/lib/website/index.d.ts +6 -0
  295. package/lib/website/index.js +75 -0
  296. package/package.json +49 -0
@@ -0,0 +1,125 @@
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/menuManager/index.ts
20
+ var menuManager_exports = {};
21
+ __export(menuManager_exports, {
22
+ MenuManager: () => MenuManager
23
+ });
24
+ module.exports = __toCommonJS(menuManager_exports);
25
+ var import_hooks = require("./hooks");
26
+ var MenuManager = class {
27
+ menuItems = [];
28
+ menuMaps = {};
29
+ app;
30
+ useMenu = import_hooks.useMenu;
31
+ MenuProvider = import_hooks.MenuProvider;
32
+ constructor(items, app) {
33
+ this.app = app;
34
+ this.set(items);
35
+ }
36
+ // 设置菜单项
37
+ set(items) {
38
+ this.menuItems = items;
39
+ this.getMenuMaps();
40
+ }
41
+ // 获取菜单项
42
+ getMenus() {
43
+ return this.menuItems;
44
+ }
45
+ getMenuMaps() {
46
+ const maps = {};
47
+ const fn = (items) => {
48
+ items.forEach((item) => {
49
+ maps[item.path] = item;
50
+ if (item.children) {
51
+ fn(item.children);
52
+ }
53
+ });
54
+ };
55
+ fn(this.menuItems);
56
+ this.menuMaps = maps;
57
+ }
58
+ // 根据路径查找菜单项
59
+ findMenuItemByPath(items, path) {
60
+ var _a;
61
+ let menu = this.menuMaps[path];
62
+ if (menu) {
63
+ return menu;
64
+ }
65
+ const getPathname = (url) => {
66
+ const questionMarkIndex = url.indexOf("?");
67
+ const hashIndex = url.indexOf("#");
68
+ let 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
+ const inputPathname = getPathname(path);
79
+ for (const item of items) {
80
+ if (((_a = item == null ? void 0 : item.path) == null ? void 0 : _a.includes("/:")) && path.startsWith(item.path.split("/:")[0])) {
81
+ return item;
82
+ }
83
+ const itemPathname = getPathname((item == null ? void 0 : item.path) || "");
84
+ if (itemPathname === inputPathname) {
85
+ return item;
86
+ }
87
+ if (item.children) {
88
+ const found = this.findMenuItemByPath(item.children, path);
89
+ if (found) return found;
90
+ }
91
+ }
92
+ return null;
93
+ }
94
+ // 查找给定key的父级菜单key
95
+ findParent(items, key, parent = null) {
96
+ for (const item of items) {
97
+ if (item.key === key) return parent;
98
+ if (item.children) {
99
+ const found = this.findParent(item.children, key, item);
100
+ if (found) return found;
101
+ }
102
+ }
103
+ return null;
104
+ }
105
+ getShowChildren(items) {
106
+ return items.filter((item) => !item.hide);
107
+ }
108
+ // 根据key查找菜单项
109
+ findMenuItemByKey(items, key) {
110
+ for (const item of items) {
111
+ if (item.key === key) {
112
+ return item;
113
+ }
114
+ if (item.children) {
115
+ const found = this.findMenuItemByKey(item.children, key);
116
+ if (found) return found;
117
+ }
118
+ }
119
+ return null;
120
+ }
121
+ };
122
+ // Annotate the CommonJS export names for ESM import in node:
123
+ 0 && (module.exports = {
124
+ MenuManager
125
+ });
@@ -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,62 @@
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/models/global.ts
20
+ var global_exports = {};
21
+ __export(global_exports, {
22
+ default: () => global_default
23
+ });
24
+ module.exports = __toCommonJS(global_exports);
25
+ var modal = {
26
+ namespace: "global",
27
+ state: {
28
+ /* 测试登录逻辑状态 */
29
+ isLogin: false,
30
+ account: null,
31
+ core: null,
32
+ isInstallAPP: false,
33
+ app: {
34
+ status: {
35
+ login: false,
36
+ storage: false,
37
+ network: false,
38
+ materials: false,
39
+ pisell2: false
40
+ }
41
+ }
42
+ },
43
+ effects: {
44
+ *init({ params }, { put, call }) {
45
+ }
46
+ },
47
+ reducers: {
48
+ saveGlobalState(state, { params }) {
49
+ console.log("params", params);
50
+ return { ...state, ...params };
51
+ },
52
+ setInit(state, { payload }) {
53
+ console.log(payload);
54
+ return { ...state, isInstallAPP: payload };
55
+ }
56
+ },
57
+ subscriptions: {
58
+ _init({ dispatch }) {
59
+ }
60
+ }
61
+ };
62
+ var global_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,69 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
+ // If the importer is in node compatibility mode or this is not an ESM
21
+ // file that has been converted to a CommonJS file using a Babel-
22
+ // compatible transform (i.e. "__esModule" has not been set), then set
23
+ // "default" to the CommonJS "module.exports" for node compatibility.
24
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
+ mod
26
+ ));
27
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
+
29
+ // src/models/index.ts
30
+ var models_exports = {};
31
+ __export(models_exports, {
32
+ default: () => models_default
33
+ });
34
+ module.exports = __toCommonJS(models_exports);
35
+ var import_dva_core = require("dva-core");
36
+ var import_hooks = __toESM(require("../hooks"));
37
+ var import_global = __toESM(require("./global"));
38
+ var import_react_redux = require("react-redux");
39
+ var models = [import_global.default];
40
+ var app = (0, import_dva_core.create)();
41
+ models.forEach((item) => app.model(item));
42
+ var getStore = () => app._store;
43
+ var getDataByModel = (model, key) => {
44
+ var _a;
45
+ let modelData = (_a = getStore().getState()) == null ? void 0 : _a[model];
46
+ if (key !== void 0) {
47
+ return modelData == null ? void 0 : modelData[key];
48
+ }
49
+ return modelData;
50
+ };
51
+ var setDataByModel = (model, key, value) => {
52
+ getStore().dispatch({
53
+ type: `${model}/${String(key)}`,
54
+ payload: value
55
+ });
56
+ };
57
+ var setConfig = (models2) => {
58
+ models2.forEach((item) => app.model(item));
59
+ app.start();
60
+ getStore().getDataByModel = getDataByModel;
61
+ getStore().setDataByModel = setDataByModel;
62
+ getStore().useStore = import_hooks.default.useStore;
63
+ getStore().useDispatch = import_hooks.default.useDispatch;
64
+ };
65
+ var models_default = {
66
+ getStore,
67
+ StoreProvider: import_react_redux.Provider,
68
+ setConfig
69
+ };
@@ -0,0 +1,2 @@
1
+ export interface ModelsConfig {
2
+ }
@@ -0,0 +1,17 @@
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/models/type.ts
16
+ var type_exports = {};
17
+ module.exports = __toCommonJS(type_exports);
File without changes
File without changes
@@ -0,0 +1,5 @@
1
+ /**
2
+ * 发布订阅模块使用示例
3
+ * 此文件仅用于演示,不会被实际引入项目
4
+ */
5
+ export {};
@@ -0,0 +1,61 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __copyProps = (to, from, except, desc) => {
8
+ if (from && typeof from === "object" || typeof from === "function") {
9
+ for (let key of __getOwnPropNames(from))
10
+ if (!__hasOwnProp.call(to, key) && key !== except)
11
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
12
+ }
13
+ return to;
14
+ };
15
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
16
+ // If the importer is in node compatibility mode or this is not an ESM
17
+ // file that has been converted to a CommonJS file using a Babel-
18
+ // compatible transform (i.e. "__esModule" has not been set), then set
19
+ // "default" to the CommonJS "module.exports" for node compatibility.
20
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
21
+ mod
22
+ ));
23
+
24
+ // src/pubsub/example.ts
25
+ var import_index = __toESM(require("./index"));
26
+ var handleUserLogin = (userData) => {
27
+ console.log(`用户 ${userData.username} 登录成功`);
28
+ };
29
+ var subscription = import_index.default.subscribe("user:login", handleUserLogin);
30
+ setTimeout(() => {
31
+ import_index.default.publish("user:login", {
32
+ userId: "user_123",
33
+ username: "张三",
34
+ timestamp: Date.now()
35
+ });
36
+ }, 1e3);
37
+ import_index.default.once("notification:welcome", (message) => {
38
+ console.log(`欢迎通知: ${message}`);
39
+ });
40
+ import_index.default.publish("notification:welcome", "欢迎来到我们的平台!");
41
+ import_index.default.publish("notification:welcome", "这条消息不会被处理");
42
+ import_index.default.subscribe("cart:update", (itemId, quantity, price) => {
43
+ console.log(`购物车更新: 商品ID=${itemId}, 数量=${quantity}, 价格=${price}`);
44
+ const subtotal = quantity * price;
45
+ console.log(`小计: ¥${subtotal.toFixed(2)}`);
46
+ });
47
+ import_index.default.publish("cart:update", "product_456", 2, 99.5);
48
+ import_index.default.subscribe("data:process", (data) => {
49
+ console.log("处理数据...");
50
+ throw new Error("数据处理失败");
51
+ });
52
+ import_index.default.subscribe("data:process", (data) => {
53
+ console.log("第二个处理器仍然会执行");
54
+ });
55
+ import_index.default.publish("data:process", { id: 789 });
56
+ var hasLoginSubscribers = import_index.default.hasSubscribers("user:login");
57
+ console.log(`用户登录事件是否有订阅者: ${hasLoginSubscribers}`);
58
+ var loginSubscriberCount = import_index.default.getSubscriberCount("user:login");
59
+ console.log(`用户登录事件的订阅者数量: ${loginSubscriberCount}`);
60
+ import_index.default.clearEvent("user:login");
61
+ console.log("已清除所有用户登录事件的订阅");
@@ -0,0 +1,73 @@
1
+ /**
2
+ * 发布订阅模块
3
+ * 用于组件/服务间的事件通信
4
+ */
5
+ declare type EventCallback = (...args: any[]) => void;
6
+ interface EventSubscription {
7
+ unsubscribe: () => void;
8
+ }
9
+ declare class PubSub {
10
+ private events;
11
+ /**
12
+ * 订阅事件
13
+ * @param event 事件名称
14
+ * @param callback 回调函数
15
+ * @returns 订阅对象,可用于取消订阅
16
+ */
17
+ subscribe(event: string, callback: EventCallback): EventSubscription;
18
+ /**
19
+ * 取消订阅事件
20
+ * @param event 事件名称
21
+ * @param callback 回调函数
22
+ * @returns 是否成功取消订阅
23
+ */
24
+ unsubscribe(event: string, callback: EventCallback): boolean;
25
+ /**
26
+ * 发布事件
27
+ * @param event 事件名称
28
+ * @param args 事件参数
29
+ */
30
+ publish(event: string, ...args: any[]): void;
31
+ /**
32
+ * @title: 异步发布, 某些事件需要延迟发布
33
+ * @description:
34
+ * @param {string} event
35
+ * @param {number} timeout
36
+ * @param {array} args
37
+ * @return {*}
38
+ * @Author: zhiwei.Wang
39
+ */
40
+ publishDelay(event: string, delay?: number, ...args: any[]): void;
41
+ /**
42
+ * 移除某个事件的所有订阅
43
+ * @param event 事件名称
44
+ * @returns 是否成功移除
45
+ */
46
+ clearEvent(event: string): boolean;
47
+ /**
48
+ * 移除所有事件订阅
49
+ */
50
+ clearAllEvents(): void;
51
+ /**
52
+ * 获取事件的订阅数量
53
+ * @param event 事件名称
54
+ * @returns 订阅数量
55
+ */
56
+ getSubscriberCount(event: string): number;
57
+ /**
58
+ * 检查事件是否有订阅者
59
+ * @param event 事件名称
60
+ * @returns 是否有订阅者
61
+ */
62
+ hasSubscribers(event: string): boolean;
63
+ /**
64
+ * 一次性订阅事件,事件触发后自动取消订阅
65
+ * @param event 事件名称
66
+ * @param callback 回调函数
67
+ * @returns 订阅对象,可用于取消订阅
68
+ */
69
+ once(event: string, callback: EventCallback): EventSubscription;
70
+ }
71
+ declare const pubsub: PubSub;
72
+ export default pubsub;
73
+ export { PubSub, type EventCallback, type EventSubscription };
@@ -0,0 +1,141 @@
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/pubsub/index.ts
20
+ var pubsub_exports = {};
21
+ __export(pubsub_exports, {
22
+ PubSub: () => PubSub,
23
+ default: () => pubsub_default
24
+ });
25
+ module.exports = __toCommonJS(pubsub_exports);
26
+ var PubSub = class {
27
+ events = /* @__PURE__ */ new Map();
28
+ /**
29
+ * 订阅事件
30
+ * @param event 事件名称
31
+ * @param callback 回调函数
32
+ * @returns 订阅对象,可用于取消订阅
33
+ */
34
+ subscribe(event, callback) {
35
+ if (!this.events.has(event)) {
36
+ this.events.set(event, /* @__PURE__ */ new Set());
37
+ }
38
+ const callbacks = this.events.get(event);
39
+ callbacks.add(callback);
40
+ return {
41
+ unsubscribe: () => {
42
+ this.unsubscribe(event, callback);
43
+ }
44
+ };
45
+ }
46
+ /**
47
+ * 取消订阅事件
48
+ * @param event 事件名称
49
+ * @param callback 回调函数
50
+ * @returns 是否成功取消订阅
51
+ */
52
+ unsubscribe(event, callback) {
53
+ const callbacks = this.events.get(event);
54
+ if (!callbacks) {
55
+ return false;
56
+ }
57
+ return callbacks.delete(callback);
58
+ }
59
+ /**
60
+ * 发布事件
61
+ * @param event 事件名称
62
+ * @param args 事件参数
63
+ */
64
+ publish(event, ...args) {
65
+ const callbacks = this.events.get(event);
66
+ if (!callbacks) {
67
+ return;
68
+ }
69
+ callbacks.forEach((callback) => {
70
+ try {
71
+ callback(...args);
72
+ } catch (error) {
73
+ console.error(`执行事件"${event}"的回调时出错:`, error);
74
+ }
75
+ });
76
+ }
77
+ /**
78
+ * @title: 异步发布, 某些事件需要延迟发布
79
+ * @description:
80
+ * @param {string} event
81
+ * @param {number} timeout
82
+ * @param {array} args
83
+ * @return {*}
84
+ * @Author: zhiwei.Wang
85
+ */
86
+ publishDelay(event, delay = 0, ...args) {
87
+ setTimeout(() => {
88
+ this.publish(event, ...args);
89
+ }, delay);
90
+ }
91
+ /**
92
+ * 移除某个事件的所有订阅
93
+ * @param event 事件名称
94
+ * @returns 是否成功移除
95
+ */
96
+ clearEvent(event) {
97
+ return this.events.delete(event);
98
+ }
99
+ /**
100
+ * 移除所有事件订阅
101
+ */
102
+ clearAllEvents() {
103
+ this.events.clear();
104
+ }
105
+ /**
106
+ * 获取事件的订阅数量
107
+ * @param event 事件名称
108
+ * @returns 订阅数量
109
+ */
110
+ getSubscriberCount(event) {
111
+ const callbacks = this.events.get(event);
112
+ return callbacks ? callbacks.size : 0;
113
+ }
114
+ /**
115
+ * 检查事件是否有订阅者
116
+ * @param event 事件名称
117
+ * @returns 是否有订阅者
118
+ */
119
+ hasSubscribers(event) {
120
+ return this.getSubscriberCount(event) > 0;
121
+ }
122
+ /**
123
+ * 一次性订阅事件,事件触发后自动取消订阅
124
+ * @param event 事件名称
125
+ * @param callback 回调函数
126
+ * @returns 订阅对象,可用于取消订阅
127
+ */
128
+ once(event, callback) {
129
+ const wrappedCallback = (...args) => {
130
+ this.unsubscribe(event, wrappedCallback);
131
+ callback(...args);
132
+ };
133
+ return this.subscribe(event, wrappedCallback);
134
+ }
135
+ };
136
+ var pubsub = new PubSub();
137
+ var pubsub_default = pubsub;
138
+ // Annotate the CommonJS export names for ESM import in node:
139
+ 0 && (module.exports = {
140
+ PubSub
141
+ });
File without changes
File without changes
@@ -0,0 +1,46 @@
1
+ import { CacheProps } from './type';
2
+ export declare type CacheType = 'memory' | 'storage' | 'indexDB';
3
+ /**
4
+ * @title: 设置缓存
5
+ * @description:
6
+ * @return {*}
7
+ * @Author: zhiwei.Wang
8
+ */
9
+ export declare const setCache: (key: string, data: any, cache: CacheProps) => Promise<void>;
10
+ /**
11
+ * @title: 删除缓存数据
12
+ * @description:
13
+ * @return {*}
14
+ * @Author: zhiwei.Wang
15
+ */
16
+ export declare const removeCache: (key: string, cache: CacheProps) => void;
17
+ /**
18
+ * @title: 获取数据
19
+ * @description:
20
+ * @param {any} url
21
+ * @param {any} data
22
+ * @return {*}
23
+ * @Author: zhiwei.Wang
24
+ */
25
+ export declare const getCacheData: (url: string, data: any, cache: CacheProps) => Promise<any>;
26
+ /**
27
+ * @title: 设置缓存
28
+ * @description:
29
+ * @param {any} url 路径
30
+ * @param {any} data 参数
31
+ * @param {any} res 数据
32
+ * @return {*}
33
+ * @Author: zhiwei.Wang
34
+ */
35
+ export declare const setCacheData: (url: string, data: any, res: any, cache?: CacheProps) => any | null;
36
+ /**
37
+ * @title: 缓存函数包装器
38
+ * @description:
39
+ * @param {any} url
40
+ * @param {any} data
41
+ * @param {any} config
42
+ * @param {any} fn
43
+ * @return {*}
44
+ * @Author: zhiwei.Wang
45
+ */
46
+ export declare const cacheFn: (props: any, fn: any) => Promise<any>;