@zl-ui-kit/composables 0.3.3 → 0.5.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 +11 -11
- package/dist/index.d.ts +67 -206
- package/dist/index.js +183 -758
- package/package.json +2 -6
package/dist/index.js
CHANGED
|
@@ -105,6 +105,133 @@ function useDict(key, options = {}) {
|
|
|
105
105
|
return Object.assign(dict, { label });
|
|
106
106
|
}
|
|
107
107
|
|
|
108
|
+
// src/useGlobalData.ts
|
|
109
|
+
import { isFunction, isPlainObject as isPlainObject2, withResolvers } from "@zl-ui-kit/utils";
|
|
110
|
+
import { createGlobalState as createGlobalState2, useStorage } from "@vueuse/core";
|
|
111
|
+
import { computed as computed3, nextTick, readonly, ref as ref2, watch } from "vue";
|
|
112
|
+
var SYNC_KEYS = ["locale", "theme", "token"];
|
|
113
|
+
function createStorages() {
|
|
114
|
+
return {
|
|
115
|
+
locale: useStorage("$zl_locale", ""),
|
|
116
|
+
theme: useStorage("$zl_theme", "light"),
|
|
117
|
+
token: useStorage("$zl_token", void 0)
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
function readStorages(storages) {
|
|
121
|
+
return {
|
|
122
|
+
locale: storages.locale.value,
|
|
123
|
+
theme: storages.theme.value,
|
|
124
|
+
token: storages.token.value
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
function createInitialState(storages) {
|
|
128
|
+
return {
|
|
129
|
+
initialed: true,
|
|
130
|
+
...readStorages(storages),
|
|
131
|
+
isI18nKeyVisible: false,
|
|
132
|
+
roles: [],
|
|
133
|
+
permissions: [],
|
|
134
|
+
user: void 0,
|
|
135
|
+
localeMessages: {},
|
|
136
|
+
elLocaleMessages: void 0,
|
|
137
|
+
config: void 0
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
var useGlobalData = createGlobalState2(() => {
|
|
141
|
+
const storages = createStorages();
|
|
142
|
+
const globalData = ref2(createInitialState(storages));
|
|
143
|
+
const waiters = /* @__PURE__ */ new Set();
|
|
144
|
+
function updateBodyAttribute(key, value) {
|
|
145
|
+
if (typeof document === "undefined")
|
|
146
|
+
return;
|
|
147
|
+
document.body.setAttribute(key, String(value ?? ""));
|
|
148
|
+
}
|
|
149
|
+
updateBodyAttribute("data-theme", storages.theme.value);
|
|
150
|
+
updateBodyAttribute("data-locale", storages.locale.value);
|
|
151
|
+
watch(
|
|
152
|
+
() => SYNC_KEYS.map((key) => globalData.value[key]),
|
|
153
|
+
(values) => {
|
|
154
|
+
values.forEach((value, index) => {
|
|
155
|
+
const key = SYNC_KEYS[index];
|
|
156
|
+
if (storages[key].value === value)
|
|
157
|
+
return;
|
|
158
|
+
storages[key].value = value;
|
|
159
|
+
if (key === "theme")
|
|
160
|
+
updateBodyAttribute("data-theme", value);
|
|
161
|
+
if (key === "locale")
|
|
162
|
+
updateBodyAttribute("data-locale", value);
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
);
|
|
166
|
+
watch(globalData, () => {
|
|
167
|
+
waiters.forEach((fn) => fn());
|
|
168
|
+
}, { deep: true });
|
|
169
|
+
function getConfig(key, defaultValue) {
|
|
170
|
+
return globalData.value.config?.[key] ?? defaultValue;
|
|
171
|
+
}
|
|
172
|
+
function isConfig(key, compareValue = "true") {
|
|
173
|
+
return globalData.value.config?.[key] === compareValue;
|
|
174
|
+
}
|
|
175
|
+
async function setAndWaitUntil({ set, until }) {
|
|
176
|
+
if (!set && !isFunction(until))
|
|
177
|
+
return;
|
|
178
|
+
if (isPlainObject2(set))
|
|
179
|
+
globalData.value = { ...globalData.value, ...set };
|
|
180
|
+
if (!isFunction(until)) {
|
|
181
|
+
await nextTick();
|
|
182
|
+
return;
|
|
183
|
+
}
|
|
184
|
+
const { resolve, promise } = withResolvers();
|
|
185
|
+
const waiter = () => {
|
|
186
|
+
if (!until(globalData.value))
|
|
187
|
+
return;
|
|
188
|
+
waiters.delete(waiter);
|
|
189
|
+
resolve();
|
|
190
|
+
};
|
|
191
|
+
waiters.add(waiter);
|
|
192
|
+
nextTick(waiter);
|
|
193
|
+
return promise;
|
|
194
|
+
}
|
|
195
|
+
function resetUser() {
|
|
196
|
+
globalData.value = {
|
|
197
|
+
...globalData.value,
|
|
198
|
+
user: void 0,
|
|
199
|
+
roles: [],
|
|
200
|
+
permissions: [],
|
|
201
|
+
token: void 0
|
|
202
|
+
};
|
|
203
|
+
storages.token.value = void 0;
|
|
204
|
+
}
|
|
205
|
+
const toComputed = (prop) => {
|
|
206
|
+
return computed3({
|
|
207
|
+
get() {
|
|
208
|
+
return globalData.value[prop];
|
|
209
|
+
},
|
|
210
|
+
set(value) {
|
|
211
|
+
globalData.value = { ...globalData.value, [prop]: value };
|
|
212
|
+
return true;
|
|
213
|
+
}
|
|
214
|
+
});
|
|
215
|
+
};
|
|
216
|
+
return Object.assign(globalData, {
|
|
217
|
+
initialed: readonly(toComputed("initialed")),
|
|
218
|
+
locale: toComputed("locale"),
|
|
219
|
+
theme: toComputed("theme"),
|
|
220
|
+
token: toComputed("token"),
|
|
221
|
+
isI18nKeyVisible: toComputed("isI18nKeyVisible"),
|
|
222
|
+
roles: toComputed("roles"),
|
|
223
|
+
permissions: toComputed("permissions"),
|
|
224
|
+
user: toComputed("user"),
|
|
225
|
+
localeMessages: toComputed("localeMessages"),
|
|
226
|
+
elLocaleMessages: toComputed("elLocaleMessages"),
|
|
227
|
+
config: toComputed("config"),
|
|
228
|
+
getConfig,
|
|
229
|
+
isConfig,
|
|
230
|
+
setAndWaitUntil,
|
|
231
|
+
resetUser
|
|
232
|
+
});
|
|
233
|
+
});
|
|
234
|
+
|
|
108
235
|
// src/useGlobalMessage.ts
|
|
109
236
|
import { ElMessage, ElMessageBox, ElNotification } from "element-plus";
|
|
110
237
|
var confirmPromise = (config, onOk, onCancel) => {
|
|
@@ -155,236 +282,11 @@ function useGlobalMessage(_directMode = false) {
|
|
|
155
282
|
}
|
|
156
283
|
|
|
157
284
|
// src/useLocale.ts
|
|
158
|
-
import { toValue
|
|
285
|
+
import { toValue, watch as watch2 } from "vue";
|
|
159
286
|
import { createI18n } from "vue-i18n";
|
|
160
|
-
|
|
161
|
-
// src/useMicroGlobalData.ts
|
|
162
|
-
import { isFunction, isPlainObject as isPlainObject2, withResolvers } from "@zl-ui-kit/utils";
|
|
163
|
-
import { createGlobalState as createGlobalState2, useStorage } from "@vueuse/core";
|
|
164
|
-
import { computed as computed3, customRef, nextTick, readonly, ref as ref2, toValue, watch } from "vue";
|
|
165
|
-
|
|
166
|
-
// src/internal/microApp.ts
|
|
167
|
-
import _microApp from "@micro-zoe/micro-app";
|
|
168
|
-
function usable(mod) {
|
|
169
|
-
try {
|
|
170
|
-
return mod && typeof mod.getGlobalData === "function" ? mod : void 0;
|
|
171
|
-
} catch {
|
|
172
|
-
return void 0;
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
function resolveMicroApp() {
|
|
176
|
-
if (typeof window !== "undefined") {
|
|
177
|
-
const injected = window.microApp;
|
|
178
|
-
if (injected)
|
|
179
|
-
return injected;
|
|
180
|
-
}
|
|
181
|
-
return usable(_microApp);
|
|
182
|
-
}
|
|
183
|
-
function isMicroChildRuntime() {
|
|
184
|
-
return typeof window !== "undefined" && !!window.microApp;
|
|
185
|
-
}
|
|
186
|
-
function requireMicroApp(api) {
|
|
187
|
-
const app = resolveMicroApp();
|
|
188
|
-
if (!app) {
|
|
189
|
-
throw new Error(
|
|
190
|
-
`[zl-ui] ${api}() \u4F9D\u8D56 micro-app\uFF0C\u8BF7\u5148\u5B89\u88C5\uFF1Anpm i @micro-zoe/micro-app
|
|
191
|
-
\u82E5\u4E0D\u9700\u8981\u5FAE\u524D\u7AEF\u80FD\u529B\uFF0C\u8BF7\u6539\u7528 @zl-ui-kit/composables \u4E3B\u5165\u53E3\u4E2D\u7684\u5176\u5B83 hook\u3002`
|
|
192
|
-
);
|
|
193
|
-
}
|
|
194
|
-
return app;
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
// src/useMicroGlobalData.ts
|
|
198
|
-
var devMockEnabled = false;
|
|
199
|
-
function enableGlobalDataMock(enabled = true) {
|
|
200
|
-
devMockEnabled = enabled;
|
|
201
|
-
}
|
|
202
|
-
function createStorages() {
|
|
203
|
-
return {
|
|
204
|
-
locale: useStorage("$zl_locale", ""),
|
|
205
|
-
theme: useStorage("$zl_theme", "light"),
|
|
206
|
-
token: useStorage("$zl_token", void 0)
|
|
207
|
-
};
|
|
208
|
-
}
|
|
209
|
-
function createInitialedData(storages) {
|
|
210
|
-
return {
|
|
211
|
-
initialed: true,
|
|
212
|
-
locale: storages.locale.value,
|
|
213
|
-
theme: storages.theme.value,
|
|
214
|
-
token: storages.token.value,
|
|
215
|
-
isI18nKeyVisible: false,
|
|
216
|
-
roles: [],
|
|
217
|
-
permissions: [],
|
|
218
|
-
user: void 0,
|
|
219
|
-
localeMessages: {},
|
|
220
|
-
elLocaleMessages: void 0,
|
|
221
|
-
config: void 0
|
|
222
|
-
};
|
|
223
|
-
}
|
|
224
|
-
function useDevMockGlobalData() {
|
|
225
|
-
const storages = createStorages();
|
|
226
|
-
const globalData = ref2(createInitialedData(storages));
|
|
227
|
-
function getConfig(key, defaultValue) {
|
|
228
|
-
return globalData.value.config?.[key] ?? defaultValue;
|
|
229
|
-
}
|
|
230
|
-
function isConfig(key, compareValue = "true") {
|
|
231
|
-
return globalData.value.config?.[key] === compareValue;
|
|
232
|
-
}
|
|
233
|
-
async function setAndWaitUntil({ set }) {
|
|
234
|
-
globalData.value = { ...globalData.value, ...set };
|
|
235
|
-
await nextTick();
|
|
236
|
-
}
|
|
237
|
-
const _toComputed = (prop) => {
|
|
238
|
-
return computed3({
|
|
239
|
-
get() {
|
|
240
|
-
return globalData.value[prop];
|
|
241
|
-
},
|
|
242
|
-
set(value) {
|
|
243
|
-
globalData.value = {
|
|
244
|
-
...globalData.value,
|
|
245
|
-
[prop]: value
|
|
246
|
-
};
|
|
247
|
-
return true;
|
|
248
|
-
}
|
|
249
|
-
});
|
|
250
|
-
};
|
|
251
|
-
updateBodyAttribute("data-theme", storages.theme.value);
|
|
252
|
-
updateBodyAttribute("data-locale", storages.locale.value);
|
|
253
|
-
return Object.assign(globalData, {
|
|
254
|
-
initialed: readonly(_toComputed("initialed")),
|
|
255
|
-
locale: _toComputed("locale"),
|
|
256
|
-
theme: _toComputed("theme"),
|
|
257
|
-
token: _toComputed("token"),
|
|
258
|
-
isI18nKeyVisible: _toComputed("isI18nKeyVisible"),
|
|
259
|
-
roles: _toComputed("roles"),
|
|
260
|
-
permissions: _toComputed("permissions"),
|
|
261
|
-
user: _toComputed("user"),
|
|
262
|
-
localeMessages: _toComputed("localeMessages"),
|
|
263
|
-
elLocaleMessages: _toComputed("elLocaleMessages"),
|
|
264
|
-
config: _toComputed("config")
|
|
265
|
-
}, { getConfig, isConfig, setAndWaitUntil });
|
|
266
|
-
}
|
|
267
|
-
var useMicroGlobalData = createGlobalState2(() => {
|
|
268
|
-
const microApp = resolveMicroApp();
|
|
269
|
-
if (!microApp) {
|
|
270
|
-
console.warn(
|
|
271
|
-
"[useMicroGlobalData] \u672A\u68C0\u6D4B\u5230 micro-app\uFF0C\u5DF2\u964D\u7EA7\u4E3A\u672C\u5730\u5B58\u50A8\u6A21\u5F0F\uFF08$zl_locale / $zl_theme / $zl_token\uFF09\u3002\u9700\u8981\u8DE8\u5E94\u7528\u540C\u6B65\u8BF7\u5B89\u88C5 @micro-zoe/micro-app\u3002"
|
|
272
|
-
);
|
|
273
|
-
return useDevMockGlobalData();
|
|
274
|
-
}
|
|
275
|
-
if (devMockEnabled && !isMicroChildRuntime()) {
|
|
276
|
-
console.warn("[useMicroGlobalData] \u4F7F\u7528\u5F00\u53D1\u6001 mock \u6570\u636E\uFF08enableGlobalDataMock \u5DF2\u5F00\u542F\uFF09");
|
|
277
|
-
return useDevMockGlobalData();
|
|
278
|
-
}
|
|
279
|
-
const storages = createStorages();
|
|
280
|
-
const triggers = /* @__PURE__ */ new Set();
|
|
281
|
-
let _computedSetTrigger;
|
|
282
|
-
const globalData = customRef((track, trigger2) => {
|
|
283
|
-
_computedSetTrigger = trigger2;
|
|
284
|
-
return {
|
|
285
|
-
get() {
|
|
286
|
-
track();
|
|
287
|
-
return microApp.getGlobalData() || Object.fromEntries(Object.entries(storages).map(([key, storage]) => [key, toValue(storage)]));
|
|
288
|
-
},
|
|
289
|
-
set(value) {
|
|
290
|
-
microApp.setGlobalData(value);
|
|
291
|
-
return true;
|
|
292
|
-
}
|
|
293
|
-
};
|
|
294
|
-
});
|
|
295
|
-
function trigger() {
|
|
296
|
-
_computedSetTrigger();
|
|
297
|
-
nextTick(() => {
|
|
298
|
-
triggers.forEach((fn) => fn());
|
|
299
|
-
});
|
|
300
|
-
}
|
|
301
|
-
microApp.addGlobalDataListener(trigger);
|
|
302
|
-
if (!globalData.value.initialed) {
|
|
303
|
-
globalData.value = createInitialedData(storages);
|
|
304
|
-
}
|
|
305
|
-
updateBodyAttribute("data-theme", storages.theme.value);
|
|
306
|
-
updateBodyAttribute("data-locale", storages.locale.value);
|
|
307
|
-
const storagesKey = Object.keys(storages);
|
|
308
|
-
watch(() => storagesKey.map((key) => globalData.value[key]), (values) => {
|
|
309
|
-
values.forEach((value, index) => {
|
|
310
|
-
const key = storagesKey[index];
|
|
311
|
-
if (storages[key].value !== value) {
|
|
312
|
-
storages[key].value = value;
|
|
313
|
-
if (key === "theme") {
|
|
314
|
-
updateBodyAttribute("data-theme", value);
|
|
315
|
-
}
|
|
316
|
-
if (key === "locale") {
|
|
317
|
-
updateBodyAttribute("data-locale", value);
|
|
318
|
-
}
|
|
319
|
-
}
|
|
320
|
-
});
|
|
321
|
-
});
|
|
322
|
-
const _toComputed = (prop) => {
|
|
323
|
-
return computed3({
|
|
324
|
-
get() {
|
|
325
|
-
return globalData.value[prop];
|
|
326
|
-
},
|
|
327
|
-
set(value) {
|
|
328
|
-
globalData.value = { [prop]: value };
|
|
329
|
-
return true;
|
|
330
|
-
}
|
|
331
|
-
});
|
|
332
|
-
};
|
|
333
|
-
function setAndWaitUntil({ set, until }) {
|
|
334
|
-
if (!set && !until && !isPlainObject2(set) && !isFunction(until)) {
|
|
335
|
-
return Promise.resolve();
|
|
336
|
-
}
|
|
337
|
-
const { resolve, promise } = withResolvers();
|
|
338
|
-
globalData.value = set;
|
|
339
|
-
const triggerFn = () => {
|
|
340
|
-
if (until?.(globalData.value)) {
|
|
341
|
-
triggers.delete(triggerFn);
|
|
342
|
-
resolve();
|
|
343
|
-
}
|
|
344
|
-
};
|
|
345
|
-
triggers.add(triggerFn);
|
|
346
|
-
return promise;
|
|
347
|
-
}
|
|
348
|
-
function getConfig(key, defaultValue) {
|
|
349
|
-
return globalData.value.config?.[key] ?? defaultValue;
|
|
350
|
-
}
|
|
351
|
-
function isConfig(key, compareValue = "true") {
|
|
352
|
-
return globalData.value.config?.[key] === compareValue;
|
|
353
|
-
}
|
|
354
|
-
function resetUser() {
|
|
355
|
-
globalData.value = { user: void 0, roles: [], permissions: [], token: void 0 };
|
|
356
|
-
storages.token.value = void 0;
|
|
357
|
-
}
|
|
358
|
-
return Object.assign(globalData, {
|
|
359
|
-
initialed: readonly(_toComputed("initialed")),
|
|
360
|
-
locale: _toComputed("locale"),
|
|
361
|
-
theme: _toComputed("theme"),
|
|
362
|
-
token: _toComputed("token"),
|
|
363
|
-
isI18nKeyVisible: _toComputed("isI18nKeyVisible"),
|
|
364
|
-
roles: _toComputed("roles"),
|
|
365
|
-
permissions: _toComputed("permissions"),
|
|
366
|
-
user: _toComputed("user"),
|
|
367
|
-
localeMessages: _toComputed("localeMessages"),
|
|
368
|
-
elLocaleMessages: _toComputed("elLocaleMessages"),
|
|
369
|
-
config: _toComputed("config"),
|
|
370
|
-
setAndWaitUntil,
|
|
371
|
-
getConfig,
|
|
372
|
-
isConfig,
|
|
373
|
-
resetUser
|
|
374
|
-
});
|
|
375
|
-
});
|
|
376
|
-
function updateBodyAttribute(key, value) {
|
|
377
|
-
if (typeof document === "undefined")
|
|
378
|
-
return;
|
|
379
|
-
[document.body, ...document.querySelectorAll("micro-app-body")].forEach((el) => {
|
|
380
|
-
el.setAttribute(key, String(value ?? ""));
|
|
381
|
-
});
|
|
382
|
-
}
|
|
383
|
-
|
|
384
|
-
// src/useLocale.ts
|
|
385
287
|
var elLocaleMessagesStore = {};
|
|
386
288
|
function useLocale(options = {}, loader) {
|
|
387
|
-
const { locale, localeMessages, elLocaleMessages, isI18nKeyVisible } =
|
|
289
|
+
const { locale, localeMessages, elLocaleMessages, isI18nKeyVisible } = useGlobalData();
|
|
388
290
|
function postTranslation(translated, key) {
|
|
389
291
|
if (isI18nKeyVisible.value)
|
|
390
292
|
return key;
|
|
@@ -418,7 +320,7 @@ function useLocale(options = {}, loader) {
|
|
|
418
320
|
}, { immediate: true });
|
|
419
321
|
let storeLocale;
|
|
420
322
|
watch2(isI18nKeyVisible, (visible) => {
|
|
421
|
-
const currentLocale =
|
|
323
|
+
const currentLocale = toValue(i18n.global.locale);
|
|
422
324
|
if (visible) {
|
|
423
325
|
storeLocale = [currentLocale, i18n.global.getLocaleMessage(currentLocale)];
|
|
424
326
|
i18n.global.setLocaleMessage(currentLocale, {});
|
|
@@ -448,490 +350,6 @@ function useLocale(options = {}, loader) {
|
|
|
448
350
|
};
|
|
449
351
|
}
|
|
450
352
|
|
|
451
|
-
// src/useZlT.ts
|
|
452
|
-
import { useI18n } from "vue-i18n";
|
|
453
|
-
function useZlT() {
|
|
454
|
-
let t = (key, fallback) => fallback ?? key;
|
|
455
|
-
try {
|
|
456
|
-
const globalT = useI18n({ useScope: "global" }).t;
|
|
457
|
-
t = (key, fallback, params) => {
|
|
458
|
-
const msg = params ? globalT(key, params) : globalT(key);
|
|
459
|
-
return msg === key ? fallback ?? key : msg;
|
|
460
|
-
};
|
|
461
|
-
} catch {
|
|
462
|
-
}
|
|
463
|
-
return { t };
|
|
464
|
-
}
|
|
465
|
-
|
|
466
|
-
// src/useMicroAction.ts
|
|
467
|
-
import { createSharedComposable, tryOnScopeDispose as tryOnScopeDispose2 } from "@vueuse/core";
|
|
468
|
-
import { watch as watch3 } from "vue";
|
|
469
|
-
|
|
470
|
-
// src/useMicroApp.ts
|
|
471
|
-
import { createGlobalState as createGlobalState3 } from "@vueuse/core";
|
|
472
|
-
import { ref as ref3 } from "vue";
|
|
473
|
-
var useMicroApp = createGlobalState3(() => {
|
|
474
|
-
const apps = ref3([]);
|
|
475
|
-
function isMicroBase() {
|
|
476
|
-
return typeof window !== "undefined" && !!window.__MICRO_APP_BASE_APPLICATION__;
|
|
477
|
-
}
|
|
478
|
-
function isMicroChild() {
|
|
479
|
-
return typeof window !== "undefined" && !!window.__MICRO_APP_ENVIRONMENT__;
|
|
480
|
-
}
|
|
481
|
-
function updateApps() {
|
|
482
|
-
apps.value = requireMicroApp("useMicroApp().updateApps").getActiveApps();
|
|
483
|
-
}
|
|
484
|
-
function startMicroApp(config = {}) {
|
|
485
|
-
const microApp = requireMicroApp("useMicroApp().startMicroApp");
|
|
486
|
-
microApp.start({
|
|
487
|
-
...config,
|
|
488
|
-
lifeCycles: {
|
|
489
|
-
mounted(data) {
|
|
490
|
-
updateApps();
|
|
491
|
-
config?.lifeCycles?.mounted?.(data);
|
|
492
|
-
},
|
|
493
|
-
// micro-app 的卸载生命周期名为 unmount,对外保持 unmounted 语义
|
|
494
|
-
unmount(data) {
|
|
495
|
-
updateApps();
|
|
496
|
-
config?.lifeCycles?.unmounted?.(data);
|
|
497
|
-
}
|
|
498
|
-
}
|
|
499
|
-
});
|
|
500
|
-
return microApp;
|
|
501
|
-
}
|
|
502
|
-
return { apps, isMicroBase, isMicroChild, updateApps, startMicroApp };
|
|
503
|
-
});
|
|
504
|
-
|
|
505
|
-
// src/useMicroAction.ts
|
|
506
|
-
var ACTION_PREFIX = "action__";
|
|
507
|
-
var ACTION_ROOT_PREFIX = "action__root__";
|
|
508
|
-
function _action(action, onlyRoot = false) {
|
|
509
|
-
return `${onlyRoot ? ACTION_ROOT_PREFIX : ACTION_PREFIX}${action}`;
|
|
510
|
-
}
|
|
511
|
-
function isEmitRoot(action) {
|
|
512
|
-
return action.startsWith(`${ACTION_ROOT_PREFIX}emit-`);
|
|
513
|
-
}
|
|
514
|
-
var useMicroListener = createSharedComposable(() => {
|
|
515
|
-
const { isMicroBase, isMicroChild, apps } = useMicroApp();
|
|
516
|
-
const listenerMap = /* @__PURE__ */ new Map();
|
|
517
|
-
const handler = (data) => {
|
|
518
|
-
Object.entries(data).forEach(([args, key]) => {
|
|
519
|
-
if (isEmitRoot(key) && isMicroBase() && isMicroChild()) {
|
|
520
|
-
window.microApp?.dispatch({ [JSON.stringify(args)]: key });
|
|
521
|
-
return;
|
|
522
|
-
}
|
|
523
|
-
const action = key.replace(ACTION_ROOT_PREFIX, "").replace(ACTION_PREFIX, "");
|
|
524
|
-
const callbackSet = listenerMap.get(action);
|
|
525
|
-
if (!callbackSet?.size) {
|
|
526
|
-
return;
|
|
527
|
-
}
|
|
528
|
-
delete data[args];
|
|
529
|
-
callbackSet.forEach((callback) => callback(...JSON.parse(args)));
|
|
530
|
-
});
|
|
531
|
-
};
|
|
532
|
-
const listeners = [];
|
|
533
|
-
if (isMicroChild()) {
|
|
534
|
-
const _microApp2 = window.microApp;
|
|
535
|
-
_microApp2?.addDataListener(handler);
|
|
536
|
-
listeners.push(() => {
|
|
537
|
-
_microApp2?.removeDataListener(handler);
|
|
538
|
-
});
|
|
539
|
-
}
|
|
540
|
-
if (isMicroBase()) {
|
|
541
|
-
const microApp = requireMicroApp("useMicroAction");
|
|
542
|
-
listeners.push(() => {
|
|
543
|
-
apps.value.forEach((app) => {
|
|
544
|
-
microApp.removeDataListener(app, handler);
|
|
545
|
-
});
|
|
546
|
-
});
|
|
547
|
-
watch3(apps, (newApps, oldApps) => {
|
|
548
|
-
oldApps.forEach((app) => {
|
|
549
|
-
microApp.removeDataListener(app, handler);
|
|
550
|
-
});
|
|
551
|
-
newApps.forEach((app) => {
|
|
552
|
-
microApp.addDataListener(app, handler);
|
|
553
|
-
});
|
|
554
|
-
}, { deep: true });
|
|
555
|
-
}
|
|
556
|
-
const _ensureGetCallbackSet = (action) => {
|
|
557
|
-
let callbackSet = listenerMap.get(action);
|
|
558
|
-
if (!callbackSet) {
|
|
559
|
-
callbackSet = /* @__PURE__ */ new Set();
|
|
560
|
-
listenerMap.set(action, callbackSet);
|
|
561
|
-
}
|
|
562
|
-
return callbackSet;
|
|
563
|
-
};
|
|
564
|
-
const on = (action, callback) => {
|
|
565
|
-
_ensureGetCallbackSet(action).add(callback);
|
|
566
|
-
};
|
|
567
|
-
const off = (action, callback) => {
|
|
568
|
-
const callbackSet = listenerMap.get(action);
|
|
569
|
-
if (callbackSet) {
|
|
570
|
-
callbackSet.delete(callback);
|
|
571
|
-
}
|
|
572
|
-
};
|
|
573
|
-
const once = (action, callback) => {
|
|
574
|
-
const callbackSet = _ensureGetCallbackSet(action);
|
|
575
|
-
const handler2 = (...args) => {
|
|
576
|
-
callback(...args);
|
|
577
|
-
callbackSet.delete(handler2);
|
|
578
|
-
};
|
|
579
|
-
callbackSet.add(handler2);
|
|
580
|
-
};
|
|
581
|
-
const dispose = () => {
|
|
582
|
-
listenerMap.clear();
|
|
583
|
-
listeners.forEach((fn) => fn());
|
|
584
|
-
};
|
|
585
|
-
tryOnScopeDispose2(dispose);
|
|
586
|
-
return { on, off, once };
|
|
587
|
-
});
|
|
588
|
-
function useMicroAction(action, appName) {
|
|
589
|
-
const { apps } = useMicroApp();
|
|
590
|
-
const _actionName = _action(action);
|
|
591
|
-
return (...args) => {
|
|
592
|
-
const _apps = !appName ? apps.value : apps.value.filter((app) => app === appName);
|
|
593
|
-
if (!_apps.length)
|
|
594
|
-
return;
|
|
595
|
-
const microApp = requireMicroApp("useMicroAction");
|
|
596
|
-
_apps.forEach((app) => {
|
|
597
|
-
microApp.setData(app, { [JSON.stringify(args)]: _actionName });
|
|
598
|
-
});
|
|
599
|
-
};
|
|
600
|
-
}
|
|
601
|
-
function useMicroActionAsync(action, appName) {
|
|
602
|
-
const _actionName = _action(action);
|
|
603
|
-
const { isMicroBase, isMicroChild } = useMicroApp();
|
|
604
|
-
if (!isMicroBase()) {
|
|
605
|
-
return (...args) => {
|
|
606
|
-
return new Promise((resolve, reject) => {
|
|
607
|
-
window.microApp?.dispatch({ [JSON.stringify(args)]: _actionName }, (promises) => {
|
|
608
|
-
Promise.all(promises).then(resolve, reject);
|
|
609
|
-
});
|
|
610
|
-
});
|
|
611
|
-
};
|
|
612
|
-
}
|
|
613
|
-
if (isMicroChild()) {
|
|
614
|
-
return (...args) => {
|
|
615
|
-
return new Promise((resolve, reject) => {
|
|
616
|
-
const microApp = requireMicroApp("useMicroActionAsync");
|
|
617
|
-
microApp.setData(appName, { [JSON.stringify(args)]: _actionName }, (promises) => {
|
|
618
|
-
Promise.all(promises).then(resolve, reject);
|
|
619
|
-
});
|
|
620
|
-
});
|
|
621
|
-
};
|
|
622
|
-
}
|
|
623
|
-
return (..._args) => Promise.resolve([]);
|
|
624
|
-
}
|
|
625
|
-
function useMicroResultListener(action, callback) {
|
|
626
|
-
const { isMicroBase } = useMicroApp();
|
|
627
|
-
const _actionName = _action(action);
|
|
628
|
-
const handler = async (data) => {
|
|
629
|
-
for (const [args, key] of Object.entries(data)) {
|
|
630
|
-
if (key === _actionName) {
|
|
631
|
-
delete data[args];
|
|
632
|
-
return await callback(...JSON.parse(args));
|
|
633
|
-
}
|
|
634
|
-
}
|
|
635
|
-
};
|
|
636
|
-
const micro = isMicroBase() ? requireMicroApp("useMicroResultListener") : typeof window !== "undefined" ? window.microApp : void 0;
|
|
637
|
-
micro?.addDataListener(handler);
|
|
638
|
-
}
|
|
639
|
-
function dispatchMicroAction(action, appName, ...data) {
|
|
640
|
-
const _actionName = _action(action);
|
|
641
|
-
return new Promise((resolve) => {
|
|
642
|
-
requireMicroApp("dispatchMicroAction").setData(appName, { [JSON.stringify(data)]: _actionName }, resolve);
|
|
643
|
-
});
|
|
644
|
-
}
|
|
645
|
-
|
|
646
|
-
// src/usePageTabs.ts
|
|
647
|
-
import { createGlobalState as createGlobalState4 } from "@vueuse/core";
|
|
648
|
-
import { computed as computed4, getCurrentInstance, nextTick as nextTick2, reactive, readonly as readonly2, ref as ref4, shallowReactive, watch as watch4 } from "vue";
|
|
649
|
-
function pushMicroRouter({ micro, url }) {
|
|
650
|
-
if (!micro || !url)
|
|
651
|
-
return;
|
|
652
|
-
const microApp = requireMicroApp("usePageTabs");
|
|
653
|
-
const activeApps = microApp.getActiveApps();
|
|
654
|
-
if (!activeApps.includes(micro))
|
|
655
|
-
return;
|
|
656
|
-
return microApp.router.push({ name: micro, path: url });
|
|
657
|
-
}
|
|
658
|
-
var createPageTabsState = createGlobalState4(() => {
|
|
659
|
-
const { on } = useMicroListener();
|
|
660
|
-
const roots = reactive({});
|
|
661
|
-
const activeRootKey = ref4(null);
|
|
662
|
-
const activeRoot = computed4(() => activeRootKey.value ? roots[activeRootKey.value] : null);
|
|
663
|
-
const pageTabs = computed4(() => {
|
|
664
|
-
if (!activeRoot.value)
|
|
665
|
-
return [];
|
|
666
|
-
return activeRoot.value.tabs.reduce((acc, cur) => {
|
|
667
|
-
const getChildren = (item) => {
|
|
668
|
-
if (item.children) {
|
|
669
|
-
const children = item.children.map((i) => getChildren(i)).flat();
|
|
670
|
-
Object.assign(children[0], { title: item.title, icon: item.icon });
|
|
671
|
-
return children;
|
|
672
|
-
} else {
|
|
673
|
-
return [item];
|
|
674
|
-
}
|
|
675
|
-
};
|
|
676
|
-
if (cur.children) {
|
|
677
|
-
return [...acc, ...getChildren(cur)];
|
|
678
|
-
} else {
|
|
679
|
-
return [...acc, cur];
|
|
680
|
-
}
|
|
681
|
-
}, []);
|
|
682
|
-
});
|
|
683
|
-
const current = computed4(() => {
|
|
684
|
-
return pageTabs.value.find((item) => item.key === activeRoot.value?.activeTabKey);
|
|
685
|
-
});
|
|
686
|
-
const micros = shallowReactive({});
|
|
687
|
-
async function _removePageTabByKey(key, root = activeRoot.value) {
|
|
688
|
-
const index = root.tabs.findIndex((item) => item.key === key);
|
|
689
|
-
if (index === -1)
|
|
690
|
-
return false;
|
|
691
|
-
const tab = root.tabs[index];
|
|
692
|
-
try {
|
|
693
|
-
if (typeof tab.beforeRemove === "function") {
|
|
694
|
-
const shouldRemove = await tab.beforeRemove();
|
|
695
|
-
if (shouldRemove === false)
|
|
696
|
-
return false;
|
|
697
|
-
}
|
|
698
|
-
root.tabs.splice(index, 1);
|
|
699
|
-
const parentTab = root._parentMap[key];
|
|
700
|
-
delete root._parentMap[key];
|
|
701
|
-
if (root.activeTabKey === key) {
|
|
702
|
-
root.activeTabKey = root.tabs.at(index - 1)?.key ?? root.tabs[0]?.key ?? "";
|
|
703
|
-
}
|
|
704
|
-
return [tab, parentTab];
|
|
705
|
-
} catch {
|
|
706
|
-
return false;
|
|
707
|
-
}
|
|
708
|
-
}
|
|
709
|
-
on("dispatch-page-key-change", ({ key, root }) => {
|
|
710
|
-
const changedRoot = roots[root];
|
|
711
|
-
if (!changedRoot)
|
|
712
|
-
return;
|
|
713
|
-
changedRoot.activeTabKey = key;
|
|
714
|
-
activeRootKey.value = root;
|
|
715
|
-
});
|
|
716
|
-
on("dispatch-page-key-remove", ({ key, root, isRoot }) => {
|
|
717
|
-
if (isRoot) {
|
|
718
|
-
roots[root] = void 0;
|
|
719
|
-
if (activeRootKey.value === root) {
|
|
720
|
-
const rootKeys = Object.keys(roots);
|
|
721
|
-
activeRootKey.value = rootKeys.at(rootKeys.indexOf(root) - 1) ?? null;
|
|
722
|
-
}
|
|
723
|
-
return;
|
|
724
|
-
}
|
|
725
|
-
const changedRoot = roots[root];
|
|
726
|
-
if (!changedRoot)
|
|
727
|
-
return;
|
|
728
|
-
_removePageTabByKey(key, changedRoot);
|
|
729
|
-
});
|
|
730
|
-
watch4(current, (val) => {
|
|
731
|
-
if (!val?.micro)
|
|
732
|
-
return;
|
|
733
|
-
if (!val.isChildMicro)
|
|
734
|
-
return;
|
|
735
|
-
if (!micros[val.micro]) {
|
|
736
|
-
micros[val.micro] = val.url;
|
|
737
|
-
} else if (val.url) {
|
|
738
|
-
pushMicroRouter(val);
|
|
739
|
-
} else {
|
|
740
|
-
pushMicroRouter({ micro: val.micro, url: val.rootKey });
|
|
741
|
-
}
|
|
742
|
-
});
|
|
743
|
-
return {
|
|
744
|
-
roots,
|
|
745
|
-
activeRoot,
|
|
746
|
-
activeRootKey,
|
|
747
|
-
micros,
|
|
748
|
-
pageTabs,
|
|
749
|
-
current,
|
|
750
|
-
_removePageTabByKey
|
|
751
|
-
};
|
|
752
|
-
});
|
|
753
|
-
function usePageTabs() {
|
|
754
|
-
const { roots, activeRootKey, micros, _removePageTabByKey, ...state } = createPageTabsState();
|
|
755
|
-
const { isMicroBase } = useMicroApp();
|
|
756
|
-
const vm = getCurrentInstance();
|
|
757
|
-
function createPageTabsRoot(root) {
|
|
758
|
-
if (!roots[root.key]) {
|
|
759
|
-
const rootTab = { ...root, isRoot: true };
|
|
760
|
-
roots[root.key] = {
|
|
761
|
-
tabs: [rootTab],
|
|
762
|
-
activeTabKey: rootTab.key,
|
|
763
|
-
_parentMap: shallowReactive({})
|
|
764
|
-
};
|
|
765
|
-
}
|
|
766
|
-
activeRootKey.value = root.key;
|
|
767
|
-
}
|
|
768
|
-
function addPageTab(tab, options) {
|
|
769
|
-
const { update, childMicro = true } = { update: false, ...options };
|
|
770
|
-
const root = roots[activeRootKey.value];
|
|
771
|
-
const lastActiveTabKey = root.activeTabKey;
|
|
772
|
-
root._parentMap[tab.key] = vm;
|
|
773
|
-
root.activeTabKey = tab.key;
|
|
774
|
-
const index = root.tabs.findIndex((item) => item.key === tab.key);
|
|
775
|
-
if (index > -1 && !update) {
|
|
776
|
-
return false;
|
|
777
|
-
}
|
|
778
|
-
let currentTab = { ...tab, _parentTabKey: lastActiveTabKey };
|
|
779
|
-
if (isComponentTab(tab)) {
|
|
780
|
-
const { title, key, icon, beforeRemove, component, props, ..._props } = tab;
|
|
781
|
-
currentTab = { title, key, icon, beforeRemove, component, props: { ...props, ..._props }, _parentTabKey: lastActiveTabKey };
|
|
782
|
-
} else if (tab.micro && isMicroBase() && childMicro) {
|
|
783
|
-
currentTab.isChildMicro = true;
|
|
784
|
-
addMicro(currentTab);
|
|
785
|
-
}
|
|
786
|
-
if (index > -1) {
|
|
787
|
-
root.tabs[index] = currentTab;
|
|
788
|
-
} else {
|
|
789
|
-
root.tabs.push(currentTab);
|
|
790
|
-
}
|
|
791
|
-
return true;
|
|
792
|
-
}
|
|
793
|
-
async function removePageTab(tabOrKey = roots[activeRootKey.value].activeTabKey) {
|
|
794
|
-
if (!tabOrKey)
|
|
795
|
-
return;
|
|
796
|
-
if (typeof tabOrKey === "string") {
|
|
797
|
-
return _removePageTabByKey(tabOrKey);
|
|
798
|
-
}
|
|
799
|
-
if (tabOrKey.isChildRoot) {
|
|
800
|
-
await _removeChildRoot(tabOrKey);
|
|
801
|
-
} else if (tabOrKey.isChild) {
|
|
802
|
-
dispatchMicroAction("dispatch-page-key-remove", tabOrKey.micro, {
|
|
803
|
-
key: tabOrKey.key,
|
|
804
|
-
root: tabOrKey.rootKey
|
|
805
|
-
});
|
|
806
|
-
} else {
|
|
807
|
-
return _removePageTabByKey(tabOrKey.key);
|
|
808
|
-
}
|
|
809
|
-
return false;
|
|
810
|
-
}
|
|
811
|
-
function clearPageTab(rootKey = activeRootKey.value) {
|
|
812
|
-
const rootKeys = Object.keys(roots);
|
|
813
|
-
delete roots[rootKey];
|
|
814
|
-
if (rootKey === activeRootKey.value) {
|
|
815
|
-
const index = rootKeys.indexOf(rootKey);
|
|
816
|
-
rootKeys.splice(index, 1);
|
|
817
|
-
activeRootKey.value = rootKeys.at(index - 1) ?? null;
|
|
818
|
-
}
|
|
819
|
-
}
|
|
820
|
-
function setRootChild(tabs, activeChildTabKey, micro) {
|
|
821
|
-
if (!activeChildTabKey || micro.startsWith("flowable_"))
|
|
822
|
-
return;
|
|
823
|
-
const root = roots[activeRootKey.value];
|
|
824
|
-
const childRootTab = tabs[0];
|
|
825
|
-
const childRootTabKey = `${childRootTab.micro}__${childRootTab.key}`;
|
|
826
|
-
const currentTab = state.pageTabs.value.find((tab) => tab.key === root.activeTabKey);
|
|
827
|
-
root._parentTabMap ?? (root._parentTabMap = {});
|
|
828
|
-
if (!root._parentTabMap[childRootTabKey]) {
|
|
829
|
-
root._parentTabMap[childRootTabKey] = currentTab;
|
|
830
|
-
}
|
|
831
|
-
const parentTab = root._parentTabMap[childRootTabKey];
|
|
832
|
-
function childTabFormatter(tab) {
|
|
833
|
-
return { ...tab, isChild: true, isChildMicro: !!tab.micro, parentTab, childRootTabKey };
|
|
834
|
-
}
|
|
835
|
-
const oldTabs = parentTab.children;
|
|
836
|
-
if (!oldTabs?.length) {
|
|
837
|
-
parentTab.children = tabs.map(childTabFormatter);
|
|
838
|
-
} else {
|
|
839
|
-
const newTabs = parentTab.children = [];
|
|
840
|
-
if (tabs.length > oldTabs.length) {
|
|
841
|
-
newTabs.push(...oldTabs, ...tabs.slice(oldTabs.length).map(childTabFormatter));
|
|
842
|
-
} else if (tabs.length < oldTabs.length) {
|
|
843
|
-
const oldChildMap = oldTabs.reduce((acc, cur) => {
|
|
844
|
-
acc[cur.key] = cur;
|
|
845
|
-
return acc;
|
|
846
|
-
}, {});
|
|
847
|
-
newTabs.push(...tabs.map((tab) => {
|
|
848
|
-
return oldChildMap[tab.key] || childTabFormatter(tab);
|
|
849
|
-
}));
|
|
850
|
-
} else {
|
|
851
|
-
newTabs.push(...oldTabs);
|
|
852
|
-
}
|
|
853
|
-
}
|
|
854
|
-
root.activeTabKey = activeChildTabKey;
|
|
855
|
-
}
|
|
856
|
-
async function removeCurrentTab(callback) {
|
|
857
|
-
const root = state.activeRoot.value;
|
|
858
|
-
const removedTab = await _removePageTabByKey(root.activeTabKey);
|
|
859
|
-
if (!removedTab || typeof callback !== "function")
|
|
860
|
-
return false;
|
|
861
|
-
const [tab, parentTab] = removedTab;
|
|
862
|
-
if (state.pageTabs.value.find((item) => item.key === tab._parentTabKey)) {
|
|
863
|
-
root.activeTabKey = tab._parentTabKey;
|
|
864
|
-
await nextTick2();
|
|
865
|
-
await callback(parentTab?.exposed);
|
|
866
|
-
}
|
|
867
|
-
return true;
|
|
868
|
-
}
|
|
869
|
-
async function _removeChildRoot(tab) {
|
|
870
|
-
if (!tab.isChildRoot)
|
|
871
|
-
return;
|
|
872
|
-
const root = roots[activeRootKey.value];
|
|
873
|
-
const childRootKey = `${tab.micro}__${tab.key}`;
|
|
874
|
-
const parentTab = root._parentTabMap?.[childRootKey];
|
|
875
|
-
if (!parentTab)
|
|
876
|
-
return;
|
|
877
|
-
delete root._parentTabMap?.[childRootKey];
|
|
878
|
-
const realParentTab = parentTab.parentTab;
|
|
879
|
-
dispatchMicroAction("dispatch-page-key-remove", tab.micro, {
|
|
880
|
-
key: tab.key,
|
|
881
|
-
root: tab.rootKey,
|
|
882
|
-
isRoot: true
|
|
883
|
-
});
|
|
884
|
-
if (realParentTab) {
|
|
885
|
-
dispatchMicroAction("dispatch-page-key-remove", realParentTab.micro, {
|
|
886
|
-
key: parentTab.key,
|
|
887
|
-
root: parentTab.rootKey
|
|
888
|
-
});
|
|
889
|
-
} else {
|
|
890
|
-
_removePageTabByKey(parentTab.key);
|
|
891
|
-
}
|
|
892
|
-
}
|
|
893
|
-
async function setCurrentTab(tab) {
|
|
894
|
-
const root = roots[activeRootKey.value];
|
|
895
|
-
if (!tab || !root || root.activeTabKey === tab.key)
|
|
896
|
-
return;
|
|
897
|
-
if (tab.isChild) {
|
|
898
|
-
if (state.current.value?.micro !== tab.micro) {
|
|
899
|
-
root.activeTabKey = tab.key;
|
|
900
|
-
await nextTick2();
|
|
901
|
-
}
|
|
902
|
-
dispatchMicroAction("dispatch-page-key-change", tab.micro, {
|
|
903
|
-
key: tab.key,
|
|
904
|
-
root: tab.rootKey
|
|
905
|
-
});
|
|
906
|
-
} else {
|
|
907
|
-
root.activeTabKey = tab.key;
|
|
908
|
-
}
|
|
909
|
-
}
|
|
910
|
-
function addMicro({ micro, url }) {
|
|
911
|
-
if (!micro || !url || micros[micro])
|
|
912
|
-
return false;
|
|
913
|
-
micros[micro] = url;
|
|
914
|
-
return true;
|
|
915
|
-
}
|
|
916
|
-
return {
|
|
917
|
-
...state,
|
|
918
|
-
roots,
|
|
919
|
-
micros: readonly2(micros),
|
|
920
|
-
activeRootKey: readonly2(activeRootKey),
|
|
921
|
-
addMicro,
|
|
922
|
-
setRootChild,
|
|
923
|
-
createPageTabsRoot,
|
|
924
|
-
addPageTab,
|
|
925
|
-
removePageTab,
|
|
926
|
-
removeCurrentTab,
|
|
927
|
-
clearPageTab,
|
|
928
|
-
setCurrentTab
|
|
929
|
-
};
|
|
930
|
-
}
|
|
931
|
-
function isComponentTab(tab) {
|
|
932
|
-
return !!tab.component;
|
|
933
|
-
}
|
|
934
|
-
|
|
935
353
|
// src/useRequest/plugins/definePlugin.ts
|
|
936
354
|
function definePlugin(plugin) {
|
|
937
355
|
return plugin;
|
|
@@ -959,23 +377,23 @@ var DEFAULT_PAGINATION_OPTIONS = {
|
|
|
959
377
|
};
|
|
960
378
|
|
|
961
379
|
// src/useRequest/useDataRequest.ts
|
|
962
|
-
import { computed as
|
|
380
|
+
import { computed as computed4 } from "vue";
|
|
963
381
|
|
|
964
382
|
// src/useRequest/useRequestImpl.ts
|
|
965
|
-
import { tryOnScopeDispose as
|
|
383
|
+
import { tryOnScopeDispose as tryOnScopeDispose2 } from "@vueuse/core";
|
|
966
384
|
import { inject as inject2 } from "vue";
|
|
967
385
|
|
|
968
386
|
// src/useRequest/createRequest.ts
|
|
969
387
|
import { shallowCopy } from "@zl-ui-kit/utils";
|
|
970
|
-
import { ref as
|
|
388
|
+
import { ref as ref3, shallowRef } from "vue";
|
|
971
389
|
function createRequest(service, options = {}, initialState = {}) {
|
|
972
390
|
const { initialData } = options;
|
|
973
|
-
const loading =
|
|
391
|
+
const loading = ref3(initialState.loading ?? false);
|
|
974
392
|
const data = shallowRef(initialData);
|
|
975
|
-
const error =
|
|
976
|
-
const params =
|
|
977
|
-
const plugins =
|
|
978
|
-
const status =
|
|
393
|
+
const error = ref3(void 0);
|
|
394
|
+
const params = ref3();
|
|
395
|
+
const plugins = ref3([]);
|
|
396
|
+
const status = ref3("");
|
|
979
397
|
const context = {};
|
|
980
398
|
const onPluginRunner = (event, ...args) => {
|
|
981
399
|
if (event === "onRequest") {
|
|
@@ -1002,7 +420,7 @@ function createRequest(service, options = {}, initialState = {}) {
|
|
|
1002
420
|
});
|
|
1003
421
|
};
|
|
1004
422
|
setState({ status: "pending" });
|
|
1005
|
-
const count =
|
|
423
|
+
const count = ref3(0);
|
|
1006
424
|
context.runAsync = async (...args) => {
|
|
1007
425
|
setState({ status: "pending" });
|
|
1008
426
|
const currentCount = ++count.value;
|
|
@@ -1090,7 +508,7 @@ function createRequest(service, options = {}, initialState = {}) {
|
|
|
1090
508
|
|
|
1091
509
|
// src/useRequest/plugins/useDownloadPlugin.ts
|
|
1092
510
|
import { fileSave } from "@zl-ui-kit/utils";
|
|
1093
|
-
import { toValue as
|
|
511
|
+
import { toValue as toValue2 } from "vue";
|
|
1094
512
|
var useDownloadPlugin_default = definePlugin((_requestInstance, options = {}) => {
|
|
1095
513
|
const { outputFile } = options;
|
|
1096
514
|
if (!outputFile) {
|
|
@@ -1100,7 +518,7 @@ var useDownloadPlugin_default = definePlugin((_requestInstance, options = {}) =>
|
|
|
1100
518
|
onSuccess(res) {
|
|
1101
519
|
if (res instanceof Blob && res.type !== "application/json") {
|
|
1102
520
|
const blob = new Blob([res]);
|
|
1103
|
-
fileSave(blob,
|
|
521
|
+
fileSave(blob, toValue2(outputFile));
|
|
1104
522
|
}
|
|
1105
523
|
}
|
|
1106
524
|
};
|
|
@@ -1108,7 +526,7 @@ var useDownloadPlugin_default = definePlugin((_requestInstance, options = {}) =>
|
|
|
1108
526
|
|
|
1109
527
|
// src/useRequest/plugins/useLoadingPlugin.ts
|
|
1110
528
|
import { promiseTimeout, useTimeoutFn } from "@vueuse/core";
|
|
1111
|
-
import { toValue as
|
|
529
|
+
import { toValue as toValue3 } from "vue";
|
|
1112
530
|
var useLoadingPlugin_default = definePlugin((requestInstance, options = {}) => {
|
|
1113
531
|
const { loadingDelay = 0, loadingKeep = 0 } = options;
|
|
1114
532
|
const { start, stop } = useTimeoutFn(
|
|
@@ -1124,15 +542,15 @@ var useLoadingPlugin_default = definePlugin((requestInstance, options = {}) => {
|
|
|
1124
542
|
onBefore() {
|
|
1125
543
|
start();
|
|
1126
544
|
return {
|
|
1127
|
-
loading: !
|
|
545
|
+
loading: !toValue3(loadingDelay)
|
|
1128
546
|
};
|
|
1129
547
|
},
|
|
1130
548
|
onRequest(service) {
|
|
1131
|
-
if (!
|
|
549
|
+
if (!toValue3(loadingKeep))
|
|
1132
550
|
return () => service();
|
|
1133
551
|
return () => Promise.allSettled([
|
|
1134
552
|
service(),
|
|
1135
|
-
promiseTimeout(
|
|
553
|
+
promiseTimeout(toValue3(loadingDelay) + toValue3(loadingKeep))
|
|
1136
554
|
]).then(([res]) => {
|
|
1137
555
|
if (res.status === "fulfilled") {
|
|
1138
556
|
return res.value;
|
|
@@ -1152,15 +570,15 @@ var useLoadingPlugin_default = definePlugin((requestInstance, options = {}) => {
|
|
|
1152
570
|
|
|
1153
571
|
// src/useRequest/plugins/useReadyPlugin.ts
|
|
1154
572
|
import { whenever } from "@vueuse/core";
|
|
1155
|
-
import { ref as
|
|
573
|
+
import { ref as ref4, toValue as toValue4 } from "vue";
|
|
1156
574
|
var useReadyPlugin_default = definePlugin((requestInstance, options = {}) => {
|
|
1157
|
-
const { ready =
|
|
1158
|
-
whenever(() =>
|
|
575
|
+
const { ready = ref4(true), defaultParams = [] } = options;
|
|
576
|
+
whenever(() => toValue4(ready), () => {
|
|
1159
577
|
requestInstance.context.run(...defaultParams);
|
|
1160
578
|
}, { flush: "sync" });
|
|
1161
579
|
return {
|
|
1162
580
|
onBefore() {
|
|
1163
|
-
if (!
|
|
581
|
+
if (!toValue4(ready)) {
|
|
1164
582
|
return { isBreak: true };
|
|
1165
583
|
}
|
|
1166
584
|
return void 0;
|
|
@@ -1169,13 +587,13 @@ var useReadyPlugin_default = definePlugin((requestInstance, options = {}) => {
|
|
|
1169
587
|
});
|
|
1170
588
|
|
|
1171
589
|
// src/useRequest/plugins/useRefreshDepsPlugin.ts
|
|
1172
|
-
import { watch as
|
|
590
|
+
import { watch as watch3 } from "vue";
|
|
1173
591
|
var useRefreshDepsPlugin_default = definePlugin((requestInstance, options = {}) => {
|
|
1174
592
|
const { refreshDeps, refreshDepsAction, manual } = options;
|
|
1175
593
|
if (!refreshDeps) {
|
|
1176
594
|
return {};
|
|
1177
595
|
}
|
|
1178
|
-
|
|
596
|
+
watch3(refreshDeps, (..._args) => {
|
|
1179
597
|
if (refreshDepsAction) {
|
|
1180
598
|
refreshDepsAction();
|
|
1181
599
|
} else if (!manual) {
|
|
@@ -1200,7 +618,7 @@ function useRequestImpl(service, options = {}, plugins = []) {
|
|
|
1200
618
|
const params = requestInstance.params.value || defaultParams;
|
|
1201
619
|
requestInstance.context.run(...params);
|
|
1202
620
|
}
|
|
1203
|
-
|
|
621
|
+
tryOnScopeDispose2(requestInstance.context.cancel);
|
|
1204
622
|
return {
|
|
1205
623
|
__is_use_request: true,
|
|
1206
624
|
loading: requestInstance.loading,
|
|
@@ -1227,7 +645,7 @@ function useDataRequest(service, options, plugins) {
|
|
|
1227
645
|
const { dataKey = "data", initialData, ...restOptions } = options || {};
|
|
1228
646
|
const request = useRequest(service, restOptions, plugins);
|
|
1229
647
|
const _data = request.data;
|
|
1230
|
-
const data =
|
|
648
|
+
const data = computed4(() => {
|
|
1231
649
|
const rawData = _data.value || {};
|
|
1232
650
|
return rawData[dataKey] ?? initialData;
|
|
1233
651
|
});
|
|
@@ -1236,7 +654,7 @@ function useDataRequest(service, options, plugins) {
|
|
|
1236
654
|
|
|
1237
655
|
// src/useRequest/usePageableRequest.ts
|
|
1238
656
|
import { isArray } from "@zl-ui-kit/utils";
|
|
1239
|
-
import { computed as
|
|
657
|
+
import { computed as computed5, inject as inject3 } from "vue";
|
|
1240
658
|
function usePaginationRequest(service, options, plugins) {
|
|
1241
659
|
const { pagination = {}, ...restOptions } = options || {};
|
|
1242
660
|
const injectedGlobalOptions = inject3(GLOBAL_OPTIONS_PROVIDER_KEY, {});
|
|
@@ -1246,15 +664,15 @@ function usePaginationRequest(service, options, plugins) {
|
|
|
1246
664
|
...restOptions
|
|
1247
665
|
};
|
|
1248
666
|
const { data: _data, params, run, ...rest } = useRequest(service, finalOptions, plugins);
|
|
1249
|
-
const data =
|
|
667
|
+
const data = computed5(() => {
|
|
1250
668
|
const rawData = _data.value || {};
|
|
1251
669
|
return isArray(rawData) ? rawData : rawData[dataKey] || [];
|
|
1252
670
|
});
|
|
1253
|
-
const total =
|
|
671
|
+
const total = computed5(() => {
|
|
1254
672
|
const rawData = _data.value || {};
|
|
1255
673
|
return isArray(rawData) ? rawData.length : rawData[totalKey] || 0;
|
|
1256
674
|
});
|
|
1257
|
-
const current =
|
|
675
|
+
const current = computed5({
|
|
1258
676
|
get() {
|
|
1259
677
|
return params.value?.[0]?.[currentKey] ?? finalOptions.defaultParams[0]?.[currentKey];
|
|
1260
678
|
},
|
|
@@ -1262,7 +680,7 @@ function usePaginationRequest(service, options, plugins) {
|
|
|
1262
680
|
changeCurrent(val);
|
|
1263
681
|
}
|
|
1264
682
|
});
|
|
1265
|
-
const pageSize =
|
|
683
|
+
const pageSize = computed5({
|
|
1266
684
|
get() {
|
|
1267
685
|
return params.value?.[0]?.[pageSizeKey] ?? finalOptions.defaultParams[0]?.[pageSizeKey];
|
|
1268
686
|
},
|
|
@@ -1299,7 +717,7 @@ function usePaginationRequest(service, options, plugins) {
|
|
|
1299
717
|
function usePageableRequest(service, options, plugins) {
|
|
1300
718
|
const request = useRequest(service, options, plugins);
|
|
1301
719
|
const _data = request.data;
|
|
1302
|
-
const data =
|
|
720
|
+
const data = computed5(() => {
|
|
1303
721
|
const rawData = _data.value || [];
|
|
1304
722
|
if (isArray(rawData)) {
|
|
1305
723
|
return rawData;
|
|
@@ -1319,7 +737,7 @@ function useRequestProvider(options) {
|
|
|
1319
737
|
|
|
1320
738
|
// src/useSash.ts
|
|
1321
739
|
import { useEventListener } from "@vueuse/core";
|
|
1322
|
-
import { toValue as
|
|
740
|
+
import { toValue as toValue5, useTemplateRef } from "vue";
|
|
1323
741
|
function useSash(refName, { start, onMousedown, onMousemove, onMouseup, onDoubleClick } = {}) {
|
|
1324
742
|
const sashElRef = useTemplateRef(refName);
|
|
1325
743
|
function handleSashMousedown(e) {
|
|
@@ -1327,7 +745,7 @@ function useSash(refName, { start, onMousedown, onMousemove, onMouseup, onDouble
|
|
|
1327
745
|
const startX = e.clientX;
|
|
1328
746
|
const startY = e.clientY;
|
|
1329
747
|
onMousedown?.(e);
|
|
1330
|
-
const startSnapshot =
|
|
748
|
+
const startSnapshot = toValue5(start);
|
|
1331
749
|
const handleMousemove = (e2) => {
|
|
1332
750
|
e2.preventDefault();
|
|
1333
751
|
const dx = e2.clientX - startX;
|
|
@@ -1354,19 +772,19 @@ function useSash(refName, { start, onMousedown, onMousemove, onMouseup, onDouble
|
|
|
1354
772
|
// src/useServiceType.ts
|
|
1355
773
|
function useServiceType(options = {}) {
|
|
1356
774
|
const { platformKey = "zl.service.type", blockchainKey = "blockchain.service.type" } = options;
|
|
1357
|
-
const { isConfig, getConfig } =
|
|
775
|
+
const { isConfig, getConfig } = useGlobalData();
|
|
1358
776
|
const isPlatform = isConfig(platformKey, "platform");
|
|
1359
777
|
const isBlockchain = blockchainKey ? ["0", "1"].includes(getConfig(blockchainKey, "")) : false;
|
|
1360
778
|
return { isPlatform, isBlockchain };
|
|
1361
779
|
}
|
|
1362
780
|
|
|
1363
781
|
// src/useUKey/index.ts
|
|
1364
|
-
import { createSharedComposable
|
|
1365
|
-
import { ref as
|
|
1366
|
-
var useUKey =
|
|
1367
|
-
const { getConfig } =
|
|
782
|
+
import { createSharedComposable, useTimeoutFn as useTimeoutFn2 } from "@vueuse/core";
|
|
783
|
+
import { ref as ref5 } from "vue";
|
|
784
|
+
var useUKey = createSharedComposable(() => {
|
|
785
|
+
const { getConfig } = useGlobalData();
|
|
1368
786
|
const port = getConfig("zl.feature.shufflePort", "8080");
|
|
1369
|
-
const sn =
|
|
787
|
+
const sn = ref5("");
|
|
1370
788
|
const getSnResolver = {
|
|
1371
789
|
resolve: (_value) => {
|
|
1372
790
|
},
|
|
@@ -1443,6 +861,21 @@ var useUKey = createSharedComposable2(() => {
|
|
|
1443
861
|
stopHeartbeat: stop
|
|
1444
862
|
};
|
|
1445
863
|
});
|
|
864
|
+
|
|
865
|
+
// src/useZlT.ts
|
|
866
|
+
import { useI18n } from "vue-i18n";
|
|
867
|
+
function useZlT() {
|
|
868
|
+
let t = (key, fallback) => fallback ?? key;
|
|
869
|
+
try {
|
|
870
|
+
const globalT = useI18n({ useScope: "global" }).t;
|
|
871
|
+
t = (key, fallback, params) => {
|
|
872
|
+
const msg = params ? globalT(key, params) : globalT(key);
|
|
873
|
+
return msg === key ? fallback ?? key : msg;
|
|
874
|
+
};
|
|
875
|
+
} catch {
|
|
876
|
+
}
|
|
877
|
+
return { t };
|
|
878
|
+
}
|
|
1446
879
|
export {
|
|
1447
880
|
DEFAULT_PAGINATION_OPTIONS,
|
|
1448
881
|
GLOBAL_OPTIONS_PROVIDER_KEY,
|
|
@@ -1450,8 +883,6 @@ export {
|
|
|
1450
883
|
createCacheComputed,
|
|
1451
884
|
definePlugin as defineUseRequestPlugin,
|
|
1452
885
|
dictInjectKey,
|
|
1453
|
-
dispatchMicroAction,
|
|
1454
|
-
enableGlobalDataMock,
|
|
1455
886
|
getDictSource,
|
|
1456
887
|
getGlobalOptions,
|
|
1457
888
|
mergeMessages,
|
|
@@ -1461,15 +892,9 @@ export {
|
|
|
1461
892
|
useDict,
|
|
1462
893
|
useDictProvider,
|
|
1463
894
|
useDictStore,
|
|
895
|
+
useGlobalData,
|
|
1464
896
|
useGlobalMessage,
|
|
1465
897
|
useLocale,
|
|
1466
|
-
useMicroAction,
|
|
1467
|
-
useMicroActionAsync,
|
|
1468
|
-
useMicroApp,
|
|
1469
|
-
useMicroGlobalData,
|
|
1470
|
-
useMicroListener,
|
|
1471
|
-
useMicroResultListener,
|
|
1472
|
-
usePageTabs,
|
|
1473
898
|
usePageableRequest,
|
|
1474
899
|
usePaginationRequest,
|
|
1475
900
|
useRequest,
|