@gct-paas/render 0.1.4-dev.8 → 0.1.4-dev.9

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 (51) hide show
  1. package/dist/index.esm.min.mjs +7684 -15
  2. package/dist/index.min.cjs +9 -1
  3. package/dist/index.system.min.js +9 -1
  4. package/es/Event/Dependency/controller.d.ts +13 -0
  5. package/es/Event/Dependency/controller.mjs +97 -0
  6. package/es/Event/Dependency/displayRule.d.ts +19 -0
  7. package/es/Event/Dependency/displayRule.mjs +76 -0
  8. package/es/Event/Dependency/useDependency.d.ts +7 -0
  9. package/es/Event/Dependency/useDependencyToShow.d.ts +10 -0
  10. package/es/Event/Dependency/useDependencyToShow.mjs +109 -0
  11. package/es/Event/baseEvent.d.ts +160 -0
  12. package/es/Event/baseEvent.mjs +445 -0
  13. package/es/Event/bizServiceRequest.d.ts +26 -0
  14. package/es/Event/bizServiceRequest.mjs +47 -0
  15. package/es/Event/eventType.d.ts +20 -0
  16. package/es/Event/index.d.ts +4 -0
  17. package/es/Event/utils/appRedis.d.ts +29 -0
  18. package/es/Event/utils/appRedis.mjs +50 -0
  19. package/es/Event/utils/processRovedInfo.d.ts +100 -0
  20. package/es/Event/utils/processRovedInfo.mjs +297 -0
  21. package/es/Event/utils/runGlobalByPage.d.ts +332 -0
  22. package/es/Event/utils/runGlobalByPage.mjs +306 -0
  23. package/es/Event/utils/verificationVar.d.ts +2 -0
  24. package/es/Event/utils/verificationVar.mjs +42 -0
  25. package/es/enums/index.d.ts +14 -0
  26. package/es/enums/index.mjs +6 -0
  27. package/es/hooks/useStorageRef.d.ts +9 -0
  28. package/es/hooks/useStorageRef.mjs +33 -0
  29. package/es/index.d.ts +2 -0
  30. package/es/index.mjs +22 -0
  31. package/es/register/index.d.ts +1 -0
  32. package/es/register/render-register/render-register.d.ts +54 -0
  33. package/es/register/render-register/render-register.mjs +59 -0
  34. package/es/types/index.d.ts +6 -0
  35. package/es/utils/cacheAdapter.d.ts +7 -0
  36. package/es/utils/cacheAdapter.mjs +57 -0
  37. package/es/utils/expression/index.d.ts +6 -0
  38. package/es/utils/expression/index.mjs +133 -0
  39. package/es/utils/expression/regularExpression/methods.d.ts +77 -0
  40. package/es/utils/expression/regularExpression/methods.mjs +729 -0
  41. package/es/utils/field-attrs/index.d.ts +1 -1
  42. package/es/utils/get-ref-data.d.ts +1 -0
  43. package/es/utils/get-ref-data.mjs +62 -0
  44. package/es/utils/getFieldSchema.d.ts +1 -3
  45. package/es/utils/getFieldSchema.mjs +83 -0
  46. package/es/utils/index.d.ts +5 -0
  47. package/es/utils/model-transformer.d.ts +46 -0
  48. package/es/utils/model-transformer.mjs +77 -0
  49. package/es/utils/useStyle.d.ts +21 -0
  50. package/es/utils/useStyle.mjs +17 -0
  51. package/package.json +25 -6
@@ -0,0 +1,445 @@
1
+ import { t, INNER_EVENT, FormComponents } from '@gct-paas/core';
2
+ import { toRaw } from 'vue';
3
+ import _, { differenceBy, cloneDeep } from 'lodash-es';
4
+ import BigNumberJS from 'bignumber.js';
5
+ import dayjs from 'dayjs';
6
+ import { useStyleTag } from '@vueuse/core';
7
+ import { ProcessAppRovedData } from './utils/processRovedInfo.mjs';
8
+ import { Globals } from './utils/runGlobalByPage.mjs';
9
+ import { BizService, $httpBizService, $request } from './bizServiceRequest.mjs';
10
+ import '../utils/field-attrs/basicAttrs.mjs';
11
+ import '@gct-paas/schema';
12
+ import { transformData, transformSourceData } from '../utils/model-transformer.mjs';
13
+ import '../utils/expression/index.mjs';
14
+ import 'qs';
15
+
16
+ class Events {
17
+ context;
18
+ searchVNodes;
19
+ cssData;
20
+ pageKey;
21
+ exports;
22
+ #Oberver;
23
+ #VNodes;
24
+ /**流程信息 */
25
+ ProcessAppRoved;
26
+ pageLayoutMode;
27
+ constructor({
28
+ js,
29
+ css,
30
+ pageKey,
31
+ ContextPc
32
+ }) {
33
+ this.cssData = this.#createCss(css);
34
+ this.searchVNodes = {};
35
+ this.exports = {};
36
+ this.#VNodes = {};
37
+ this.#Oberver = {};
38
+ this.context = new ContextPc({
39
+ $ref: this.getComponent.bind(this),
40
+ $asyncRef: this.getSyncComponent.bind(this)
41
+ });
42
+ this.#createFunction(js);
43
+ Globals.setContextByKey(this.context, pageKey);
44
+ this.pageKey = pageKey;
45
+ }
46
+ /**初始化流程节点信息 */
47
+ async runProcessBySaskId({
48
+ taskId,
49
+ processInstanceId,
50
+ examineAndApproveState,
51
+ refFormId
52
+ }) {
53
+ this.ProcessAppRoved = new ProcessAppRovedData({
54
+ taskId,
55
+ processInstanceId,
56
+ examineAndApproveState,
57
+ refFormId
58
+ });
59
+ await this.ProcessAppRoved.readyProcess();
60
+ }
61
+ #createCss(str, attr = {}) {
62
+ if (!str) return;
63
+ const { css, load, unload } = useStyleTag(str, attr);
64
+ return { css, load, unload };
65
+ }
66
+ /**保存所有组件的props*/
67
+ runContext(key, widget) {
68
+ this.context.gctWidgets[key] = widget;
69
+ }
70
+ /**触发内置事件 */
71
+ async runEventByName(eventName, events = {}, ...arg) {
72
+ const E = events[eventName];
73
+ let data;
74
+ if (!E) return;
75
+ if (Array.isArray(E)) {
76
+ data = await builtInEvents(E, this.context, arg);
77
+ } else {
78
+ const fun = this.exports[E.name];
79
+ if (!fun) throw `函数${E.name}不存在`;
80
+ data = await fun(...arg, toRaw(E.extraParams));
81
+ }
82
+ return data;
83
+ }
84
+ /**执行公共函数事件 */
85
+ async runExportByName(eventName, ...arg) {
86
+ try {
87
+ const fun = this.exports[eventName];
88
+ if (!fun) throw `函数${eventName}不存在`;
89
+ return fun(...arg);
90
+ } catch (error) {
91
+ console.error(error);
92
+ }
93
+ }
94
+ /**异步执行公共函数事件 */
95
+ async runAsyncExportByName(eventName, ...arg) {
96
+ try {
97
+ const fun = this.exports[eventName];
98
+ if (!fun) throw `函数${eventName}不存在`;
99
+ await this.getReadyByFun(fun);
100
+ return fun(...arg);
101
+ } catch (error) {
102
+ console.error(error);
103
+ }
104
+ }
105
+ #createFunction(jsJSON) {
106
+ if (!jsJSON) return;
107
+ try {
108
+ const fun = new Function("exports", "CTX", jsJSON);
109
+ fun(this.exports, this.context);
110
+ } catch (error) {
111
+ console.error(error, "createFunction");
112
+ }
113
+ }
114
+ // 把小组件的实例按照key存起来
115
+ initNode(key, options) {
116
+ if (key) {
117
+ this.#VNodes[key] = options;
118
+ this.#publish(key, options);
119
+ }
120
+ }
121
+ /**组件销毁 */
122
+ destroyNode(key) {
123
+ delete this.#VNodes[key];
124
+ delete this.#Oberver[key];
125
+ }
126
+ // 执行查询
127
+ initSearchs(key, callback, comId) {
128
+ if (!key) return;
129
+ if (this.searchVNodes[key]) {
130
+ const item = this.searchVNodes[key].find((i) => i.comId === comId);
131
+ if (item) {
132
+ item.callback = callback;
133
+ } else {
134
+ this.searchVNodes[key].push({ callback, comId });
135
+ }
136
+ } else {
137
+ this.searchVNodes[key] = [{ callback, comId }];
138
+ }
139
+ }
140
+ // 取消注册的查询
141
+ cancelInitSearchs(key, comId) {
142
+ if (!key || !this.searchVNodes[key]) return;
143
+ this.searchVNodes[key] = this.searchVNodes[key].filter(
144
+ (i) => i.comId !== comId
145
+ );
146
+ if (this.searchVNodes[key].length === 0) {
147
+ delete this.searchVNodes[key];
148
+ }
149
+ }
150
+ runTableBySearch(key, data) {
151
+ const funArg = this.searchVNodes[key] || [];
152
+ funArg.forEach(({ callback }) => callback(data));
153
+ }
154
+ /**
155
+ * 组件初始化订阅
156
+ * @param {*} key 组件唯一key
157
+ * @param {*} eventName 事件名称
158
+ */
159
+ #subscribeready(key, callback) {
160
+ const options = this.#VNodes[key];
161
+ if (options) {
162
+ callback(key, options);
163
+ } else if (this.#Oberver[key]) {
164
+ this.#Oberver[key].push(callback);
165
+ } else {
166
+ this.#Oberver[key] = [callback];
167
+ }
168
+ }
169
+ /**
170
+ *
171
+ * @param key 执行回调
172
+ */
173
+ #publish(key, options) {
174
+ if (this.#Oberver[key]) {
175
+ this.#Oberver[key].forEach((fun) => {
176
+ fun(options);
177
+ });
178
+ }
179
+ }
180
+ /**
181
+ * 获取组件公用方法 getComponent(identity),根据组件唯一标识获取组件。
182
+ * @param {*} key
183
+ * @returns
184
+ */
185
+ getComponent(key) {
186
+ const options = this.#VNodes[key];
187
+ if (options) {
188
+ return new GctComponent(key, options);
189
+ }
190
+ console.error(key + "组件不存在或者未初始化");
191
+ }
192
+ /**
193
+ * 获取组件公用方法 getComponent(identity),根据组件唯一标识获取组件。
194
+ * @param {*} key
195
+ * @returns
196
+ */
197
+ getSyncComponent(key) {
198
+ if (!key) return Promise.reject("标识不能为空");
199
+ const options = this.#VNodes[key];
200
+ if (options) {
201
+ return Promise.resolve(new GctComponent(key, options));
202
+ }
203
+ return new Promise((resolve, reject) => {
204
+ const timer = setTimeout(() => {
205
+ reject(key + "不存在或者被隐藏");
206
+ }, 3e4);
207
+ this.#subscribeready(key, (options2) => {
208
+ clearTimeout(timer);
209
+ resolve(new GctComponent(key, options2));
210
+ });
211
+ });
212
+ }
213
+ /**
214
+ * 指定函数中使用到的组件初始化后才执行
215
+ * @param fun
216
+ * @returns
217
+ */
218
+ async getReadyByFun(fun) {
219
+ if (typeof fun !== "function") return Promise.reject("参数必须是函数");
220
+ const funstr = String(fun);
221
+ const P = funstr.match(/\$ref\((["'A-Za-z0-9_-]+)\)/g)?.map((i) => {
222
+ const key = i.match(/\$ref\(['|"]([A-Za-z0-9_-]+)['|"]\)/)?.[1];
223
+ return this.getSyncComponent(key);
224
+ }) || [];
225
+ await Promise.all(P);
226
+ }
227
+ /**
228
+ * 流程处理
229
+ * @param processDateValue
230
+ * @param data
231
+ */
232
+ async processHandle(data, {
233
+ opinion,
234
+ reassignId,
235
+ signature,
236
+ countersignUserIds,
237
+ button
238
+ }) {
239
+ const { taskId, processInstanceId } = this.ProcessAppRoved;
240
+ const processData = {
241
+ procInstId: processInstanceId,
242
+ data,
243
+ opinion,
244
+ button,
245
+ countersignUserIds,
246
+ taskId,
247
+ signature,
248
+ reassignId
249
+ };
250
+ await _gct.api.apaas.pmProcessEngine.postProcExecute(processData);
251
+ }
252
+ /**流程审批校验 */
253
+ async checkedProcess(formProcessId) {
254
+ const { processId } = this.ProcessAppRoved || {};
255
+ if (!processId)
256
+ return Promise.reject(t("sys.process.pleaseInitiateTheProcessFirst"));
257
+ if (formProcessId !== processId)
258
+ return Promise.reject(t("sys.process.processInstanceMismatch"));
259
+ }
260
+ }
261
+ class Context {
262
+ /**根据key获取当前组件 */
263
+ $ref;
264
+ /**根据key异步获取获取组件 */
265
+ $asyncRef;
266
+ /**根据id获取模态框 */
267
+ $getModal;
268
+ /**关闭当前上下文模态框 */
269
+ $closeModal;
270
+ /** 跳转指定页面 */
271
+ $push;
272
+ /**调用第三方服务 */
273
+ $customBizService = BizService;
274
+ /**建模追溯 */
275
+ $modelingTraceability;
276
+ /** 电子签名 */
277
+ $modelingElectronicSignature;
278
+ /** 单据打印预览弹框 */
279
+ $documentPrint;
280
+ /** 在线表单信息弹框 */
281
+ $onlineFormModal;
282
+ /** eDHR填报全屏弹框 */
283
+ $eDHRFillFullScreenModal;
284
+ /** 表单填报弹框 */
285
+ $openDocumentFillingModal;
286
+ /** 签名确认弹框 */
287
+ $modelingSignatureConfirm;
288
+ $routeQuery;
289
+ /**组件id和widget 的map */
290
+ gctWidgets = {};
291
+ /**ctx 下的工具函数 */
292
+ $utility = {
293
+ _,
294
+ cloneDeep,
295
+ differenceBy,
296
+ dayjs,
297
+ BigNumber: BigNumberJS,
298
+ plus(a, b) {
299
+ return new BigNumberJS(a).plus(new BigNumberJS(b)).toNumber();
300
+ },
301
+ minus(a, b) {
302
+ return new BigNumberJS(a).minus(new BigNumberJS(b)).toNumber();
303
+ },
304
+ multipliedBy(a, b) {
305
+ return new BigNumberJS(a).multipliedBy(new BigNumberJS(b)).toNumber();
306
+ },
307
+ div(a, b) {
308
+ return new BigNumberJS(a).div(new BigNumberJS(b)).toNumber();
309
+ },
310
+ /**表格数据data,dict翻译 */
311
+ transformSourceData,
312
+ /**表单数据data,dict翻译*/
313
+ transformData
314
+ };
315
+ $httpBizService = $httpBizService;
316
+ $request = $request;
317
+ constructor({ $ref, $asyncRef }) {
318
+ this.$asyncRef = $asyncRef;
319
+ this.$ref = $ref;
320
+ }
321
+ $getPremission(id) {
322
+ return Globals.getPremission(id);
323
+ }
324
+ /**
325
+ *
326
+ * @param key 组件权限标识
327
+ * @param id 组件id
328
+ */
329
+ $setPremission(key, id) {
330
+ Globals.setPremission(key, id);
331
+ }
332
+ /**获取应用全局变量 */
333
+ $getAppGlobalVar(id) {
334
+ return Globals.getGlobalVar(id);
335
+ }
336
+ /**设置应用全局变量 */
337
+ $setAppGlobalVar(id, value) {
338
+ Globals.setGlobalVar(id, value);
339
+ }
340
+ /**获取页面全局变量老版本兼容问题暂时不删除 后续不维护*/
341
+ $getPageGlobalVar(id) {
342
+ return Globals.getPageGlobalVar(id);
343
+ }
344
+ /**设置页面变量老版本 兼容问题暂时不删除 后续不维护 */
345
+ $setPageGlobalVar(id, value) {
346
+ Globals.setPageGlobalVar(id, value);
347
+ }
348
+ /**获取页面全局变量 */
349
+ $getPageVar(id) {
350
+ return Globals.getPageVar(id);
351
+ }
352
+ /**设置页面全局变量 */
353
+ $setPageVar(id, value) {
354
+ Globals.setPageVar(id, value);
355
+ }
356
+ /**根据模态框id 获取上下文 id不传默认页面上下文*/
357
+ $getCtxById(modalKey) {
358
+ return Globals.getContextByKey(modalKey);
359
+ }
360
+ /**设置组件的属性 */
361
+ $setPropsByKey(key, fromProp) {
362
+ const toProps = this.gctWidgets[key]?.props;
363
+ if (!toProps) return;
364
+ for (const k in fromProp) {
365
+ toProps[k] = fromProp[k];
366
+ }
367
+ }
368
+ /**获取组件的属性 */
369
+ $getPropsByKey(key, PropsKey = [], root) {
370
+ const widget = this.gctWidgets[key];
371
+ if (!widget) return {};
372
+ const props = root || !widget.props ? widget : widget.props;
373
+ if (typeof PropsKey === "string") {
374
+ PropsKey = [PropsKey];
375
+ }
376
+ return PropsKey.reduce((pre, curr) => {
377
+ pre[curr] = props[curr];
378
+ return pre;
379
+ }, {});
380
+ }
381
+ /**全局loading */
382
+ $loading;
383
+ }
384
+ class GctComponent {
385
+ modelKey;
386
+ getValue;
387
+ setValue;
388
+ /**提交 */
389
+ submit;
390
+ /**刷新 */
391
+ reload;
392
+ key;
393
+ constructor(key, options) {
394
+ this.key = key;
395
+ const elRef = options.elRef;
396
+ Object.keys(elRef).forEach((k) => {
397
+ this[k] = elRef[k];
398
+ });
399
+ }
400
+ }
401
+ async function builtInEvents(eventList, context, args) {
402
+ const allEvent = eventList.map(transformEventFun.bind(context, args));
403
+ await Promise.all(allEvent);
404
+ }
405
+ async function transformEventFun(args, item) {
406
+ const { name, refId, scopeId, modalTitle } = item;
407
+ const ids = modalTitle?.split(".") || [];
408
+ let widget;
409
+ if (ids.length > 1) {
410
+ const orgWidget = this.gctWidgets?.[ids[0]] || {};
411
+ const opes = [];
412
+ getAllOpe(opes, orgWidget);
413
+ widget = opes.find((i) => i.id === ids[1]) || {};
414
+ } else if (ids.length) {
415
+ widget = this.gctWidgets?.[ids[0]];
416
+ }
417
+ if (name === INNER_EVENT.OPEN_MODAL) {
418
+ await this.$getModal(refId).open({ title: widget?.props?.title });
419
+ }
420
+ if (name === INNER_EVENT.CLOSE_MODAL) {
421
+ if (refId) {
422
+ await this.$getModal(refId).close();
423
+ } else {
424
+ await this.$closeModal();
425
+ }
426
+ }
427
+ if (name === INNER_EVENT.REFRESH_TABLE) {
428
+ const com = await this.$getCtxById(scopeId).$asyncRef(refId);
429
+ await com.reload(args ? args[0] : null);
430
+ }
431
+ }
432
+ function getAllOpe(arr, widget) {
433
+ const children = widget.children || [];
434
+ for (const i of children) {
435
+ if (i.type && i.type == FormComponents.CustomButton) {
436
+ arr.push(i);
437
+ } else {
438
+ if (i.children?.length) {
439
+ getAllOpe(arr, i);
440
+ }
441
+ }
442
+ }
443
+ }
444
+
445
+ export { Context, Events };
@@ -0,0 +1,26 @@
1
+ import { BizServiceEnum, EntityModelCategoryEnum } from '@gct-paas/core';
2
+ import { AxiosRequestConfig } from 'axios';
3
+ export declare const BizService: {
4
+ post: (path: PathType, query?: IObject, data?: IObject, config?: AxiosRequestConfig) => Promise<unknown>;
5
+ get: (path: PathType, query?: IObject, data?: IObject, config?: AxiosRequestConfig) => Promise<unknown>;
6
+ put: (path: PathType, query?: IObject, data?: IObject, config?: AxiosRequestConfig) => Promise<unknown>;
7
+ delete: (path: PathType, query?: IObject, data?: IObject, config?: AxiosRequestConfig) => Promise<unknown>;
8
+ };
9
+ /**
10
+ * 系统内置业务服务请求
11
+ * @param path
12
+ * @param params
13
+ * @param config
14
+ * @returns
15
+ */
16
+ export declare function $httpBizService(path: PathType, params: Record<string, unknown>, config?: AxiosRequestConfig): Promise<unknown>;
17
+ /**post 业务服务请求 */
18
+ export declare function $request(modelKey: string, action: PathType['action'], { body, query }?: IObject, config?: AxiosRequestConfig): Promise<unknown>;
19
+ type BizServiceParams = Record<string, unknown>;
20
+ export interface PathType {
21
+ key: string;
22
+ action: keyof typeof BizServiceEnum;
23
+ modelCategory?: EntityModelCategoryEnum;
24
+ }
25
+ export type BizServiceMethod = (path: PathType, params: BizServiceParams, ...args: unknown[]) => Promise<unknown>;
26
+ export {};
@@ -0,0 +1,47 @@
1
+ import { EntityModelCategoryEnum, BizServiceEnum } from '@gct-paas/core';
2
+
3
+ const bizServiceRequestHook = (api) => (path, query = {}, data = {}, config = {}) => {
4
+ return api(
5
+ {
6
+ modelKey: path.key,
7
+ bsKey: path.action,
8
+ modelCategory: path.modelCategory ?? EntityModelCategoryEnum.ENTITY
9
+ },
10
+ query,
11
+ data,
12
+ config
13
+ );
14
+ };
15
+ const BizService = {
16
+ post: bizServiceRequestHook(
17
+ _gct.api.apaas.modelComprehensive.postBizServiceModelCategoryModelKeyBsKey
18
+ ),
19
+ get: bizServiceRequestHook(
20
+ _gct.api.apaas.modelComprehensive.getBizServiceModelCategoryModelKeyBsKey
21
+ ),
22
+ put: bizServiceRequestHook(
23
+ _gct.api.apaas.modelComprehensive.putBizServiceModelCategoryModelKeyBsKey
24
+ ),
25
+ delete: bizServiceRequestHook(
26
+ _gct.api.apaas.modelComprehensive.deleteBizServiceModelCategoryModelKeyBsKey
27
+ )
28
+ };
29
+ async function $httpBizService(path, params, config = {}) {
30
+ const method = BizServiceEnum[path.action];
31
+ return BizService[method](path, params, config);
32
+ }
33
+ async function $request(modelKey, action, { body = {}, query = {} } = {}, config = {}) {
34
+ const res = await _gct.api.apaas.modelComprehensive.postBizServiceGeneralModelCategoryModelKeyBsKey(
35
+ {
36
+ bsKey: action,
37
+ modelKey,
38
+ modelCategory: EntityModelCategoryEnum.ENTITY
39
+ },
40
+ query,
41
+ body,
42
+ config
43
+ );
44
+ return res;
45
+ }
46
+
47
+ export { $httpBizService, $request, BizService };
@@ -0,0 +1,20 @@
1
+ import { FormComponents, ButtonTypeEnum } from '@gct-paas/core';
2
+ export interface InitNodeOptions {
3
+ /**组件方法 */
4
+ elRef: Record<string, FunctionType> | null;
5
+ /**组件类型 */
6
+ type: FormComponents;
7
+ }
8
+ export interface EventsConstructor {
9
+ js: string;
10
+ css: string;
11
+ pageKey?: string;
12
+ }
13
+ export interface processDateValue {
14
+ bizServiceKey: string;
15
+ button: ButtonTypeEnum;
16
+ message?: string;
17
+ processInstanceId?: string;
18
+ processKey: string;
19
+ }
20
+ export type FunctionType = (...arg: unknown[]) => unknown;
@@ -0,0 +1,4 @@
1
+ export { Globals, pageGlobaVariables, globalVarCaches, formMap, setFormData, pageDataforJson, getPageTitle, getPremission, } from './utils/runGlobalByPage';
2
+ export { Events, Context } from './baseEvent';
3
+ export { type EventsConstructor } from './eventType';
4
+ export * from './Dependency/useDependencyToShow';
@@ -0,0 +1,29 @@
1
+ import { UserLoginResp } from '@gct-paas/api/platform';
2
+ export declare class GlobaAppInfo {
3
+ /**环境变量 */
4
+ static ENV: string;
5
+ /**应用标识 */
6
+ static AID: string;
7
+ /**用户信息 */
8
+ static userInfo: UserLoginResp;
9
+ /**app初始化变量 */
10
+ static runApp({ userInfo, env, aid }: RunAppParams): void;
11
+ }
12
+ /**获取缓存变量 */
13
+ export declare const useCreateAppredis: <T = unknown>({ value: defaultValue, appredis, key: varKey, type, }: UseCreateAppredisOptions<T>) => GlobalVar<T>;
14
+ interface RunAppParams {
15
+ env: string;
16
+ aid: string;
17
+ userInfo: UserLoginResp;
18
+ }
19
+ interface GlobalVar<T = unknown> {
20
+ value: T;
21
+ type: unknown;
22
+ }
23
+ export interface UseCreateAppredisOptions<T = unknown> {
24
+ value: T;
25
+ appredis: boolean;
26
+ key: string;
27
+ type: unknown;
28
+ }
29
+ export {};
@@ -0,0 +1,50 @@
1
+ import { useGctSelect } from '../../hooks/useStorageRef.mjs';
2
+
3
+ class GlobaAppInfo {
4
+ /**环境变量 */
5
+ static ENV;
6
+ /**应用标识 */
7
+ static AID;
8
+ /**用户信息 */
9
+ static userInfo;
10
+ /**app初始化变量 */
11
+ static runApp({ userInfo, env, aid }) {
12
+ this.ENV = env;
13
+ this.AID = aid;
14
+ this.userInfo = userInfo;
15
+ }
16
+ }
17
+ const useCreateAppredis = ({
18
+ value: defaultValue,
19
+ appredis,
20
+ key: varKey,
21
+ type
22
+ }) => {
23
+ const isredis = GlobaAppInfo.ENV !== "dev" ? appredis : false;
24
+ const key = `${GlobaAppInfo.AID}_${GlobaAppInfo.userInfo?.userId}`;
25
+ const { cacheMap } = useGctSelect(key);
26
+ const globalVar = new Proxy(
27
+ { value: defaultValue, type },
28
+ {
29
+ get(target, name) {
30
+ if (isredis && name === "value") {
31
+ return cacheMap.value[varKey];
32
+ }
33
+ return Reflect.get(target, name);
34
+ },
35
+ set(target, name, value, receiver) {
36
+ if (isredis && name === "value") {
37
+ if (cacheMap.value[varKey]) {
38
+ cacheMap.value[varKey] = value;
39
+ } else {
40
+ cacheMap.value = { ...cacheMap.value, [varKey]: value };
41
+ }
42
+ }
43
+ return Reflect.set(target, name, value, receiver);
44
+ }
45
+ }
46
+ );
47
+ return globalVar;
48
+ };
49
+
50
+ export { GlobaAppInfo, useCreateAppredis };