@zl-ui-kit/composables 0.0.0-stage → 0.2.0
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 +20 -2
- package/dist/index.d.ts +595 -0
- package/dist/index.js +1439 -0
- package/package.json +61 -4
package/dist/index.js
ADDED
|
@@ -0,0 +1,1439 @@
|
|
|
1
|
+
// src/createCacheComputed.ts
|
|
2
|
+
import { tryOnScopeDispose } from "@vueuse/core";
|
|
3
|
+
import { computed } from "vue";
|
|
4
|
+
function createCacheComputed(getter) {
|
|
5
|
+
const cache = /* @__PURE__ */ new Map();
|
|
6
|
+
const useComputed = (obj) => {
|
|
7
|
+
if (!cache.has(obj)) {
|
|
8
|
+
cache.set(obj, computed(() => getter(obj)));
|
|
9
|
+
}
|
|
10
|
+
return cache.get(obj);
|
|
11
|
+
};
|
|
12
|
+
tryOnScopeDispose(() => {
|
|
13
|
+
cache.clear();
|
|
14
|
+
});
|
|
15
|
+
return Object.assign(useComputed, {
|
|
16
|
+
clear: () => cache.clear()
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
// src/mergeMessages.ts
|
|
21
|
+
function isPlainObject(value) {
|
|
22
|
+
return Object.prototype.toString.call(value) === "[object Object]";
|
|
23
|
+
}
|
|
24
|
+
function deepMerge(base, override) {
|
|
25
|
+
const out = { ...base };
|
|
26
|
+
for (const [key, value] of Object.entries(override)) {
|
|
27
|
+
out[key] = isPlainObject(value) && isPlainObject(out[key]) ? deepMerge(out[key], value) : value;
|
|
28
|
+
}
|
|
29
|
+
return out;
|
|
30
|
+
}
|
|
31
|
+
function mergeMessages(base, ...overrides) {
|
|
32
|
+
let result = { ...base ?? {} };
|
|
33
|
+
for (const override of overrides) {
|
|
34
|
+
if (!override)
|
|
35
|
+
continue;
|
|
36
|
+
result = deepMerge(result, override);
|
|
37
|
+
}
|
|
38
|
+
return result;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// src/useDict.ts
|
|
42
|
+
import { computed as computed2, inject, provide, ref } from "vue";
|
|
43
|
+
import { createGlobalState } from "@vueuse/core";
|
|
44
|
+
var useDictStore = createGlobalState(() => {
|
|
45
|
+
const dictStore = ref({});
|
|
46
|
+
const loadingKeys = ref({});
|
|
47
|
+
let globalSource = null;
|
|
48
|
+
function setDictSource2(source) {
|
|
49
|
+
globalSource = source;
|
|
50
|
+
}
|
|
51
|
+
function getDictSource2() {
|
|
52
|
+
return globalSource;
|
|
53
|
+
}
|
|
54
|
+
async function ensureDict(key, localSource) {
|
|
55
|
+
if (dictStore.value[key]?.length) {
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
if (loadingKeys.value[key]) {
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
const sources = [localSource, globalSource].filter(Boolean);
|
|
62
|
+
if (!sources.length) {
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
loadingKeys.value = { ...loadingKeys.value, [key]: true };
|
|
66
|
+
try {
|
|
67
|
+
for (const source of sources) {
|
|
68
|
+
const items = typeof source === "function" ? await source(key) : source[key];
|
|
69
|
+
if (items?.length) {
|
|
70
|
+
dictStore.value = { ...dictStore.value, [key]: items };
|
|
71
|
+
break;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
} finally {
|
|
75
|
+
loadingKeys.value = { ...loadingKeys.value, [key]: false };
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
return { dictStore, loadingKeys, setDictSource: setDictSource2, getDictSource: getDictSource2, ensureDict };
|
|
79
|
+
});
|
|
80
|
+
function setDictSource(source) {
|
|
81
|
+
useDictStore().setDictSource(source);
|
|
82
|
+
}
|
|
83
|
+
function getDictSource() {
|
|
84
|
+
return useDictStore().getDictSource();
|
|
85
|
+
}
|
|
86
|
+
var dictInjectKey = /* @__PURE__ */ Symbol("dictInjectKey");
|
|
87
|
+
function useDictProvider(source) {
|
|
88
|
+
provide(dictInjectKey, { source });
|
|
89
|
+
}
|
|
90
|
+
function useDict(key, options = {}) {
|
|
91
|
+
const store = useDictStore();
|
|
92
|
+
const { source } = inject(dictInjectKey, {});
|
|
93
|
+
if (options.data?.length) {
|
|
94
|
+
store.dictStore.value = { ...store.dictStore.value, [key]: options.data };
|
|
95
|
+
} else {
|
|
96
|
+
store.ensureDict(key, source);
|
|
97
|
+
}
|
|
98
|
+
const dict = computed2(() => store.dictStore.value[key] || []);
|
|
99
|
+
const label = computed2(() => {
|
|
100
|
+
return dict.value.reduce((acc, item) => {
|
|
101
|
+
acc[item.value] = item.label;
|
|
102
|
+
return acc;
|
|
103
|
+
}, {});
|
|
104
|
+
});
|
|
105
|
+
return Object.assign(dict, { label });
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
// src/useGlobalMessage.ts
|
|
109
|
+
import { ElMessage, ElMessageBox, ElNotification } from "element-plus";
|
|
110
|
+
var confirmPromise = (config, onOk, onCancel) => {
|
|
111
|
+
const { throwOnOk, throwOnCancel, ...messageBoxOptions } = config;
|
|
112
|
+
return new Promise((resolve, reject) => {
|
|
113
|
+
ElMessageBox.confirm(messageBoxOptions.message ?? "", messageBoxOptions.title ?? "", {
|
|
114
|
+
...messageBoxOptions,
|
|
115
|
+
beforeClose: async (action, instance, doneRaw) => {
|
|
116
|
+
const done = doneRaw;
|
|
117
|
+
const ctx = { close: done, resolve, reject, instance };
|
|
118
|
+
if (action === "confirm") {
|
|
119
|
+
try {
|
|
120
|
+
await onOk?.(ctx);
|
|
121
|
+
resolve("Ok");
|
|
122
|
+
done();
|
|
123
|
+
} catch (error) {
|
|
124
|
+
if (throwOnOk) {
|
|
125
|
+
done(false);
|
|
126
|
+
reject(error);
|
|
127
|
+
} else {
|
|
128
|
+
resolve(false);
|
|
129
|
+
done();
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
} else {
|
|
133
|
+
try {
|
|
134
|
+
await onCancel?.(ctx);
|
|
135
|
+
if (throwOnCancel) {
|
|
136
|
+
done(false);
|
|
137
|
+
reject(new Error("Cancel"));
|
|
138
|
+
} else {
|
|
139
|
+
resolve("Cancel");
|
|
140
|
+
done();
|
|
141
|
+
}
|
|
142
|
+
} catch (error) {
|
|
143
|
+
done(false);
|
|
144
|
+
reject(error);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
}).catch(() => {
|
|
149
|
+
});
|
|
150
|
+
});
|
|
151
|
+
};
|
|
152
|
+
var MessageBox = Object.assign(ElMessageBox, { confirmPromise });
|
|
153
|
+
function useGlobalMessage(_directMode = false) {
|
|
154
|
+
return { Message: ElMessage, Modal: MessageBox, Notification: ElNotification };
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
// src/useLocale.ts
|
|
158
|
+
import { toValue as toValue2, watch as watch2 } from "vue";
|
|
159
|
+
import { createI18n } from "vue-i18n";
|
|
160
|
+
|
|
161
|
+
// src/useMicroGlobalData.ts
|
|
162
|
+
import { isFunction, isPlainObject as isPlainObject2, withResolvers } from "@zl-ui-kit/utils";
|
|
163
|
+
import _microApp from "@micro-zoe/micro-app";
|
|
164
|
+
import { createGlobalState as createGlobalState2, useStorage } from "@vueuse/core";
|
|
165
|
+
import { computed as computed3, customRef, nextTick, readonly, ref as ref2, toValue, watch } from "vue";
|
|
166
|
+
var microApp = window.microApp || _microApp;
|
|
167
|
+
var devMockEnabled = false;
|
|
168
|
+
function enableGlobalDataMock(enabled = true) {
|
|
169
|
+
devMockEnabled = enabled;
|
|
170
|
+
}
|
|
171
|
+
function createStorages() {
|
|
172
|
+
return {
|
|
173
|
+
locale: useStorage("$zl_locale", ""),
|
|
174
|
+
theme: useStorage("$zl_theme", "light"),
|
|
175
|
+
token: useStorage("$zl_token", void 0)
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
function createInitialedData(storages) {
|
|
179
|
+
return {
|
|
180
|
+
initialed: true,
|
|
181
|
+
locale: storages.locale.value,
|
|
182
|
+
theme: storages.theme.value,
|
|
183
|
+
token: storages.token.value,
|
|
184
|
+
isI18nKeyVisible: false,
|
|
185
|
+
roles: [],
|
|
186
|
+
permissions: [],
|
|
187
|
+
user: void 0,
|
|
188
|
+
localeMessages: {},
|
|
189
|
+
elLocaleMessages: void 0,
|
|
190
|
+
config: void 0
|
|
191
|
+
};
|
|
192
|
+
}
|
|
193
|
+
function useDevMockGlobalData() {
|
|
194
|
+
const storages = createStorages();
|
|
195
|
+
const globalData = ref2(createInitialedData(storages));
|
|
196
|
+
function getConfig(key, defaultValue) {
|
|
197
|
+
return globalData.value.config?.[key] ?? defaultValue;
|
|
198
|
+
}
|
|
199
|
+
function isConfig(key, compareValue = "true") {
|
|
200
|
+
return globalData.value.config?.[key] === compareValue;
|
|
201
|
+
}
|
|
202
|
+
async function setAndWaitUntil({ set }) {
|
|
203
|
+
globalData.value = { ...globalData.value, ...set };
|
|
204
|
+
await nextTick();
|
|
205
|
+
}
|
|
206
|
+
const _toComputed = (prop) => {
|
|
207
|
+
return computed3({
|
|
208
|
+
get() {
|
|
209
|
+
return globalData.value[prop];
|
|
210
|
+
},
|
|
211
|
+
set(value) {
|
|
212
|
+
globalData.value = {
|
|
213
|
+
...globalData.value,
|
|
214
|
+
[prop]: value
|
|
215
|
+
};
|
|
216
|
+
return true;
|
|
217
|
+
}
|
|
218
|
+
});
|
|
219
|
+
};
|
|
220
|
+
updateBodyAttribute("data-theme", storages.theme.value);
|
|
221
|
+
updateBodyAttribute("data-locale", storages.locale.value);
|
|
222
|
+
return Object.assign(globalData, {
|
|
223
|
+
initialed: readonly(_toComputed("initialed")),
|
|
224
|
+
locale: _toComputed("locale"),
|
|
225
|
+
theme: _toComputed("theme"),
|
|
226
|
+
token: _toComputed("token"),
|
|
227
|
+
isI18nKeyVisible: _toComputed("isI18nKeyVisible"),
|
|
228
|
+
roles: _toComputed("roles"),
|
|
229
|
+
permissions: _toComputed("permissions"),
|
|
230
|
+
user: _toComputed("user"),
|
|
231
|
+
localeMessages: _toComputed("localeMessages"),
|
|
232
|
+
elLocaleMessages: _toComputed("elLocaleMessages"),
|
|
233
|
+
config: _toComputed("config")
|
|
234
|
+
}, { getConfig, isConfig, setAndWaitUntil });
|
|
235
|
+
}
|
|
236
|
+
var useMicroGlobalData = createGlobalState2(() => {
|
|
237
|
+
if (devMockEnabled && !window.microApp) {
|
|
238
|
+
console.warn("[useMicroGlobalData] \u4F7F\u7528\u5F00\u53D1\u6001 mock \u6570\u636E\uFF08enableGlobalDataMock \u5DF2\u5F00\u542F\uFF09");
|
|
239
|
+
return useDevMockGlobalData();
|
|
240
|
+
}
|
|
241
|
+
const storages = createStorages();
|
|
242
|
+
const triggers = /* @__PURE__ */ new Set();
|
|
243
|
+
let _computedSetTrigger;
|
|
244
|
+
const globalData = customRef((track, trigger2) => {
|
|
245
|
+
_computedSetTrigger = trigger2;
|
|
246
|
+
return {
|
|
247
|
+
get() {
|
|
248
|
+
track();
|
|
249
|
+
return microApp.getGlobalData() || Object.fromEntries(Object.entries(storages).map(([key, storage]) => [key, toValue(storage)]));
|
|
250
|
+
},
|
|
251
|
+
set(value) {
|
|
252
|
+
microApp.setGlobalData(value);
|
|
253
|
+
return true;
|
|
254
|
+
}
|
|
255
|
+
};
|
|
256
|
+
});
|
|
257
|
+
function trigger() {
|
|
258
|
+
_computedSetTrigger();
|
|
259
|
+
nextTick(() => {
|
|
260
|
+
triggers.forEach((fn) => fn());
|
|
261
|
+
});
|
|
262
|
+
}
|
|
263
|
+
microApp.addGlobalDataListener(trigger);
|
|
264
|
+
if (!globalData.value.initialed) {
|
|
265
|
+
globalData.value = createInitialedData(storages);
|
|
266
|
+
}
|
|
267
|
+
updateBodyAttribute("data-theme", storages.theme.value);
|
|
268
|
+
updateBodyAttribute("data-locale", storages.locale.value);
|
|
269
|
+
const storagesKey = Object.keys(storages);
|
|
270
|
+
watch(() => storagesKey.map((key) => globalData.value[key]), (values) => {
|
|
271
|
+
values.forEach((value, index) => {
|
|
272
|
+
const key = storagesKey[index];
|
|
273
|
+
if (storages[key].value !== value) {
|
|
274
|
+
storages[key].value = value;
|
|
275
|
+
if (key === "theme") {
|
|
276
|
+
updateBodyAttribute("data-theme", value);
|
|
277
|
+
}
|
|
278
|
+
if (key === "locale") {
|
|
279
|
+
updateBodyAttribute("data-locale", value);
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
});
|
|
283
|
+
});
|
|
284
|
+
const _toComputed = (prop) => {
|
|
285
|
+
return computed3({
|
|
286
|
+
get() {
|
|
287
|
+
return globalData.value[prop];
|
|
288
|
+
},
|
|
289
|
+
set(value) {
|
|
290
|
+
globalData.value = { [prop]: value };
|
|
291
|
+
return true;
|
|
292
|
+
}
|
|
293
|
+
});
|
|
294
|
+
};
|
|
295
|
+
function setAndWaitUntil({ set, until }) {
|
|
296
|
+
if (!set && !until && !isPlainObject2(set) && !isFunction(until)) {
|
|
297
|
+
return Promise.resolve();
|
|
298
|
+
}
|
|
299
|
+
const { resolve, promise } = withResolvers();
|
|
300
|
+
globalData.value = set;
|
|
301
|
+
const triggerFn = () => {
|
|
302
|
+
if (until?.(globalData.value)) {
|
|
303
|
+
triggers.delete(triggerFn);
|
|
304
|
+
resolve();
|
|
305
|
+
}
|
|
306
|
+
};
|
|
307
|
+
triggers.add(triggerFn);
|
|
308
|
+
return promise;
|
|
309
|
+
}
|
|
310
|
+
function getConfig(key, defaultValue) {
|
|
311
|
+
return globalData.value.config?.[key] ?? defaultValue;
|
|
312
|
+
}
|
|
313
|
+
function isConfig(key, compareValue = "true") {
|
|
314
|
+
return globalData.value.config?.[key] === compareValue;
|
|
315
|
+
}
|
|
316
|
+
function resetUser() {
|
|
317
|
+
globalData.value = { user: void 0, roles: [], permissions: [], token: void 0 };
|
|
318
|
+
storages.token.value = void 0;
|
|
319
|
+
}
|
|
320
|
+
return Object.assign(globalData, {
|
|
321
|
+
initialed: readonly(_toComputed("initialed")),
|
|
322
|
+
locale: _toComputed("locale"),
|
|
323
|
+
theme: _toComputed("theme"),
|
|
324
|
+
token: _toComputed("token"),
|
|
325
|
+
isI18nKeyVisible: _toComputed("isI18nKeyVisible"),
|
|
326
|
+
roles: _toComputed("roles"),
|
|
327
|
+
permissions: _toComputed("permissions"),
|
|
328
|
+
user: _toComputed("user"),
|
|
329
|
+
localeMessages: _toComputed("localeMessages"),
|
|
330
|
+
elLocaleMessages: _toComputed("elLocaleMessages"),
|
|
331
|
+
config: _toComputed("config"),
|
|
332
|
+
setAndWaitUntil,
|
|
333
|
+
getConfig,
|
|
334
|
+
isConfig,
|
|
335
|
+
resetUser
|
|
336
|
+
});
|
|
337
|
+
});
|
|
338
|
+
function updateBodyAttribute(key, value) {
|
|
339
|
+
;
|
|
340
|
+
[document.body, ...document.querySelectorAll("micro-app-body")].forEach((el) => {
|
|
341
|
+
el.setAttribute(key, String(value ?? ""));
|
|
342
|
+
});
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
// src/useLocale.ts
|
|
346
|
+
var elLocaleMessagesStore = {};
|
|
347
|
+
function useLocale(options = {}, loader) {
|
|
348
|
+
const { locale, localeMessages, elLocaleMessages, isI18nKeyVisible } = useMicroGlobalData();
|
|
349
|
+
function postTranslation(translated, key) {
|
|
350
|
+
if (isI18nKeyVisible.value)
|
|
351
|
+
return key;
|
|
352
|
+
return options.postTranslation ? options.postTranslation(translated, key) : translated;
|
|
353
|
+
}
|
|
354
|
+
const i18n = createI18n({
|
|
355
|
+
locale: locale.value,
|
|
356
|
+
...options,
|
|
357
|
+
legacy: false,
|
|
358
|
+
postTranslation
|
|
359
|
+
});
|
|
360
|
+
if (options.messages) {
|
|
361
|
+
localeMessages.value = options.messages;
|
|
362
|
+
}
|
|
363
|
+
const loadedLocale = [];
|
|
364
|
+
watch2(locale, async (value) => {
|
|
365
|
+
if (!value)
|
|
366
|
+
return;
|
|
367
|
+
i18n.global.locale.value = value;
|
|
368
|
+
if (loader) {
|
|
369
|
+
if (loadedLocale.includes(value)) {
|
|
370
|
+
elLocaleMessages.value = elLocaleMessagesStore[value];
|
|
371
|
+
return;
|
|
372
|
+
}
|
|
373
|
+
const messages = await loader(value);
|
|
374
|
+
loadedLocale.push(value);
|
|
375
|
+
localeMessages.value = messages.localeMessages;
|
|
376
|
+
elLocaleMessages.value = messages.elLocaleMessages;
|
|
377
|
+
elLocaleMessagesStore[value] = messages.elLocaleMessages;
|
|
378
|
+
}
|
|
379
|
+
}, { immediate: true });
|
|
380
|
+
let storeLocale;
|
|
381
|
+
watch2(isI18nKeyVisible, (visible) => {
|
|
382
|
+
const currentLocale = toValue2(i18n.global.locale);
|
|
383
|
+
if (visible) {
|
|
384
|
+
storeLocale = [currentLocale, i18n.global.getLocaleMessage(currentLocale)];
|
|
385
|
+
i18n.global.setLocaleMessage(currentLocale, {});
|
|
386
|
+
} else if (storeLocale) {
|
|
387
|
+
i18n.global.setLocaleMessage(storeLocale[0], storeLocale[1]);
|
|
388
|
+
storeLocale = void 0;
|
|
389
|
+
}
|
|
390
|
+
});
|
|
391
|
+
watch2(localeMessages, (messages) => {
|
|
392
|
+
if (!messages || typeof messages !== "object")
|
|
393
|
+
return;
|
|
394
|
+
if (!("locale" in messages)) {
|
|
395
|
+
for (const [loc2, msg] of Object.entries(messages)) {
|
|
396
|
+
if (msg && typeof msg === "object")
|
|
397
|
+
i18n.global.setLocaleMessage(loc2, msg);
|
|
398
|
+
}
|
|
399
|
+
return;
|
|
400
|
+
}
|
|
401
|
+
const { locale: loc, ...rest } = messages;
|
|
402
|
+
if (loc)
|
|
403
|
+
i18n.global.setLocaleMessage(loc, rest);
|
|
404
|
+
}, { immediate: true });
|
|
405
|
+
return {
|
|
406
|
+
i18n,
|
|
407
|
+
isI18nKeyVisible,
|
|
408
|
+
locale
|
|
409
|
+
};
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
// src/useZlT.ts
|
|
413
|
+
import { useI18n } from "vue-i18n";
|
|
414
|
+
function useZlT() {
|
|
415
|
+
let t = (key, fallback) => fallback ?? key;
|
|
416
|
+
try {
|
|
417
|
+
const globalT = useI18n({ useScope: "global" }).t;
|
|
418
|
+
t = (key, fallback, params) => {
|
|
419
|
+
const msg = params ? globalT(key, params) : globalT(key);
|
|
420
|
+
return msg === key ? fallback ?? key : msg;
|
|
421
|
+
};
|
|
422
|
+
} catch {
|
|
423
|
+
}
|
|
424
|
+
return { t };
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
// src/useMicroAction.ts
|
|
428
|
+
import microApp3 from "@micro-zoe/micro-app";
|
|
429
|
+
import { createSharedComposable, tryOnScopeDispose as tryOnScopeDispose2 } from "@vueuse/core";
|
|
430
|
+
import { watch as watch3 } from "vue";
|
|
431
|
+
|
|
432
|
+
// src/useMicroApp.ts
|
|
433
|
+
import microApp2 from "@micro-zoe/micro-app";
|
|
434
|
+
import { createGlobalState as createGlobalState3 } from "@vueuse/core";
|
|
435
|
+
import { ref as ref3 } from "vue";
|
|
436
|
+
var useMicroApp = createGlobalState3(() => {
|
|
437
|
+
const apps = ref3([]);
|
|
438
|
+
function isMicroBase() {
|
|
439
|
+
return !!window.__MICRO_APP_BASE_APPLICATION__;
|
|
440
|
+
}
|
|
441
|
+
function isMicroChild() {
|
|
442
|
+
return !!window.__MICRO_APP_ENVIRONMENT__;
|
|
443
|
+
}
|
|
444
|
+
function updateApps() {
|
|
445
|
+
apps.value = microApp2.getActiveApps();
|
|
446
|
+
}
|
|
447
|
+
function startMicroApp(config = {}) {
|
|
448
|
+
microApp2.start({
|
|
449
|
+
...config,
|
|
450
|
+
lifeCycles: {
|
|
451
|
+
mounted(data) {
|
|
452
|
+
updateApps();
|
|
453
|
+
config?.lifeCycles?.mounted?.(data);
|
|
454
|
+
},
|
|
455
|
+
// micro-app 的卸载生命周期名为 unmount,对外保持 unmounted 语义
|
|
456
|
+
unmount(data) {
|
|
457
|
+
updateApps();
|
|
458
|
+
config?.lifeCycles?.unmounted?.(data);
|
|
459
|
+
}
|
|
460
|
+
}
|
|
461
|
+
});
|
|
462
|
+
return microApp2;
|
|
463
|
+
}
|
|
464
|
+
return { apps, isMicroBase, isMicroChild, updateApps, startMicroApp };
|
|
465
|
+
});
|
|
466
|
+
|
|
467
|
+
// src/useMicroAction.ts
|
|
468
|
+
var ACTION_PREFIX = "action__";
|
|
469
|
+
var ACTION_ROOT_PREFIX = "action__root__";
|
|
470
|
+
function _action(action, onlyRoot = false) {
|
|
471
|
+
return `${onlyRoot ? ACTION_ROOT_PREFIX : ACTION_PREFIX}${action}`;
|
|
472
|
+
}
|
|
473
|
+
function isEmitRoot(action) {
|
|
474
|
+
return action.startsWith(`${ACTION_ROOT_PREFIX}emit-`);
|
|
475
|
+
}
|
|
476
|
+
var useMicroListener = createSharedComposable(() => {
|
|
477
|
+
const { isMicroBase, isMicroChild, apps } = useMicroApp();
|
|
478
|
+
const listenerMap = /* @__PURE__ */ new Map();
|
|
479
|
+
const handler = (data) => {
|
|
480
|
+
Object.entries(data).forEach(([args, key]) => {
|
|
481
|
+
if (isEmitRoot(key) && isMicroBase() && isMicroChild()) {
|
|
482
|
+
window.microApp?.dispatch({ [JSON.stringify(args)]: key });
|
|
483
|
+
return;
|
|
484
|
+
}
|
|
485
|
+
const action = key.replace(ACTION_ROOT_PREFIX, "").replace(ACTION_PREFIX, "");
|
|
486
|
+
const callbackSet = listenerMap.get(action);
|
|
487
|
+
if (!callbackSet?.size) {
|
|
488
|
+
return;
|
|
489
|
+
}
|
|
490
|
+
delete data[args];
|
|
491
|
+
callbackSet.forEach((callback) => callback(...JSON.parse(args)));
|
|
492
|
+
});
|
|
493
|
+
};
|
|
494
|
+
const listeners = [];
|
|
495
|
+
if (isMicroChild()) {
|
|
496
|
+
const _microApp2 = window.microApp;
|
|
497
|
+
_microApp2?.addDataListener(handler);
|
|
498
|
+
listeners.push(() => {
|
|
499
|
+
_microApp2?.removeDataListener(handler);
|
|
500
|
+
});
|
|
501
|
+
}
|
|
502
|
+
if (isMicroBase()) {
|
|
503
|
+
listeners.push(() => {
|
|
504
|
+
apps.value.forEach((app) => {
|
|
505
|
+
microApp3.removeDataListener(app, handler);
|
|
506
|
+
});
|
|
507
|
+
});
|
|
508
|
+
watch3(apps, (newApps, oldApps) => {
|
|
509
|
+
oldApps.forEach((app) => {
|
|
510
|
+
microApp3.removeDataListener(app, handler);
|
|
511
|
+
});
|
|
512
|
+
newApps.forEach((app) => {
|
|
513
|
+
microApp3.addDataListener(app, handler);
|
|
514
|
+
});
|
|
515
|
+
}, { deep: true });
|
|
516
|
+
}
|
|
517
|
+
const _ensureGetCallbackSet = (action) => {
|
|
518
|
+
let callbackSet = listenerMap.get(action);
|
|
519
|
+
if (!callbackSet) {
|
|
520
|
+
callbackSet = /* @__PURE__ */ new Set();
|
|
521
|
+
listenerMap.set(action, callbackSet);
|
|
522
|
+
}
|
|
523
|
+
return callbackSet;
|
|
524
|
+
};
|
|
525
|
+
const on = (action, callback) => {
|
|
526
|
+
_ensureGetCallbackSet(action).add(callback);
|
|
527
|
+
};
|
|
528
|
+
const off = (action, callback) => {
|
|
529
|
+
const callbackSet = listenerMap.get(action);
|
|
530
|
+
if (callbackSet) {
|
|
531
|
+
callbackSet.delete(callback);
|
|
532
|
+
}
|
|
533
|
+
};
|
|
534
|
+
const once = (action, callback) => {
|
|
535
|
+
const callbackSet = _ensureGetCallbackSet(action);
|
|
536
|
+
const handler2 = (...args) => {
|
|
537
|
+
callback(...args);
|
|
538
|
+
callbackSet.delete(handler2);
|
|
539
|
+
};
|
|
540
|
+
callbackSet.add(handler2);
|
|
541
|
+
};
|
|
542
|
+
const dispose = () => {
|
|
543
|
+
listenerMap.clear();
|
|
544
|
+
listeners.forEach((fn) => fn());
|
|
545
|
+
};
|
|
546
|
+
tryOnScopeDispose2(dispose);
|
|
547
|
+
return { on, off, once };
|
|
548
|
+
});
|
|
549
|
+
function useMicroAction(action, appName) {
|
|
550
|
+
const { apps } = useMicroApp();
|
|
551
|
+
const _actionName = _action(action);
|
|
552
|
+
return (...args) => {
|
|
553
|
+
const _apps = !appName ? apps.value : apps.value.filter((app) => app === appName);
|
|
554
|
+
_apps.forEach((app) => {
|
|
555
|
+
microApp3.setData(app, { [JSON.stringify(args)]: _actionName });
|
|
556
|
+
});
|
|
557
|
+
};
|
|
558
|
+
}
|
|
559
|
+
function useMicroActionAsync(action, appName) {
|
|
560
|
+
const _actionName = _action(action);
|
|
561
|
+
const { isMicroBase, isMicroChild } = useMicroApp();
|
|
562
|
+
if (!isMicroBase()) {
|
|
563
|
+
return (...args) => {
|
|
564
|
+
return new Promise((resolve, reject) => {
|
|
565
|
+
window.microApp?.dispatch({ [JSON.stringify(args)]: _actionName }, (promises) => {
|
|
566
|
+
Promise.all(promises).then(resolve, reject);
|
|
567
|
+
});
|
|
568
|
+
});
|
|
569
|
+
};
|
|
570
|
+
}
|
|
571
|
+
if (isMicroChild()) {
|
|
572
|
+
return (...args) => {
|
|
573
|
+
return new Promise((resolve, reject) => {
|
|
574
|
+
microApp3.setData(appName, { [JSON.stringify(args)]: _actionName }, (promises) => {
|
|
575
|
+
Promise.all(promises).then(resolve, reject);
|
|
576
|
+
});
|
|
577
|
+
});
|
|
578
|
+
};
|
|
579
|
+
}
|
|
580
|
+
return (..._args) => Promise.resolve([]);
|
|
581
|
+
}
|
|
582
|
+
function useMicroResultListener(action, callback) {
|
|
583
|
+
const { isMicroBase } = useMicroApp();
|
|
584
|
+
const _actionName = _action(action);
|
|
585
|
+
const handler = async (data) => {
|
|
586
|
+
for (const [args, key] of Object.entries(data)) {
|
|
587
|
+
if (key === _actionName) {
|
|
588
|
+
delete data[args];
|
|
589
|
+
return await callback(...JSON.parse(args));
|
|
590
|
+
}
|
|
591
|
+
}
|
|
592
|
+
};
|
|
593
|
+
const micro = isMicroBase() ? microApp3 : window.microApp;
|
|
594
|
+
micro?.addDataListener(handler);
|
|
595
|
+
}
|
|
596
|
+
function dispatchMicroAction(action, appName, ...data) {
|
|
597
|
+
const _actionName = _action(action);
|
|
598
|
+
return new Promise((resolve) => {
|
|
599
|
+
microApp3.setData(appName, { [JSON.stringify(data)]: _actionName }, resolve);
|
|
600
|
+
});
|
|
601
|
+
}
|
|
602
|
+
|
|
603
|
+
// src/usePageTabs.ts
|
|
604
|
+
import microApp4 from "@micro-zoe/micro-app";
|
|
605
|
+
import { createGlobalState as createGlobalState4 } from "@vueuse/core";
|
|
606
|
+
import { computed as computed4, getCurrentInstance, nextTick as nextTick2, reactive, readonly as readonly2, ref as ref4, shallowReactive, watch as watch4 } from "vue";
|
|
607
|
+
function pushMicroRouter({ micro, url }) {
|
|
608
|
+
if (!micro || !url)
|
|
609
|
+
return;
|
|
610
|
+
const activeApps = microApp4.getActiveApps();
|
|
611
|
+
if (!activeApps.includes(micro))
|
|
612
|
+
return;
|
|
613
|
+
return microApp4.router.push({ name: micro, path: url });
|
|
614
|
+
}
|
|
615
|
+
var createPageTabsState = createGlobalState4(() => {
|
|
616
|
+
const { on } = useMicroListener();
|
|
617
|
+
const roots = reactive({});
|
|
618
|
+
const activeRootKey = ref4(null);
|
|
619
|
+
const activeRoot = computed4(() => activeRootKey.value ? roots[activeRootKey.value] : null);
|
|
620
|
+
const pageTabs = computed4(() => {
|
|
621
|
+
if (!activeRoot.value)
|
|
622
|
+
return [];
|
|
623
|
+
return activeRoot.value.tabs.reduce((acc, cur) => {
|
|
624
|
+
const getChildren = (item) => {
|
|
625
|
+
if (item.children) {
|
|
626
|
+
const children = item.children.map((i) => getChildren(i)).flat();
|
|
627
|
+
Object.assign(children[0], { title: item.title, icon: item.icon });
|
|
628
|
+
return children;
|
|
629
|
+
} else {
|
|
630
|
+
return [item];
|
|
631
|
+
}
|
|
632
|
+
};
|
|
633
|
+
if (cur.children) {
|
|
634
|
+
return [...acc, ...getChildren(cur)];
|
|
635
|
+
} else {
|
|
636
|
+
return [...acc, cur];
|
|
637
|
+
}
|
|
638
|
+
}, []);
|
|
639
|
+
});
|
|
640
|
+
const current = computed4(() => {
|
|
641
|
+
return pageTabs.value.find((item) => item.key === activeRoot.value?.activeTabKey);
|
|
642
|
+
});
|
|
643
|
+
const micros = shallowReactive({});
|
|
644
|
+
async function _removePageTabByKey(key, root = activeRoot.value) {
|
|
645
|
+
const index = root.tabs.findIndex((item) => item.key === key);
|
|
646
|
+
if (index === -1)
|
|
647
|
+
return false;
|
|
648
|
+
const tab = root.tabs[index];
|
|
649
|
+
try {
|
|
650
|
+
if (typeof tab.beforeRemove === "function") {
|
|
651
|
+
const shouldRemove = await tab.beforeRemove();
|
|
652
|
+
if (shouldRemove === false)
|
|
653
|
+
return false;
|
|
654
|
+
}
|
|
655
|
+
root.tabs.splice(index, 1);
|
|
656
|
+
const parentTab = root._parentMap[key];
|
|
657
|
+
delete root._parentMap[key];
|
|
658
|
+
if (root.activeTabKey === key) {
|
|
659
|
+
root.activeTabKey = root.tabs.at(index - 1)?.key ?? root.tabs[0]?.key ?? "";
|
|
660
|
+
}
|
|
661
|
+
return [tab, parentTab];
|
|
662
|
+
} catch {
|
|
663
|
+
return false;
|
|
664
|
+
}
|
|
665
|
+
}
|
|
666
|
+
on("dispatch-page-key-change", ({ key, root }) => {
|
|
667
|
+
const changedRoot = roots[root];
|
|
668
|
+
if (!changedRoot)
|
|
669
|
+
return;
|
|
670
|
+
changedRoot.activeTabKey = key;
|
|
671
|
+
activeRootKey.value = root;
|
|
672
|
+
});
|
|
673
|
+
on("dispatch-page-key-remove", ({ key, root, isRoot }) => {
|
|
674
|
+
if (isRoot) {
|
|
675
|
+
roots[root] = void 0;
|
|
676
|
+
if (activeRootKey.value === root) {
|
|
677
|
+
const rootKeys = Object.keys(roots);
|
|
678
|
+
activeRootKey.value = rootKeys.at(rootKeys.indexOf(root) - 1) ?? null;
|
|
679
|
+
}
|
|
680
|
+
return;
|
|
681
|
+
}
|
|
682
|
+
const changedRoot = roots[root];
|
|
683
|
+
if (!changedRoot)
|
|
684
|
+
return;
|
|
685
|
+
_removePageTabByKey(key, changedRoot);
|
|
686
|
+
});
|
|
687
|
+
watch4(current, (val) => {
|
|
688
|
+
if (!val?.micro)
|
|
689
|
+
return;
|
|
690
|
+
if (!val.isChildMicro)
|
|
691
|
+
return;
|
|
692
|
+
if (!micros[val.micro]) {
|
|
693
|
+
micros[val.micro] = val.url;
|
|
694
|
+
} else if (val.url) {
|
|
695
|
+
pushMicroRouter(val);
|
|
696
|
+
} else {
|
|
697
|
+
pushMicroRouter({ micro: val.micro, url: val.rootKey });
|
|
698
|
+
}
|
|
699
|
+
});
|
|
700
|
+
return {
|
|
701
|
+
roots,
|
|
702
|
+
activeRoot,
|
|
703
|
+
activeRootKey,
|
|
704
|
+
micros,
|
|
705
|
+
pageTabs,
|
|
706
|
+
current,
|
|
707
|
+
_removePageTabByKey
|
|
708
|
+
};
|
|
709
|
+
});
|
|
710
|
+
function usePageTabs() {
|
|
711
|
+
const { roots, activeRootKey, micros, _removePageTabByKey, ...state } = createPageTabsState();
|
|
712
|
+
const { isMicroBase } = useMicroApp();
|
|
713
|
+
const vm = getCurrentInstance();
|
|
714
|
+
function createPageTabsRoot(root) {
|
|
715
|
+
if (!roots[root.key]) {
|
|
716
|
+
const rootTab = { ...root, isRoot: true };
|
|
717
|
+
roots[root.key] = {
|
|
718
|
+
tabs: [rootTab],
|
|
719
|
+
activeTabKey: rootTab.key,
|
|
720
|
+
_parentMap: shallowReactive({})
|
|
721
|
+
};
|
|
722
|
+
}
|
|
723
|
+
activeRootKey.value = root.key;
|
|
724
|
+
}
|
|
725
|
+
function addPageTab(tab, options) {
|
|
726
|
+
const { update, childMicro = true } = { update: false, ...options };
|
|
727
|
+
const root = roots[activeRootKey.value];
|
|
728
|
+
const lastActiveTabKey = root.activeTabKey;
|
|
729
|
+
root._parentMap[tab.key] = vm;
|
|
730
|
+
root.activeTabKey = tab.key;
|
|
731
|
+
const index = root.tabs.findIndex((item) => item.key === tab.key);
|
|
732
|
+
if (index > -1 && !update) {
|
|
733
|
+
return false;
|
|
734
|
+
}
|
|
735
|
+
let currentTab = { ...tab, _parentTabKey: lastActiveTabKey };
|
|
736
|
+
if (isComponentTab(tab)) {
|
|
737
|
+
const { title, key, icon, beforeRemove, component, props, ..._props } = tab;
|
|
738
|
+
currentTab = { title, key, icon, beforeRemove, component, props: { ...props, ..._props }, _parentTabKey: lastActiveTabKey };
|
|
739
|
+
} else if (tab.micro && isMicroBase() && childMicro) {
|
|
740
|
+
currentTab.isChildMicro = true;
|
|
741
|
+
addMicro(currentTab);
|
|
742
|
+
}
|
|
743
|
+
if (index > -1) {
|
|
744
|
+
root.tabs[index] = currentTab;
|
|
745
|
+
} else {
|
|
746
|
+
root.tabs.push(currentTab);
|
|
747
|
+
}
|
|
748
|
+
return true;
|
|
749
|
+
}
|
|
750
|
+
async function removePageTab(tabOrKey = roots[activeRootKey.value].activeTabKey) {
|
|
751
|
+
if (!tabOrKey)
|
|
752
|
+
return;
|
|
753
|
+
if (typeof tabOrKey === "string") {
|
|
754
|
+
return _removePageTabByKey(tabOrKey);
|
|
755
|
+
}
|
|
756
|
+
if (tabOrKey.isChildRoot) {
|
|
757
|
+
await _removeChildRoot(tabOrKey);
|
|
758
|
+
} else if (tabOrKey.isChild) {
|
|
759
|
+
dispatchMicroAction("dispatch-page-key-remove", tabOrKey.micro, {
|
|
760
|
+
key: tabOrKey.key,
|
|
761
|
+
root: tabOrKey.rootKey
|
|
762
|
+
});
|
|
763
|
+
} else {
|
|
764
|
+
return _removePageTabByKey(tabOrKey.key);
|
|
765
|
+
}
|
|
766
|
+
return false;
|
|
767
|
+
}
|
|
768
|
+
function clearPageTab(rootKey = activeRootKey.value) {
|
|
769
|
+
const rootKeys = Object.keys(roots);
|
|
770
|
+
delete roots[rootKey];
|
|
771
|
+
if (rootKey === activeRootKey.value) {
|
|
772
|
+
const index = rootKeys.indexOf(rootKey);
|
|
773
|
+
rootKeys.splice(index, 1);
|
|
774
|
+
activeRootKey.value = rootKeys.at(index - 1) ?? null;
|
|
775
|
+
}
|
|
776
|
+
}
|
|
777
|
+
function setRootChild(tabs, activeChildTabKey, micro) {
|
|
778
|
+
if (!activeChildTabKey || micro.startsWith("flowable_"))
|
|
779
|
+
return;
|
|
780
|
+
const root = roots[activeRootKey.value];
|
|
781
|
+
const childRootTab = tabs[0];
|
|
782
|
+
const childRootTabKey = `${childRootTab.micro}__${childRootTab.key}`;
|
|
783
|
+
const currentTab = state.pageTabs.value.find((tab) => tab.key === root.activeTabKey);
|
|
784
|
+
root._parentTabMap ?? (root._parentTabMap = {});
|
|
785
|
+
if (!root._parentTabMap[childRootTabKey]) {
|
|
786
|
+
root._parentTabMap[childRootTabKey] = currentTab;
|
|
787
|
+
}
|
|
788
|
+
const parentTab = root._parentTabMap[childRootTabKey];
|
|
789
|
+
function childTabFormatter(tab) {
|
|
790
|
+
return { ...tab, isChild: true, isChildMicro: !!tab.micro, parentTab, childRootTabKey };
|
|
791
|
+
}
|
|
792
|
+
const oldTabs = parentTab.children;
|
|
793
|
+
if (!oldTabs?.length) {
|
|
794
|
+
parentTab.children = tabs.map(childTabFormatter);
|
|
795
|
+
} else {
|
|
796
|
+
const newTabs = parentTab.children = [];
|
|
797
|
+
if (tabs.length > oldTabs.length) {
|
|
798
|
+
newTabs.push(...oldTabs, ...tabs.slice(oldTabs.length).map(childTabFormatter));
|
|
799
|
+
} else if (tabs.length < oldTabs.length) {
|
|
800
|
+
const oldChildMap = oldTabs.reduce((acc, cur) => {
|
|
801
|
+
acc[cur.key] = cur;
|
|
802
|
+
return acc;
|
|
803
|
+
}, {});
|
|
804
|
+
newTabs.push(...tabs.map((tab) => {
|
|
805
|
+
return oldChildMap[tab.key] || childTabFormatter(tab);
|
|
806
|
+
}));
|
|
807
|
+
} else {
|
|
808
|
+
newTabs.push(...oldTabs);
|
|
809
|
+
}
|
|
810
|
+
}
|
|
811
|
+
root.activeTabKey = activeChildTabKey;
|
|
812
|
+
}
|
|
813
|
+
async function removeCurrentTab(callback) {
|
|
814
|
+
const root = state.activeRoot.value;
|
|
815
|
+
const removedTab = await _removePageTabByKey(root.activeTabKey);
|
|
816
|
+
if (!removedTab || typeof callback !== "function")
|
|
817
|
+
return false;
|
|
818
|
+
const [tab, parentTab] = removedTab;
|
|
819
|
+
if (state.pageTabs.value.find((item) => item.key === tab._parentTabKey)) {
|
|
820
|
+
root.activeTabKey = tab._parentTabKey;
|
|
821
|
+
await nextTick2();
|
|
822
|
+
await callback(parentTab?.exposed);
|
|
823
|
+
}
|
|
824
|
+
return true;
|
|
825
|
+
}
|
|
826
|
+
async function _removeChildRoot(tab) {
|
|
827
|
+
if (!tab.isChildRoot)
|
|
828
|
+
return;
|
|
829
|
+
const root = roots[activeRootKey.value];
|
|
830
|
+
const childRootKey = `${tab.micro}__${tab.key}`;
|
|
831
|
+
const parentTab = root._parentTabMap?.[childRootKey];
|
|
832
|
+
if (!parentTab)
|
|
833
|
+
return;
|
|
834
|
+
delete root._parentTabMap?.[childRootKey];
|
|
835
|
+
const realParentTab = parentTab.parentTab;
|
|
836
|
+
dispatchMicroAction("dispatch-page-key-remove", tab.micro, {
|
|
837
|
+
key: tab.key,
|
|
838
|
+
root: tab.rootKey,
|
|
839
|
+
isRoot: true
|
|
840
|
+
});
|
|
841
|
+
if (realParentTab) {
|
|
842
|
+
dispatchMicroAction("dispatch-page-key-remove", realParentTab.micro, {
|
|
843
|
+
key: parentTab.key,
|
|
844
|
+
root: parentTab.rootKey
|
|
845
|
+
});
|
|
846
|
+
} else {
|
|
847
|
+
_removePageTabByKey(parentTab.key);
|
|
848
|
+
}
|
|
849
|
+
}
|
|
850
|
+
async function setCurrentTab(tab) {
|
|
851
|
+
const root = roots[activeRootKey.value];
|
|
852
|
+
if (!tab || !root || root.activeTabKey === tab.key)
|
|
853
|
+
return;
|
|
854
|
+
if (tab.isChild) {
|
|
855
|
+
if (state.current.value?.micro !== tab.micro) {
|
|
856
|
+
root.activeTabKey = tab.key;
|
|
857
|
+
await nextTick2();
|
|
858
|
+
}
|
|
859
|
+
dispatchMicroAction("dispatch-page-key-change", tab.micro, {
|
|
860
|
+
key: tab.key,
|
|
861
|
+
root: tab.rootKey
|
|
862
|
+
});
|
|
863
|
+
} else {
|
|
864
|
+
root.activeTabKey = tab.key;
|
|
865
|
+
}
|
|
866
|
+
}
|
|
867
|
+
function addMicro({ micro, url }) {
|
|
868
|
+
if (!micro || !url || micros[micro])
|
|
869
|
+
return false;
|
|
870
|
+
micros[micro] = url;
|
|
871
|
+
return true;
|
|
872
|
+
}
|
|
873
|
+
return {
|
|
874
|
+
...state,
|
|
875
|
+
roots,
|
|
876
|
+
micros: readonly2(micros),
|
|
877
|
+
activeRootKey: readonly2(activeRootKey),
|
|
878
|
+
addMicro,
|
|
879
|
+
setRootChild,
|
|
880
|
+
createPageTabsRoot,
|
|
881
|
+
addPageTab,
|
|
882
|
+
removePageTab,
|
|
883
|
+
removeCurrentTab,
|
|
884
|
+
clearPageTab,
|
|
885
|
+
setCurrentTab
|
|
886
|
+
};
|
|
887
|
+
}
|
|
888
|
+
function isComponentTab(tab) {
|
|
889
|
+
return !!tab.component;
|
|
890
|
+
}
|
|
891
|
+
|
|
892
|
+
// src/useRequest/plugins/definePlugin.ts
|
|
893
|
+
function definePlugin(plugin) {
|
|
894
|
+
return plugin;
|
|
895
|
+
}
|
|
896
|
+
|
|
897
|
+
// src/useRequest/config.ts
|
|
898
|
+
var GLOBAL_OPTIONS = {};
|
|
899
|
+
function getGlobalOptions() {
|
|
900
|
+
return GLOBAL_OPTIONS;
|
|
901
|
+
}
|
|
902
|
+
function setGlobalOptions(options) {
|
|
903
|
+
Object.assign(GLOBAL_OPTIONS, options);
|
|
904
|
+
}
|
|
905
|
+
function clearGlobalOptions() {
|
|
906
|
+
Object.keys(GLOBAL_OPTIONS).forEach((key) => {
|
|
907
|
+
delete GLOBAL_OPTIONS[key];
|
|
908
|
+
});
|
|
909
|
+
}
|
|
910
|
+
var GLOBAL_OPTIONS_PROVIDER_KEY = /* @__PURE__ */ Symbol("GLOBAL_OPTIONS_PROVIDER_KEY");
|
|
911
|
+
var DEFAULT_PAGINATION_OPTIONS = {
|
|
912
|
+
currentKey: "pageNum",
|
|
913
|
+
pageSizeKey: "pageSize",
|
|
914
|
+
totalKey: "total",
|
|
915
|
+
dataKey: "rows"
|
|
916
|
+
};
|
|
917
|
+
|
|
918
|
+
// src/useRequest/useDataRequest.ts
|
|
919
|
+
import { computed as computed5 } from "vue";
|
|
920
|
+
|
|
921
|
+
// src/useRequest/useRequestImpl.ts
|
|
922
|
+
import { tryOnScopeDispose as tryOnScopeDispose3 } from "@vueuse/core";
|
|
923
|
+
import { inject as inject2 } from "vue";
|
|
924
|
+
|
|
925
|
+
// src/useRequest/createRequest.ts
|
|
926
|
+
import { shallowCopy } from "@zl-ui-kit/utils";
|
|
927
|
+
import { ref as ref5, shallowRef } from "vue";
|
|
928
|
+
function createRequest(service, options = {}, initialState = {}) {
|
|
929
|
+
const { initialData } = options;
|
|
930
|
+
const loading = ref5(initialState.loading ?? false);
|
|
931
|
+
const data = shallowRef(initialData);
|
|
932
|
+
const error = ref5(void 0);
|
|
933
|
+
const params = ref5();
|
|
934
|
+
const plugins = ref5([]);
|
|
935
|
+
const status = ref5("");
|
|
936
|
+
const context = {};
|
|
937
|
+
const onPluginRunner = (event, ...args) => {
|
|
938
|
+
if (event === "onRequest") {
|
|
939
|
+
const services = plugins.value.map((plugin) => plugin.onRequest).filter(Boolean);
|
|
940
|
+
const composedService = () => {
|
|
941
|
+
let next = args[0];
|
|
942
|
+
for (const service2 of services) {
|
|
943
|
+
next = service2(next);
|
|
944
|
+
}
|
|
945
|
+
return next();
|
|
946
|
+
};
|
|
947
|
+
return { servicePromise: composedService() };
|
|
948
|
+
} else {
|
|
949
|
+
return Object.assign({}, ...plugins.value.map((plugin) => plugin[event]?.(...args)));
|
|
950
|
+
}
|
|
951
|
+
};
|
|
952
|
+
const state = { loading, data, error, params, status };
|
|
953
|
+
const setState = (newState) => {
|
|
954
|
+
Object.keys(newState).forEach((key) => {
|
|
955
|
+
if (key in state) {
|
|
956
|
+
;
|
|
957
|
+
state[key].value = newState[key];
|
|
958
|
+
}
|
|
959
|
+
});
|
|
960
|
+
};
|
|
961
|
+
setState({ status: "pending" });
|
|
962
|
+
const count = ref5(0);
|
|
963
|
+
context.runAsync = async (...args) => {
|
|
964
|
+
setState({ status: "pending" });
|
|
965
|
+
const currentCount = ++count.value;
|
|
966
|
+
const { isBreak = false, isReturn = false, ...rest } = onPluginRunner("onBefore", args);
|
|
967
|
+
if (isBreak) {
|
|
968
|
+
setState({ status: "finished" });
|
|
969
|
+
return new Promise(() => {
|
|
970
|
+
});
|
|
971
|
+
}
|
|
972
|
+
setState({ loading: true, params: args, ...rest });
|
|
973
|
+
if (isReturn) {
|
|
974
|
+
setState({ status: "finished", loading: false });
|
|
975
|
+
return rest.data;
|
|
976
|
+
}
|
|
977
|
+
options.onBefore?.(args);
|
|
978
|
+
try {
|
|
979
|
+
const serviceWrapper = () => new Promise((r) => r(service(...params.value)));
|
|
980
|
+
let { servicePromise } = onPluginRunner("onRequest", serviceWrapper);
|
|
981
|
+
if (!servicePromise) {
|
|
982
|
+
servicePromise = serviceWrapper();
|
|
983
|
+
}
|
|
984
|
+
const res = await servicePromise;
|
|
985
|
+
if (currentCount !== count.value) {
|
|
986
|
+
return new Promise(() => {
|
|
987
|
+
});
|
|
988
|
+
}
|
|
989
|
+
setState({
|
|
990
|
+
loading: false,
|
|
991
|
+
data: res,
|
|
992
|
+
status: "finished",
|
|
993
|
+
error: void 0
|
|
994
|
+
});
|
|
995
|
+
onPluginRunner("onSuccess", res, args);
|
|
996
|
+
options.onSuccess?.(res, args);
|
|
997
|
+
onPluginRunner("onFinally", res, args);
|
|
998
|
+
options.onFinally?.(args);
|
|
999
|
+
return res;
|
|
1000
|
+
} catch (error2) {
|
|
1001
|
+
if (currentCount !== count.value) {
|
|
1002
|
+
return new Promise(() => {
|
|
1003
|
+
});
|
|
1004
|
+
}
|
|
1005
|
+
setState({ loading: false, error: error2, status: "finished" });
|
|
1006
|
+
onPluginRunner("onError", error2, args);
|
|
1007
|
+
options.onError?.(error2, args);
|
|
1008
|
+
onPluginRunner("onFinally", error2, args);
|
|
1009
|
+
options.onFinally?.(args);
|
|
1010
|
+
throw error2;
|
|
1011
|
+
}
|
|
1012
|
+
};
|
|
1013
|
+
context.run = (...args) => {
|
|
1014
|
+
context.runAsync(...args).catch((error2) => {
|
|
1015
|
+
if (!options.onError) {
|
|
1016
|
+
console.error(error2);
|
|
1017
|
+
}
|
|
1018
|
+
});
|
|
1019
|
+
};
|
|
1020
|
+
context.cancel = () => {
|
|
1021
|
+
count.value++;
|
|
1022
|
+
setState({ loading: false });
|
|
1023
|
+
onPluginRunner("onCancel");
|
|
1024
|
+
};
|
|
1025
|
+
context.refresh = () => {
|
|
1026
|
+
context.run(...params.value || []);
|
|
1027
|
+
};
|
|
1028
|
+
context.refreshAsync = () => {
|
|
1029
|
+
return context.runAsync(...params.value || []);
|
|
1030
|
+
};
|
|
1031
|
+
context.mutate = ((mutatorOrData) => {
|
|
1032
|
+
const _data = typeof mutatorOrData === "function" ? mutatorOrData(data.value) : mutatorOrData;
|
|
1033
|
+
const mutateData = shallowCopy(_data);
|
|
1034
|
+
setState({ data: mutateData });
|
|
1035
|
+
onPluginRunner("onMutate", mutateData);
|
|
1036
|
+
});
|
|
1037
|
+
return {
|
|
1038
|
+
loading,
|
|
1039
|
+
data,
|
|
1040
|
+
error,
|
|
1041
|
+
params,
|
|
1042
|
+
plugins,
|
|
1043
|
+
status,
|
|
1044
|
+
context
|
|
1045
|
+
};
|
|
1046
|
+
}
|
|
1047
|
+
|
|
1048
|
+
// src/useRequest/plugins/useDownloadPlugin.ts
|
|
1049
|
+
import { fileSave } from "@zl-ui-kit/utils";
|
|
1050
|
+
import { toValue as toValue3 } from "vue";
|
|
1051
|
+
var useDownloadPlugin_default = definePlugin((_requestInstance, options = {}) => {
|
|
1052
|
+
const { outputFile } = options;
|
|
1053
|
+
if (!outputFile) {
|
|
1054
|
+
return {};
|
|
1055
|
+
}
|
|
1056
|
+
return {
|
|
1057
|
+
onSuccess(res) {
|
|
1058
|
+
if (res instanceof Blob && res.type !== "application/json") {
|
|
1059
|
+
const blob = new Blob([res]);
|
|
1060
|
+
fileSave(blob, toValue3(outputFile));
|
|
1061
|
+
}
|
|
1062
|
+
}
|
|
1063
|
+
};
|
|
1064
|
+
});
|
|
1065
|
+
|
|
1066
|
+
// src/useRequest/plugins/useLoadingPlugin.ts
|
|
1067
|
+
import { promiseTimeout, useTimeoutFn } from "@vueuse/core";
|
|
1068
|
+
import { toValue as toValue4 } from "vue";
|
|
1069
|
+
var useLoadingPlugin_default = definePlugin((requestInstance, options = {}) => {
|
|
1070
|
+
const { loadingDelay = 0, loadingKeep = 0 } = options;
|
|
1071
|
+
const { start, stop } = useTimeoutFn(
|
|
1072
|
+
() => {
|
|
1073
|
+
if (requestInstance.status.value === "pending") {
|
|
1074
|
+
requestInstance.loading.value = true;
|
|
1075
|
+
}
|
|
1076
|
+
},
|
|
1077
|
+
loadingDelay,
|
|
1078
|
+
{ immediate: false }
|
|
1079
|
+
);
|
|
1080
|
+
return {
|
|
1081
|
+
onBefore() {
|
|
1082
|
+
start();
|
|
1083
|
+
return {
|
|
1084
|
+
loading: !toValue4(loadingDelay)
|
|
1085
|
+
};
|
|
1086
|
+
},
|
|
1087
|
+
onRequest(service) {
|
|
1088
|
+
if (!toValue4(loadingKeep))
|
|
1089
|
+
return () => service();
|
|
1090
|
+
return () => Promise.allSettled([
|
|
1091
|
+
service(),
|
|
1092
|
+
promiseTimeout(toValue4(loadingDelay) + toValue4(loadingKeep))
|
|
1093
|
+
]).then(([res]) => {
|
|
1094
|
+
if (res.status === "fulfilled") {
|
|
1095
|
+
return res.value;
|
|
1096
|
+
} else {
|
|
1097
|
+
return Promise.reject(res.reason);
|
|
1098
|
+
}
|
|
1099
|
+
});
|
|
1100
|
+
},
|
|
1101
|
+
onCancel() {
|
|
1102
|
+
stop();
|
|
1103
|
+
},
|
|
1104
|
+
onFinally() {
|
|
1105
|
+
stop();
|
|
1106
|
+
}
|
|
1107
|
+
};
|
|
1108
|
+
});
|
|
1109
|
+
|
|
1110
|
+
// src/useRequest/plugins/useReadyPlugin.ts
|
|
1111
|
+
import { whenever } from "@vueuse/core";
|
|
1112
|
+
import { ref as ref6, toValue as toValue5 } from "vue";
|
|
1113
|
+
var useReadyPlugin_default = definePlugin((requestInstance, options = {}) => {
|
|
1114
|
+
const { ready = ref6(true), defaultParams = [] } = options;
|
|
1115
|
+
whenever(() => toValue5(ready), () => {
|
|
1116
|
+
requestInstance.context.run(...defaultParams);
|
|
1117
|
+
}, { flush: "sync" });
|
|
1118
|
+
return {
|
|
1119
|
+
onBefore() {
|
|
1120
|
+
if (!toValue5(ready)) {
|
|
1121
|
+
return { isBreak: true };
|
|
1122
|
+
}
|
|
1123
|
+
return void 0;
|
|
1124
|
+
}
|
|
1125
|
+
};
|
|
1126
|
+
});
|
|
1127
|
+
|
|
1128
|
+
// src/useRequest/plugins/useRefreshDepsPlugin.ts
|
|
1129
|
+
import { watch as watch5 } from "vue";
|
|
1130
|
+
var useRefreshDepsPlugin_default = definePlugin((requestInstance, options = {}) => {
|
|
1131
|
+
const { refreshDeps, refreshDepsAction, manual } = options;
|
|
1132
|
+
if (!refreshDeps) {
|
|
1133
|
+
return {};
|
|
1134
|
+
}
|
|
1135
|
+
watch5(refreshDeps, (..._args) => {
|
|
1136
|
+
if (refreshDepsAction) {
|
|
1137
|
+
refreshDepsAction();
|
|
1138
|
+
} else if (!manual) {
|
|
1139
|
+
requestInstance.context.refresh();
|
|
1140
|
+
}
|
|
1141
|
+
});
|
|
1142
|
+
return {};
|
|
1143
|
+
});
|
|
1144
|
+
|
|
1145
|
+
// src/useRequest/useRequestImpl.ts
|
|
1146
|
+
function useRequestImpl(service, options = {}, plugins = []) {
|
|
1147
|
+
const injectOptions = inject2(GLOBAL_OPTIONS_PROVIDER_KEY, {});
|
|
1148
|
+
const _options = {
|
|
1149
|
+
...getGlobalOptions(),
|
|
1150
|
+
...injectOptions,
|
|
1151
|
+
...options
|
|
1152
|
+
};
|
|
1153
|
+
const { manual = false, defaultParams = [] } = _options;
|
|
1154
|
+
const requestInstance = createRequest(service, _options);
|
|
1155
|
+
requestInstance.plugins.value = [...plugins, useLoadingPlugin_default, useReadyPlugin_default, useRefreshDepsPlugin_default, useDownloadPlugin_default].map((plugin) => plugin(requestInstance, _options));
|
|
1156
|
+
if (!manual) {
|
|
1157
|
+
const params = requestInstance.params.value || defaultParams;
|
|
1158
|
+
requestInstance.context.run(...params);
|
|
1159
|
+
}
|
|
1160
|
+
tryOnScopeDispose3(requestInstance.context.cancel);
|
|
1161
|
+
return {
|
|
1162
|
+
__is_use_request: true,
|
|
1163
|
+
loading: requestInstance.loading,
|
|
1164
|
+
data: requestInstance.data,
|
|
1165
|
+
error: requestInstance.error,
|
|
1166
|
+
params: requestInstance.params,
|
|
1167
|
+
status: requestInstance.status,
|
|
1168
|
+
cancel: requestInstance.context.cancel,
|
|
1169
|
+
mutate: requestInstance.context.mutate,
|
|
1170
|
+
run: requestInstance.context.run,
|
|
1171
|
+
runAsync: requestInstance.context.runAsync,
|
|
1172
|
+
refresh: requestInstance.context.refresh,
|
|
1173
|
+
refreshAsync: requestInstance.context.refreshAsync
|
|
1174
|
+
};
|
|
1175
|
+
}
|
|
1176
|
+
|
|
1177
|
+
// src/useRequest/useRequest.ts
|
|
1178
|
+
function useRequest(service, options, plugins = []) {
|
|
1179
|
+
return useRequestImpl(service, options, plugins);
|
|
1180
|
+
}
|
|
1181
|
+
|
|
1182
|
+
// src/useRequest/useDataRequest.ts
|
|
1183
|
+
function useDataRequest(service, options, plugins) {
|
|
1184
|
+
const { dataKey = "data", initialData, ...restOptions } = options || {};
|
|
1185
|
+
const request = useRequest(service, restOptions, plugins);
|
|
1186
|
+
const _data = request.data;
|
|
1187
|
+
const data = computed5(() => {
|
|
1188
|
+
const rawData = _data.value || {};
|
|
1189
|
+
return rawData[dataKey] ?? initialData;
|
|
1190
|
+
});
|
|
1191
|
+
return Object.assign(request, { data });
|
|
1192
|
+
}
|
|
1193
|
+
|
|
1194
|
+
// src/useRequest/usePageableRequest.ts
|
|
1195
|
+
import { isArray } from "@zl-ui-kit/utils";
|
|
1196
|
+
import { computed as computed6, inject as inject3 } from "vue";
|
|
1197
|
+
function usePaginationRequest(service, options, plugins) {
|
|
1198
|
+
const { pagination = {}, ...restOptions } = options || {};
|
|
1199
|
+
const injectedGlobalOptions = inject3(GLOBAL_OPTIONS_PROVIDER_KEY, {});
|
|
1200
|
+
const { currentKey, pageSizeKey, totalKey, dataKey } = Object.assign({}, DEFAULT_PAGINATION_OPTIONS, getGlobalOptions().pagination, injectedGlobalOptions.pagination, pagination);
|
|
1201
|
+
const finalOptions = {
|
|
1202
|
+
defaultParams: [{ [currentKey]: 1, [pageSizeKey]: 30 }],
|
|
1203
|
+
...restOptions
|
|
1204
|
+
};
|
|
1205
|
+
const { data: _data, params, run, ...rest } = useRequest(service, finalOptions, plugins);
|
|
1206
|
+
const data = computed6(() => {
|
|
1207
|
+
const rawData = _data.value || {};
|
|
1208
|
+
return isArray(rawData) ? rawData : rawData[dataKey] || [];
|
|
1209
|
+
});
|
|
1210
|
+
const total = computed6(() => {
|
|
1211
|
+
const rawData = _data.value || {};
|
|
1212
|
+
return isArray(rawData) ? rawData.length : rawData[totalKey] || 0;
|
|
1213
|
+
});
|
|
1214
|
+
const current = computed6({
|
|
1215
|
+
get() {
|
|
1216
|
+
return params.value?.[0]?.[currentKey] ?? finalOptions.defaultParams[0]?.[currentKey];
|
|
1217
|
+
},
|
|
1218
|
+
set(val) {
|
|
1219
|
+
changeCurrent(val);
|
|
1220
|
+
}
|
|
1221
|
+
});
|
|
1222
|
+
const pageSize = computed6({
|
|
1223
|
+
get() {
|
|
1224
|
+
return params.value?.[0]?.[pageSizeKey] ?? finalOptions.defaultParams[0]?.[pageSizeKey];
|
|
1225
|
+
},
|
|
1226
|
+
set(val) {
|
|
1227
|
+
changePageSize(val);
|
|
1228
|
+
}
|
|
1229
|
+
});
|
|
1230
|
+
function _paging(paginationParams) {
|
|
1231
|
+
const [oldParams, ...restParams] = params.value || [];
|
|
1232
|
+
run(...[{ ...oldParams, ...paginationParams }, ...restParams]);
|
|
1233
|
+
}
|
|
1234
|
+
function changeCurrent(pageNum) {
|
|
1235
|
+
_paging({ [currentKey]: pageNum });
|
|
1236
|
+
}
|
|
1237
|
+
function changePageSize(size) {
|
|
1238
|
+
_paging({ [pageSizeKey]: size, [currentKey]: 1 });
|
|
1239
|
+
}
|
|
1240
|
+
function changePagination(page, size) {
|
|
1241
|
+
_paging({ [currentKey]: page, [pageSizeKey]: size });
|
|
1242
|
+
}
|
|
1243
|
+
return {
|
|
1244
|
+
data,
|
|
1245
|
+
params,
|
|
1246
|
+
total,
|
|
1247
|
+
current,
|
|
1248
|
+
pageSize,
|
|
1249
|
+
run,
|
|
1250
|
+
changeCurrent,
|
|
1251
|
+
changePageSize,
|
|
1252
|
+
changePagination,
|
|
1253
|
+
...rest
|
|
1254
|
+
};
|
|
1255
|
+
}
|
|
1256
|
+
function usePageableRequest(service, options, plugins) {
|
|
1257
|
+
const request = useRequest(service, options, plugins);
|
|
1258
|
+
const _data = request.data;
|
|
1259
|
+
const data = computed6(() => {
|
|
1260
|
+
const rawData = _data.value || [];
|
|
1261
|
+
if (isArray(rawData)) {
|
|
1262
|
+
return rawData;
|
|
1263
|
+
} else {
|
|
1264
|
+
const [param] = request.params.value || [];
|
|
1265
|
+
return { ...rawData, pageNum: param?.pageNum, pageSize: param?.pageSize };
|
|
1266
|
+
}
|
|
1267
|
+
});
|
|
1268
|
+
return Object.assign(request, { data });
|
|
1269
|
+
}
|
|
1270
|
+
|
|
1271
|
+
// src/useRequest/useRequestProvider.ts
|
|
1272
|
+
import { provide as provide2 } from "vue";
|
|
1273
|
+
function useRequestProvider(options) {
|
|
1274
|
+
provide2(GLOBAL_OPTIONS_PROVIDER_KEY, options);
|
|
1275
|
+
}
|
|
1276
|
+
|
|
1277
|
+
// src/useSash.ts
|
|
1278
|
+
import { useEventListener } from "@vueuse/core";
|
|
1279
|
+
import { toValue as toValue6, useTemplateRef } from "vue";
|
|
1280
|
+
function useSash(refName, { start, onMousedown, onMousemove, onMouseup, onDoubleClick } = {}) {
|
|
1281
|
+
const sashElRef = useTemplateRef(refName);
|
|
1282
|
+
function handleSashMousedown(e) {
|
|
1283
|
+
e.preventDefault();
|
|
1284
|
+
const startX = e.clientX;
|
|
1285
|
+
const startY = e.clientY;
|
|
1286
|
+
onMousedown?.(e);
|
|
1287
|
+
const startSnapshot = toValue6(start);
|
|
1288
|
+
const handleMousemove = (e2) => {
|
|
1289
|
+
e2.preventDefault();
|
|
1290
|
+
const dx = e2.clientX - startX;
|
|
1291
|
+
const dy = e2.clientY - startY;
|
|
1292
|
+
onMousemove?.({ dx, dy, start: startSnapshot }, e2);
|
|
1293
|
+
};
|
|
1294
|
+
const handleMouseup = (e2) => {
|
|
1295
|
+
document.removeEventListener("mousemove", handleMousemove);
|
|
1296
|
+
document.removeEventListener("mouseup", handleMouseup);
|
|
1297
|
+
onMouseup?.(e2);
|
|
1298
|
+
};
|
|
1299
|
+
document.addEventListener("mousemove", handleMousemove);
|
|
1300
|
+
document.addEventListener("mouseup", handleMouseup);
|
|
1301
|
+
}
|
|
1302
|
+
useEventListener(sashElRef, "mousedown", handleSashMousedown);
|
|
1303
|
+
if (onDoubleClick) {
|
|
1304
|
+
useEventListener(sashElRef, "dblclick", onDoubleClick);
|
|
1305
|
+
}
|
|
1306
|
+
return {
|
|
1307
|
+
sashElRef
|
|
1308
|
+
};
|
|
1309
|
+
}
|
|
1310
|
+
|
|
1311
|
+
// src/useServiceType.ts
|
|
1312
|
+
function useServiceType(options = {}) {
|
|
1313
|
+
const { platformKey = "zl.service.type", blockchainKey = "blockchain.service.type" } = options;
|
|
1314
|
+
const { isConfig, getConfig } = useMicroGlobalData();
|
|
1315
|
+
const isPlatform = isConfig(platformKey, "platform");
|
|
1316
|
+
const isBlockchain = blockchainKey ? ["0", "1"].includes(getConfig(blockchainKey, "")) : false;
|
|
1317
|
+
return { isPlatform, isBlockchain };
|
|
1318
|
+
}
|
|
1319
|
+
|
|
1320
|
+
// src/useUKey/index.ts
|
|
1321
|
+
import { createSharedComposable as createSharedComposable2, useTimeoutFn as useTimeoutFn2 } from "@vueuse/core";
|
|
1322
|
+
import { ref as ref7 } from "vue";
|
|
1323
|
+
var useUKey = createSharedComposable2(() => {
|
|
1324
|
+
const { getConfig } = useMicroGlobalData();
|
|
1325
|
+
const port = getConfig("zl.feature.shufflePort", "8080");
|
|
1326
|
+
const sn = ref7("");
|
|
1327
|
+
const getSnResolver = {
|
|
1328
|
+
resolve: (_value) => {
|
|
1329
|
+
},
|
|
1330
|
+
reject: (_reason) => {
|
|
1331
|
+
}
|
|
1332
|
+
};
|
|
1333
|
+
const { start, stop } = useTimeoutFn2(_getSn, 200, { immediate: false });
|
|
1334
|
+
async function _getSn() {
|
|
1335
|
+
try {
|
|
1336
|
+
sn.value = await request({ function: "sn" });
|
|
1337
|
+
getSnResolver.resolve(sn.value);
|
|
1338
|
+
start();
|
|
1339
|
+
} catch {
|
|
1340
|
+
start();
|
|
1341
|
+
sn.value = "";
|
|
1342
|
+
}
|
|
1343
|
+
}
|
|
1344
|
+
const getSn = () => {
|
|
1345
|
+
return new Promise((resolve, reject) => {
|
|
1346
|
+
getSnResolver.resolve = resolve;
|
|
1347
|
+
getSnResolver.reject = reject;
|
|
1348
|
+
_getSn();
|
|
1349
|
+
});
|
|
1350
|
+
};
|
|
1351
|
+
const getUser = (pin) => request({ function: "user", sn: sn.value, pin });
|
|
1352
|
+
const getDevice = async () => {
|
|
1353
|
+
const data = await request({ function: "dn", sn: sn.value });
|
|
1354
|
+
return {
|
|
1355
|
+
...data,
|
|
1356
|
+
sn: sn.value
|
|
1357
|
+
};
|
|
1358
|
+
};
|
|
1359
|
+
const isUserExists = async () => {
|
|
1360
|
+
const data = await request({ function: "isempty", sn: sn.value });
|
|
1361
|
+
return data === "false";
|
|
1362
|
+
};
|
|
1363
|
+
const getCSR = (data) => request({
|
|
1364
|
+
function: "csr",
|
|
1365
|
+
pin: "111111",
|
|
1366
|
+
C: "CN",
|
|
1367
|
+
ST: "Beijing",
|
|
1368
|
+
L: "Beijing",
|
|
1369
|
+
O: data.partyName,
|
|
1370
|
+
OU: data.nodeLabel,
|
|
1371
|
+
CN: data.userName
|
|
1372
|
+
});
|
|
1373
|
+
const writeCRT = (username, certbase64, newpin) => request({ function: "importcert", sn: sn.value, certbase64, username, newpin });
|
|
1374
|
+
const sendSign = ({ pin, data }) => request({ function: "sm2sign", pin, sn: sn.value, data });
|
|
1375
|
+
async function request(data) {
|
|
1376
|
+
const res = await fetch(`http://127.0.0.1:${port}/function`, {
|
|
1377
|
+
method: "post",
|
|
1378
|
+
body: JSON.stringify(data),
|
|
1379
|
+
headers: {
|
|
1380
|
+
"content-type": "application/json"
|
|
1381
|
+
}
|
|
1382
|
+
});
|
|
1383
|
+
const json = await res.json();
|
|
1384
|
+
if (json.code !== "200") {
|
|
1385
|
+
const error = new Error(json.msg);
|
|
1386
|
+
error.code = json.code;
|
|
1387
|
+
throw error;
|
|
1388
|
+
}
|
|
1389
|
+
return json?.data || json;
|
|
1390
|
+
}
|
|
1391
|
+
return {
|
|
1392
|
+
sn,
|
|
1393
|
+
getSn,
|
|
1394
|
+
getUser,
|
|
1395
|
+
getDevice,
|
|
1396
|
+
isUserExists,
|
|
1397
|
+
getCSR,
|
|
1398
|
+
writeCRT,
|
|
1399
|
+
sendSign,
|
|
1400
|
+
stopHeartbeat: stop
|
|
1401
|
+
};
|
|
1402
|
+
});
|
|
1403
|
+
export {
|
|
1404
|
+
DEFAULT_PAGINATION_OPTIONS,
|
|
1405
|
+
GLOBAL_OPTIONS_PROVIDER_KEY,
|
|
1406
|
+
clearGlobalOptions,
|
|
1407
|
+
createCacheComputed,
|
|
1408
|
+
definePlugin as defineUseRequestPlugin,
|
|
1409
|
+
dictInjectKey,
|
|
1410
|
+
dispatchMicroAction,
|
|
1411
|
+
enableGlobalDataMock,
|
|
1412
|
+
getDictSource,
|
|
1413
|
+
getGlobalOptions,
|
|
1414
|
+
mergeMessages,
|
|
1415
|
+
setDictSource,
|
|
1416
|
+
setGlobalOptions,
|
|
1417
|
+
useDataRequest,
|
|
1418
|
+
useDict,
|
|
1419
|
+
useDictProvider,
|
|
1420
|
+
useDictStore,
|
|
1421
|
+
useGlobalMessage,
|
|
1422
|
+
useLocale,
|
|
1423
|
+
useMicroAction,
|
|
1424
|
+
useMicroActionAsync,
|
|
1425
|
+
useMicroApp,
|
|
1426
|
+
useMicroGlobalData,
|
|
1427
|
+
useMicroListener,
|
|
1428
|
+
useMicroResultListener,
|
|
1429
|
+
usePageTabs,
|
|
1430
|
+
usePageableRequest,
|
|
1431
|
+
usePaginationRequest,
|
|
1432
|
+
useRequest,
|
|
1433
|
+
useRequestProvider,
|
|
1434
|
+
useSash,
|
|
1435
|
+
useServiceType,
|
|
1436
|
+
useUKey,
|
|
1437
|
+
useZlT
|
|
1438
|
+
};
|
|
1439
|
+
//# sourceMappingURL=index.js.map
|