@zxiaosi/sdk 0.1.1 → 0.1.2

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.
@@ -1,481 +0,0 @@
1
- import { ConfigProviderProps } from "antd";
2
- import React, { ComponentType, ReactElement } from "react";
3
- import { AxiosError, AxiosInstance, AxiosRequestConfig, AxiosResponse, CreateAxiosDefaults } from "axios";
4
- import { Location, NavigateFunction, RouteObject, UIMatch } from "react-router-dom";
5
- import { MenuDataItem, ProLayoutProps } from "@ant-design/pro-layout";
6
- import { MicroApp, ObjectType, RegistrableApp } from "qiankun";
7
- import intl from "react-intl-universal";
8
- import * as zustand0 from "zustand";
9
-
10
- //#region src/components/antdConfigProvider/index.d.ts
11
- /**
12
- * Antd 配置
13
- * - 填充了 theme 和 locale 属性
14
- * - 详情参考: https://ant.design/components/config-provider-cn
15
- */
16
- declare const AntdConfigProvider: React.FC<ConfigProviderProps>;
17
- //#endregion
18
- //#region src/components/mainApp/index.d.ts
19
- /** 主应用的根组件 */
20
- declare const MainApp: React.FC;
21
- //#endregion
22
- //#region src/plugins/api/http.d.ts
23
- interface ApiRequestOption extends AxiosRequestConfig {
24
- /** 请求唯一key(默认自动生成) */
25
- requestId?: string;
26
- /** 是否需要原始数据 */
27
- isOriginalData?: boolean;
28
- /** 是否显示错误信息 */
29
- isShowFailMsg?: boolean;
30
- }
31
- //#endregion
32
- //#region src/plugins/api/index.d.ts
33
- interface ApiOptions {
34
- /** Axios配置 */
35
- config?: CreateAxiosDefaults;
36
- /** 取消请求控制器 */
37
- controllers?: Map<string, AbortController>;
38
- /**
39
- * 自定义请求实例
40
- * - 将替代 SDK 内置的请求实例
41
- * @example instance = axios.create(options)
42
- */
43
- instance?: AxiosInstance;
44
- /**
45
- * 获取用户信息
46
- * {@link UserInfo}
47
- * @example { data: { user: { ... }, permissions: [], roles: [], settings: {} }, code: 200 }
48
- */
49
- getUserInfoApi?: () => Promise<AxiosResponse<UserInfo>>;
50
- /**
51
- * 获取路由数据
52
- * @example { data: [{path: '/', name: '首页', element: 'Home'}], code: 200 }
53
- */
54
- getRoutesApi?: () => Promise<AxiosResponse<RouteObject[]>>;
55
- }
56
- interface ApiResult extends Required<ApiOptions> {
57
- /**
58
- * 请求
59
- * @param url 请求地址
60
- * @param options 自定义配置项
61
- */
62
- readonly request: (url: string, options?: ApiRequestOption) => Promise<AxiosResponse<any, any>>;
63
- /**
64
- * 二次加工请求
65
- * @param url 请求地址
66
- * @param options 自定义配置项
67
- * @returns [resp, err, cancel]
68
- */
69
- readonly request2: (url: string, options?: ApiRequestOption) => Promise<[AxiosResponse<any, any>, AxiosError, () => void]>;
70
- /**
71
- * 下载文件
72
- * @param url 请求地址
73
- * @param options 自定义配置项
74
- * @returns [resp, err, cancel]
75
- */
76
- readonly download: (url: string, options?: ApiRequestOption) => Promise<[AxiosResponse<any, any>, AxiosError, () => void]>;
77
- }
78
- /**
79
- * 请求插件
80
- * - 详情参考 {@link ApiOptions} {@link ApiResult}
81
- * - 内置了请求, 通过 sdk.api.request 发起请求
82
- * - 可通过外部传入 instance 自定义请求实例
83
- * - 预置了获取用户信息, 获取路由, 登录接口等接口, 以便组件使用
84
- * @example sdk.api.request('/getTemp', { method: 'POST', ... })
85
- * @example sdk.api.request('/getTemp', { method: 'POST', isOriginalData: true }) // 返回原始数据
86
- * @example sdk.api.request('/getTemp', { method: 'POST', isShowFailMsg: false }) // 不显示错误信息
87
- */
88
- declare const SdkApiPlugin: Plugin<'api'>;
89
- //#endregion
90
- //#region src/plugins/app/index.d.ts
91
- interface AppOptions {
92
- /** 菜单数据 */
93
- menuData?: MenuDataItem[];
94
- /** 所有路由信息 */
95
- allRoutes?: RouteObject[];
96
- /** 微应用信息 */
97
- microApps?: RegistrableApp<ObjectType>[];
98
- /** 微应用实例 */
99
- microAppsInstance?: Map<string, MicroApp>;
100
- /** 用户信息 */
101
- user?: UserInfo['user'];
102
- /** 用户权限 */
103
- permissions?: UserInfo['permissions'];
104
- /** 用户角色 */
105
- roles?: UserInfo['roles'];
106
- /** 用户设置 */
107
- settings?: UserInfo['settings'];
108
- }
109
- interface AppResult extends Required<AppOptions> {
110
- /**
111
- * 跳转登录页
112
- */
113
- readonly pageToLogin: () => void;
114
- /**
115
- * 获取重定向路径
116
- */
117
- readonly getRedirectPath: () => string;
118
- }
119
- /**
120
- * 项目插件
121
- * - 详情参考 {@link AppOptions} {@link AppResult}
122
- * - 主要存储接口数据
123
- */
124
- declare const SdkAppPlugin: Plugin<'app'>;
125
- //#endregion
126
- //#region src/plugins/client/index.d.ts
127
- interface ClientOptions {}
128
- interface ClientResult extends Required<ClientOptions> {
129
- /** 主应用 location */
130
- location: Location;
131
- /** 主应用navigate(解决子应用跳转问题) */
132
- navigate: NavigateFunction;
133
- /** 路由匹配(用于面包屑) */
134
- matches: UIMatch[];
135
- }
136
- /**
137
- * 路由插件
138
- * - 详情参考 {@link ClientOptions} {@link ClientResult}
139
- * - 路由信息 sdk.client.location
140
- * - 路由跳转 sdk.client.navigate
141
- * - 面包屑信息 sdk.client.matches
142
- */
143
- declare const SdkClientPlugin: Plugin<'client'>;
144
- //#endregion
145
- //#region src/plugins/config/index.d.ts
146
- interface ConfigOptions {
147
- /** 环境变量 */
148
- env?: Record<string, any>;
149
- /** 主题 */
150
- theme?: ThemeProps;
151
- /** 国际化 */
152
- locale?: LocaleProps;
153
- /**
154
- * qiankun模式(切换模式后请打开新的窗口)
155
- * - 'router': 基于路由模式
156
- * - 'load': 手动加载模式
157
- */
158
- qiankunMode?: 'router' | 'load';
159
- /** 登录页路由 */
160
- loginPath?: string;
161
- /**
162
- * 登录后跳转的路由
163
- * - 优先使用指定值
164
- * - 其次使用重定向的值
165
- * - 最后使用菜单中第一项
166
- */
167
- defaultPath?: string;
168
- /**
169
- * 自定义路由信息
170
- * - 目前只支持最外层路由自定义
171
- * - 会合并到 sdk.app.allRoutes 中
172
- */
173
- customRoutes?: RouteObject[];
174
- /** Antd 配置 */
175
- antdConfig?: ConfigProviderProps;
176
- /** ProLayout 配置 */
177
- proLayoutConfig?: ProLayoutProps;
178
- }
179
- interface ConfigResult extends Required<ConfigOptions> {}
180
- /**
181
- * 配置项插件
182
- * - 详情参考 {@link ConfigOptions} {@link ConfigResult}
183
- * - 配置 localStorage 变量名称
184
- * - 配置 默认主题、国际化
185
- * - 配置 默认登录路径、跳转路径、自定义路由
186
- * - 配置 Antd 配置、ProLayout 配置
187
- */
188
- declare const SdkConfigPlugin: Plugin<'config'>;
189
- //#endregion
190
- //#region src/plugins/i18n/index.d.ts
191
- interface I18nOptions {
192
- /**
193
- * React Intl Universal
194
- * - 不要解构使用, const { get } = useIntl() 会报错
195
- * - 如果项目不使用 React Compiler, 可以直接使用 sdk.i18n.intl
196
- * - 如果使用 React Compiler, 请使用 useIntl() 方法获取
197
- * @example
198
- * const intl = useIntl();
199
- * intl.get(key).d(defaultValue)
200
- */
201
- intl?: typeof intl;
202
- /**
203
- * React Intl Universal 配置的语言包
204
- * @example
205
- * {
206
- * 'zh-CN': {
207
- * test: '测试国际化'
208
- * },
209
- * 'en-US': {
210
- * test: 'Test Intl'
211
- * }
212
- * }
213
- */
214
- intlConfig?: Record<string, any>;
215
- /**
216
- * 加载 Antd 语言包
217
- * @param locale 语言包名
218
- * @example
219
- * import enUS from 'antd/es/locale/en_US';
220
- * import zhCN from 'antd/es/locale/zh_CN';
221
- * import dayjs from 'dayjs';
222
- * import 'dayjs/locale/en';
223
- * import 'dayjs/locale/zh';
224
- *
225
- * const loadLocale = (locale: string) => {
226
- * switch (locale) {
227
- * case 'en-US':
228
- * dayjs.locale('en');
229
- * return enUS;
230
- * case 'zh-CN':
231
- * dayjs.locale('zh');
232
- * return zhCN;
233
- * default:
234
- * return undefined;
235
- * }
236
- * }
237
- */
238
- loadLocale?: (locale: string) => any;
239
- }
240
- interface I18nResult extends Required<I18nOptions> {}
241
- /**
242
- * 国际化插件
243
- * - 详情参考 {@link I18nOptions} {@link I18nResult}
244
- * - 集成 React Intl Universal 和 Antd 国际化
245
- * - 需要从外部引入语言包, 详见 intlConfig 和 loadLocale 配置项
246
- */
247
- declare const SdkI18nPlugin: Plugin<'i18n'>;
248
- //#endregion
249
- //#region src/plugins/storage/index.d.ts
250
- interface StorageOptions {
251
- /** 国际化存储名称 */
252
- localeKey?: string;
253
- /** 主题存储名称 */
254
- themeKey?: string;
255
- /** Token存储名称 */
256
- tokenKey?: string;
257
- }
258
- interface StorageResult extends Required<StorageOptions> {
259
- /** 获取当前国际化 */
260
- readonly getLocale: () => LocaleProps;
261
- /** 设置/切换切换国际化 */
262
- readonly setLocale: (locale: LocaleProps) => void;
263
- /** 清除国际化 */
264
- readonly clearLocale: () => void;
265
- /** 获取当前主题 */
266
- readonly getTheme: () => ThemeProps;
267
- /** 设置/切换主题 */
268
- readonly setTheme: (theme: ThemeProps) => void;
269
- /** 清除主题 */
270
- readonly clearTheme: () => void;
271
- /** 获取当前 Token */
272
- readonly getToken: () => string | null;
273
- /** 设置 Token */
274
- readonly setToken: (token: string) => void;
275
- /** 清除 Token */
276
- readonly clearToken: () => void;
277
- }
278
- /**
279
- * 本地缓存插件
280
- * - 详情参考 {@link StorageOptions} {@link StorageResult}
281
- * - 配置 localStorage 变量名称
282
- * - 提供 国际化、主题、Token 的 get、change、clear 方法
283
- * @example sdk.storage.getToken() // 获取 Token
284
- * @example sdk.storage.changeTheme('dark') // 切换主题
285
- * @example sdk.storage.clearLocale() // 清除国际化
286
- */
287
- declare const SdkStoragePlugin: Plugin<'storage'>;
288
- //#endregion
289
- //#region src/plugins/store/createAppState.d.ts
290
- interface AppStateStoreProps {
291
- /** 子应用加载状态 */
292
- microAppState: boolean;
293
- /** 设置子应用加载状态 */
294
- setMicroAppState: (state: boolean) => void;
295
- }
296
- /** 子应用状态切片 */
297
- //#endregion
298
- //#region src/plugins/store/createInitState.d.ts
299
- interface InitStateStoreProps {
300
- /** 初始变量 */
301
- initState: UserInfo;
302
- /** 设置初始变量 */
303
- setInitState: (initState: UserInfo) => void;
304
- }
305
- /** 初始变量切片 */
306
- //#endregion
307
- //#region src/plugins/store/createLocale.d.ts
308
- interface LocaleStoreProps {
309
- /** 国际化 */
310
- locale: LocaleProps;
311
- /** 设置国际化 */
312
- setLocale: (locale: LocaleProps) => void;
313
- }
314
- /** 国际化状态切片 */
315
- //#endregion
316
- //#region src/plugins/store/createTheme.d.ts
317
- interface ThemeStoreProps {
318
- /** 主题 */
319
- theme: ThemeProps;
320
- /** 设置主题 */
321
- setTheme: (theme: ThemeProps) => void;
322
- }
323
- /** 主题状态切片 */
324
- //#endregion
325
- //#region src/plugins/store/index.d.ts
326
- type StoreOptions = AppStateStoreProps & InitStateStoreProps & LocaleStoreProps & ThemeStoreProps;
327
- type StoreResult = typeof globalStore;
328
- /**
329
- * 创建 Store 切片
330
- * - 这里单独声明变量, 主要是为了使用返回类型 StoreResult 🤔
331
- */
332
- declare const globalStore: Omit<zustand0.StoreApi<StoreOptions>, "subscribe"> & {
333
- subscribe: {
334
- (listener: (selectedState: StoreOptions, previousSelectedState: StoreOptions) => void): () => void;
335
- <U>(selector: (state: StoreOptions) => U, listener: (selectedState: U, previousSelectedState: U) => void, options?: {
336
- equalityFn?: (a: U, b: U) => boolean;
337
- fireImmediately?: boolean;
338
- }): () => void;
339
- };
340
- };
341
- /**
342
- * 全局状态管理插件
343
- * - 详情参考 {@link StoreOptions} {@link StoreResult}
344
- * - 此插件不会合并传入属性
345
- * @example const setTheme = useStore(sdk.store, (state) => state.setTheme)
346
- * @example const { theme, setTheme } = useStore(sdk.store, useShallow((state) => { theme: state.theme, setTheme: state.setTheme }))
347
- * @example const [theme, setTheme] = useStore(sdk.store, useShallow((state) => [state.theme, state.setTheme]))
348
- * @example sdk.store?.getState()?.setTheme('light')
349
- * @example sdk.store.subscribe((state) => state.theme, (theme) => { console.log('theme', theme) }, { fireImmediately: true }) // fireImmediately 立即变更
350
- */
351
- declare const SdkStorePlugin: Plugin<'store'>;
352
- //#endregion
353
- //#region src/plugins/ui/index.d.ts
354
- interface UIOptions {
355
- /** 组件 */
356
- [key: string]: ComponentType | ((name: string) => ComponentType);
357
- }
358
- interface UIResult extends Required<UIOptions> {
359
- /**
360
- * 获取组件
361
- * @param name 组件名称
362
- */
363
- readonly getComponent: (name: string) => ComponentType;
364
- /**
365
- * 渲染组件
366
- * @param name 组件名称
367
- */
368
- readonly renderComponent: (name: string, props?: any) => ReactElement;
369
- }
370
- /**
371
- * 组件插件
372
- * - 详情参考 {@link UIOptions} {@link UIResult}
373
- * - 内置了 Login、NotFound、Microapp、Layout 等组件, 可传入覆盖
374
- * - 组件共享
375
- * - 在主应用中, 可通过 use(SdkUIPlugin, { MyComponent }) 传入组件
376
- * - 在子应用中, 可通过 sdk.ui.renderComponent('MyComponent') 使用组件
377
- */
378
- declare const SdkUIPlugin: Plugin<'ui'>;
379
- //#endregion
380
- //#region src/types.d.ts
381
- type ThemeProps = 'light' | 'dark' | (string & {});
382
- type LocaleProps = 'zh-CN' | 'en-US' | (string & {});
383
- interface UserInfo {
384
- /** 用户信息 */
385
- user?: any;
386
- /** 用户权限 */
387
- permissions?: string[];
388
- /** 用户角色 */
389
- roles?: string[];
390
- /** 用户设置 */
391
- settings?: {
392
- theme?: ThemeProps;
393
- locale?: LocaleProps;
394
- };
395
- }
396
- type PluginName = keyof PluginOptions;
397
- interface PluginOptions {
398
- /** 请求插件 */
399
- api?: ApiOptions;
400
- /** 项目插件 */
401
- app?: AppOptions;
402
- /** 路由插件 */
403
- client?: ClientOptions;
404
- /** 配置项插件 */
405
- config?: ConfigOptions;
406
- /** 国际化插件 */
407
- i18n?: I18nOptions;
408
- /** 本地缓存插件 */
409
- storage?: StorageOptions;
410
- /** 状态管理插件 */
411
- store?: StoreOptions;
412
- /** 组件插件 */
413
- ui?: UIOptions;
414
- }
415
- interface PluginResults {
416
- /** 请求插件 */
417
- api: ApiResult;
418
- /** 项目插件 */
419
- app: AppResult;
420
- /** 路由插件 */
421
- client: ClientResult;
422
- /** 配置项插件 */
423
- config: ConfigResult;
424
- /** 国际化插件 */
425
- i18n: I18nResult;
426
- /** 本地缓存插件 */
427
- storage: StorageResult;
428
- /** 状态管理插件 */
429
- store: StoreResult;
430
- /** 组件插件 */
431
- ui: UIResult;
432
- }
433
- interface Plugin<K$1 extends PluginName> {
434
- /** 插件名字 */
435
- name: K$1;
436
- /** 插件安装方法 */
437
- install: (sdk: SdkResult, options?: PluginOptions[K$1]) => void;
438
- /** 插件配置项 */
439
- options?: PluginOptions[K$1];
440
- }
441
- interface SdkBase {
442
- /** SDK 名称 */
443
- name: string;
444
- /** 插件列表 */
445
- _plugins: Map<string, Plugin<never>>;
446
- /** 挂载sdk - Window */
447
- mount: (name: string) => void;
448
- /** 卸载sdk - Window */
449
- unmount: () => void;
450
- /** 使用插件 */
451
- use: <K extends PluginName>(plugin: Plugin<K>, options?: PluginOptions[K]) => this;
452
- }
453
- type SdkResult = SdkBase & PluginResults;
454
- //#endregion
455
- //#region src/core/index.d.ts
456
- declare class Sdk implements SdkResult {
457
- name: SdkResult['name'];
458
- _plugins: SdkResult['_plugins'];
459
- api: SdkResult['api'];
460
- app: SdkResult['app'];
461
- client: SdkResult['client'];
462
- config: SdkResult['config'];
463
- i18n: SdkResult['i18n'];
464
- storage: SdkResult['storage'];
465
- store: SdkResult['store'];
466
- ui: SdkResult['ui'];
467
- constructor();
468
- mount(name: string): void;
469
- unmount(): void;
470
- use<K extends keyof PluginOptions>(plugin: Plugin<K>, options?: PluginOptions[K]): this;
471
- }
472
- /**
473
- * sdk 实例
474
- * @example sdk.use(SdkPlugin) // 使用插件
475
- * @example sdk.mount('SdkName') // 挂载到 window 上
476
- * @example sdk.unmount() // 卸载
477
- */
478
- declare const sdk: Sdk;
479
- //#endregion
480
- export { AntdConfigProvider, ApiOptions, ApiResult, AppOptions, AppResult, ClientOptions, ClientResult, ConfigOptions, ConfigResult, I18nOptions, I18nResult, MainApp, SdkApiPlugin, SdkAppPlugin, SdkClientPlugin, SdkConfigPlugin, SdkI18nPlugin, SdkStoragePlugin, SdkStorePlugin, SdkUIPlugin, StorageOptions, StorageResult, StoreOptions, StoreResult, UIOptions, UIResult, sdk };
481
- //# sourceMappingURL=index.d.cts.map