@zl-ui-kit/composables 0.4.0 → 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 CHANGED
@@ -9,22 +9,22 @@ ZL UI 组合式函数库(TypeScript):
9
9
  | --- | --- |
10
10
  | `useRequest/useDataRequest/usePaginationRequest/usePageableRequest` | 请求体系(插件机制:loading/ready/refreshDeps/download,可 `defineUseRequestPlugin` 自定义) |
11
11
  | `useGlobalMessage` | **Element Plus 版** ElMessage/ElMessageBox/ElNotification 封装;`Modal.confirmPromise` 语义与参考实现一致 |
12
- | `useMicroApp/useMicroAction/useMicroGlobalData` | micro-app 微前端通信层(globalData/事件派发/主子身份) |
13
- | `useDict/useDictStore/useDictProvider/setDictSource` | 字典(独立 Vue3 状态管理 store 缓存,不依赖微前端;支持组件直传 / 局部 source / 全局 source 三级注入) |
14
- | `useLocale` | vue-i18n + 主应用语言联动(`elLocaleMessages` 对接 EP locale) |
15
- | `usePageTabs` | 多应用页签管理 |
12
+ | `useGlobalData` | 全局应用数据(locale / theme / token / 用户 / 权限 / config),纯 `localStorage` 持久化 |
13
+ | `useDict/useDictStore/useDictProvider/setDictSource` | 字典(独立 Vue3 状态管理 store 缓存,不依赖全局数据;支持组件直传 / 局部 source / 全局 source 三级注入) |
14
+ | `useLocale` | vue-i18n + 全局语言联动(`elLocaleMessages` 对接 EP locale) |
16
15
  | `useSash/useServiceType/useUKey/createCacheComputed` | 其他工具 hook |
17
16
 
18
- ## 运行前提(微前端模块)
17
+ ## 运行前提
19
18
 
20
- `@micro-zoe/micro-app` 是**可选 peer**(0.3.2 起)。`useMicroApp` / `useMicroAction` / `usePageTabs` 在缺失时会抛出带安装指引的错误;`useMicroGlobalData` 则**自动降级**为本地存储模式(`$zl_locale` / `$zl_theme` / `$zl_token`),因此 `useLocale`、主题、字典在纯 Web 应用中照常可用。
19
+ **无微前端依赖**:0.5.0 起本包不再包含任何微前端代码,`@micro-zoe/micro-app` 已从 peer 依赖中移除,
20
+ 产物里也没有它的静态 import(旧版在 Node 原生 ESM / SSR 下会因这条 import 报 `ERR_MODULE_NOT_FOUND`)。
21
21
 
22
- ```bash
23
- # 只在用微前端时才需要
24
- npm i @micro-zoe/micro-app
25
- ```
22
+ 全局数据(语言 / 主题 / 令牌 / 用户 / 权限 / `config`)由 `useGlobalData()` 提供:
23
+ `locale` / `theme` / `token` 经 `useStorage` 持久化到 `$zl_locale` / `$zl_theme` / `$zl_token`,
24
+ 其余字段为内存态、由宿主自行写入。旧名 `useMicroGlobalData` 与 `useMicroApp` / `useMicroAction` /
25
+ `usePageTabs` / `enableGlobalDataMock` 均已移除。
26
26
 
27
- `enableGlobalDataMock()` 仍保留用于强制 mock 调试,但**不再是**使用 `useMicroGlobalData` 的必要条件。字典模块(`useDict` 等)本身不依赖微前端。
27
+ `useLocale`、`ZlI18nProvider`、主题、字典等能力的行为与用法不变。
28
28
 
29
29
  ## 本地调试
30
30
 
package/dist/index.d.ts CHANGED
@@ -1,6 +1,5 @@
1
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';
2
+ import { ComputedRef, InjectionKey, Ref, WritableComputedRef, MaybeRef, MaybeRefOrGetter, WatchSource, UnwrapRef, ref } from 'vue';
4
3
  import { ElMessageBoxOptions, ElMessage, ElMessageBox, ElNotification } from 'element-plus';
5
4
  import { I18nOptions, I18n } from 'vue-i18n';
6
5
 
@@ -90,6 +89,49 @@ interface UseDictOptions {
90
89
  */
91
90
  declare function useDict(key: string, options?: UseDictOptions): UseDictReturn;
92
91
 
92
+ /**
93
+ * 全局应用数据(语言 / 主题 / 令牌 / 用户 / 权限 / 配置)
94
+ *
95
+ * 纯前端实现:只依赖 `useStorage`(localStorage)与组件内响应式状态,
96
+ * **不依赖任何微前端框架**。存储键沿用 `$zl_locale` / `$zl_theme` / `$zl_token`,
97
+ * 从旧版 `useMicroGlobalData` 升级过来时已持久化的数据不会丢。
98
+ */
99
+
100
+ interface GlobalDataState {
101
+ initialed: boolean;
102
+ locale: string;
103
+ theme: string;
104
+ token: string | undefined;
105
+ isI18nKeyVisible: boolean;
106
+ roles: string[];
107
+ permissions: string[];
108
+ user: any;
109
+ localeMessages: Record<string, any>;
110
+ elLocaleMessages: any;
111
+ config: Record<string, any> | undefined;
112
+ }
113
+ interface UseGlobalDataReturn extends Ref<Partial<GlobalDataState>> {
114
+ initialed: Readonly<Ref<boolean>>;
115
+ locale: WritableComputedRef<string>;
116
+ theme: WritableComputedRef<string>;
117
+ token: WritableComputedRef<string | undefined>;
118
+ isI18nKeyVisible: WritableComputedRef<boolean>;
119
+ roles: WritableComputedRef<string[]>;
120
+ permissions: WritableComputedRef<string[]>;
121
+ user: WritableComputedRef<any>;
122
+ localeMessages: WritableComputedRef<Record<string, any>>;
123
+ elLocaleMessages: WritableComputedRef<any>;
124
+ config: WritableComputedRef<Record<string, any> | undefined>;
125
+ getConfig: <T = any>(key: string, defaultValue?: T) => T;
126
+ isConfig: (key: string, compareValue?: string) => boolean;
127
+ setAndWaitUntil: (options: {
128
+ set?: Record<string, any>;
129
+ until?: (data: any) => boolean;
130
+ }) => Promise<void>;
131
+ resetUser: () => void;
132
+ }
133
+ declare const useGlobalData: () => UseGlobalDataReturn;
134
+
93
135
  /**
94
136
  * 全局消息(Element Plus 版)
95
137
  * 对外保持参考实现 API:Message / Modal(含 confirmPromise 扩展)/ Notification
@@ -124,7 +166,7 @@ interface GlobalMessage {
124
166
  declare function useGlobalMessage(_directMode?: boolean): GlobalMessage;
125
167
 
126
168
  /**
127
- * 国际化(vue-i18n)+ 微前端全局语言联动(elLocaleMessages 对接 Element Plus locale)
169
+ * 国际化(vue-i18n)+ 全局语言联动(elLocaleMessages 对接 Element Plus locale)
128
170
  */
129
171
 
130
172
  interface LocaleLoaderResult {
@@ -147,208 +189,6 @@ interface UseLocaleReturn {
147
189
  */
148
190
  declare function useLocale(options?: UseLocaleOptions, loader?: LocaleLoader): UseLocaleReturn;
149
191
 
150
- /**
151
- * 安全的国际化翻译函数(组件库渐进式接入 vue-i18n 的桥梁)。
152
- *
153
- * - 若宿主已 `app.use(i18n)` 安装 vue-i18n:委托其全局 t 进行翻译;
154
- * - 若宿主未接入 i18n(存量应用):安全降级为 fallback / key,绝不抛错。
155
- *
156
- * 这样组件库可在「不破坏现有消费方」的前提下,逐步把硬编码中文替换为
157
- * `t('zl.xxx', '中文兜底')`,待宿主统一安装 i18n 后即自动多语言化。
158
- */
159
- /** 命名插值参数,如 t('zl.upload.accept', fallback, { accept: '.png' }) */
160
- type TranslateParams = Record<string, unknown>;
161
- /**
162
- * @param key 语言包 key(规范:`zl.<组件>.<语义>`)
163
- * @param fallback 兜底文案(宿主未装 i18n / key 未命中时使用;可传入已插值的字符串)
164
- * @param params 命名插值参数(命中语言包时由 vue-i18n 插值 `{name}` 占位)
165
- */
166
- type Translate = (key: string, fallback?: string, params?: TranslateParams) => string;
167
- declare function useZlT(): {
168
- t: Translate;
169
- };
170
-
171
- /**
172
- * micro-app 跨应用动作通信层(主/子应用事件总线语义)
173
- */
174
- type MicroActionCallback = (...args: any[]) => void;
175
- interface UseMicroListenerReturn {
176
- on: (action: string, callback: MicroActionCallback) => void;
177
- off: (action: string, callback: MicroActionCallback) => void;
178
- once: (action: string, callback: MicroActionCallback) => void;
179
- }
180
- declare const useMicroListener: () => UseMicroListenerReturn;
181
- /**
182
- * 向子应用(或指定应用)派发动作,返回可直接调用的派发函数
183
- */
184
- declare function useMicroAction(action: string, appName?: string): (...args: any[]) => void;
185
- /**
186
- * 派发动作并等待 Promise 化结果
187
- */
188
- declare function useMicroActionAsync(action: string, appName?: string): (...args: any[]) => Promise<unknown>;
189
- /**
190
- * 监听动作的执行结果
191
- */
192
- declare function useMicroResultListener(action: string, callback: MicroActionCallback): void;
193
- /**
194
- * 向指定子应用派发动作(回调式)
195
- */
196
- declare function dispatchMicroAction(action: string, appName: string, ...data: any[]): Promise<void>;
197
-
198
- /**
199
- * micro-app 微应用管理(主/子应用身份判断、启动、活跃应用列表)
200
- */
201
-
202
- interface StartMicroAppConfig {
203
- [key: string]: any;
204
- lifeCycles?: {
205
- mounted?: (data?: any) => void;
206
- unmounted?: (data?: any) => void;
207
- };
208
- }
209
- interface UseMicroAppReturn {
210
- apps: Ref<string[]>;
211
- /** 是否主应用(多层嵌套时可同时为子应用) */
212
- isMicroBase: () => boolean;
213
- /** 是否子应用(多层嵌套时可同时为主应用) */
214
- isMicroChild: () => boolean;
215
- updateApps: () => void;
216
- startMicroApp: (config?: StartMicroAppConfig) => any;
217
- }
218
- declare const useMicroApp: () => UseMicroAppReturn;
219
-
220
- /**
221
- * micro-app 全局数据(globalData)响应式访问层
222
- * 脱敏/注入式改造(需求 §7.3、§12-Q3):
223
- * - 存储键 $zl_locale/$zl_theme/$zl_token
224
- * - arcoLocaleMessages → elLocaleMessages(Element Plus locale)
225
- * - 原 import.meta.env 开发的 mock 开关改为 enableGlobalDataMock() 显式开启(首次 useMicroGlobalData 前调用)
226
- */
227
-
228
- /**
229
- * 开发态启用本地 mock globalData(原实现经构建环境变量开启,现显式注入)
230
- */
231
- declare function enableGlobalDataMock(enabled?: boolean): void;
232
- interface GlobalDataState {
233
- initialed: boolean;
234
- locale: string;
235
- theme: string;
236
- token: string | undefined;
237
- isI18nKeyVisible: boolean;
238
- roles: string[];
239
- permissions: string[];
240
- user: any;
241
- localeMessages: Record<string, any>;
242
- elLocaleMessages: any;
243
- config: Record<string, any> | undefined;
244
- }
245
- interface UseMicroGlobalDataReturn extends Ref<Partial<GlobalDataState>> {
246
- initialed: Readonly<Ref<boolean>>;
247
- locale: WritableComputedRef<string>;
248
- theme: WritableComputedRef<string>;
249
- token: WritableComputedRef<string | undefined>;
250
- isI18nKeyVisible: WritableComputedRef<boolean>;
251
- roles: WritableComputedRef<string[]>;
252
- permissions: WritableComputedRef<string[]>;
253
- user: WritableComputedRef<any>;
254
- localeMessages: WritableComputedRef<Record<string, any>>;
255
- elLocaleMessages: WritableComputedRef<any>;
256
- config: WritableComputedRef<Record<string, any> | undefined>;
257
- getConfig: <T = any>(key: string, defaultValue?: T) => T;
258
- isConfig: (key: string, compareValue?: string) => boolean;
259
- setAndWaitUntil: (options: {
260
- set?: Record<string, any>;
261
- until?: (data: any) => boolean;
262
- }) => Promise<void>;
263
- resetUser: () => void;
264
- }
265
- declare const useMicroGlobalData: () => UseMicroGlobalDataReturn;
266
-
267
- type RootOptions = RootComponentOptions | RootMicroOptions;
268
- interface RootComponentOptions {
269
- title: string;
270
- key: string;
271
- icon?: string;
272
- component: Component;
273
- }
274
- interface RootMicroOptions {
275
- title: string;
276
- key: string;
277
- icon?: string;
278
- micro: string;
279
- url: string;
280
- }
281
- interface RootStore {
282
- tabs: TabStored[];
283
- activeTabKey: string;
284
- _parentTabMap?: Record<string, TabStored>;
285
- _parentMap: Record<string, any>;
286
- }
287
- type Tab = ComponentTab | MicroTab;
288
- type TabStored = Tab & {
289
- isRoot?: boolean;
290
- isChildRoot?: boolean;
291
- isChild?: boolean;
292
- isChildMicro?: boolean;
293
- rootKey?: string;
294
- micro?: string;
295
- url?: string;
296
- children?: TabStored[];
297
- parentTab?: TabStored;
298
- /** 用于删除本 tab 时,获取父 Tab 的实例 */
299
- _parentTabKey?: string;
300
- /** 子 root 页签标识(micro__key) */
301
- childRootTabKey?: string;
302
- /** 组件页签对外暴露的实例(供回调获取) */
303
- exposed?: any;
304
- };
305
- interface ComponentTab {
306
- key: string;
307
- title: string;
308
- icon?: string;
309
- beforeRemove?: () => boolean | void | Promise<boolean | void>;
310
- component: Component;
311
- props?: Record<string, any>;
312
- }
313
- interface MicroTab {
314
- key: string;
315
- title: string;
316
- icon?: string;
317
- beforeRemove?: () => boolean | void | Promise<boolean | void>;
318
- micro: string;
319
- url: string;
320
- }
321
- type ComponentTabVNode = VNode;
322
-
323
- /**
324
- * 页签管理(micro-app 多应用页签模型:root 树 → 扁平页签 → 当前激活页签)
325
- * 内部逻辑保持参考实现语义;类型签名见 ./types/usePageTabs
326
- */
327
-
328
- interface UsePageTabsReturn {
329
- roots: Record<string, RootStore | undefined>;
330
- activeRoot: ComputedRef<RootStore | null>;
331
- pageTabs: ComputedRef<TabStored[]>;
332
- current: ComputedRef<TabStored | undefined>;
333
- micros: Readonly<Record<string, string>>;
334
- activeRootKey: Readonly<Ref<string | null>>;
335
- addMicro: (option: {
336
- micro?: string;
337
- url?: string;
338
- }) => boolean;
339
- setRootChild: (tabs: TabStored[], activeChildTabKey: string, micro: string) => void;
340
- createPageTabsRoot: (root: RootOptions) => void;
341
- addPageTab: (tab: Tab & Record<string, any>, options?: {
342
- update?: boolean;
343
- childMicro?: boolean;
344
- }) => boolean;
345
- removePageTab: (tabOrKey?: TabStored | string) => Promise<void | [TabStored, TabStored] | false>;
346
- removeCurrentTab: (callback?: (exposed?: any) => Promise<void> | void) => Promise<boolean | void>;
347
- clearPageTab: (rootKey?: string) => void;
348
- setCurrentTab: (tab: TabStored) => Promise<void>;
349
- }
350
- declare function usePageTabs(): UsePageTabsReturn;
351
-
352
192
  type Prettify<T> = {
353
193
  [K in keyof T]: T[K];
354
194
  } & {};
@@ -591,4 +431,25 @@ interface UseUKeyReturn {
591
431
  }
592
432
  declare const useUKey: () => UseUKeyReturn;
593
433
 
594
- 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 };
434
+ /**
435
+ * 安全的国际化翻译函数(组件库渐进式接入 vue-i18n 的桥梁)。
436
+ *
437
+ * - 若宿主已 `app.use(i18n)` 安装 vue-i18n:委托其全局 t 进行翻译;
438
+ * - 若宿主未接入 i18n(存量应用):安全降级为 fallback / key,绝不抛错。
439
+ *
440
+ * 这样组件库可在「不破坏现有消费方」的前提下,逐步把硬编码中文替换为
441
+ * `t('zl.xxx', '中文兜底')`,待宿主统一安装 i18n 后即自动多语言化。
442
+ */
443
+ /** 命名插值参数,如 t('zl.upload.accept', fallback, { accept: '.png' }) */
444
+ type TranslateParams = Record<string, unknown>;
445
+ /**
446
+ * @param key 语言包 key(规范:`zl.<组件>.<语义>`)
447
+ * @param fallback 兜底文案(宿主未装 i18n / key 未命中时使用;可传入已插值的字符串)
448
+ * @param params 命名插值参数(命中语言包时由 vue-i18n 插值 `{name}` 占位)
449
+ */
450
+ type Translate = (key: string, fallback?: string, params?: TranslateParams) => string;
451
+ declare function useZlT(): {
452
+ t: Translate;
453
+ };
454
+
455
+ export { type CacheComputed, 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 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 Service, type State, type Translate, type TranslateParams, type UKeyCSRData, type UKeyDeviceInfo, type UKeyRequestData, type UnwrapRefObject, type UnwrapState, type UseDataRequestOptions, type UseDataRequestReturn, type UseDictOptions, type UseDictReturn, type UseGlobalDataReturn, type UseLocaleOptions, type UseLocaleReturn, type UsePageableRequestReturn, type UsePaginationRequestOptions, type UsePaginationRequestReturn, type UseRequestReturn, type UseSashOptions, type UseSashReturn, type UseServiceTypeOptions, type UseServiceTypeReturn, type UseUKeyReturn, clearGlobalOptions, createCacheComputed, definePlugin as defineUseRequestPlugin, dictInjectKey, getDictSource, getGlobalOptions, mergeMessages, setDictSource, setGlobalOptions, useDataRequest, useDict, useDictProvider, useDictStore, useGlobalData, useGlobalMessage, useLocale, usePageableRequest, usePaginationRequest, useRequest, useRequestProvider, useSash, useServiceType, useUKey, useZlT };