@litianxiang/portal-core 0.1.18 → 0.1.20
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 +29 -3
- package/dist/index.js +30 -5
- package/package.json +4 -1
package/dist/index.d.ts
CHANGED
|
@@ -52,14 +52,14 @@ interface InactivityResult {
|
|
|
52
52
|
declare function calcInactivityAction(lastActiveTime: number | null | undefined, now: number, config?: InactivityConfig): InactivityResult;
|
|
53
53
|
|
|
54
54
|
interface CreateAuthHttpClientOptions {
|
|
55
|
-
axios
|
|
55
|
+
axios?: any;
|
|
56
56
|
baseURL?: string;
|
|
57
57
|
timeout?: number;
|
|
58
58
|
getUserStore: () => any;
|
|
59
59
|
getLoadingStore: () => any;
|
|
60
60
|
authLoginUrl?: string;
|
|
61
61
|
ssoStorageKey?: string;
|
|
62
|
-
refreshUrl
|
|
62
|
+
refreshUrl?: string;
|
|
63
63
|
inactiveExpireMs?: number;
|
|
64
64
|
inactiveBufferMs?: number;
|
|
65
65
|
onShowError?: (msg: string) => void;
|
|
@@ -318,4 +318,30 @@ declare function createLoadingStoreOptions(): {
|
|
|
318
318
|
};
|
|
319
319
|
};
|
|
320
320
|
|
|
321
|
-
|
|
321
|
+
/**
|
|
322
|
+
* 统一登录、SSO 相关的配置常量
|
|
323
|
+
*
|
|
324
|
+
* - DEFAULT_SSO_STORAGE_KEY: 统一登录站点在 localStorage 中使用的 key
|
|
325
|
+
* - DEFAULT_AUTH_LOGIN_ENV_KEY: 前端项目中约定的统一登录地址环境变量名
|
|
326
|
+
* - DEFAULT_AUTH_LOGIN_PATH: 统一登录站点在当前域下的默认路径
|
|
327
|
+
*/
|
|
328
|
+
declare const DEFAULT_SSO_STORAGE_KEY = "user-store";
|
|
329
|
+
declare const DEFAULT_AUTH_LOGIN_ENV_KEY = "VITE_AUTH_LOGIN_URL";
|
|
330
|
+
declare const DEFAULT_AUTH_LOGIN_PATH = "/auth/#/login";
|
|
331
|
+
/**
|
|
332
|
+
* 根据当前 window.location 生成统一登录地址
|
|
333
|
+
*
|
|
334
|
+
* 在 SSR 环境下会返回空字符串,前端项目可自行兜底。
|
|
335
|
+
*/
|
|
336
|
+
declare function getDefaultAuthLoginUrl(): string;
|
|
337
|
+
interface AuthConfig {
|
|
338
|
+
/** 统一登录站点在 localStorage 中使用的 key,默认 user-store */
|
|
339
|
+
ssoStorageKey: string;
|
|
340
|
+
/** 前端项目中约定的统一登录地址环境变量名,默认 VITE_AUTH_LOGIN_URL */
|
|
341
|
+
authLoginEnvKey: string;
|
|
342
|
+
/** 统一登录站点在当前域下的默认路径,默认 /auth/#/login */
|
|
343
|
+
authLoginPath: string;
|
|
344
|
+
}
|
|
345
|
+
declare const AUTH_CONFIG: AuthConfig;
|
|
346
|
+
|
|
347
|
+
export { AUTH_CONFIG, type AppRouterOptions, type AuthConfig, type BreadcrumbItem, type CoreMenuItem, type CoreUserStoreLike, type CreateAuthHttpClientOptions, DEFAULT_AUTH_LOGIN_ENV_KEY, DEFAULT_AUTH_LOGIN_PATH, DEFAULT_HOME_PATH, DEFAULT_SSO_STORAGE_KEY, type FetchUserMenuForStoreOptions, type FontSize, type InactivityConfig, type InactivityResult, type LoadingState, type LogoutToAuthOptions, type MenuHelper, type MenuHelperOptions, type PermissionHelper, type PermissionHelperOptions, type PresetRangeKey, type SidebarMenuFilterOptions, type SyncFromAuthStoreOptions, type TabItem, type ThemeConfig, type ThemeMode, type TimeInput, type TimeRange, type TransformMenuOptions, addTab, applyTheme, buildAllMenuTree, buildPageMenuList, calcInactivityAction, closeAll, closeLeft, closeOthers, closeRight, createAppRouter, createAuthHttpClient, createLoadingStoreOptions, createLogoutToAuth, createMenuHelper, createPermissionHelper, createRange, fetchUserMenuForStore, filterSidebarMenu, findFirstPagePath, formatRange, formatTime, formatToMonthDay, formatToWanShou, formatToYi, formatWanYuanToYi, getDefaultAuthLoginUrl, getPresetRange, humanizeTime, initTheme, isInRange, removeTab, syncFromAuthStoreToStore, timeDiff, transformMenuTree, useThemeWatcher, useTime };
|
package/dist/index.js
CHANGED
|
@@ -223,6 +223,24 @@ function calcInactivityAction(lastActiveTime, now, config = {}) {
|
|
|
223
223
|
};
|
|
224
224
|
}
|
|
225
225
|
|
|
226
|
+
// src/http/http.ts
|
|
227
|
+
import axiosLib from "axios";
|
|
228
|
+
|
|
229
|
+
// src/config/auth-config.ts
|
|
230
|
+
var DEFAULT_SSO_STORAGE_KEY = "user-store";
|
|
231
|
+
var DEFAULT_AUTH_LOGIN_ENV_KEY = "VITE_AUTH_LOGIN_URL";
|
|
232
|
+
var DEFAULT_AUTH_LOGIN_PATH = "/auth/#/login";
|
|
233
|
+
function getDefaultAuthLoginUrl() {
|
|
234
|
+
if (typeof window === "undefined") return "";
|
|
235
|
+
const origin = window.location.origin || "";
|
|
236
|
+
return `${origin}${DEFAULT_AUTH_LOGIN_PATH}`;
|
|
237
|
+
}
|
|
238
|
+
var AUTH_CONFIG = {
|
|
239
|
+
ssoStorageKey: DEFAULT_SSO_STORAGE_KEY,
|
|
240
|
+
authLoginEnvKey: DEFAULT_AUTH_LOGIN_ENV_KEY,
|
|
241
|
+
authLoginPath: DEFAULT_AUTH_LOGIN_PATH
|
|
242
|
+
};
|
|
243
|
+
|
|
226
244
|
// src/http/http.ts
|
|
227
245
|
function createAuthHttpClient(options) {
|
|
228
246
|
const {
|
|
@@ -232,20 +250,22 @@ function createAuthHttpClient(options) {
|
|
|
232
250
|
getUserStore,
|
|
233
251
|
getLoadingStore,
|
|
234
252
|
authLoginUrl,
|
|
235
|
-
ssoStorageKey =
|
|
236
|
-
refreshUrl,
|
|
253
|
+
ssoStorageKey = AUTH_CONFIG.ssoStorageKey,
|
|
254
|
+
refreshUrl = "/proxy/auth/api/token/refresh",
|
|
237
255
|
inactiveExpireMs,
|
|
238
256
|
inactiveBufferMs,
|
|
239
257
|
onShowError
|
|
240
258
|
} = options;
|
|
241
|
-
const
|
|
259
|
+
const axiosInstance = axios || axiosLib;
|
|
260
|
+
const resolvedAuthLoginUrl = authLoginUrl || import.meta?.env?.[AUTH_CONFIG.authLoginEnvKey] || getDefaultAuthLoginUrl();
|
|
261
|
+
const http = axiosInstance.create({
|
|
242
262
|
baseURL,
|
|
243
263
|
timeout
|
|
244
264
|
});
|
|
245
265
|
const logoutToAuth = createLogoutToAuth({
|
|
246
266
|
getUserStore,
|
|
247
267
|
getLoadingStore,
|
|
248
|
-
authLoginUrl,
|
|
268
|
+
authLoginUrl: resolvedAuthLoginUrl,
|
|
249
269
|
ssoStorageKey
|
|
250
270
|
});
|
|
251
271
|
let isRefreshing = false;
|
|
@@ -275,7 +295,7 @@ function createAuthHttpClient(options) {
|
|
|
275
295
|
if (shouldRefresh && !isRefreshing) {
|
|
276
296
|
isRefreshing = true;
|
|
277
297
|
try {
|
|
278
|
-
const response = await
|
|
298
|
+
const response = await axiosInstance.post(refreshUrl, {}, {
|
|
279
299
|
headers: { Authorization: `Bearer ${refreshToken}` }
|
|
280
300
|
});
|
|
281
301
|
const result = response.data;
|
|
@@ -843,7 +863,11 @@ function createLoadingStoreOptions() {
|
|
|
843
863
|
};
|
|
844
864
|
}
|
|
845
865
|
export {
|
|
866
|
+
AUTH_CONFIG,
|
|
867
|
+
DEFAULT_AUTH_LOGIN_ENV_KEY,
|
|
868
|
+
DEFAULT_AUTH_LOGIN_PATH,
|
|
846
869
|
DEFAULT_HOME_PATH,
|
|
870
|
+
DEFAULT_SSO_STORAGE_KEY,
|
|
847
871
|
addTab,
|
|
848
872
|
applyTheme,
|
|
849
873
|
buildAllMenuTree,
|
|
@@ -869,6 +893,7 @@ export {
|
|
|
869
893
|
formatToWanShou,
|
|
870
894
|
formatToYi,
|
|
871
895
|
formatWanYuanToYi,
|
|
896
|
+
getDefaultAuthLoginUrl,
|
|
872
897
|
getPresetRange,
|
|
873
898
|
humanizeTime,
|
|
874
899
|
initTheme,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@litianxiang/portal-core",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.20",
|
|
4
4
|
"private": false,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -17,6 +17,9 @@
|
|
|
17
17
|
"vue-router": "^4.5.0",
|
|
18
18
|
"dayjs": "^1.11.0"
|
|
19
19
|
},
|
|
20
|
+
"dependencies": {
|
|
21
|
+
"axios": "^1.8.4"
|
|
22
|
+
},
|
|
20
23
|
"devDependencies": {
|
|
21
24
|
"tsup": "^8.3.0",
|
|
22
25
|
"typescript": "^5.6.3",
|