@zl-ui-kit/composables 0.0.0-stage → 0.3.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/LICENSE +21 -0
- package/README.md +20 -2
- package/dist/index.d.ts +595 -0
- package/dist/index.js +1439 -0
- package/package.json +71 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Vik05
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,21 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @zl-ui-kit/composables
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
ZL UI 组合式函数库(TypeScript):
|
|
4
|
+
|
|
5
|
+
| 模块 | 说明 |
|
|
6
|
+
| --- | --- |
|
|
7
|
+
| `useRequest/useDataRequest/usePaginationRequest/usePageableRequest` | 请求体系(插件机制:loading/ready/refreshDeps/download,可 `defineUseRequestPlugin` 自定义) |
|
|
8
|
+
| `useGlobalMessage` | **Element Plus 版** ElMessage/ElMessageBox/ElNotification 封装;`Modal.confirmPromise` 语义与参考实现一致 |
|
|
9
|
+
| `useMicroApp/useMicroAction/useMicroGlobalData` | micro-app 微前端通信层(globalData/事件派发/主子身份) |
|
|
10
|
+
| `useDict/useDictStore/useDictProvider/setDictSource` | 字典(独立 Vue3 状态管理 store 缓存,不依赖微前端;支持组件直传 / 局部 source / 全局 source 三级注入) |
|
|
11
|
+
| `useLocale` | vue-i18n + 主应用语言联动(`elLocaleMessages` 对接 EP locale) |
|
|
12
|
+
| `usePageTabs` | 多应用页签管理 |
|
|
13
|
+
| `useSash/useServiceType/useUKey/createCacheComputed` | 其他工具 hook |
|
|
14
|
+
|
|
15
|
+
## 运行前提(微前端模块)
|
|
16
|
+
|
|
17
|
+
`useMicro*`、`usePageTabs` 默认运行于 micro-app 微前端环境(决策 §12-Q11:保留并标注前提)。无主应用环境调试时可在**首次调用** `useMicroGlobalData()` 前执行 `enableGlobalDataMock()` 启用本地 mock。字典模块(`useDict` 等)已独立,不依赖微前端,可直接在任意项目中使用。
|
|
18
|
+
|
|
19
|
+
## 本地调试
|
|
20
|
+
|
|
21
|
+
playground alias 直指 `src/`;`pnpm build`(tsup)。详见 `docs/调试指南.md`。发布见 `docs/发布流程.md`。
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,595 @@
|
|
|
1
|
+
import * as vue from 'vue';
|
|
2
|
+
import { ComputedRef, InjectionKey, WritableComputedRef, Ref, Component, VNode, MaybeRef, MaybeRefOrGetter, WatchSource, UnwrapRef, ref } from 'vue';
|
|
3
|
+
export { ComputedRef } from 'vue';
|
|
4
|
+
import { ElMessageBoxOptions, ElMessage, ElMessageBox, ElNotification } from 'element-plus';
|
|
5
|
+
import { I18nOptions, I18n } from 'vue-i18n';
|
|
6
|
+
import microApp from '@micro-zoe/micro-app';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* 带缓存的 computed 工厂:同一对象的计算结果缓存,作用域销毁时自动清理
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
interface CacheComputed<T, R> {
|
|
13
|
+
(obj: T): ComputedRef<R>;
|
|
14
|
+
clear: () => void;
|
|
15
|
+
}
|
|
16
|
+
declare function createCacheComputed<T, R>(getter: (obj: T) => R): CacheComputed<T, R>;
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* i18n 语言包深度合并工具。
|
|
20
|
+
*
|
|
21
|
+
* 语言包结构为「locale → key → 文案」,消费者只需写要覆盖的 key,
|
|
22
|
+
* 未提供的部分由组件库默认包保留。支持嵌套对象(vue-i18n 的层级 message)。
|
|
23
|
+
*/
|
|
24
|
+
type AnyRecord = Record<string, any>;
|
|
25
|
+
/**
|
|
26
|
+
* 深度合并语言包,**后者覆盖前者**,未提供的 key 保留原值。
|
|
27
|
+
*
|
|
28
|
+
* ```ts
|
|
29
|
+
* mergeMessages(
|
|
30
|
+
* { zh: { 'zl.a': '1', 'zl.b': '2' } },
|
|
31
|
+
* { zh: { 'zl.b': '覆盖值' } },
|
|
32
|
+
* )
|
|
33
|
+
* // => { zh: { 'zl.a': '1', 'zl.b': '覆盖值' } }
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
declare function mergeMessages<T extends AnyRecord>(base?: T, ...overrides: (AnyRecord | undefined)[]): T;
|
|
37
|
+
|
|
38
|
+
/** 字典项 */
|
|
39
|
+
interface DictItem {
|
|
40
|
+
label: string;
|
|
41
|
+
value: string;
|
|
42
|
+
icon?: string;
|
|
43
|
+
type?: string;
|
|
44
|
+
}
|
|
45
|
+
/** 字典数据源:静态字典表,或按 key 动态加载(可异步) */
|
|
46
|
+
type DictSource = Record<string, DictItem[]> | ((key: string) => DictItem[] | Promise<DictItem[]>);
|
|
47
|
+
/**
|
|
48
|
+
* 全局字典 store(Vue3 状态管理:createGlobalState 单例)
|
|
49
|
+
* - dictStore:已加载字典的缓存(key → DictItem[])
|
|
50
|
+
* - loadingKeys:各 key 的加载态(同时充当「加载中」去重锁)
|
|
51
|
+
*/
|
|
52
|
+
declare const useDictStore: () => {
|
|
53
|
+
dictStore: vue.Ref<Record<string, DictItem[]>, Record<string, DictItem[]>>;
|
|
54
|
+
loadingKeys: vue.Ref<Record<string, boolean>, Record<string, boolean>>;
|
|
55
|
+
setDictSource: (source: DictSource | null) => void;
|
|
56
|
+
getDictSource: () => DictSource | null;
|
|
57
|
+
ensureDict: (key: string, localSource?: DictSource) => Promise<void>;
|
|
58
|
+
};
|
|
59
|
+
/**
|
|
60
|
+
* 全局注册字典数据源(应用入口调用一次)—— 委托给全局字典 store
|
|
61
|
+
* - 静态表:`setDictSource({ resourceType: [{label,value}], ... })`
|
|
62
|
+
* - 异步加载:`setDictSource(async (key) => await api.getDict(key))`
|
|
63
|
+
* - 传 `null` 清空
|
|
64
|
+
*/
|
|
65
|
+
declare function setDictSource(source: DictSource | null): void;
|
|
66
|
+
/** 读取当前全局字典数据源(委托给全局字典 store) */
|
|
67
|
+
declare function getDictSource(): DictSource | null;
|
|
68
|
+
interface DictInjectContext {
|
|
69
|
+
/** 局部字典数据源(覆盖全局 source) */
|
|
70
|
+
source?: DictSource;
|
|
71
|
+
}
|
|
72
|
+
/** 字典数据源注入键(useDictProvider 提供) */
|
|
73
|
+
declare const dictInjectKey: InjectionKey<DictInjectContext>;
|
|
74
|
+
/**
|
|
75
|
+
* 为某棵组件子树提供局部字典数据源(覆盖全局 source,非微前端注入)。
|
|
76
|
+
* 在子树根组件 setup 中调用即可。
|
|
77
|
+
*/
|
|
78
|
+
declare function useDictProvider(source: DictSource): void;
|
|
79
|
+
interface UseDictReturn extends ComputedRef<DictItem[]> {
|
|
80
|
+
/** value → label 映射 */
|
|
81
|
+
label: ComputedRef<Record<string, string>>;
|
|
82
|
+
}
|
|
83
|
+
interface UseDictOptions {
|
|
84
|
+
/** 直接传入该 key 的字典数据(组件级外部传入;写入缓存后统一解析,优先级最高) */
|
|
85
|
+
data?: DictItem[];
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* 字典 hook:读全局 dictStore 并解析。
|
|
89
|
+
* @param key 字典键
|
|
90
|
+
* @param options.data 组件级直传字典数据(可选,优先级最高)
|
|
91
|
+
*/
|
|
92
|
+
declare function useDict(key: string, options?: UseDictOptions): UseDictReturn;
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* 全局消息(Element Plus 版)
|
|
96
|
+
* 对外保持参考实现 API:Message / Modal(含 confirmPromise 扩展)/ Notification
|
|
97
|
+
*/
|
|
98
|
+
|
|
99
|
+
interface ConfirmPromiseOptions extends ElMessageBoxOptions {
|
|
100
|
+
/** onOk 抛错时是否向上抛出(默认吞错并 resolve(false)) */
|
|
101
|
+
throwOnOk?: boolean;
|
|
102
|
+
/** 取消时是否 reject(默认 resolve('Cancel')) */
|
|
103
|
+
throwOnCancel?: boolean;
|
|
104
|
+
}
|
|
105
|
+
interface ConfirmPromiseContext {
|
|
106
|
+
close: (ignore?: boolean) => void;
|
|
107
|
+
resolve: (value?: unknown) => void;
|
|
108
|
+
reject: (reason?: unknown) => void;
|
|
109
|
+
instance: unknown;
|
|
110
|
+
}
|
|
111
|
+
type ConfirmPromise = (config: ConfirmPromiseOptions, onOk?: (ctx: ConfirmPromiseContext) => void | Promise<void>, onCancel?: (ctx: ConfirmPromiseContext) => void | Promise<void>) => Promise<'Ok' | 'Cancel' | false | unknown>;
|
|
112
|
+
/** ElMessageBox 的 confirmPromise 扩展类型 */
|
|
113
|
+
type MessageBoxExt = typeof ElMessageBox & {
|
|
114
|
+
confirmPromise: ConfirmPromise;
|
|
115
|
+
};
|
|
116
|
+
interface GlobalMessage {
|
|
117
|
+
Message: typeof ElMessage;
|
|
118
|
+
Modal: MessageBoxExt;
|
|
119
|
+
Notification: typeof ElNotification;
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* 全局消息快捷访问
|
|
123
|
+
* @param directMode 兼容参考实现的参数(直接返回原始实例)
|
|
124
|
+
*/
|
|
125
|
+
declare function useGlobalMessage(_directMode?: boolean): GlobalMessage;
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* 国际化(vue-i18n)+ 微前端全局语言联动(elLocaleMessages 对接 Element Plus locale)
|
|
129
|
+
*/
|
|
130
|
+
|
|
131
|
+
interface LocaleLoaderResult {
|
|
132
|
+
localeMessages: Record<string, any>;
|
|
133
|
+
elLocaleMessages: Record<string, any>;
|
|
134
|
+
}
|
|
135
|
+
type LocaleLoader = (locale: string) => Promise<LocaleLoaderResult>;
|
|
136
|
+
type UseLocaleOptions = I18nOptions & {
|
|
137
|
+
postTranslation?: (translated: string, key: string) => string;
|
|
138
|
+
};
|
|
139
|
+
interface UseLocaleReturn {
|
|
140
|
+
i18n: I18n;
|
|
141
|
+
locale: WritableComputedRef<string>;
|
|
142
|
+
isI18nKeyVisible: WritableComputedRef<boolean>;
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* 创建与主应用语言联动的 i18n 实例
|
|
146
|
+
* @param options i18n 选项(messages 等)
|
|
147
|
+
* @param loader 语言包按需加载器,返回业务语言包与 Element Plus 语言包
|
|
148
|
+
*/
|
|
149
|
+
declare function useLocale(options?: UseLocaleOptions, loader?: LocaleLoader): UseLocaleReturn;
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* 安全的国际化翻译函数(组件库渐进式接入 vue-i18n 的桥梁)。
|
|
153
|
+
*
|
|
154
|
+
* - 若宿主已 `app.use(i18n)` 安装 vue-i18n:委托其全局 t 进行翻译;
|
|
155
|
+
* - 若宿主未接入 i18n(存量应用):安全降级为 fallback / key,绝不抛错。
|
|
156
|
+
*
|
|
157
|
+
* 这样组件库可在「不破坏现有消费方」的前提下,逐步把硬编码中文替换为
|
|
158
|
+
* `t('zl.xxx', '中文兜底')`,待宿主统一安装 i18n 后即自动多语言化。
|
|
159
|
+
*/
|
|
160
|
+
/** 命名插值参数,如 t('zl.upload.accept', fallback, { accept: '.png' }) */
|
|
161
|
+
type TranslateParams = Record<string, unknown>;
|
|
162
|
+
/**
|
|
163
|
+
* @param key 语言包 key(规范:`zl.<组件>.<语义>`)
|
|
164
|
+
* @param fallback 兜底文案(宿主未装 i18n / key 未命中时使用;可传入已插值的字符串)
|
|
165
|
+
* @param params 命名插值参数(命中语言包时由 vue-i18n 插值 `{name}` 占位)
|
|
166
|
+
*/
|
|
167
|
+
type Translate = (key: string, fallback?: string, params?: TranslateParams) => string;
|
|
168
|
+
declare function useZlT(): {
|
|
169
|
+
t: Translate;
|
|
170
|
+
};
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* micro-app 跨应用动作通信层(主/子应用事件总线语义)
|
|
174
|
+
*/
|
|
175
|
+
type MicroActionCallback = (...args: any[]) => void;
|
|
176
|
+
interface UseMicroListenerReturn {
|
|
177
|
+
on: (action: string, callback: MicroActionCallback) => void;
|
|
178
|
+
off: (action: string, callback: MicroActionCallback) => void;
|
|
179
|
+
once: (action: string, callback: MicroActionCallback) => void;
|
|
180
|
+
}
|
|
181
|
+
declare const useMicroListener: () => UseMicroListenerReturn;
|
|
182
|
+
/**
|
|
183
|
+
* 向子应用(或指定应用)派发动作,返回可直接调用的派发函数
|
|
184
|
+
*/
|
|
185
|
+
declare function useMicroAction(action: string, appName?: string): (...args: any[]) => void;
|
|
186
|
+
/**
|
|
187
|
+
* 派发动作并等待 Promise 化结果
|
|
188
|
+
*/
|
|
189
|
+
declare function useMicroActionAsync(action: string, appName?: string): (...args: any[]) => Promise<unknown>;
|
|
190
|
+
/**
|
|
191
|
+
* 监听动作的执行结果
|
|
192
|
+
*/
|
|
193
|
+
declare function useMicroResultListener(action: string, callback: MicroActionCallback): void;
|
|
194
|
+
/**
|
|
195
|
+
* 向指定子应用派发动作(回调式)
|
|
196
|
+
*/
|
|
197
|
+
declare function dispatchMicroAction(action: string, appName: string, ...data: any[]): Promise<void>;
|
|
198
|
+
|
|
199
|
+
/**
|
|
200
|
+
* micro-app 微应用管理(主/子应用身份判断、启动、活跃应用列表)
|
|
201
|
+
*/
|
|
202
|
+
|
|
203
|
+
interface StartMicroAppConfig {
|
|
204
|
+
[key: string]: any;
|
|
205
|
+
lifeCycles?: {
|
|
206
|
+
mounted?: (data?: any) => void;
|
|
207
|
+
unmounted?: (data?: any) => void;
|
|
208
|
+
};
|
|
209
|
+
}
|
|
210
|
+
interface UseMicroAppReturn {
|
|
211
|
+
apps: Ref<string[]>;
|
|
212
|
+
/** 是否主应用(多层嵌套时可同时为子应用) */
|
|
213
|
+
isMicroBase: () => boolean;
|
|
214
|
+
/** 是否子应用(多层嵌套时可同时为主应用) */
|
|
215
|
+
isMicroChild: () => boolean;
|
|
216
|
+
updateApps: () => void;
|
|
217
|
+
startMicroApp: (config?: StartMicroAppConfig) => typeof microApp;
|
|
218
|
+
}
|
|
219
|
+
declare const useMicroApp: () => UseMicroAppReturn;
|
|
220
|
+
|
|
221
|
+
/**
|
|
222
|
+
* micro-app 全局数据(globalData)响应式访问层
|
|
223
|
+
* 脱敏/注入式改造(需求 §7.3、§12-Q3):
|
|
224
|
+
* - 存储键 $zl_locale/$zl_theme/$zl_token
|
|
225
|
+
* - arcoLocaleMessages → elLocaleMessages(Element Plus locale)
|
|
226
|
+
* - 原 import.meta.env 开发的 mock 开关改为 enableGlobalDataMock() 显式开启(首次 useMicroGlobalData 前调用)
|
|
227
|
+
*/
|
|
228
|
+
|
|
229
|
+
/**
|
|
230
|
+
* 开发态启用本地 mock globalData(原实现经构建环境变量开启,现显式注入)
|
|
231
|
+
*/
|
|
232
|
+
declare function enableGlobalDataMock(enabled?: boolean): void;
|
|
233
|
+
interface GlobalDataState {
|
|
234
|
+
initialed: boolean;
|
|
235
|
+
locale: string;
|
|
236
|
+
theme: string;
|
|
237
|
+
token: string | undefined;
|
|
238
|
+
isI18nKeyVisible: boolean;
|
|
239
|
+
roles: string[];
|
|
240
|
+
permissions: string[];
|
|
241
|
+
user: any;
|
|
242
|
+
localeMessages: Record<string, any>;
|
|
243
|
+
elLocaleMessages: any;
|
|
244
|
+
config: Record<string, any> | undefined;
|
|
245
|
+
}
|
|
246
|
+
interface UseMicroGlobalDataReturn extends Ref<Partial<GlobalDataState>> {
|
|
247
|
+
initialed: Readonly<Ref<boolean>>;
|
|
248
|
+
locale: WritableComputedRef<string>;
|
|
249
|
+
theme: WritableComputedRef<string>;
|
|
250
|
+
token: WritableComputedRef<string | undefined>;
|
|
251
|
+
isI18nKeyVisible: WritableComputedRef<boolean>;
|
|
252
|
+
roles: WritableComputedRef<string[]>;
|
|
253
|
+
permissions: WritableComputedRef<string[]>;
|
|
254
|
+
user: WritableComputedRef<any>;
|
|
255
|
+
localeMessages: WritableComputedRef<Record<string, any>>;
|
|
256
|
+
elLocaleMessages: WritableComputedRef<any>;
|
|
257
|
+
config: WritableComputedRef<Record<string, any> | undefined>;
|
|
258
|
+
getConfig: <T = any>(key: string, defaultValue?: T) => T;
|
|
259
|
+
isConfig: (key: string, compareValue?: string) => boolean;
|
|
260
|
+
setAndWaitUntil: (options: {
|
|
261
|
+
set?: Record<string, any>;
|
|
262
|
+
until?: (data: any) => boolean;
|
|
263
|
+
}) => Promise<void>;
|
|
264
|
+
resetUser: () => void;
|
|
265
|
+
}
|
|
266
|
+
declare const useMicroGlobalData: () => UseMicroGlobalDataReturn;
|
|
267
|
+
|
|
268
|
+
type RootOptions = RootComponentOptions | RootMicroOptions;
|
|
269
|
+
interface RootComponentOptions {
|
|
270
|
+
title: string;
|
|
271
|
+
key: string;
|
|
272
|
+
icon?: string;
|
|
273
|
+
component: Component;
|
|
274
|
+
}
|
|
275
|
+
interface RootMicroOptions {
|
|
276
|
+
title: string;
|
|
277
|
+
key: string;
|
|
278
|
+
icon?: string;
|
|
279
|
+
micro: string;
|
|
280
|
+
url: string;
|
|
281
|
+
}
|
|
282
|
+
interface RootStore {
|
|
283
|
+
tabs: TabStored[];
|
|
284
|
+
activeTabKey: string;
|
|
285
|
+
_parentTabMap?: Record<string, TabStored>;
|
|
286
|
+
_parentMap: Record<string, any>;
|
|
287
|
+
}
|
|
288
|
+
type Tab = ComponentTab | MicroTab;
|
|
289
|
+
type TabStored = Tab & {
|
|
290
|
+
isRoot?: boolean;
|
|
291
|
+
isChildRoot?: boolean;
|
|
292
|
+
isChild?: boolean;
|
|
293
|
+
isChildMicro?: boolean;
|
|
294
|
+
rootKey?: string;
|
|
295
|
+
micro?: string;
|
|
296
|
+
url?: string;
|
|
297
|
+
children?: TabStored[];
|
|
298
|
+
parentTab?: TabStored;
|
|
299
|
+
/** 用于删除本 tab 时,获取父 Tab 的实例 */
|
|
300
|
+
_parentTabKey?: string;
|
|
301
|
+
/** 子 root 页签标识(micro__key) */
|
|
302
|
+
childRootTabKey?: string;
|
|
303
|
+
/** 组件页签对外暴露的实例(供回调获取) */
|
|
304
|
+
exposed?: any;
|
|
305
|
+
};
|
|
306
|
+
interface ComponentTab {
|
|
307
|
+
key: string;
|
|
308
|
+
title: string;
|
|
309
|
+
icon?: string;
|
|
310
|
+
beforeRemove?: () => boolean | void | Promise<boolean | void>;
|
|
311
|
+
component: Component;
|
|
312
|
+
props?: Record<string, any>;
|
|
313
|
+
}
|
|
314
|
+
interface MicroTab {
|
|
315
|
+
key: string;
|
|
316
|
+
title: string;
|
|
317
|
+
icon?: string;
|
|
318
|
+
beforeRemove?: () => boolean | void | Promise<boolean | void>;
|
|
319
|
+
micro: string;
|
|
320
|
+
url: string;
|
|
321
|
+
}
|
|
322
|
+
type ComponentTabVNode = VNode;
|
|
323
|
+
|
|
324
|
+
/**
|
|
325
|
+
* 页签管理(micro-app 多应用页签模型:root 树 → 扁平页签 → 当前激活页签)
|
|
326
|
+
* 内部逻辑保持参考实现语义;类型签名见 ./types/usePageTabs
|
|
327
|
+
*/
|
|
328
|
+
|
|
329
|
+
interface UsePageTabsReturn {
|
|
330
|
+
roots: Record<string, RootStore | undefined>;
|
|
331
|
+
activeRoot: ComputedRef<RootStore | null>;
|
|
332
|
+
pageTabs: ComputedRef<TabStored[]>;
|
|
333
|
+
current: ComputedRef<TabStored | undefined>;
|
|
334
|
+
micros: Readonly<Record<string, string>>;
|
|
335
|
+
activeRootKey: Readonly<Ref<string | null>>;
|
|
336
|
+
addMicro: (option: {
|
|
337
|
+
micro?: string;
|
|
338
|
+
url?: string;
|
|
339
|
+
}) => boolean;
|
|
340
|
+
setRootChild: (tabs: TabStored[], activeChildTabKey: string, micro: string) => void;
|
|
341
|
+
createPageTabsRoot: (root: RootOptions) => void;
|
|
342
|
+
addPageTab: (tab: Tab & Record<string, any>, options?: {
|
|
343
|
+
update?: boolean;
|
|
344
|
+
childMicro?: boolean;
|
|
345
|
+
}) => boolean;
|
|
346
|
+
removePageTab: (tabOrKey?: TabStored | string) => Promise<void | [TabStored, TabStored] | false>;
|
|
347
|
+
removeCurrentTab: (callback?: (exposed?: any) => Promise<void> | void) => Promise<boolean | void>;
|
|
348
|
+
clearPageTab: (rootKey?: string) => void;
|
|
349
|
+
setCurrentTab: (tab: TabStored) => Promise<void>;
|
|
350
|
+
}
|
|
351
|
+
declare function usePageTabs(): UsePageTabsReturn;
|
|
352
|
+
|
|
353
|
+
type Prettify<T> = {
|
|
354
|
+
[K in keyof T]: T[K];
|
|
355
|
+
} & {};
|
|
356
|
+
interface RequestOptions<R, P extends unknown[]> {
|
|
357
|
+
manual?: boolean;
|
|
358
|
+
defaultParams?: P;
|
|
359
|
+
initialData?: R;
|
|
360
|
+
onBefore?: (params: P) => void;
|
|
361
|
+
onSuccess?: (data: R, params: P) => void;
|
|
362
|
+
onError?: (err: Error, params: P) => void;
|
|
363
|
+
onFinally?: (params: P) => void;
|
|
364
|
+
}
|
|
365
|
+
interface PluginDownloadOptions {
|
|
366
|
+
outputFile?: MaybeRefOrGetter<string>;
|
|
367
|
+
}
|
|
368
|
+
interface PluginLoadingOptions {
|
|
369
|
+
loadingDelay?: MaybeRef<number>;
|
|
370
|
+
loadingKeep?: MaybeRef<number>;
|
|
371
|
+
}
|
|
372
|
+
interface PluginReadyOptions {
|
|
373
|
+
ready?: Ref<boolean>;
|
|
374
|
+
}
|
|
375
|
+
interface PluginRefreshDepsOptions {
|
|
376
|
+
refreshDeps?: WatchSource | WatchSource[];
|
|
377
|
+
refreshDepsAction?: () => void;
|
|
378
|
+
}
|
|
379
|
+
type Options<R, P extends unknown[]> = Prettify<RequestOptions<R, P> & PluginDownloadOptions & PluginLoadingOptions & PluginReadyOptions & PluginRefreshDepsOptions>;
|
|
380
|
+
type Service<R, P extends unknown[]> = (...args: P) => Promise<R>;
|
|
381
|
+
type RequestStatus = '' | 'pending' | 'finished' | 'error';
|
|
382
|
+
interface State<R, P extends unknown[]> {
|
|
383
|
+
loading: Ref<boolean>;
|
|
384
|
+
data: Ref<R | undefined>;
|
|
385
|
+
params: Ref<P>;
|
|
386
|
+
error: Ref<Error | undefined>;
|
|
387
|
+
status: Ref<RequestStatus>;
|
|
388
|
+
}
|
|
389
|
+
type UnwrapRefObject<T> = {
|
|
390
|
+
[P in keyof T]: UnwrapRef<T[P]>;
|
|
391
|
+
};
|
|
392
|
+
type UnwrapState<R, P extends unknown[]> = UnwrapRefObject<State<R, P>>;
|
|
393
|
+
type MutateFunction<R> = (data: R) => R;
|
|
394
|
+
interface FunctionContext<R, P extends unknown[]> {
|
|
395
|
+
run: (...args: P) => void;
|
|
396
|
+
runAsync: (...args: P) => Promise<R>;
|
|
397
|
+
refresh: () => void;
|
|
398
|
+
refreshAsync: () => Promise<R>;
|
|
399
|
+
cancel: () => void;
|
|
400
|
+
mutate: (data: R | MutateFunction<R>) => void;
|
|
401
|
+
}
|
|
402
|
+
interface RequestInstance<R, P extends unknown[]> extends State<R, P> {
|
|
403
|
+
context: FunctionContext<R, P>;
|
|
404
|
+
plugins: Ref<PluginReturn<R, P>[]>;
|
|
405
|
+
}
|
|
406
|
+
interface PluginOnBeforeReturn<R, P extends unknown[]> extends Partial<UnwrapState<R, P>> {
|
|
407
|
+
isBreak?: boolean;
|
|
408
|
+
isReturn?: boolean;
|
|
409
|
+
}
|
|
410
|
+
interface PluginReturn<R, P extends unknown[]> {
|
|
411
|
+
onBefore?: (params: P) => PluginOnBeforeReturn<R, P> | void;
|
|
412
|
+
onRequest?: (service: () => Promise<R>) => () => Promise<R>;
|
|
413
|
+
onSuccess?: (data: R, params: P) => void;
|
|
414
|
+
onError?: (error: Error, params: P) => void;
|
|
415
|
+
onFinally?: (params: P, data: R, error: Error) => void;
|
|
416
|
+
onCancel?: () => void;
|
|
417
|
+
onMutate?: (data: R) => void;
|
|
418
|
+
}
|
|
419
|
+
type PluginImplementType<R, P extends unknown[]> = (requestInstance: RequestInstance<R, P>, options?: Options<R, P>) => PluginReturn<R, P>;
|
|
420
|
+
interface UseDataRequestOptions<R, P extends unknown[]> extends Options<R, P> {
|
|
421
|
+
/** @default `data` */
|
|
422
|
+
dataKey?: string;
|
|
423
|
+
}
|
|
424
|
+
interface PaginationExtendsOptions {
|
|
425
|
+
pagination: {
|
|
426
|
+
/** @default `pageNum` */
|
|
427
|
+
currentKey?: string;
|
|
428
|
+
/** @default `pageSize` */
|
|
429
|
+
pageSizeKey?: string;
|
|
430
|
+
/** @default `total` */
|
|
431
|
+
totalKey?: string;
|
|
432
|
+
/** @default `rows` */
|
|
433
|
+
dataKey?: string;
|
|
434
|
+
};
|
|
435
|
+
}
|
|
436
|
+
type UsePaginationRequestOptions<R, P extends unknown[]> = Prettify<Options<R, P> & {
|
|
437
|
+
pagination?: Partial<PaginationExtendsOptions['pagination']>;
|
|
438
|
+
}>;
|
|
439
|
+
type GlobalOptions = Partial<Prettify<PluginLoadingOptions & PaginationExtendsOptions>>;
|
|
440
|
+
/** useRequest 返回值形态 */
|
|
441
|
+
interface UseRequestReturn<R, P extends unknown[]> extends State<R, P> {
|
|
442
|
+
__is_use_request: true;
|
|
443
|
+
cancel: () => void;
|
|
444
|
+
mutate: (data: R | MutateFunction<R>) => void;
|
|
445
|
+
run: (...args: P) => void;
|
|
446
|
+
runAsync: (...args: P) => Promise<R>;
|
|
447
|
+
refresh: () => void;
|
|
448
|
+
refreshAsync: () => Promise<R>;
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
/**
|
|
452
|
+
* 插件定义工具(类型快捷方式)
|
|
453
|
+
*/
|
|
454
|
+
|
|
455
|
+
declare function definePlugin<R, P extends unknown[]>(plugin: PluginImplementType<R, P>): PluginImplementType<R, P>;
|
|
456
|
+
|
|
457
|
+
/**
|
|
458
|
+
* useRequest 全局配置(全局默认项 + provide/inject 作用域默认项)
|
|
459
|
+
*/
|
|
460
|
+
|
|
461
|
+
declare function getGlobalOptions(): GlobalOptions;
|
|
462
|
+
declare function setGlobalOptions(options: GlobalOptions): void;
|
|
463
|
+
declare function clearGlobalOptions(): void;
|
|
464
|
+
declare const GLOBAL_OPTIONS_PROVIDER_KEY: InjectionKey<GlobalOptions>;
|
|
465
|
+
declare const DEFAULT_PAGINATION_OPTIONS: {
|
|
466
|
+
currentKey: string;
|
|
467
|
+
pageSizeKey: string;
|
|
468
|
+
totalKey: string;
|
|
469
|
+
dataKey: string;
|
|
470
|
+
};
|
|
471
|
+
|
|
472
|
+
/**
|
|
473
|
+
* useDataRequest:自动解包响应的 data 字段
|
|
474
|
+
*/
|
|
475
|
+
|
|
476
|
+
interface UseDataRequestReturn<R, P extends unknown[]> extends Omit<UseRequestReturn<R, P>, 'data'> {
|
|
477
|
+
data: ComputedRef<any>;
|
|
478
|
+
}
|
|
479
|
+
declare function useDataRequest<R, P extends unknown[]>(service: Service<R, P>, options?: UseDataRequestOptions<R, P>, plugins?: PluginImplementType<R, P>[]): UseDataRequestReturn<R, P>;
|
|
480
|
+
|
|
481
|
+
/**
|
|
482
|
+
* usePaginationRequest:分页请求(current/pageSize/total/data 键名可配)
|
|
483
|
+
* usePageableRequest:本地分页数据补页码
|
|
484
|
+
*/
|
|
485
|
+
|
|
486
|
+
interface UsePaginationRequestReturn<R, P extends unknown[]> extends Omit<UseRequestReturn<R, P>, 'data'> {
|
|
487
|
+
data: ComputedRef<any[]>;
|
|
488
|
+
total: ComputedRef<number>;
|
|
489
|
+
current: WritableComputedRef<number | undefined>;
|
|
490
|
+
pageSize: WritableComputedRef<number | undefined>;
|
|
491
|
+
changeCurrent: (pageNum: number) => void;
|
|
492
|
+
changePageSize: (pageSize: number) => void;
|
|
493
|
+
changePagination: (current: number, pageSize: number) => void;
|
|
494
|
+
}
|
|
495
|
+
declare function usePaginationRequest<R, P extends unknown[]>(service: Service<R, P>, options?: UsePaginationRequestOptions<R, P>, plugins?: PluginImplementType<R, P>[]): UsePaginationRequestReturn<R, P>;
|
|
496
|
+
interface UsePageableRequestReturn<R, P extends unknown[]> extends UseRequestReturn<R, P> {
|
|
497
|
+
data: ComputedRef<any>;
|
|
498
|
+
}
|
|
499
|
+
declare function usePageableRequest<R, P extends unknown[]>(service: Service<R, P>, options?: Options<R, P>, plugins?: PluginImplementType<R, P>[]): UsePageableRequestReturn<R, P>;
|
|
500
|
+
|
|
501
|
+
/**
|
|
502
|
+
* useRequest:默认携带 loading/ready/refreshDeps/download 四个内置插件
|
|
503
|
+
*/
|
|
504
|
+
|
|
505
|
+
declare function useRequest<R, P extends unknown[] = []>(service: Service<R, P>, options?: Options<R, P>, plugins?: PluginImplementType<R, P>[]): UseRequestReturn<R, P>;
|
|
506
|
+
|
|
507
|
+
/**
|
|
508
|
+
* useRequest 作用域配置(provide 全局默认项)
|
|
509
|
+
*/
|
|
510
|
+
|
|
511
|
+
declare function useRequestProvider(options: GlobalOptions): void;
|
|
512
|
+
|
|
513
|
+
/**
|
|
514
|
+
* 拖拽分隔条(sash)交互
|
|
515
|
+
*/
|
|
516
|
+
|
|
517
|
+
interface UseSashOptions<Start> {
|
|
518
|
+
/** 拖拽起点快照(ref 或 getter) */
|
|
519
|
+
start?: () => Start;
|
|
520
|
+
onMousedown?: (e: MouseEvent) => void;
|
|
521
|
+
onMousemove?: (payload: {
|
|
522
|
+
dx: number;
|
|
523
|
+
dy: number;
|
|
524
|
+
start: Start;
|
|
525
|
+
}, e: MouseEvent) => void;
|
|
526
|
+
onMouseup?: (e: MouseEvent) => void;
|
|
527
|
+
onDoubleClick?: (e: MouseEvent) => void;
|
|
528
|
+
}
|
|
529
|
+
interface UseSashReturn {
|
|
530
|
+
sashElRef: Ref<HTMLElement | null>;
|
|
531
|
+
}
|
|
532
|
+
declare function useSash<Start = undefined>(refName: string, { start, onMousedown, onMousemove, onMouseup, onDoubleClick }?: UseSashOptions<Start>): UseSashReturn;
|
|
533
|
+
|
|
534
|
+
/**
|
|
535
|
+
* 服务类型判断(读取主应用下发的 globalData.config)
|
|
536
|
+
* 默认配置键含业务语义(决策 2026-10-25 参数化保留):
|
|
537
|
+
* - platformKey:'zl.service.type' === 'platform' → 平台版
|
|
538
|
+
* - blockchainKey:'blockchain.service.type' ∈ ['0','1'] → 区块链版
|
|
539
|
+
* 消费方可传任意键以适配自身 config 约定
|
|
540
|
+
*/
|
|
541
|
+
interface UseServiceTypeOptions {
|
|
542
|
+
/** 平台版判断的配置键,默认 'zl.service.type' */
|
|
543
|
+
platformKey?: string;
|
|
544
|
+
/** 区块链版判断的配置键,默认 'blockchain.service.type'(传空串跳过判断) */
|
|
545
|
+
blockchainKey?: string;
|
|
546
|
+
}
|
|
547
|
+
interface UseServiceTypeReturn {
|
|
548
|
+
/** 是否平台版(config[platformKey] === 'platform') */
|
|
549
|
+
isPlatform: boolean;
|
|
550
|
+
/** 是否区块链版(config[blockchainKey] ∈ ['0','1']) */
|
|
551
|
+
isBlockchain: boolean;
|
|
552
|
+
}
|
|
553
|
+
declare function useServiceType(options?: UseServiceTypeOptions): UseServiceTypeReturn;
|
|
554
|
+
|
|
555
|
+
/**
|
|
556
|
+
* UKey 硬件key(厂商 SDK 经 @zl-ui-kit/utils/vendor/mtoken.js 注入 window,此处封装轮询与签名流程)
|
|
557
|
+
* 运行前提(决策 2026-10-25:保留+标注):需本机 UKey 厂商 HTTP 服务(默认 127.0.0.1:8080,
|
|
558
|
+
* 端口经 globalData.config['zl.feature.shufflePort'] 可配);CSR 默认字段(C=CN/ST=Beijing、pin 111111)
|
|
559
|
+
* 为厂商协议约定。无 UKey 硬件环境的项目不应调用本 hook。
|
|
560
|
+
* 脱敏改造(需求 §7.3):配置键前缀 zl.、设备信息接口 getDevice(原命名含来源前缀)
|
|
561
|
+
*/
|
|
562
|
+
|
|
563
|
+
interface UKeyRequestData {
|
|
564
|
+
function: string;
|
|
565
|
+
sn?: string;
|
|
566
|
+
pin?: string;
|
|
567
|
+
[key: string]: unknown;
|
|
568
|
+
}
|
|
569
|
+
interface UKeyCSRData {
|
|
570
|
+
partyName: string;
|
|
571
|
+
nodeLabel: string;
|
|
572
|
+
userName: string;
|
|
573
|
+
}
|
|
574
|
+
interface UKeyDeviceInfo {
|
|
575
|
+
[key: string]: any;
|
|
576
|
+
sn: string;
|
|
577
|
+
}
|
|
578
|
+
interface UseUKeyReturn {
|
|
579
|
+
sn: ReturnType<typeof ref<string>>;
|
|
580
|
+
getSn: () => Promise<string>;
|
|
581
|
+
getUser: (pin: string) => Promise<any>;
|
|
582
|
+
getDevice: () => Promise<UKeyDeviceInfo>;
|
|
583
|
+
isUserExists: () => Promise<boolean>;
|
|
584
|
+
getCSR: (data: UKeyCSRData) => Promise<any>;
|
|
585
|
+
writeCRT: (username: string, certbase64: string, newpin: string) => Promise<any>;
|
|
586
|
+
sendSign: (params: {
|
|
587
|
+
pin: string;
|
|
588
|
+
sn: string;
|
|
589
|
+
data: string;
|
|
590
|
+
}) => Promise<any>;
|
|
591
|
+
stopHeartbeat: () => void;
|
|
592
|
+
}
|
|
593
|
+
declare const useUKey: () => UseUKeyReturn;
|
|
594
|
+
|
|
595
|
+
export { type CacheComputed, type ComponentTab, type ComponentTabVNode, type ConfirmPromise, type ConfirmPromiseContext, type ConfirmPromiseOptions, DEFAULT_PAGINATION_OPTIONS, type DictInjectContext, type DictItem, type DictSource, type FunctionContext, GLOBAL_OPTIONS_PROVIDER_KEY, type GlobalDataState, type GlobalMessage, type GlobalOptions, type LocaleLoader, type LocaleLoaderResult, type MessageBoxExt, type MicroActionCallback, type MicroTab, type MutateFunction, type Options, type PaginationExtendsOptions, type PluginDownloadOptions, type PluginImplementType, type PluginLoadingOptions, type PluginOnBeforeReturn, type PluginReadyOptions, type PluginRefreshDepsOptions, type PluginReturn, type Prettify, type RequestInstance, type RequestOptions, type RequestStatus, type RootComponentOptions, type RootMicroOptions, type RootOptions, type RootStore, type Service, type StartMicroAppConfig, type State, type Tab, type TabStored, type Translate, type TranslateParams, type UKeyCSRData, type UKeyDeviceInfo, type UKeyRequestData, type UnwrapRefObject, type UnwrapState, type UseDataRequestOptions, type UseDataRequestReturn, type UseDictOptions, type UseDictReturn, type UseLocaleOptions, type UseLocaleReturn, type UseMicroAppReturn, type UseMicroGlobalDataReturn, type UseMicroListenerReturn, type UsePageTabsReturn, type UsePageableRequestReturn, type UsePaginationRequestOptions, type UsePaginationRequestReturn, type UseRequestReturn, type UseSashOptions, type UseSashReturn, type UseServiceTypeOptions, type UseServiceTypeReturn, type UseUKeyReturn, clearGlobalOptions, createCacheComputed, definePlugin as defineUseRequestPlugin, dictInjectKey, dispatchMicroAction, enableGlobalDataMock, getDictSource, getGlobalOptions, mergeMessages, setDictSource, setGlobalOptions, useDataRequest, useDict, useDictProvider, useDictStore, useGlobalMessage, useLocale, useMicroAction, useMicroActionAsync, useMicroApp, useMicroGlobalData, useMicroListener, useMicroResultListener, usePageTabs, usePageableRequest, usePaginationRequest, useRequest, useRequestProvider, useSash, useServiceType, useUKey, useZlT };
|