@zxiaosi/sdk 0.1.7 → 0.1.9
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/dist/index.d.ts +103 -8
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { AxiosInstance, AxiosRequestConfig, AxiosResponse, CreateAxiosDefaults } from "axios";
|
|
2
2
|
import { ConfigProviderProps } from "antd";
|
|
3
|
+
import intl from "react-intl-universal";
|
|
3
4
|
import * as zustand0 from "zustand";
|
|
5
|
+
import { ComponentType, ReactElement } from "react";
|
|
4
6
|
import { Location, NavigateFunction, RouteObject, UIMatch } from "react-router-dom";
|
|
5
7
|
import { MenuDataItem, ProLayoutProps } from "@ant-design/pro-layout";
|
|
6
8
|
import { MicroApp, ObjectType, RegistrableApp } from "qiankun";
|
|
@@ -34,13 +36,13 @@ interface ApiOptions {
|
|
|
34
36
|
* {@link UserInfo}
|
|
35
37
|
* @example { data: { user: { ... }, permissions: [], roles: [], settings: {} }, code: 200 }
|
|
36
38
|
*/
|
|
37
|
-
getUserInfoApi
|
|
39
|
+
getUserInfoApi?(): Promise<AxiosResponse<UserInfo>>;
|
|
38
40
|
/**
|
|
39
41
|
* 获取路由数据
|
|
40
42
|
* {@link RouteObject}
|
|
41
43
|
* @example { data: [{path: '/', name: '首页', element: 'Home'}], code: 200 }
|
|
42
44
|
*/
|
|
43
|
-
getRoutesApi
|
|
45
|
+
getRoutesApi?(): Promise<AxiosResponse<RouteObject[]>>;
|
|
44
46
|
}
|
|
45
47
|
interface ApiResults extends Required<ApiOptions> {
|
|
46
48
|
/**
|
|
@@ -48,7 +50,7 @@ interface ApiResults extends Required<ApiOptions> {
|
|
|
48
50
|
* @param url 请求地址
|
|
49
51
|
* @param options 自定义配置项
|
|
50
52
|
*/
|
|
51
|
-
|
|
53
|
+
request(url: string, options?: ApiRequestOption): Promise<AxiosResponse<any, any>>;
|
|
52
54
|
}
|
|
53
55
|
/**
|
|
54
56
|
* 请求插件
|
|
@@ -174,6 +176,62 @@ interface ConfigResults extends Required<ConfigOptions> {}
|
|
|
174
176
|
*/
|
|
175
177
|
declare const SdkConfigPlugin: Plugin<'config'>;
|
|
176
178
|
//#endregion
|
|
179
|
+
//#region src/plugins/i18n/index.d.ts
|
|
180
|
+
interface I18nOptions {
|
|
181
|
+
/**
|
|
182
|
+
* React Intl Universal
|
|
183
|
+
* - 不要解构使用, const { get } = useIntl() 会报错
|
|
184
|
+
* - 如果项目不使用 React Compiler, 可以直接使用 sdk.i18n.intl
|
|
185
|
+
* @example const intl = useIntl(); intl.get(key).d(defaultValue)
|
|
186
|
+
*/
|
|
187
|
+
intl?: typeof intl;
|
|
188
|
+
/**
|
|
189
|
+
* React Intl Universal 配置的语言包
|
|
190
|
+
* @example
|
|
191
|
+
* {
|
|
192
|
+
* 'zh-CN': {
|
|
193
|
+
* test: '测试国际化'
|
|
194
|
+
* },
|
|
195
|
+
* 'en-US': {
|
|
196
|
+
* test: 'Test Intl'
|
|
197
|
+
* }
|
|
198
|
+
* }
|
|
199
|
+
*/
|
|
200
|
+
intlConfig?: Record<string, any>;
|
|
201
|
+
/**
|
|
202
|
+
* 加载 Antd 语言包
|
|
203
|
+
* @param locale 语言包名
|
|
204
|
+
* @example
|
|
205
|
+
* import enUS from 'antd/es/locale/en_US';
|
|
206
|
+
* import zhCN from 'antd/es/locale/zh_CN';
|
|
207
|
+
* import dayjs from 'dayjs';
|
|
208
|
+
* import 'dayjs/locale/en';
|
|
209
|
+
* import 'dayjs/locale/zh';
|
|
210
|
+
*
|
|
211
|
+
* const loadLocale = (locale: string) => {
|
|
212
|
+
* switch (locale) {
|
|
213
|
+
* case 'en-US':
|
|
214
|
+
* dayjs.locale('en');
|
|
215
|
+
* return enUS;
|
|
216
|
+
* case 'zh-CN':
|
|
217
|
+
* dayjs.locale('zh');
|
|
218
|
+
* return zhCN;
|
|
219
|
+
* default:
|
|
220
|
+
* return undefined;
|
|
221
|
+
* }
|
|
222
|
+
* }
|
|
223
|
+
*/
|
|
224
|
+
loadLocale?(locale: string): any;
|
|
225
|
+
}
|
|
226
|
+
interface I18nResults extends Required<I18nOptions> {}
|
|
227
|
+
/**
|
|
228
|
+
* 多语言
|
|
229
|
+
* - 详情参考 {@link I18nOptions} {@link I18nResults}
|
|
230
|
+
* - 集成 React Intl Universal 和 Antd 国际化
|
|
231
|
+
* - 需要从外部引入语言包, 详见 intlConfig 和 loadLocale 配置项
|
|
232
|
+
*/
|
|
233
|
+
declare const SdkI18nPlugin: Plugin<'i18n'>;
|
|
234
|
+
//#endregion
|
|
177
235
|
//#region src/plugins/storage/index.d.ts
|
|
178
236
|
interface StorageOptions {
|
|
179
237
|
/** 国际化存储名称 */
|
|
@@ -219,7 +277,7 @@ interface InitStateStoreProps {
|
|
|
219
277
|
/** 初始变量 */
|
|
220
278
|
initState: UserInfo;
|
|
221
279
|
/** 设置初始变量 */
|
|
222
|
-
setInitState
|
|
280
|
+
setInitState(initState: UserInfo): void;
|
|
223
281
|
}
|
|
224
282
|
/** 初始变量状态 */
|
|
225
283
|
//#endregion
|
|
@@ -228,7 +286,7 @@ interface LocaleStoreProps {
|
|
|
228
286
|
/** 国际化 */
|
|
229
287
|
locale: LocaleProps;
|
|
230
288
|
/** 设置国际化 */
|
|
231
|
-
setLocale
|
|
289
|
+
setLocale(locale: LocaleProps): void;
|
|
232
290
|
}
|
|
233
291
|
/** 国际化状态 */
|
|
234
292
|
//#endregion
|
|
@@ -237,7 +295,7 @@ interface MicroAppStateStoreProps {
|
|
|
237
295
|
/** 子应用加载状态 */
|
|
238
296
|
microAppLoading: boolean;
|
|
239
297
|
/** 设置子应用加载状态 */
|
|
240
|
-
setMicroAppLoading
|
|
298
|
+
setMicroAppLoading(state: boolean): void;
|
|
241
299
|
}
|
|
242
300
|
/** 子应用状态 */
|
|
243
301
|
//#endregion
|
|
@@ -246,7 +304,7 @@ interface ThemeStoreProps {
|
|
|
246
304
|
/** 主题 */
|
|
247
305
|
theme: ThemeProps;
|
|
248
306
|
/** 设置主题 */
|
|
249
|
-
setTheme
|
|
307
|
+
setTheme(theme: ThemeProps): void;
|
|
250
308
|
}
|
|
251
309
|
/** 主题状态 */
|
|
252
310
|
//#endregion
|
|
@@ -278,6 +336,33 @@ declare const globalStore: Omit<zustand0.StoreApi<StoreOptions>, "subscribe"> &
|
|
|
278
336
|
*/
|
|
279
337
|
declare const SdkStorePlugin: Plugin<'store'>;
|
|
280
338
|
//#endregion
|
|
339
|
+
//#region src/plugins/ui/index.d.ts
|
|
340
|
+
interface UIOptions {
|
|
341
|
+
/** 组件 */
|
|
342
|
+
[key: string]: ComponentType | ((name: string) => ComponentType);
|
|
343
|
+
}
|
|
344
|
+
interface UIResults extends Required<UIOptions> {
|
|
345
|
+
/**
|
|
346
|
+
* 获取组件
|
|
347
|
+
* @param name 组件名称
|
|
348
|
+
*/
|
|
349
|
+
getComponent(name: string): ComponentType;
|
|
350
|
+
/**
|
|
351
|
+
* 渲染组件
|
|
352
|
+
* @param name 组件名称
|
|
353
|
+
*/
|
|
354
|
+
renderComponent(name: string, props?: any): ReactElement;
|
|
355
|
+
}
|
|
356
|
+
/**
|
|
357
|
+
* 可复用组件
|
|
358
|
+
* - 详情参考 {@link UIOptions} {@link UIResults}
|
|
359
|
+
* - 内置了 Layout、Loading、Login、Mainapp、Microapp、NotFound 等组件, 可传入覆盖
|
|
360
|
+
* - 组件共享
|
|
361
|
+
* - 在主应用中, 可通过 use(SdkUIPlugin, { MyComponent }) 传入组件
|
|
362
|
+
* - 在子应用中, 可通过 sdk.ui.renderComponent('MyComponent') 使用组件
|
|
363
|
+
*/
|
|
364
|
+
declare const SdkUIPlugin: Plugin<'ui'>;
|
|
365
|
+
//#endregion
|
|
281
366
|
//#region src/types.d.ts
|
|
282
367
|
type ThemeProps = 'light' | 'dark' | (string & {});
|
|
283
368
|
type LocaleProps = 'zh-CN' | 'en-US' | (string & {});
|
|
@@ -303,10 +388,14 @@ interface PluginOptions {
|
|
|
303
388
|
client?: ClientOptions;
|
|
304
389
|
/** Sdk 配置信息 */
|
|
305
390
|
config?: ConfigOptions;
|
|
391
|
+
/** 多语言 */
|
|
392
|
+
i18n?: I18nOptions;
|
|
306
393
|
/** 本地缓存 */
|
|
307
394
|
storage?: StorageOptions;
|
|
308
395
|
/** 全局状态管理 */
|
|
309
396
|
store?: StoreOptions;
|
|
397
|
+
/** 可复用组件 */
|
|
398
|
+
ui?: UIOptions;
|
|
310
399
|
}
|
|
311
400
|
interface PluginResults {
|
|
312
401
|
/** 全局请求 */
|
|
@@ -317,10 +406,14 @@ interface PluginResults {
|
|
|
317
406
|
client: ClientResults;
|
|
318
407
|
/** Sdk 配置信息 */
|
|
319
408
|
config: ConfigResults;
|
|
409
|
+
/** 多语言 */
|
|
410
|
+
i18n: I18nResults;
|
|
320
411
|
/** 本地缓存 */
|
|
321
412
|
storage: StorageResults;
|
|
322
413
|
/** 全局状态管理 */
|
|
323
414
|
store: StoreResults;
|
|
415
|
+
/** 可复用组件 */
|
|
416
|
+
ui: UIResults;
|
|
324
417
|
}
|
|
325
418
|
type PluginName = keyof PluginOptions;
|
|
326
419
|
interface Plugin<K extends PluginName> {
|
|
@@ -353,8 +446,10 @@ declare class Sdk implements SdkResult {
|
|
|
353
446
|
app: SdkResult['app'];
|
|
354
447
|
client: SdkResult['client'];
|
|
355
448
|
config: SdkResult['config'];
|
|
449
|
+
i18n: SdkResult['i18n'];
|
|
356
450
|
storage: SdkResult['storage'];
|
|
357
451
|
store: SdkResult['store'];
|
|
452
|
+
ui: SdkResult['ui'];
|
|
358
453
|
constructor();
|
|
359
454
|
mount(name: string): void;
|
|
360
455
|
extend(name: string): void;
|
|
@@ -365,5 +460,5 @@ declare class Sdk implements SdkResult {
|
|
|
365
460
|
*/
|
|
366
461
|
declare const sdk: Sdk;
|
|
367
462
|
//#endregion
|
|
368
|
-
export { type ApiOptions, type ApiResults, type AppOptions, type AppResults, type ClientOptions, type ClientResults, type ConfigOptions, type ConfigResults, SdkApiPlugin, SdkAppPlugin, SdkClientPlugin, SdkConfigPlugin, SdkStoragePlugin, SdkStorePlugin, type StorageOptions, type StorageResults, type StoreOptions, type StoreResults, sdk };
|
|
463
|
+
export { type ApiOptions, type ApiResults, type AppOptions, type AppResults, type ClientOptions, type ClientResults, type ConfigOptions, type ConfigResults, type I18nOptions, type I18nResults, SdkApiPlugin, SdkAppPlugin, SdkClientPlugin, SdkConfigPlugin, SdkI18nPlugin, SdkStoragePlugin, SdkStorePlugin, SdkUIPlugin, type StorageOptions, type StorageResults, type StoreOptions, type StoreResults, type UIOptions, type UIResults, sdk };
|
|
369
464
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import e from"axios";import{message as t}from"antd";import{createStore as
|
|
1
|
+
import e from"axios";import{message as t}from"antd";import n from"react-intl-universal";import{createStore as r}from"zustand";import{subscribeWithSelector as i}from"zustand/middleware";import{createElement as a}from"react";const o=new class{name;_plugins;api;app;client;config;i18n;storage;store;ui;constructor(){this.name=``,this._plugins=new Map}mount(e){if(window[e])throw Error(`The SDK already exists - ${e}`);console.log(`%c SDK mounted:`,`color: pink; font-weight: bold;`,e),this.name=e;let t=new Proxy(this,{get:(e,t,n)=>e?Reflect.get(e,t,n):null,set:()=>(console.error(`The SDK cannot be modified.`),!1),deleteProperty:()=>(console.error(`The SDK cannot be deleted.`),!1)});window[this.name]=t}extend(e){if(!window[e])throw Error(`The SDK not found - ${e}`);console.log(`%c SDK extended:`,`color: pink; font-weight: bold;`,e),Object.assign(this,window[e])}use(e,t){let{name:n,install:r}=e;if(!n)throw Error(`${n} plugin has no name`);if(typeof r!=`function`)throw Error(`${n} plugin is not a function`);return r(this,t),this._plugins.set(n,{...e,options:t}),this}};function s(e){if(!e||typeof e!=`object`)return!1;let t=Object.getPrototypeOf(e);return t===null||t===Object.prototype||Object.getPrototypeOf(t)===null?Object.prototype.toString.call(e)===`[object Object]`:!1}function c(e){return e===`__proto__`}function l(e,t){let n=Object.keys(t);for(let r=0;r<n.length;r++){let i=n[r];if(c(i))continue;let a=t[i],o=e[i];Array.isArray(a)?Array.isArray(o)?e[i]=l(o,a):e[i]=l([],a):s(a)?s(o)?e[i]=l(o,a):e[i]=l({},a):(o===void 0||a!==void 0)&&(e[i]=a)}return e}const u=e=>{let{requestId:t,url:n,method:r,params:i,data:a}=e;return t||`${r}:${n}?${JSON.stringify(i)}&${JSON.stringify(a)}`},d=e=>{let t=u(e),n=o.api.controllers.get(t);n&&(n.abort(),o.api.controllers.delete(t))};var f=class{instance;constructor(t={}){this.instance=e.create(t),this.defaultRequestInterceptor(),this.defaultResponseInterceptor()}defaultRequestInterceptor(){this.instance.interceptors.request.use(function(e){if(e?.isCancelRequest){let t=u(e);d(e);let n=new AbortController;o.api.controllers.set(t,n),e.requestId=t,e.signal=n.signal}let t=o.storage.getToken();return e.headers.lang=o.config.locale,e.headers.Authorization=t,l(e.headers,o.api.config.headers||{}),e},function(e){return console.error(`请求错误`),Promise.reject(e)})}defaultResponseInterceptor(){this.instance.interceptors.response.use(function(e){let{data:n,config:r}=e,{isOriginalData:i,isShowFailMsg:a,isCancelRequest:s}=r,{code:c,msg:l}=n;return c!==0&&(a&&t.error(l),console.error(`response error: `,r.url,l),c==20041&&o.app.pageToLogin()),s&&o.api.controllers.delete(r.requestId),i?e:e.data},function(n){let{response:r,config:i}=n,{isShowFailMsg:a}=i;if(e.isCancel(n))return Promise.reject(n);if(r){let{status:e,data:n,statusText:i}=r;a&&t.error(n.msg||i),e==401&&o.app.pageToLogin()}else a&&t.error(`请求超时或服务器异常,请检查网络或联系管理员`),console.error(`Request error:`,i.url,n);return Promise.reject(n)})}getInstance(){return this.instance}};const p={name:`api`,install(e,t={}){let n={baseURL:`/`,timeout:0,...t.config},r=t?.instance||new f(n).getInstance();e.api=l({config:n,controllers:new Map,instance:null,request:(e,t={})=>r.request({url:e,isOriginalData:!1,isShowFailMsg:!0,isCancelRequest:!0,...t}),getUserInfoApi:()=>e.api.request(`/getUserInfo`,{method:`GET`}),getRoutesApi:()=>e.api.request(`/routes`,{method:`GET`})},t)}},m={name:`app`,install(e,t={}){e.app=l({menuData:[],allRoutes:[],microApps:[],microAppsInstance:new Map,user:null,permissions:[],roles:[],settings:{},clearData:()=>{e.app.menuData=[],e.app.allRoutes=e.app.allRoutes.filter(e=>e.path!==`/`),e.app.microApps=[],e.app.microAppsInstance.forEach(e=>e.unmount()),e.app.microAppsInstance.clear(),e.app.user=null,e.app.permissions=[],e.app.roles=[],e.app.settings={}},pageToLogin:()=>{e.storage.clearToken();let t=window.location.pathname||`/`,n=e.config.loginPath,r=t===n?n:`${n}?redirect=${encodeURIComponent(t)}`;e.config.qiankunMode===`router`?window.location.replace(r):(e.app.clearData(),e.client.navigate(r,{replace:!0}))},getRedirectPath:()=>{let t=e.config.defaultPath;if(t)return t;let n=new URLSearchParams(window.location.search);return decodeURIComponent(n.get(`redirect`)||``)||`/`}},t)}},h=`client`,g={name:h,install(e,t={}){e[h]=l({location:null,navigate:null,matches:null},t)}},_=`config`,v={name:_,install(e,t={}){e[_]=l({env:{},qiankunMode:`router`,theme:null,locale:null,loginPath:`/login`,defaultPath:``,customRoutes:[],antdConfig:{},proLayoutConfig:{title:`Demo`}},t)}},y=`i18n`,b={name:y,install(e,t={}){e[y]=l({intl:n,intlConfig:{},loadLocale:e=>void 0},t)}},x=`storage`,S={name:x,install(e,t={}){e[x]=l({localeKey:`locale`,themeKey:`theme`,tokenKey:`token`,getLocale:()=>localStorage.getItem(e.storage.localeKey),setLocale:t=>{localStorage.setItem(e.storage.localeKey,t)},clearLocale:()=>{localStorage.removeItem(e.storage.localeKey)},getTheme:()=>localStorage.getItem(e.storage.themeKey),setTheme:t=>{localStorage.setItem(e.storage.themeKey,t)},clearTheme:()=>{localStorage.removeItem(e.storage.themeKey)},getToken:()=>localStorage.getItem(e.storage.tokenKey),setToken:t=>{localStorage.setItem(e.storage.tokenKey,t)},clearToken:()=>{localStorage.removeItem(e.storage.tokenKey)}},t)}},C=(e,t)=>({initState:{},setInitState:t=>{e(()=>({initState:t})),o.app={...o.app,...t}}}),w=(e,t)=>({locale:null,setLocale:t=>{e(()=>({locale:t})),o.config.locale=t,o.storage.setLocale(t),document.documentElement.setAttribute(`lang`,t);let r=o.i18n.intlConfig;n.init({currentLocale:t,locales:r});try{let e=o.i18n.loadLocale?.(t)||void 0;o.config.antdConfig.locale=e}catch(e){console.error(`sdk.i18n.loadLocale error:`,e)}}}),T=(e,t)=>({microAppLoading:!1,setMicroAppLoading:t=>e(()=>({microAppLoading:t}))}),E=(e,t)=>({theme:null,setTheme:t=>{e(()=>({theme:t})),o.config.theme=t,o.storage.setTheme(t),document.documentElement.setAttribute(`theme`,t)}}),D=r()(i((...e)=>({...C(...e),...w(...e),...T(...e),...E(...e)}))),O=`store`,k={name:O,install(e,t={}){e[O]=D}},A={name:`ui`,install(e,t={}){e.ui=l({getComponent:t=>{if(!t)throw Error(`Sdk: Component name cannot be empty`);return e.ui[t]},renderComponent:(t,n={})=>{let r=e.ui.getComponent(t);if(!r)throw Error(`Sdk: Component ${t} not found`);return a(r,n)}},t)}};export{p as SdkApiPlugin,m as SdkAppPlugin,g as SdkClientPlugin,v as SdkConfigPlugin,b as SdkI18nPlugin,S as SdkStoragePlugin,k as SdkStorePlugin,A as SdkUIPlugin,o as sdk};
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["pluginName","SdkApiPlugin: Plugin<'api'>","Http","options","sdk","pluginName","SdkAppPlugin: Plugin<'app'>","sdk","pluginName","SdkClientPlugin: Plugin<'client'>","pluginName","SdkConfigPlugin: Plugin<'config'>","pluginName","SdkStoragePlugin: Plugin<'storage'>","sdk","createInitStateSlice: StateCreator<InitStateStoreProps>","createLocaleSlice: StateCreator<LocaleStoreProps>","createMicroAppStateSlice: StateCreator<MicroAppStateStoreProps>","createThemeSlice: StateCreator<ThemeStoreProps>","SdkStorePlugin: Plugin<'store'>"],"sources":["../src/core/index.ts","../../node_modules/.pnpm/es-toolkit@1.42.0/node_modules/es-toolkit/dist/predicate/isPlainObject.mjs","../../node_modules/.pnpm/es-toolkit@1.42.0/node_modules/es-toolkit/dist/_internal/isUnsafeProperty.mjs","../../node_modules/.pnpm/es-toolkit@1.42.0/node_modules/es-toolkit/dist/object/merge.mjs","../src/utils/request.ts","../src/plugins/api/http.ts","../src/plugins/api/index.ts","../src/plugins/app/index.tsx","../src/plugins/client/index.ts","../src/plugins/config/index.ts","../src/plugins/storage/index.ts","../src/plugins/store/createInitState.ts","../src/plugins/store/createLocale.ts","../src/plugins/store/createMicroAppLoading.ts","../src/plugins/store/createTheme.ts","../src/plugins/store/index.ts"],"sourcesContent":["import type { Plugin, PluginOptions, SdkResult } from '@/types';\n\nclass Sdk implements SdkResult {\n name: SdkResult['name'];\n _plugins: SdkResult['_plugins'];\n\n api: SdkResult['api'];\n app: SdkResult['app'];\n client: SdkResult['client'];\n config: SdkResult['config'];\n storage: SdkResult['storage'];\n store: SdkResult['store'];\n\n constructor() {\n this.name = '';\n this._plugins = new Map();\n }\n\n mount(name: string) {\n if (window[name]) throw new Error(`The SDK already exists - ${name}`);\n console.log('%c SDK mounted:', 'color: pink; font-weight: bold;', name);\n\n // 设置名称\n this.name = name;\n\n // 使用 new Proxy 禁止控制台对sdk属性的操作 (仅第一层属性)\n const _this = new Proxy(this, {\n get: (target, key, receiver) => {\n if (!target) return null;\n return Reflect.get(target, key, receiver);\n },\n set: () => {\n console.error('The SDK cannot be modified.');\n return false;\n },\n deleteProperty: () => {\n console.error('The SDK cannot be deleted.');\n return false;\n },\n });\n\n // 挂载到 Window 上\n window[this.name] = _this;\n }\n\n extend(name: string) {\n if (!window[name]) throw new Error(`The SDK not found - ${name}`);\n console.log('%c SDK extended:', 'color: pink; font-weight: bold;', name);\n\n // 合并实例属性\n Object.assign(this, window[name]);\n }\n\n use<K extends keyof PluginOptions>(\n plugin: Plugin<K>,\n options?: PluginOptions[K],\n ) {\n const { name, install } = plugin;\n\n if (!name) throw new Error(`${name} plugin has no name`);\n\n if (typeof install !== 'function')\n throw new Error(`${name} plugin is not a function`);\n\n // 插件安装\n install(this, options);\n\n // 添加到插件列表\n this._plugins.set(name, { ...plugin, options });\n\n // 链式调用\n return this;\n }\n}\n\n/**\n * sdk 实例\n */\nconst sdk = new Sdk();\n\nexport { sdk };\n","function isPlainObject(value) {\n if (!value || typeof value !== 'object') {\n return false;\n }\n const proto = Object.getPrototypeOf(value);\n const hasObjectPrototype = proto === null ||\n proto === Object.prototype ||\n Object.getPrototypeOf(proto) === null;\n if (!hasObjectPrototype) {\n return false;\n }\n return Object.prototype.toString.call(value) === '[object Object]';\n}\n\nexport { isPlainObject };\n","function isUnsafeProperty(key) {\n return key === '__proto__';\n}\n\nexport { isUnsafeProperty };\n","import { isUnsafeProperty } from '../_internal/isUnsafeProperty.mjs';\nimport { isPlainObject } from '../predicate/isPlainObject.mjs';\n\nfunction merge(target, source) {\n const sourceKeys = Object.keys(source);\n for (let i = 0; i < sourceKeys.length; i++) {\n const key = sourceKeys[i];\n if (isUnsafeProperty(key)) {\n continue;\n }\n const sourceValue = source[key];\n const targetValue = target[key];\n if (Array.isArray(sourceValue)) {\n if (Array.isArray(targetValue)) {\n target[key] = merge(targetValue, sourceValue);\n }\n else {\n target[key] = merge([], sourceValue);\n }\n }\n else if (isPlainObject(sourceValue)) {\n if (isPlainObject(targetValue)) {\n target[key] = merge(targetValue, sourceValue);\n }\n else {\n target[key] = merge({}, sourceValue);\n }\n }\n else if (targetValue === undefined || sourceValue !== undefined) {\n target[key] = sourceValue;\n }\n }\n return target;\n}\n\nexport { merge };\n","import { sdk } from '@/core';\nimport type { ApiRequestOption } from '@/plugins/api/http';\nimport type { AxiosResponse } from 'axios';\n\n/**\n * 生成请求id\n * @param config\n */\nexport const generateRequestIdUtil = (config: any) => {\n const { requestId, url, method, params, data } = config as ApiRequestOption;\n if (requestId) return requestId;\n\n return `${method}:${url}?${JSON.stringify(params)}&${JSON.stringify(data)}`;\n};\n\n/**\n * 取消请求\n * @param config 请求配置\n */\nexport const cancelRequestUtil = (config: any) => {\n const requestId = generateRequestIdUtil(config);\n\n const controller = sdk.api.controllers.get(requestId);\n if (!controller) return;\n\n controller.abort();\n sdk.api.controllers.delete(requestId);\n};\n\n/**\n * 下载文件\n * @param resp 响应数据\n */\nexport const downloadFileUtil = (resp: AxiosResponse) => {\n // 1. 从响应头中解析文件名\n const contentDisposition = resp.headers['content-disposition'];\n let filename = 'data.txt';\n\n if (contentDisposition) {\n // 使用正则匹配文件名(兼容带引号和不带引号的情况)\n const filenameMatch = contentDisposition.match(/filename=\"?(.+)\"?/);\n if (filenameMatch && filenameMatch[1]) {\n filename = filenameMatch[1];\n }\n }\n\n // 2. 创建 blob 对象\n const blob = new Blob([resp.data], { type: 'application/pdf' });\n\n // 3. 创建下载链接\n const url = window.URL.createObjectURL(blob);\n const link = document.createElement('a');\n link.href = url;\n link.download = filename; // Specify the file name\n document.body.appendChild(link);\n link.click();\n\n // 4. 释放 blob 对象\n window.URL.revokeObjectURL(url);\n document.body.removeChild(link);\n};\n","import { sdk } from '@/core';\nimport { cancelRequestUtil, generateRequestIdUtil } from '@/utils';\nimport { message } from 'antd';\nimport axios, {\n AxiosError,\n type AxiosInstance,\n type AxiosRequestConfig,\n type AxiosResponse,\n type CreateAxiosDefaults,\n type InternalAxiosRequestConfig,\n} from 'axios';\nimport { merge } from 'es-toolkit';\n\nexport interface ApiRequestOption extends AxiosRequestConfig {\n /** 请求唯一key(默认自动生成) */\n requestId?: string;\n /** 是否取消重复请求 */\n isCancelRequest?: boolean;\n /** 是否需要原始数据 */\n isOriginalData?: boolean;\n /** 是否显示错误信息 */\n isShowFailMsg?: boolean;\n}\n\n/** 请求类 */\nclass Http {\n instance: AxiosInstance;\n\n constructor(options: CreateAxiosDefaults = {}) {\n this.instance = axios.create(options); // 创建实例\n this.defaultRequestInterceptor(); // 添加默认请求拦截器\n this.defaultResponseInterceptor(); // 添加默认响应拦截器\n }\n\n /** 默认请求拦截器 */\n defaultRequestInterceptor() {\n this.instance.interceptors.request.use(\n function (config: InternalAxiosRequestConfig) {\n // @ts-ignore\n if (config?.isCancelRequest) {\n const requestId = generateRequestIdUtil(config); // 设置请求唯一标识\n cancelRequestUtil(config); // 取消重复请求\n const controller = new AbortController(); // 创建取消请求控制器\n sdk.api.controllers.set(requestId, controller); // 存储取消请求控制器\n\n config['requestId'] = requestId; // 记录请求id\n config.signal = controller.signal; // 取消请求标识\n }\n\n const token = sdk.storage.getToken();\n config.headers.lang = sdk.config.locale; // 添加语言到请求头\n config.headers.Authorization = token; // 添加token到请求头\n merge(config.headers, sdk.api.config.headers || {}); // 合并请求头\n return config;\n },\n function (error: AxiosError) {\n console.error(`请求错误`);\n return Promise.reject(error);\n },\n );\n }\n\n /** 默认响应拦截器 */\n defaultResponseInterceptor() {\n this.instance.interceptors.response.use(\n function (response: AxiosResponse) {\n const { data, config } = response;\n const { isOriginalData, isShowFailMsg, isCancelRequest } =\n config as ApiRequestOption;\n\n const { code, msg } = data;\n\n // 跟后端定义的成功标识 非0的都是失败\n if (code !== 0) {\n if (isShowFailMsg) message.error(msg);\n console.error('response error: ', config.url, msg);\n\n if (code == 20041) sdk.app.pageToLogin(); // 登录过期,跳转登录页\n }\n\n if (isCancelRequest) sdk.api.controllers.delete(config['requestId']);\n\n return isOriginalData ? response : response.data;\n },\n function (error: AxiosError) {\n const { response, config } = error;\n const { isShowFailMsg } = config as ApiRequestOption;\n\n // 如果是取消请求,则不显示错误信息\n if (axios.isCancel(error)) return Promise.reject(error);\n\n if (response) {\n // 请求成功发出且服务器也响应了状态码,但状态代码超出了 2xx 的范围\n const { status, data, statusText } = response as AxiosResponse;\n\n if (isShowFailMsg) message.error(data.msg || statusText);\n\n if (status == 401) sdk.app.pageToLogin(); // 登录过期,跳转登录页\n } else {\n // 请求已经成功发起,但没有收到响应\n if (isShowFailMsg)\n message.error('请求超时或服务器异常,请检查网络或联系管理员');\n\n console.error('Request error:', config.url, error);\n }\n\n return Promise.reject(error);\n },\n );\n }\n\n /** 获取实例 */\n getInstance() {\n return this.instance;\n }\n}\n\nexport default Http;\n","import type { Plugin, UserInfo } from '@/types';\nimport {\n type AxiosInstance,\n type AxiosResponse,\n type CreateAxiosDefaults,\n} from 'axios';\nimport { merge } from 'es-toolkit';\nimport type { RouteObject } from 'react-router-dom';\nimport Http, { type ApiRequestOption } from './http';\n\ninterface ApiOptions {\n /** Axios配置 */\n config?: CreateAxiosDefaults;\n\n /** 取消请求控制器 */\n controllers?: Map<string, AbortController>;\n\n /**\n * 自定义请求实例\n * - 替换 SDK 内置的请求实例\n * @example instance = axios.create(options)\n */\n instance?: AxiosInstance;\n\n /**\n * 获取用户信息\n * {@link UserInfo}\n * @example { data: { user: { ... }, permissions: [], roles: [], settings: {} }, code: 200 }\n */\n getUserInfoApi?: () => Promise<AxiosResponse<UserInfo>>;\n /**\n * 获取路由数据\n * {@link RouteObject}\n * @example { data: [{path: '/', name: '首页', element: 'Home'}], code: 200 }\n */\n getRoutesApi?: () => Promise<AxiosResponse<RouteObject[]>>;\n}\n\ninterface ApiResults extends Required<ApiOptions> {\n /**\n * 请求\n * @param url 请求地址\n * @param options 自定义配置项\n */\n readonly request: (\n url: string,\n options?: ApiRequestOption,\n ) => Promise<AxiosResponse<any, any>>;\n}\n\n/** 插件名称 */\nconst pluginName = 'api';\n\n/**\n * 请求插件\n * - 详情参考 {@link ApiOptions} {@link ApiResults}\n * - 内置了请求, 通过 sdk.api.request 发起请求\n * - 可通过外部传入 instance 自定义请求实例\n * - 预置了获取用户信息, 获取路由接口, 以便组件使用\n * @example sdk.api.request('/getTemp', { method: 'POST', ... })\n * @example sdk.api.request('/getTemp', { method: 'POST', isOriginalData: true }) // 返回原始数据\n * @example sdk.api.request('/getTemp', { method: 'POST', isShowFailMsg: false }) // 不显示错误信息\n * @example sdk.api.request('/getTemp', { method: 'POST', isCancelRequest: false }) // 不自动取消重复请求\n */\nconst SdkApiPlugin: Plugin<'api'> = {\n name: pluginName,\n install(sdk, options = {}) {\n // Axios 配置\n const axiosConfig = {\n baseURL: '/',\n timeout: 0,\n ...options.config,\n } satisfies ApiOptions['config'];\n\n // 创建 Axios 实例\n const instance = options?.instance || new Http(axiosConfig).getInstance();\n\n // 默认插件配置\n const defaultOptions = {\n config: axiosConfig,\n controllers: new Map(),\n\n instance: null,\n\n request: (url, options = {}) => {\n return instance.request({\n url,\n isOriginalData: false,\n isShowFailMsg: true,\n isCancelRequest: true,\n ...options,\n });\n },\n\n getUserInfoApi: () => sdk.api.request('/getUserInfo', { method: 'GET' }),\n getRoutesApi: () => sdk.api.request('/routes', { method: 'GET' }),\n } satisfies ApiResults;\n\n sdk[pluginName] = merge(defaultOptions, options);\n },\n};\n\nexport { SdkApiPlugin };\nexport type { ApiOptions, ApiResults };\n","import type { Plugin, UserInfo } from '@/types';\nimport type { MenuDataItem } from '@ant-design/pro-layout';\nimport { merge } from 'es-toolkit';\nimport type { MicroApp, ObjectType, RegistrableApp } from 'qiankun';\nimport type { RouteObject } from 'react-router-dom';\n\ninterface AppOptions {\n /** 菜单数据 */\n menuData?: MenuDataItem[];\n /** 所有路由信息 */\n allRoutes?: RouteObject[];\n\n /** 微应用信息 */\n microApps?: RegistrableApp<ObjectType>[];\n /** 微应用实例 */\n microAppsInstance?: Map<string, MicroApp>;\n\n /** 用户信息 */\n user?: UserInfo['user'];\n /** 用户权限 */\n permissions?: UserInfo['permissions'];\n /** 用户角色 */\n roles?: UserInfo['roles'];\n /** 用户设置 */\n settings?: UserInfo['settings'];\n}\n\ninterface AppResults extends Required<AppOptions> {\n /**\n * 清空数据\n */\n clearData(): void;\n /**\n * 跳转登录页\n */\n pageToLogin(): void;\n /**\n * 获取重定向路径\n */\n getRedirectPath(): string;\n}\n\n/** 插件名称 */\nconst pluginName = 'app';\n\n/**\n * 项目信息\n * - 详情参考 {@link AppOptions} {@link AppResults}\n * - 菜单信息 sdk.app.menuData\n * - 路由信息 sdk.app.allRoutes\n * - 微应用信息 sdk.app.microApps\n * - 用户信息 sdk.app.user\n * - 用户权限 sdk.app.permissions\n * - 用户角色 sdk.app.roles\n * - 用户设置 sdk.app.settings\n */\nconst SdkAppPlugin: Plugin<'app'> = {\n name: pluginName,\n install(sdk, options = {}) {\n // 默认插件配置\n const defaultOptions = {\n menuData: [],\n allRoutes: [],\n\n microApps: [],\n microAppsInstance: new Map(),\n\n user: null,\n permissions: [],\n roles: [],\n settings: {},\n\n clearData: () => {\n sdk.app.menuData = [];\n sdk.app.allRoutes = sdk.app.allRoutes.filter((_) => _.path !== '/');\n\n sdk.app.microApps = [];\n sdk.app.microAppsInstance.forEach((_) => _.unmount());\n sdk.app.microAppsInstance.clear();\n\n sdk.app.user = null;\n sdk.app.permissions = [];\n sdk.app.roles = [];\n sdk.app.settings = {};\n },\n pageToLogin: () => {\n // 清除 Token\n sdk.storage.clearToken();\n\n // 获取当前页路由\n const pathname = window.location.pathname || '/';\n const loginPath = sdk.config.loginPath;\n const path =\n pathname === loginPath\n ? loginPath\n : `${loginPath}?redirect=${encodeURIComponent(pathname)}`;\n\n // 跳转登录页\n if (sdk.config.qiankunMode === 'router') {\n window.location.replace(path); // 这里必须刷新一下页面, 否则qiankun实例不会销毁, 登录后会直接mount子应用, 而不是bootstrap子应用\n } else {\n sdk.app.clearData(); // 手动清空数据\n sdk.client.navigate(path, { replace: true }); // 使用客户端路由跳转\n }\n },\n getRedirectPath: () => {\n // 1. 优先使用指定值\n const defaultPath = sdk.config.defaultPath;\n if (defaultPath) return defaultPath;\n\n // 2. 其次使用重定向的值\n const param = new URLSearchParams(window.location.search);\n const redirect = decodeURIComponent(param.get('redirect') || '');\n if (redirect) return redirect;\n\n // 3. 最后使用菜单中第一项\n return '/';\n },\n } satisfies AppResults;\n\n sdk[pluginName] = merge(defaultOptions, options);\n },\n};\n\nexport { SdkAppPlugin };\nexport type { AppOptions, AppResults };\n","import type { Plugin } from '@/types';\nimport { merge } from 'es-toolkit';\nimport type { Location, NavigateFunction, UIMatch } from 'react-router-dom';\n\ninterface ClientOptions {}\n\ninterface ClientResults extends Required<ClientOptions> {\n /** 主应用 location */\n location: Location;\n /** 主应用navigate(解决子应用跳转问题) */\n navigate: NavigateFunction;\n /** 路由匹配(用于面包屑) */\n matches: UIMatch[];\n}\n\n/** 插件名称 */\nconst pluginName = 'client';\n\n/**\n * 全局路由信息\n * - 详情参考 {@link ClientOptions} {@link ClientResults}\n * - 路由信息 sdk.client.location\n * - 路由跳转 sdk.client.navigate\n * - 面包屑信息 sdk.client.matches\n */\nconst SdkClientPlugin: Plugin<'client'> = {\n name: pluginName,\n install(sdk, options = {}) {\n // 默认插件配置\n const defaultOptions = {\n location: null,\n navigate: null,\n matches: null,\n } satisfies ClientResults;\n\n sdk[pluginName] = merge(defaultOptions, options);\n },\n};\n\nexport { SdkClientPlugin };\nexport type { ClientOptions, ClientResults };\n","import type { LocaleProps, Plugin, ThemeProps } from '@/types';\nimport type { ProLayoutProps } from '@ant-design/pro-layout';\nimport type { ConfigProviderProps } from 'antd';\nimport { merge } from 'es-toolkit';\nimport type { RouteObject } from 'react-router-dom';\n\ninterface ConfigOptions {\n /** 环境变量(主应用共享给子应用变量) */\n env?: Record<string, any>;\n\n /** 主题 */\n theme?: ThemeProps;\n /** 国际化 */\n locale?: LocaleProps;\n\n /**\n * Qiankun模式(切换模式后请重新打开页面)\n * - router: 基于路由模式\n * - load: 手动加载模式\n */\n qiankunMode?: 'router' | 'load';\n\n /** 登录页路由 */\n loginPath?: string;\n /**\n * 登录后跳转的路由\n * - 优先使用指定值\n * - 其次使用重定向的值\n * - 最后使用菜单中第一项\n */\n defaultPath?: string;\n /**\n * 自定义路由信息\n * - 目前只支持最外层路由自定义\n * - 会合并到 sdk.app.allRoutes 中\n */\n customRoutes?: RouteObject[];\n\n /** Antd 配置 */\n antdConfig?: ConfigProviderProps;\n /** ProLayout 配置 */\n proLayoutConfig?: ProLayoutProps;\n}\n\ninterface ConfigResults extends Required<ConfigOptions> {}\n\n/** 插件名称 */\nconst pluginName = 'config';\n\n/**\n * Sdk 配置信息\n * - 详情参考 {@link ConfigOptions} {@link ConfigResults}\n * - 配置 env 环境变量\n * - 配置 默认主题、国际化\n * - 配置 Qiankun 模式\n * - 配置 默认登录路径、跳转路径、自定义路由\n * - 配置 Antd 配置、ProLayout 配置\n */\nconst SdkConfigPlugin: Plugin<'config'> = {\n name: pluginName,\n install(sdk, options = {}) {\n // 默认插件配置\n const defaultOptions = {\n env: {},\n\n qiankunMode: 'router',\n\n theme: null,\n locale: null,\n\n loginPath: '/login',\n defaultPath: '',\n customRoutes: [],\n\n antdConfig: {},\n proLayoutConfig: {\n title: 'Demo',\n },\n } satisfies ConfigResults;\n\n sdk[pluginName] = merge(defaultOptions, options);\n },\n};\n\nexport { SdkConfigPlugin };\nexport type { ConfigOptions, ConfigResults };\n","import type { LocaleProps, Plugin, ThemeProps } from '@/types';\nimport { merge } from 'es-toolkit';\n\ninterface StorageOptions {\n /** 国际化存储名称 */\n localeKey?: string;\n /** 主题存储名称 */\n themeKey?: string;\n /** Token存储名称 */\n tokenKey?: string;\n}\n\ninterface StorageResults extends Required<StorageOptions> {\n /** 获取当前国际化 */\n getLocale(): LocaleProps;\n /** 设置/切换切换国际化 */\n setLocale(locale: LocaleProps): void;\n /** 清空国际化 */\n clearLocale(): void;\n\n /** 获取当前主题 */\n getTheme(): ThemeProps;\n /** 设置/切换主题 */\n setTheme(theme: ThemeProps): void;\n /** 清空主题 */\n clearTheme(): void;\n\n /** 获取当前 Token */\n getToken(): string;\n /** 设置 Token */\n setToken(token: string): void;\n /** 清空 Token */\n clearToken(): void;\n}\n\n/** 插件名称 */\nconst pluginName = 'storage';\n\n/**\n * 本地缓存\n * - 详情参考 {@link StorageOptions} {@link StorageResults}\n * - 配置 localStorage 变量名称\n * - 提供 国际化、主题、Token 的 get、change、clear 方法\n * @example sdk.storage.getToken() // 获取 Token\n * @example sdk.storage.setTheme('dark') // 设置主题\n * @example sdk.storage.clearLocale() // 清空国际化\n */\nconst SdkStoragePlugin: Plugin<'storage'> = {\n name: pluginName,\n install(sdk, options = {}) {\n // 默认插件配置\n const defaultOptions = {\n localeKey: 'locale',\n themeKey: 'theme',\n tokenKey: 'token',\n\n getLocale: () => {\n return localStorage.getItem(sdk.storage.localeKey);\n },\n setLocale: (locale: string) => {\n localStorage.setItem(sdk.storage.localeKey, locale);\n },\n clearLocale: () => {\n localStorage.removeItem(sdk.storage.localeKey);\n },\n getTheme: () => {\n return localStorage.getItem(sdk.storage.themeKey);\n },\n setTheme: (theme: string) => {\n localStorage.setItem(sdk.storage.themeKey, theme);\n },\n clearTheme: () => {\n localStorage.removeItem(sdk.storage.themeKey);\n },\n getToken: () => {\n return localStorage.getItem(sdk.storage.tokenKey);\n },\n setToken: (token: string) => {\n localStorage.setItem(sdk.storage.tokenKey, token);\n },\n clearToken: () => {\n localStorage.removeItem(sdk.storage.tokenKey);\n },\n } satisfies StorageResults;\n\n sdk[pluginName] = merge(defaultOptions, options);\n },\n};\n\nexport { SdkStoragePlugin };\nexport type { StorageOptions, StorageResults };\n","import { sdk } from '@/core';\nimport type { UserInfo } from '@/types';\nimport type { StateCreator } from 'zustand';\n\ninterface InitStateStoreProps {\n /** 初始变量 */\n initState: UserInfo;\n /** 设置初始变量 */\n setInitState: (initState: UserInfo) => void;\n}\n\n/** 初始变量状态 */\nconst createInitStateSlice: StateCreator<InitStateStoreProps> = (set, get) => ({\n initState: {},\n setInitState: (initState) => {\n set(() => ({ initState }));\n sdk.app = { ...sdk.app, ...initState };\n },\n});\n\nexport { createInitStateSlice };\nexport type { InitStateStoreProps };\n","import { sdk } from '@/core';\nimport type { LocaleProps } from '@/types';\nimport type { StateCreator } from 'zustand';\n\ninterface LocaleStoreProps {\n /** 国际化 */\n locale: LocaleProps;\n /** 设置国际化 */\n setLocale: (locale: LocaleProps) => void;\n}\n\n/** 国际化状态 */\nconst createLocaleSlice: StateCreator<LocaleStoreProps> = (set, get) => ({\n locale: null,\n\n setLocale: (locale) => {\n set(() => ({ locale })); // 自动合并其他\n\n // 记录值\n sdk.config.locale = locale;\n sdk.storage.setLocale(locale);\n\n // 设置作用域\n document.documentElement.setAttribute('lang', locale);\n },\n});\n\nexport { createLocaleSlice };\nexport type { LocaleStoreProps };\n","import type { StateCreator } from 'zustand';\n\ninterface MicroAppStateStoreProps {\n /** 子应用加载状态 */\n microAppLoading: boolean;\n /** 设置子应用加载状态 */\n setMicroAppLoading: (state: boolean) => void;\n}\n\n/** 子应用状态 */\nconst createMicroAppStateSlice: StateCreator<MicroAppStateStoreProps> = (\n set,\n get,\n) => ({\n microAppLoading: false,\n setMicroAppLoading: (microAppLoading) => set(() => ({ microAppLoading })),\n});\n\nexport { createMicroAppStateSlice };\nexport type { MicroAppStateStoreProps };\n","import { sdk } from '@/core';\nimport type { ThemeProps } from '@/types';\nimport type { StateCreator } from 'zustand';\n\ninterface ThemeStoreProps {\n /** 主题 */\n theme: ThemeProps;\n /** 设置主题 */\n setTheme: (theme: ThemeProps) => void;\n}\n\n/** 主题状态 */\nconst createThemeSlice: StateCreator<ThemeStoreProps> = (set, get) => ({\n theme: null,\n\n setTheme: (theme) => {\n set(() => ({ theme })); // 自动合并其他\n\n // 记录值\n sdk.config.theme = theme;\n sdk.storage.setTheme(theme);\n\n // 设置作用域\n document.documentElement.setAttribute('theme', theme);\n },\n});\n\nexport { createThemeSlice };\nexport type { ThemeStoreProps };\n","import type { Plugin } from '@/types';\nimport { createStore } from 'zustand';\nimport { subscribeWithSelector } from 'zustand/middleware';\nimport {\n createInitStateSlice,\n type InitStateStoreProps,\n} from './createInitState';\nimport { createLocaleSlice, type LocaleStoreProps } from './createLocale';\nimport {\n createMicroAppStateSlice,\n type MicroAppStateStoreProps,\n} from './createMicroAppLoading';\nimport { createThemeSlice, type ThemeStoreProps } from './createTheme';\n\ntype StoreOptions = InitStateStoreProps &\n LocaleStoreProps &\n MicroAppStateStoreProps &\n ThemeStoreProps;\n\ntype StoreResults = typeof globalStore;\n\n/**\n * 创建 Store\n * - 这里单独声明变量, 主要是为了使用返回类型 StoreResults 🤔\n */\nconst globalStore = createStore<StoreOptions>()(\n subscribeWithSelector((...a) => ({\n ...createInitStateSlice(...a),\n ...createLocaleSlice(...a),\n ...createMicroAppStateSlice(...a),\n ...createThemeSlice(...a),\n })),\n);\n\n/** 插件名称 */\nconst pluginName = 'store';\n\n/**\n * 全局状态管理\n * - 详情参考 {@link StoreOptions} {@link StoreResults}\n * - 此插件不会合并传入属性\n * @example const setTheme = useStore(sdk.store, (state) => state.setTheme)\n * @example const { theme, setTheme } = useStore(sdk.store, useShallow((state) => { theme: state.theme, setTheme: state.setTheme }))\n * @example const [theme, setTheme] = useStore(sdk.store, useShallow((state) => [state.theme, state.setTheme]))\n * @example sdk.store?.getState()?.setTheme('light')\n * @example sdk.store.subscribe((state) => state.theme, (theme) => { console.log('theme', theme) }, { fireImmediately: true }) // fireImmediately 立即变更\n */\nconst SdkStorePlugin: Plugin<'store'> = {\n name: pluginName,\n install(sdk, options = {}) {\n sdk[pluginName] = globalStore satisfies StoreResults;\n },\n};\n\nexport { SdkStorePlugin };\nexport type { StoreOptions, StoreResults };\n"],"x_google_ignoreList":[1,2,3],"mappings":"qJA8EA,MAAM,EAAM,IA5EZ,KAA+B,CAC7B,KACA,SAEA,IACA,IACA,OACA,OACA,QACA,MAEA,aAAc,CACZ,KAAK,KAAO,GACZ,KAAK,SAAW,IAAI,IAGtB,MAAM,EAAc,CAClB,GAAI,OAAO,GAAO,MAAU,MAAM,4BAA4B,IAAO,CACrE,QAAQ,IAAI,kBAAmB,kCAAmC,EAAK,CAGvE,KAAK,KAAO,EAGZ,IAAM,EAAQ,IAAI,MAAM,KAAM,CAC5B,KAAM,EAAQ,EAAK,IACZ,EACE,QAAQ,IAAI,EAAQ,EAAK,EAAS,CAD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O,OAAS,EACpB,EAAI,QAAQ,UAAU,EAAO,CAG7B,SAAS,gBAAgB,aAAa,OAAQ,EAAO,EAExD,ECfKC,GACJ,EACA,KACI,CACJ,gBAAiB,GACjB,mBAAqB,GAAoB,OAAW,CAAE,kBAAiB,EAAE,CAC1E,ECJKC,GAAmD,EAAK,KAAS,CACrE,MAAO,KAEP,SAAW,GAAU,CACnB,OAAW,CAAE,QAAO,EAAE,CAGtB,EAAI,OAAO,MAAQ,EACnB,EAAI,QAAQ,SAAS,EAAM,CAG3B,SAAS,gBAAgB,aAAa,QAAS,EAAM,EAExD,ECAK,EAAc,GAA2B,CAC7C,GAAuB,GAAG,KAAO,CAC/B,GAAG,EAAqB,GAAG,EAAE,CAC7B,GAAG,EAAkB,GAAG,EAAE,CAC1B,GAAG,EAAyB,GAAG,EAAE,CACjC,GAAG,EAAiB,GAAG,EAAE,CAC1B,EAAE,CACJ,CAGK,EAAa,QAYbC,EAAkC,CACtC,KAAM,EACN,QAAQ,EAAK,EAAU,EAAE,CAAE,CACzB,EAAI,GAAc,GAErB"}
|
|
1
|
+
{"version":3,"file":"index.js","names":["pluginName","SdkApiPlugin: Plugin<'api'>","Http","options","sdk","pluginName","SdkAppPlugin: Plugin<'app'>","sdk","pluginName","SdkClientPlugin: Plugin<'client'>","pluginName","SdkConfigPlugin: Plugin<'config'>","pluginName","SdkI18nPlugin: Plugin<'i18n'>","pluginName","SdkStoragePlugin: Plugin<'storage'>","sdk","createInitStateSlice: StateCreator<InitStateStoreProps>","createLocaleSlice: StateCreator<LocaleStoreProps>","createMicroAppStateSlice: StateCreator<MicroAppStateStoreProps>","createThemeSlice: StateCreator<ThemeStoreProps>","pluginName","SdkStorePlugin: Plugin<'store'>","SdkUIPlugin: Plugin<'ui'>","sdk"],"sources":["../src/core/index.ts","../../node_modules/.pnpm/es-toolkit@1.42.0/node_modules/es-toolkit/dist/predicate/isPlainObject.mjs","../../node_modules/.pnpm/es-toolkit@1.42.0/node_modules/es-toolkit/dist/_internal/isUnsafeProperty.mjs","../../node_modules/.pnpm/es-toolkit@1.42.0/node_modules/es-toolkit/dist/object/merge.mjs","../src/utils/request.ts","../src/plugins/api/http.ts","../src/plugins/api/index.ts","../src/plugins/app/index.tsx","../src/plugins/client/index.ts","../src/plugins/config/index.ts","../src/plugins/i18n/index.ts","../src/plugins/storage/index.ts","../src/plugins/store/createInitState.ts","../src/plugins/store/createLocale.ts","../src/plugins/store/createMicroAppLoading.ts","../src/plugins/store/createTheme.ts","../src/plugins/store/index.ts","../src/plugins/ui/index.ts"],"sourcesContent":["import type { Plugin, PluginOptions, SdkResult } from '@/types';\n\nclass Sdk implements SdkResult {\n name: SdkResult['name'];\n _plugins: SdkResult['_plugins'];\n\n api: SdkResult['api'];\n app: SdkResult['app'];\n client: SdkResult['client'];\n config: SdkResult['config'];\n i18n: SdkResult['i18n'];\n storage: SdkResult['storage'];\n store: SdkResult['store'];\n ui: SdkResult['ui'];\n\n constructor() {\n this.name = '';\n this._plugins = new Map();\n }\n\n mount(name: string) {\n if (window[name]) throw new Error(`The SDK already exists - ${name}`);\n console.log('%c SDK mounted:', 'color: pink; font-weight: bold;', name);\n\n // 设置名称\n this.name = name;\n\n // 使用 new Proxy 禁止控制台对sdk属性的操作 (仅第一层属性)\n const _this = new Proxy(this, {\n get: (target, key, receiver) => {\n if (!target) return null;\n return Reflect.get(target, key, receiver);\n },\n set: () => {\n console.error('The SDK cannot be modified.');\n return false;\n },\n deleteProperty: () => {\n console.error('The SDK cannot be deleted.');\n return false;\n },\n });\n\n // 挂载到 Window 上\n window[this.name] = _this;\n }\n\n extend(name: string) {\n if (!window[name]) throw new Error(`The SDK not found - ${name}`);\n console.log('%c SDK extended:', 'color: pink; font-weight: bold;', name);\n\n // 合并实例属性\n Object.assign(this, window[name]);\n }\n\n use<K extends keyof PluginOptions>(\n plugin: Plugin<K>,\n options?: PluginOptions[K],\n ) {\n const { name, install } = plugin;\n\n if (!name) throw new Error(`${name} plugin has no name`);\n\n if (typeof install !== 'function')\n throw new Error(`${name} plugin is not a function`);\n\n // 插件安装\n install(this, options);\n\n // 添加到插件列表\n this._plugins.set(name, { ...plugin, options });\n\n // 链式调用\n return this;\n }\n}\n\n/**\n * sdk 实例\n */\nconst sdk = new Sdk();\n\nexport { sdk };\n","function isPlainObject(value) {\n if (!value || typeof value !== 'object') {\n return false;\n }\n const proto = Object.getPrototypeOf(value);\n const hasObjectPrototype = proto === null ||\n proto === Object.prototype ||\n Object.getPrototypeOf(proto) === null;\n if (!hasObjectPrototype) {\n return false;\n }\n return Object.prototype.toString.call(value) === '[object Object]';\n}\n\nexport { isPlainObject };\n","function isUnsafeProperty(key) {\n return key === '__proto__';\n}\n\nexport { isUnsafeProperty };\n","import { isUnsafeProperty } from '../_internal/isUnsafeProperty.mjs';\nimport { isPlainObject } from '../predicate/isPlainObject.mjs';\n\nfunction merge(target, source) {\n const sourceKeys = Object.keys(source);\n for (let i = 0; i < sourceKeys.length; i++) {\n const key = sourceKeys[i];\n if (isUnsafeProperty(key)) {\n continue;\n }\n const sourceValue = source[key];\n const targetValue = target[key];\n if (Array.isArray(sourceValue)) {\n if (Array.isArray(targetValue)) {\n target[key] = merge(targetValue, sourceValue);\n }\n else {\n target[key] = merge([], sourceValue);\n }\n }\n else if (isPlainObject(sourceValue)) {\n if (isPlainObject(targetValue)) {\n target[key] = merge(targetValue, sourceValue);\n }\n else {\n target[key] = merge({}, sourceValue);\n }\n }\n else if (targetValue === undefined || sourceValue !== undefined) {\n target[key] = sourceValue;\n }\n }\n return target;\n}\n\nexport { merge };\n","import { sdk } from '@/core';\nimport type { ApiRequestOption } from '@/plugins/api/http';\nimport type { AxiosResponse } from 'axios';\n\n/**\n * 生成请求id\n * @param config\n */\nexport const generateRequestIdUtil = (config: any) => {\n const { requestId, url, method, params, data } = config as ApiRequestOption;\n if (requestId) return requestId;\n\n return `${method}:${url}?${JSON.stringify(params)}&${JSON.stringify(data)}`;\n};\n\n/**\n * 取消请求\n * @param config 请求配置\n */\nexport const cancelRequestUtil = (config: any) => {\n const requestId = generateRequestIdUtil(config);\n\n const controller = sdk.api.controllers.get(requestId);\n if (!controller) return;\n\n controller.abort();\n sdk.api.controllers.delete(requestId);\n};\n\n/**\n * 下载文件\n * @param resp 响应数据\n */\nexport const downloadFileUtil = (resp: AxiosResponse) => {\n // 1. 从响应头中解析文件名\n const contentDisposition = resp.headers['content-disposition'];\n let filename = 'data.txt';\n\n if (contentDisposition) {\n // 使用正则匹配文件名(兼容带引号和不带引号的情况)\n const filenameMatch = contentDisposition.match(/filename=\"?(.+)\"?/);\n if (filenameMatch && filenameMatch[1]) {\n filename = filenameMatch[1];\n }\n }\n\n // 2. 创建 blob 对象\n const blob = new Blob([resp.data], { type: 'application/pdf' });\n\n // 3. 创建下载链接\n const url = window.URL.createObjectURL(blob);\n const link = document.createElement('a');\n link.href = url;\n link.download = filename; // Specify the file name\n document.body.appendChild(link);\n link.click();\n\n // 4. 释放 blob 对象\n window.URL.revokeObjectURL(url);\n document.body.removeChild(link);\n};\n","import { sdk } from '@/core';\nimport { cancelRequestUtil, generateRequestIdUtil } from '@/utils';\nimport { message } from 'antd';\nimport axios, {\n AxiosError,\n type AxiosInstance,\n type AxiosRequestConfig,\n type AxiosResponse,\n type CreateAxiosDefaults,\n type InternalAxiosRequestConfig,\n} from 'axios';\nimport { merge } from 'es-toolkit';\n\nexport interface ApiRequestOption extends AxiosRequestConfig {\n /** 请求唯一key(默认自动生成) */\n requestId?: string;\n /** 是否取消重复请求 */\n isCancelRequest?: boolean;\n /** 是否需要原始数据 */\n isOriginalData?: boolean;\n /** 是否显示错误信息 */\n isShowFailMsg?: boolean;\n}\n\n/** 请求类 */\nclass Http {\n instance: AxiosInstance;\n\n constructor(options: CreateAxiosDefaults = {}) {\n this.instance = axios.create(options); // 创建实例\n this.defaultRequestInterceptor(); // 添加默认请求拦截器\n this.defaultResponseInterceptor(); // 添加默认响应拦截器\n }\n\n /** 默认请求拦截器 */\n defaultRequestInterceptor() {\n this.instance.interceptors.request.use(\n function (config: InternalAxiosRequestConfig) {\n // @ts-ignore\n if (config?.isCancelRequest) {\n const requestId = generateRequestIdUtil(config); // 设置请求唯一标识\n cancelRequestUtil(config); // 取消重复请求\n const controller = new AbortController(); // 创建取消请求控制器\n sdk.api.controllers.set(requestId, controller); // 存储取消请求控制器\n\n config['requestId'] = requestId; // 记录请求id\n config.signal = controller.signal; // 取消请求标识\n }\n\n const token = sdk.storage.getToken();\n config.headers.lang = sdk.config.locale; // 添加语言到请求头\n config.headers.Authorization = token; // 添加token到请求头\n merge(config.headers, sdk.api.config.headers || {}); // 合并请求头\n return config;\n },\n function (error: AxiosError) {\n console.error(`请求错误`);\n return Promise.reject(error);\n },\n );\n }\n\n /** 默认响应拦截器 */\n defaultResponseInterceptor() {\n this.instance.interceptors.response.use(\n function (response: AxiosResponse) {\n const { data, config } = response;\n const { isOriginalData, isShowFailMsg, isCancelRequest } =\n config as ApiRequestOption;\n\n const { code, msg } = data;\n\n // 跟后端定义的成功标识 非0的都是失败\n if (code !== 0) {\n if (isShowFailMsg) message.error(msg);\n console.error('response error: ', config.url, msg);\n\n if (code == 20041) sdk.app.pageToLogin(); // 登录过期,跳转登录页\n }\n\n if (isCancelRequest) sdk.api.controllers.delete(config['requestId']);\n\n return isOriginalData ? response : response.data;\n },\n function (error: AxiosError) {\n const { response, config } = error;\n const { isShowFailMsg } = config as ApiRequestOption;\n\n // 如果是取消请求,则不显示错误信息\n if (axios.isCancel(error)) return Promise.reject(error);\n\n if (response) {\n // 请求成功发出且服务器也响应了状态码,但状态代码超出了 2xx 的范围\n const { status, data, statusText } = response as AxiosResponse;\n\n if (isShowFailMsg) message.error(data.msg || statusText);\n\n if (status == 401) sdk.app.pageToLogin(); // 登录过期,跳转登录页\n } else {\n // 请求已经成功发起,但没有收到响应\n if (isShowFailMsg)\n message.error('请求超时或服务器异常,请检查网络或联系管理员');\n\n console.error('Request error:', config.url, error);\n }\n\n return Promise.reject(error);\n },\n );\n }\n\n /** 获取实例 */\n getInstance() {\n return this.instance;\n }\n}\n\nexport default Http;\n","import type { Plugin, UserInfo } from '@/types';\nimport {\n type AxiosInstance,\n type AxiosResponse,\n type CreateAxiosDefaults,\n} from 'axios';\nimport { merge } from 'es-toolkit';\nimport type { RouteObject } from 'react-router-dom';\nimport Http, { type ApiRequestOption } from './http';\n\ninterface ApiOptions {\n /** Axios配置 */\n config?: CreateAxiosDefaults;\n\n /** 取消请求控制器 */\n controllers?: Map<string, AbortController>;\n\n /**\n * 自定义请求实例\n * - 替换 SDK 内置的请求实例\n * @example instance = axios.create(options)\n */\n instance?: AxiosInstance;\n\n /**\n * 获取用户信息\n * {@link UserInfo}\n * @example { data: { user: { ... }, permissions: [], roles: [], settings: {} }, code: 200 }\n */\n getUserInfoApi?(): Promise<AxiosResponse<UserInfo>>;\n /**\n * 获取路由数据\n * {@link RouteObject}\n * @example { data: [{path: '/', name: '首页', element: 'Home'}], code: 200 }\n */\n getRoutesApi?(): Promise<AxiosResponse<RouteObject[]>>;\n}\n\ninterface ApiResults extends Required<ApiOptions> {\n /**\n * 请求\n * @param url 请求地址\n * @param options 自定义配置项\n */\n request(\n url: string,\n options?: ApiRequestOption,\n ): Promise<AxiosResponse<any, any>>;\n}\n\n/** 插件名称 */\nconst pluginName = 'api';\n\n/**\n * 请求插件\n * - 详情参考 {@link ApiOptions} {@link ApiResults}\n * - 内置了请求, 通过 sdk.api.request 发起请求\n * - 可通过外部传入 instance 自定义请求实例\n * - 预置了获取用户信息, 获取路由接口, 以便组件使用\n * @example sdk.api.request('/getTemp', { method: 'POST', ... })\n * @example sdk.api.request('/getTemp', { method: 'POST', isOriginalData: true }) // 返回原始数据\n * @example sdk.api.request('/getTemp', { method: 'POST', isShowFailMsg: false }) // 不显示错误信息\n * @example sdk.api.request('/getTemp', { method: 'POST', isCancelRequest: false }) // 不自动取消重复请求\n */\nconst SdkApiPlugin: Plugin<'api'> = {\n name: pluginName,\n install(sdk, options = {}) {\n // Axios 配置\n const axiosConfig = {\n baseURL: '/',\n timeout: 0,\n ...options.config,\n } satisfies ApiOptions['config'];\n\n // 创建 Axios 实例\n const instance = options?.instance || new Http(axiosConfig).getInstance();\n\n // 默认插件配置\n const defaultOptions = {\n config: axiosConfig,\n controllers: new Map(),\n\n instance: null,\n\n request: (url, options = {}) => {\n return instance.request({\n url,\n isOriginalData: false,\n isShowFailMsg: true,\n isCancelRequest: true,\n ...options,\n });\n },\n\n getUserInfoApi: () => sdk.api.request('/getUserInfo', { method: 'GET' }),\n getRoutesApi: () => sdk.api.request('/routes', { method: 'GET' }),\n } satisfies ApiResults;\n\n sdk[pluginName] = merge(defaultOptions, options);\n },\n};\n\nexport { SdkApiPlugin };\nexport type { ApiOptions, ApiResults };\n","import type { Plugin, UserInfo } from '@/types';\nimport type { MenuDataItem } from '@ant-design/pro-layout';\nimport { merge } from 'es-toolkit';\nimport type { MicroApp, ObjectType, RegistrableApp } from 'qiankun';\nimport type { RouteObject } from 'react-router-dom';\n\ninterface AppOptions {\n /** 菜单数据 */\n menuData?: MenuDataItem[];\n /** 所有路由信息 */\n allRoutes?: RouteObject[];\n\n /** 微应用信息 */\n microApps?: RegistrableApp<ObjectType>[];\n /** 微应用实例 */\n microAppsInstance?: Map<string, MicroApp>;\n\n /** 用户信息 */\n user?: UserInfo['user'];\n /** 用户权限 */\n permissions?: UserInfo['permissions'];\n /** 用户角色 */\n roles?: UserInfo['roles'];\n /** 用户设置 */\n settings?: UserInfo['settings'];\n}\n\ninterface AppResults extends Required<AppOptions> {\n /**\n * 清空数据\n */\n clearData(): void;\n /**\n * 跳转登录页\n */\n pageToLogin(): void;\n /**\n * 获取重定向路径\n */\n getRedirectPath(): string;\n}\n\n/** 插件名称 */\nconst pluginName = 'app';\n\n/**\n * 项目信息\n * - 详情参考 {@link AppOptions} {@link AppResults}\n * - 菜单信息 sdk.app.menuData\n * - 路由信息 sdk.app.allRoutes\n * - 微应用信息 sdk.app.microApps\n * - 用户信息 sdk.app.user\n * - 用户权限 sdk.app.permissions\n * - 用户角色 sdk.app.roles\n * - 用户设置 sdk.app.settings\n */\nconst SdkAppPlugin: Plugin<'app'> = {\n name: pluginName,\n install(sdk, options = {}) {\n // 默认插件配置\n const defaultOptions = {\n menuData: [],\n allRoutes: [],\n\n microApps: [],\n microAppsInstance: new Map(),\n\n user: null,\n permissions: [],\n roles: [],\n settings: {},\n\n clearData: () => {\n sdk.app.menuData = [];\n sdk.app.allRoutes = sdk.app.allRoutes.filter((_) => _.path !== '/');\n\n sdk.app.microApps = [];\n sdk.app.microAppsInstance.forEach((_) => _.unmount());\n sdk.app.microAppsInstance.clear();\n\n sdk.app.user = null;\n sdk.app.permissions = [];\n sdk.app.roles = [];\n sdk.app.settings = {};\n },\n pageToLogin: () => {\n // 清除 Token\n sdk.storage.clearToken();\n\n // 获取当前页路由\n const pathname = window.location.pathname || '/';\n const loginPath = sdk.config.loginPath;\n const path =\n pathname === loginPath\n ? loginPath\n : `${loginPath}?redirect=${encodeURIComponent(pathname)}`;\n\n // 跳转登录页\n if (sdk.config.qiankunMode === 'router') {\n window.location.replace(path); // 这里必须刷新一下页面, 否则qiankun实例不会销毁, 登录后会直接mount子应用, 而不是bootstrap子应用\n } else {\n sdk.app.clearData(); // 手动清空数据\n sdk.client.navigate(path, { replace: true }); // 使用客户端路由跳转\n }\n },\n getRedirectPath: () => {\n // 1. 优先使用指定值\n const defaultPath = sdk.config.defaultPath;\n if (defaultPath) return defaultPath;\n\n // 2. 其次使用重定向的值\n const param = new URLSearchParams(window.location.search);\n const redirect = decodeURIComponent(param.get('redirect') || '');\n if (redirect) return redirect;\n\n // 3. 最后使用菜单中第一项\n return '/';\n },\n } satisfies AppResults;\n\n sdk[pluginName] = merge(defaultOptions, options);\n },\n};\n\nexport { SdkAppPlugin };\nexport type { AppOptions, AppResults };\n","import type { Plugin } from '@/types';\nimport { merge } from 'es-toolkit';\nimport type { Location, NavigateFunction, UIMatch } from 'react-router-dom';\n\ninterface ClientOptions {}\n\ninterface ClientResults extends Required<ClientOptions> {\n /** 主应用 location */\n location: Location;\n /** 主应用navigate(解决子应用跳转问题) */\n navigate: NavigateFunction;\n /** 路由匹配(用于面包屑) */\n matches: UIMatch[];\n}\n\n/** 插件名称 */\nconst pluginName = 'client';\n\n/**\n * 全局路由信息\n * - 详情参考 {@link ClientOptions} {@link ClientResults}\n * - 路由信息 sdk.client.location\n * - 路由跳转 sdk.client.navigate\n * - 面包屑信息 sdk.client.matches\n */\nconst SdkClientPlugin: Plugin<'client'> = {\n name: pluginName,\n install(sdk, options = {}) {\n // 默认插件配置\n const defaultOptions = {\n location: null,\n navigate: null,\n matches: null,\n } satisfies ClientResults;\n\n sdk[pluginName] = merge(defaultOptions, options);\n },\n};\n\nexport { SdkClientPlugin };\nexport type { ClientOptions, ClientResults };\n","import type { LocaleProps, Plugin, ThemeProps } from '@/types';\nimport type { ProLayoutProps } from '@ant-design/pro-layout';\nimport type { ConfigProviderProps } from 'antd';\nimport { merge } from 'es-toolkit';\nimport type { RouteObject } from 'react-router-dom';\n\ninterface ConfigOptions {\n /** 环境变量(主应用共享给子应用变量) */\n env?: Record<string, any>;\n\n /** 主题 */\n theme?: ThemeProps;\n /** 国际化 */\n locale?: LocaleProps;\n\n /**\n * Qiankun模式(切换模式后请重新打开页面)\n * - router: 基于路由模式\n * - load: 手动加载模式\n */\n qiankunMode?: 'router' | 'load';\n\n /** 登录页路由 */\n loginPath?: string;\n /**\n * 登录后跳转的路由\n * - 优先使用指定值\n * - 其次使用重定向的值\n * - 最后使用菜单中第一项\n */\n defaultPath?: string;\n /**\n * 自定义路由信息\n * - 目前只支持最外层路由自定义\n * - 会合并到 sdk.app.allRoutes 中\n */\n customRoutes?: RouteObject[];\n\n /** Antd 配置 */\n antdConfig?: ConfigProviderProps;\n /** ProLayout 配置 */\n proLayoutConfig?: ProLayoutProps;\n}\n\ninterface ConfigResults extends Required<ConfigOptions> {}\n\n/** 插件名称 */\nconst pluginName = 'config';\n\n/**\n * Sdk 配置信息\n * - 详情参考 {@link ConfigOptions} {@link ConfigResults}\n * - 配置 env 环境变量\n * - 配置 默认主题、国际化\n * - 配置 Qiankun 模式\n * - 配置 默认登录路径、跳转路径、自定义路由\n * - 配置 Antd 配置、ProLayout 配置\n */\nconst SdkConfigPlugin: Plugin<'config'> = {\n name: pluginName,\n install(sdk, options = {}) {\n // 默认插件配置\n const defaultOptions = {\n env: {},\n\n qiankunMode: 'router',\n\n theme: null,\n locale: null,\n\n loginPath: '/login',\n defaultPath: '',\n customRoutes: [],\n\n antdConfig: {},\n proLayoutConfig: {\n title: 'Demo',\n },\n } satisfies ConfigResults;\n\n sdk[pluginName] = merge(defaultOptions, options);\n },\n};\n\nexport { SdkConfigPlugin };\nexport type { ConfigOptions, ConfigResults };\n","import type { Plugin } from '@/types';\nimport { merge } from 'es-toolkit';\nimport intl from 'react-intl-universal';\n\ninterface I18nOptions {\n /**\n * React Intl Universal\n * - 不要解构使用, const { get } = useIntl() 会报错\n * - 如果项目不使用 React Compiler, 可以直接使用 sdk.i18n.intl\n * @example const intl = useIntl(); intl.get(key).d(defaultValue)\n */\n intl?: typeof intl;\n /**\n * React Intl Universal 配置的语言包\n * @example\n * {\n * 'zh-CN': {\n * test: '测试国际化'\n * },\n * 'en-US': {\n * test: 'Test Intl'\n * }\n * }\n */\n intlConfig?: Record<string, any>;\n /**\n * 加载 Antd 语言包\n * @param locale 语言包名\n * @example\n * import enUS from 'antd/es/locale/en_US';\n * import zhCN from 'antd/es/locale/zh_CN';\n * import dayjs from 'dayjs';\n * import 'dayjs/locale/en';\n * import 'dayjs/locale/zh';\n *\n * const loadLocale = (locale: string) => {\n * switch (locale) {\n * case 'en-US':\n * dayjs.locale('en');\n * return enUS;\n * case 'zh-CN':\n * dayjs.locale('zh');\n * return zhCN;\n * default:\n * return undefined;\n * }\n * }\n */\n loadLocale?(locale: string): any;\n}\n\ninterface I18nResults extends Required<I18nOptions> {}\n\n/** 插件名称 */\nconst pluginName = 'i18n';\n\n/**\n * 多语言\n * - 详情参考 {@link I18nOptions} {@link I18nResults}\n * - 集成 React Intl Universal 和 Antd 国际化\n * - 需要从外部引入语言包, 详见 intlConfig 和 loadLocale 配置项\n */\nconst SdkI18nPlugin: Plugin<'i18n'> = {\n name: pluginName,\n install(sdk, options = {}) {\n // 默认插件配置\n const defaultOptions = {\n intl: intl,\n intlConfig: {},\n loadLocale: (locale: string) => undefined,\n } satisfies I18nResults;\n\n sdk[pluginName] = merge(defaultOptions, options);\n },\n};\n\nexport { SdkI18nPlugin };\nexport type { I18nOptions, I18nResults };\n","import type { LocaleProps, Plugin, ThemeProps } from '@/types';\nimport { merge } from 'es-toolkit';\n\ninterface StorageOptions {\n /** 国际化存储名称 */\n localeKey?: string;\n /** 主题存储名称 */\n themeKey?: string;\n /** Token存储名称 */\n tokenKey?: string;\n}\n\ninterface StorageResults extends Required<StorageOptions> {\n /** 获取当前国际化 */\n getLocale(): LocaleProps;\n /** 设置/切换切换国际化 */\n setLocale(locale: LocaleProps): void;\n /** 清空国际化 */\n clearLocale(): void;\n\n /** 获取当前主题 */\n getTheme(): ThemeProps;\n /** 设置/切换主题 */\n setTheme(theme: ThemeProps): void;\n /** 清空主题 */\n clearTheme(): void;\n\n /** 获取当前 Token */\n getToken(): string;\n /** 设置 Token */\n setToken(token: string): void;\n /** 清空 Token */\n clearToken(): void;\n}\n\n/** 插件名称 */\nconst pluginName = 'storage';\n\n/**\n * 本地缓存\n * - 详情参考 {@link StorageOptions} {@link StorageResults}\n * - 配置 localStorage 变量名称\n * - 提供 国际化、主题、Token 的 get、change、clear 方法\n * @example sdk.storage.getToken() // 获取 Token\n * @example sdk.storage.setTheme('dark') // 设置主题\n * @example sdk.storage.clearLocale() // 清空国际化\n */\nconst SdkStoragePlugin: Plugin<'storage'> = {\n name: pluginName,\n install(sdk, options = {}) {\n // 默认插件配置\n const defaultOptions = {\n localeKey: 'locale',\n themeKey: 'theme',\n tokenKey: 'token',\n\n getLocale: () => {\n return localStorage.getItem(sdk.storage.localeKey);\n },\n setLocale: (locale: string) => {\n localStorage.setItem(sdk.storage.localeKey, locale);\n },\n clearLocale: () => {\n localStorage.removeItem(sdk.storage.localeKey);\n },\n getTheme: () => {\n return localStorage.getItem(sdk.storage.themeKey);\n },\n setTheme: (theme: string) => {\n localStorage.setItem(sdk.storage.themeKey, theme);\n },\n clearTheme: () => {\n localStorage.removeItem(sdk.storage.themeKey);\n },\n getToken: () => {\n return localStorage.getItem(sdk.storage.tokenKey);\n },\n setToken: (token: string) => {\n localStorage.setItem(sdk.storage.tokenKey, token);\n },\n clearToken: () => {\n localStorage.removeItem(sdk.storage.tokenKey);\n },\n } satisfies StorageResults;\n\n sdk[pluginName] = merge(defaultOptions, options);\n },\n};\n\nexport { SdkStoragePlugin };\nexport type { StorageOptions, StorageResults };\n","import { sdk } from '@/core';\nimport type { UserInfo } from '@/types';\nimport type { StateCreator } from 'zustand';\n\ninterface InitStateStoreProps {\n /** 初始变量 */\n initState: UserInfo;\n /** 设置初始变量 */\n setInitState(initState: UserInfo): void;\n}\n\n/** 初始变量状态 */\nconst createInitStateSlice: StateCreator<InitStateStoreProps> = (set, get) => ({\n initState: {},\n setInitState: (initState) => {\n set(() => ({ initState }));\n sdk.app = { ...sdk.app, ...initState };\n },\n});\n\nexport { createInitStateSlice };\nexport type { InitStateStoreProps };\n","import { sdk } from '@/core';\nimport type { LocaleProps } from '@/types';\nimport intl from 'react-intl-universal';\nimport type { StateCreator } from 'zustand';\n\ninterface LocaleStoreProps {\n /** 国际化 */\n locale: LocaleProps;\n /** 设置国际化 */\n setLocale(locale: LocaleProps): void;\n}\n\n/** 国际化状态 */\nconst createLocaleSlice: StateCreator<LocaleStoreProps> = (set, get) => ({\n locale: null,\n\n setLocale: (locale) => {\n set(() => ({ locale })); // 自动合并其他\n\n // 记录值\n sdk.config.locale = locale;\n sdk.storage.setLocale(locale);\n\n // 设置作用域\n document.documentElement.setAttribute('lang', locale);\n\n // 设置 React Intl Universal 语言包\n const intlConfig = sdk.i18n.intlConfig;\n intl.init({ currentLocale: locale, locales: intlConfig });\n\n // 加载 Antd 语言包\n try {\n const localeData = sdk.i18n.loadLocale?.(locale) || undefined;\n sdk.config.antdConfig.locale = localeData;\n } catch (e) {\n console.error('sdk.i18n.loadLocale error:', e);\n }\n },\n});\n\nexport { createLocaleSlice };\nexport type { LocaleStoreProps };\n","import type { StateCreator } from 'zustand';\n\ninterface MicroAppStateStoreProps {\n /** 子应用加载状态 */\n microAppLoading: boolean;\n /** 设置子应用加载状态 */\n setMicroAppLoading(state: boolean): void;\n}\n\n/** 子应用状态 */\nconst createMicroAppStateSlice: StateCreator<MicroAppStateStoreProps> = (\n set,\n get,\n) => ({\n microAppLoading: false,\n setMicroAppLoading: (microAppLoading) => set(() => ({ microAppLoading })),\n});\n\nexport { createMicroAppStateSlice };\nexport type { MicroAppStateStoreProps };\n","import { sdk } from '@/core';\nimport type { ThemeProps } from '@/types';\nimport type { StateCreator } from 'zustand';\n\ninterface ThemeStoreProps {\n /** 主题 */\n theme: ThemeProps;\n /** 设置主题 */\n setTheme(theme: ThemeProps): void;\n}\n\n/** 主题状态 */\nconst createThemeSlice: StateCreator<ThemeStoreProps> = (set, get) => ({\n theme: null,\n\n setTheme: (theme) => {\n set(() => ({ theme })); // 自动合并其他\n\n // 记录值\n sdk.config.theme = theme;\n sdk.storage.setTheme(theme);\n\n // 设置作用域\n document.documentElement.setAttribute('theme', theme);\n },\n});\n\nexport { createThemeSlice };\nexport type { ThemeStoreProps };\n","import type { Plugin } from '@/types';\nimport { createStore } from 'zustand';\nimport { subscribeWithSelector } from 'zustand/middleware';\nimport {\n createInitStateSlice,\n type InitStateStoreProps,\n} from './createInitState';\nimport { createLocaleSlice, type LocaleStoreProps } from './createLocale';\nimport {\n createMicroAppStateSlice,\n type MicroAppStateStoreProps,\n} from './createMicroAppLoading';\nimport { createThemeSlice, type ThemeStoreProps } from './createTheme';\n\ntype StoreOptions = InitStateStoreProps &\n LocaleStoreProps &\n MicroAppStateStoreProps &\n ThemeStoreProps;\n\ntype StoreResults = typeof globalStore;\n\n/**\n * 创建 Store\n * - 这里单独声明变量, 主要是为了使用返回类型 StoreResults 🤔\n */\nconst globalStore = createStore<StoreOptions>()(\n subscribeWithSelector((...a) => ({\n ...createInitStateSlice(...a),\n ...createLocaleSlice(...a),\n ...createMicroAppStateSlice(...a),\n ...createThemeSlice(...a),\n })),\n);\n\n/** 插件名称 */\nconst pluginName = 'store';\n\n/**\n * 全局状态管理\n * - 详情参考 {@link StoreOptions} {@link StoreResults}\n * - 此插件不会合并传入属性\n * @example const setTheme = useStore(sdk.store, (state) => state.setTheme)\n * @example const { theme, setTheme } = useStore(sdk.store, useShallow((state) => { theme: state.theme, setTheme: state.setTheme }))\n * @example const [theme, setTheme] = useStore(sdk.store, useShallow((state) => [state.theme, state.setTheme]))\n * @example sdk.store?.getState()?.setTheme('light')\n * @example sdk.store.subscribe((state) => state.theme, (theme) => { console.log('theme', theme) }, { fireImmediately: true }) // fireImmediately 立即变更\n */\nconst SdkStorePlugin: Plugin<'store'> = {\n name: pluginName,\n install(sdk, options = {}) {\n sdk[pluginName] = globalStore satisfies StoreResults;\n },\n};\n\nexport { SdkStorePlugin };\nexport type { StoreOptions, StoreResults };\n","import type { Plugin } from '@/types';\nimport { merge } from 'es-toolkit';\nimport { type ComponentType, createElement, type ReactElement } from 'react';\n\ninterface UIOptions {\n /** 组件 */\n [key: string]: ComponentType | ((name: string) => ComponentType);\n}\n\ninterface UIResults extends Required<UIOptions> {\n /**\n * 获取组件\n * @param name 组件名称\n */\n getComponent(name: string): ComponentType;\n /**\n * 渲染组件\n * @param name 组件名称\n */\n renderComponent(name: string, props?: any): ReactElement;\n}\n\n/** 插件名称 */\nconst pluginName = 'ui';\n\n/**\n * 可复用组件\n * - 详情参考 {@link UIOptions} {@link UIResults}\n * - 内置了 Layout、Loading、Login、Mainapp、Microapp、NotFound 等组件, 可传入覆盖\n * - 组件共享\n * - 在主应用中, 可通过 use(SdkUIPlugin, { MyComponent }) 传入组件\n * - 在子应用中, 可通过 sdk.ui.renderComponent('MyComponent') 使用组件\n */\nconst SdkUIPlugin: Plugin<'ui'> = {\n name: pluginName,\n install(sdk, options = {}) {\n // 默认插件配置\n const defaultOptions = {\n getComponent: (name) => {\n if (!name) throw new Error('Sdk: Component name cannot be empty');\n return sdk.ui[name] as ComponentType;\n },\n renderComponent: (name, props = {}) => {\n const Component = sdk.ui.getComponent(name);\n if (!Component) throw new Error(`Sdk: Component ${name} not found`);\n return createElement(Component, props);\n },\n } satisfies UIResults;\n\n sdk[pluginName] = merge(defaultOptions, options);\n },\n};\n\nexport { SdkUIPlugin };\nexport type { UIOptions, UIResults };\n"],"x_google_ignoreList":[1,2,3],"mappings":"+NAgFA,MAAM,EAAM,IA9EZ,KAA+B,CAC7B,KACA,SAEA,IACA,IACA,OACA,OACA,KACA,QACA,MACA,GAEA,aAAc,CACZ,KAAK,KAAO,GACZ,KAAK,SAAW,IAAI,IAGtB,MAAM,EAAc,CAClB,GAAI,OAAO,GAAO,MAAU,MAAM,4BAA4B,IAAO,CACrE,QAAQ,IAAI,kBAAmB,kCAAmC,EAAK,CAGvE,KAAK,KAAO,EAGZ,IAAM,EAAQ,IAAI,MAAM,KAAM,CAC5B,KAAM,EAAQ,EAAK,IACZ,EACE,QAAQ,IAAI,EAAQ,EAAK,EAAS,CADrB,KAGtB,SACE,QAAQ,MAAM,8BAA8B,CACrC,IAET,oBACE,QAAQ,MAAM,6BAA6B,CACpC,IAEV,CAAC,CAGF,OAAO,KAAK,MAAQ,EAGtB,OAAO,EAAc,CACnB,GAAI,CAAC,OAAO,GAAO,MAAU,MAAM,uBAAuB,IAAO,CACjE,QAAQ,IAAI,mBAAoB,kCAAmC,EAAK,CAGxE,OAAO,OAAO,KAAM,OAAO,GAAM,CAGnC,IACE,EACA,EACA,CACA,GAAM,CAAE,OAAM,WAAY,EAE1B,GAAI,CAAC,EAAM,MAAU,MAAM,GAAG,EAAK,qBAAqB,CAExD,GAAI,OAAO,GAAY,WACrB,M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