zmdms-utils 0.0.91 → 0.0.92
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/es/auth.d.ts +2 -1
- package/dist/es/auth.js +22 -1
- package/dist/es/file.js +2 -7
- package/dist/es/request.js +3 -3
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/package.json +1 -1
- package/src/auth.ts +22 -0
- package/src/file.ts +2 -9
- package/src/index.ts +7 -1
- package/src/request.ts +14 -14
package/dist/es/auth.d.ts
CHANGED
|
@@ -5,5 +5,6 @@ declare function getToken(): string | null;
|
|
|
5
5
|
declare function setToken(token: string): void;
|
|
6
6
|
declare function removeToken(): void;
|
|
7
7
|
declare function parseToken(token?: string): unknown;
|
|
8
|
+
declare function getPreToken(token?: string): string;
|
|
8
9
|
|
|
9
|
-
export { getToken, parseToken, removeToken, setToken };
|
|
10
|
+
export { getPreToken, getToken, parseToken, removeToken, setToken };
|
package/dist/es/auth.js
CHANGED
|
@@ -45,5 +45,26 @@ function parseToken(token) {
|
|
|
45
45
|
// 没有token
|
|
46
46
|
return null;
|
|
47
47
|
}
|
|
48
|
+
function getPreToken(token) {
|
|
49
|
+
try {
|
|
50
|
+
var tokenResult = token || getToken();
|
|
51
|
+
if (!tokenResult) {
|
|
52
|
+
return "";
|
|
53
|
+
}
|
|
54
|
+
var tokenType = window.localStorage.getItem("system-token-type") || "bearer";
|
|
55
|
+
// 统一转为小写进行比较
|
|
56
|
+
var normalizedTokenType = tokenType.toLowerCase();
|
|
57
|
+
// 检查 token 是否已包含前缀(不区分大小写)
|
|
58
|
+
if (tokenResult.toLowerCase().startsWith(normalizedTokenType + " ")) {
|
|
59
|
+
return tokenResult;
|
|
60
|
+
}
|
|
61
|
+
// 添加前缀(全部小写)
|
|
62
|
+
return "".concat(normalizedTokenType, " ").concat(tokenResult);
|
|
63
|
+
}
|
|
64
|
+
catch (err) {
|
|
65
|
+
console.error("获取token失败", err);
|
|
66
|
+
return "";
|
|
67
|
+
}
|
|
68
|
+
}
|
|
48
69
|
|
|
49
|
-
export { getToken, parseToken, removeToken, setToken };
|
|
70
|
+
export { getPreToken, getToken, parseToken, removeToken, setToken };
|
package/dist/es/file.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { getPreToken } from './auth.js';
|
|
2
2
|
import { dangerouslyXss, specialString, getFileExtension, isImageExtension } from './common.js';
|
|
3
3
|
import { BASIC_KEY, TOKEN_KEY, FILE_SERVICE, FILE_PRVIEW_SERVICE_URL } from './constants.js';
|
|
4
4
|
import { Crypto } from './crypto.js';
|
|
@@ -397,12 +397,7 @@ function createDeleteFileLink(options) {
|
|
|
397
397
|
function getBasicInfo(baseURL, token) {
|
|
398
398
|
var _a;
|
|
399
399
|
// 如果token有前缀,那么不需要处理 如果token没有前缀 添加bearer前缀
|
|
400
|
-
var newToken = token
|
|
401
|
-
if (newToken &&
|
|
402
|
-
!newToken.startsWith("Bearer ") &&
|
|
403
|
-
!newToken.startsWith("bearer ")) {
|
|
404
|
-
newToken = "bearer ".concat(newToken);
|
|
405
|
-
}
|
|
400
|
+
var newToken = getPreToken(token);
|
|
406
401
|
return {
|
|
407
402
|
token: newToken,
|
|
408
403
|
apiBaseURL: ((_a = baseURL === null || baseURL === void 0 ? void 0 : baseURL.endsWith) === null || _a === void 0 ? void 0 : _a.call(baseURL, "/"))
|
package/dist/es/request.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { __rest, __assign } from './_virtual/_tslib.js';
|
|
2
2
|
import axios from 'axios';
|
|
3
|
-
import { removeToken,
|
|
3
|
+
import { removeToken, getPreToken } from './auth.js';
|
|
4
4
|
import { TOKEN_KEY } from './constants.js';
|
|
5
5
|
|
|
6
6
|
var defaultOptions = {
|
|
@@ -242,8 +242,8 @@ var AxiosRequest = /** @class */ (function () {
|
|
|
242
242
|
newOptions.headers = {};
|
|
243
243
|
}
|
|
244
244
|
if (isAuth) {
|
|
245
|
-
var token =
|
|
246
|
-
newOptions.headers[this.tokenKey] =
|
|
245
|
+
var token = getPreToken();
|
|
246
|
+
newOptions.headers[this.tokenKey] = token;
|
|
247
247
|
}
|
|
248
248
|
// 遍历params,将undefined值 转为null值
|
|
249
249
|
if (newOptions.data) {
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export { initMicroApp } from './es/microAppCreator.js';
|
|
2
2
|
export { getMicroUrl, isQiankun } from './es/qiankunUtils.js';
|
|
3
3
|
export { initGlobalError, initMainApp } from './es/mainApp.js';
|
|
4
|
-
export { getToken, parseToken, removeToken, setToken } from './es/auth.js';
|
|
4
|
+
export { getPreToken, getToken, parseToken, removeToken, setToken } from './es/auth.js';
|
|
5
5
|
export { AxiosRequest, IOptions, IOtherOptions } from './es/request.js';
|
|
6
6
|
export { getBaseUrl } from './es/baseUrl.js';
|
|
7
7
|
export { Crypto, md5 } from './es/crypto.js';
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export { initMicroApp } from './es/microAppCreator.js';
|
|
2
2
|
export { getMicroUrl, isQiankun } from './es/qiankunUtils.js';
|
|
3
3
|
export { initGlobalError, initMainApp } from './es/mainApp.js';
|
|
4
|
-
export { getToken, parseToken, removeToken, setToken } from './es/auth.js';
|
|
4
|
+
export { getPreToken, getToken, parseToken, removeToken, setToken } from './es/auth.js';
|
|
5
5
|
export { AxiosRequest } from './es/request.js';
|
|
6
6
|
export { getBaseUrl } from './es/baseUrl.js';
|
|
7
7
|
export { Crypto, md5 } from './es/crypto.js';
|
package/package.json
CHANGED
package/src/auth.ts
CHANGED
|
@@ -45,3 +45,25 @@ export function parseToken(token?: string) {
|
|
|
45
45
|
// 没有token
|
|
46
46
|
return null;
|
|
47
47
|
}
|
|
48
|
+
|
|
49
|
+
export function getPreToken(token?: string) {
|
|
50
|
+
try {
|
|
51
|
+
const tokenResult = token || getToken();
|
|
52
|
+
if (!tokenResult) {
|
|
53
|
+
return "";
|
|
54
|
+
}
|
|
55
|
+
const tokenType =
|
|
56
|
+
window.localStorage.getItem("system-token-type") || "bearer";
|
|
57
|
+
// 统一转为小写进行比较
|
|
58
|
+
const normalizedTokenType = tokenType.toLowerCase();
|
|
59
|
+
// 检查 token 是否已包含前缀(不区分大小写)
|
|
60
|
+
if (tokenResult.toLowerCase().startsWith(normalizedTokenType + " ")) {
|
|
61
|
+
return tokenResult;
|
|
62
|
+
}
|
|
63
|
+
// 添加前缀(全部小写)
|
|
64
|
+
return `${normalizedTokenType} ${tokenResult}`;
|
|
65
|
+
} catch (err) {
|
|
66
|
+
console.error("获取token失败", err);
|
|
67
|
+
return "";
|
|
68
|
+
}
|
|
69
|
+
}
|
package/src/file.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* 附件相关接口
|
|
3
3
|
*/
|
|
4
|
-
import {
|
|
4
|
+
import { getPreToken } from "./auth";
|
|
5
5
|
import {
|
|
6
6
|
dangerouslyXss,
|
|
7
7
|
specialString,
|
|
@@ -486,14 +486,7 @@ export function createDeleteFileLink(options: IOptions) {
|
|
|
486
486
|
*/
|
|
487
487
|
function getBasicInfo(baseURL: string, token?: string) {
|
|
488
488
|
// 如果token有前缀,那么不需要处理 如果token没有前缀 添加bearer前缀
|
|
489
|
-
let newToken = token
|
|
490
|
-
if (
|
|
491
|
-
newToken &&
|
|
492
|
-
!newToken.startsWith("Bearer ") &&
|
|
493
|
-
!newToken.startsWith("bearer ")
|
|
494
|
-
) {
|
|
495
|
-
newToken = `bearer ${newToken}`;
|
|
496
|
-
}
|
|
489
|
+
let newToken = getPreToken(token);
|
|
497
490
|
return {
|
|
498
491
|
token: newToken,
|
|
499
492
|
apiBaseURL: baseURL?.endsWith?.("/")
|
package/src/index.ts
CHANGED
|
@@ -1,7 +1,13 @@
|
|
|
1
1
|
export { initMicroApp } from "./microAppCreator";
|
|
2
2
|
export { isQiankun, getMicroUrl } from "./qiankunUtils";
|
|
3
3
|
export { initMainApp, initGlobalError } from "./mainApp";
|
|
4
|
-
export {
|
|
4
|
+
export {
|
|
5
|
+
getToken,
|
|
6
|
+
setToken,
|
|
7
|
+
removeToken,
|
|
8
|
+
parseToken,
|
|
9
|
+
getPreToken,
|
|
10
|
+
} from "./auth";
|
|
5
11
|
export { AxiosRequest, type IOtherOptions, type IOptions } from "./request";
|
|
6
12
|
export { getBaseUrl } from "./baseUrl";
|
|
7
13
|
export { Crypto, md5, Base64 } from "./crypto";
|
package/src/request.ts
CHANGED
|
@@ -5,7 +5,7 @@ import axios, {
|
|
|
5
5
|
InternalAxiosRequestConfig,
|
|
6
6
|
AxiosInstance,
|
|
7
7
|
} from "axios";
|
|
8
|
-
import {
|
|
8
|
+
import { getPreToken, removeToken } from "./auth";
|
|
9
9
|
import { Crypto } from "./crypto";
|
|
10
10
|
import { TOKEN_KEY } from "./constants";
|
|
11
11
|
|
|
@@ -99,7 +99,7 @@ export class AxiosRequest {
|
|
|
99
99
|
},
|
|
100
100
|
(error) => {
|
|
101
101
|
return Promise.reject(error);
|
|
102
|
-
}
|
|
102
|
+
},
|
|
103
103
|
);
|
|
104
104
|
}
|
|
105
105
|
|
|
@@ -121,7 +121,7 @@ export class AxiosRequest {
|
|
|
121
121
|
// 统一处理响应异常
|
|
122
122
|
this.responseError(error);
|
|
123
123
|
return Promise.reject(error);
|
|
124
|
-
}
|
|
124
|
+
},
|
|
125
125
|
);
|
|
126
126
|
}
|
|
127
127
|
|
|
@@ -228,7 +228,7 @@ export class AxiosRequest {
|
|
|
228
228
|
3.5,
|
|
229
229
|
() => {
|
|
230
230
|
this.isNotFound = false;
|
|
231
|
-
}
|
|
231
|
+
},
|
|
232
232
|
);
|
|
233
233
|
}
|
|
234
234
|
return;
|
|
@@ -255,7 +255,7 @@ export class AxiosRequest {
|
|
|
255
255
|
`,
|
|
256
256
|
() => {
|
|
257
257
|
this.isTimeout = false;
|
|
258
|
-
}
|
|
258
|
+
},
|
|
259
259
|
);
|
|
260
260
|
}
|
|
261
261
|
return;
|
|
@@ -264,7 +264,7 @@ export class AxiosRequest {
|
|
|
264
264
|
if (error?.config?.isErrorMessage) {
|
|
265
265
|
// 详细信息 再开发模式开启 之后上到别的环境会去掉
|
|
266
266
|
this.modalConfirm?.(
|
|
267
|
-
`${error?.response?.data?.msg || error?.msg || "服务器异常"}
|
|
267
|
+
`${error?.response?.data?.msg || error?.msg || "服务器异常"}`,
|
|
268
268
|
);
|
|
269
269
|
// 接口地址: ${error?.config?.url}
|
|
270
270
|
// 响应状态码: ${error?.response?.status}
|
|
@@ -294,8 +294,8 @@ export class AxiosRequest {
|
|
|
294
294
|
newOptions.headers = {};
|
|
295
295
|
}
|
|
296
296
|
if (isAuth) {
|
|
297
|
-
const token =
|
|
298
|
-
newOptions.headers[this.tokenKey] =
|
|
297
|
+
const token = getPreToken();
|
|
298
|
+
newOptions.headers[this.tokenKey] = token;
|
|
299
299
|
}
|
|
300
300
|
|
|
301
301
|
// 遍历params,将undefined值 转为null值
|
|
@@ -335,12 +335,12 @@ export class AxiosRequest {
|
|
|
335
335
|
if (newOptions.isCrypto === true || newOptions.isCrypto === "aes") {
|
|
336
336
|
if (newOptions.data) {
|
|
337
337
|
newOptions.data = this.crypto?.encrypt?.(
|
|
338
|
-
JSON.stringify(newOptions.data)
|
|
338
|
+
JSON.stringify(newOptions.data),
|
|
339
339
|
);
|
|
340
340
|
}
|
|
341
341
|
if (newOptions.params) {
|
|
342
342
|
newOptions.params = this.crypto?.encrypt?.(
|
|
343
|
-
JSON.stringify(newOptions.params)
|
|
343
|
+
JSON.stringify(newOptions.params),
|
|
344
344
|
);
|
|
345
345
|
}
|
|
346
346
|
}
|
|
@@ -348,12 +348,12 @@ export class AxiosRequest {
|
|
|
348
348
|
if (newOptions.isCrypto === "des") {
|
|
349
349
|
if (newOptions.data) {
|
|
350
350
|
newOptions.data = this.crypto?.encrypt_des?.(
|
|
351
|
-
JSON.stringify(newOptions.data)
|
|
351
|
+
JSON.stringify(newOptions.data),
|
|
352
352
|
);
|
|
353
353
|
}
|
|
354
354
|
if (newOptions.params) {
|
|
355
355
|
newOptions.params = this.crypto?.encrypt_des?.(
|
|
356
|
-
JSON.stringify(newOptions.params)
|
|
356
|
+
JSON.stringify(newOptions.params),
|
|
357
357
|
);
|
|
358
358
|
}
|
|
359
359
|
}
|
|
@@ -419,7 +419,7 @@ export interface IOtherOptions {
|
|
|
419
419
|
messageWarning?: (
|
|
420
420
|
msg: string,
|
|
421
421
|
duration: number,
|
|
422
|
-
callback?: () => void
|
|
422
|
+
callback?: () => void,
|
|
423
423
|
) => void;
|
|
424
424
|
modalConfirm?: (msg: string, callback?: () => void) => void;
|
|
425
425
|
/** @deprecated 租户ID,只有登录接口 需要 传递。 */
|
|
@@ -443,7 +443,7 @@ export interface IOtherOptions {
|
|
|
443
443
|
/** 拦截器自定义 */
|
|
444
444
|
interceptorsRequestHandle?: () => void;
|
|
445
445
|
interceptorsRequestConfig?: (
|
|
446
|
-
config: InternalAxiosRequestConfig<any
|
|
446
|
+
config: InternalAxiosRequestConfig<any>,
|
|
447
447
|
) => InternalAxiosRequestConfig<any>;
|
|
448
448
|
/** 响应器自定义 */
|
|
449
449
|
interceptorsResponseHandle?: () => void;
|