@ibiz-template/core 0.0.1-alpha.0 → 0.0.1-alpha.10
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/LICENSE +21 -0
- package/out/constant/core/core.d.ts +23 -0
- package/out/constant/core/core.d.ts.map +1 -0
- package/out/constant/core/core.js +22 -0
- package/out/constant/http-status-message/http-status-message.d.ts +5 -0
- package/out/constant/http-status-message/http-status-message.d.ts.map +1 -0
- package/out/constant/http-status-message/http-status-message.js +20 -0
- package/out/constant/index.d.ts +3 -0
- package/out/constant/index.d.ts.map +1 -0
- package/out/constant/index.js +2 -0
- package/out/context/index.d.ts +38 -3
- package/out/context/index.d.ts.map +1 -1
- package/out/context/index.js +53 -6
- package/out/environment/environment.d.ts +6 -0
- package/out/environment/environment.d.ts.map +1 -0
- package/out/environment/environment.js +11 -0
- package/out/error/http-error/http-error.d.ts +18 -0
- package/out/error/http-error/http-error.d.ts.map +1 -0
- package/out/error/http-error/http-error.js +36 -0
- package/out/error/index.d.ts +3 -0
- package/out/error/index.d.ts.map +1 -0
- package/out/error/index.js +2 -0
- package/out/error/runtime-error/runtime-error.d.ts +15 -0
- package/out/error/runtime-error/runtime-error.d.ts.map +1 -0
- package/out/error/runtime-error/runtime-error.js +15 -0
- package/out/ibizsys.d.ts +44 -0
- package/out/ibizsys.d.ts.map +1 -0
- package/out/ibizsys.js +29 -0
- package/out/index.d.ts +9 -1
- package/out/index.d.ts.map +1 -1
- package/out/index.js +9 -8
- package/out/install.d.ts +9 -0
- package/out/install.d.ts.map +1 -0
- package/out/install.js +16 -0
- package/out/interface/i-environment/i-environment.d.ts +67 -0
- package/out/interface/i-environment/i-environment.d.ts.map +1 -0
- package/out/interface/{i-context/i-context.js → i-environment/i-environment.js} +0 -0
- package/out/interface/index.d.ts +2 -1
- package/out/interface/index.d.ts.map +1 -1
- package/out/interface/org-data/org-data.d.ts +43 -0
- package/out/interface/org-data/org-data.d.ts.map +1 -0
- package/out/interface/org-data/org-data.js +1 -0
- package/out/types.d.ts +48 -0
- package/out/types.d.ts.map +1 -0
- package/out/types.js +1 -0
- package/out/utils/index.d.ts +7 -0
- package/out/utils/index.d.ts.map +1 -0
- package/out/utils/index.js +6 -0
- package/out/utils/interceptor/interceptor.d.ts +13 -0
- package/out/utils/interceptor/interceptor.d.ts.map +1 -0
- package/out/utils/interceptor/interceptor.js +33 -0
- package/out/utils/namespace/namespace.d.ts +148 -0
- package/out/utils/namespace/namespace.d.ts.map +1 -0
- package/out/utils/namespace/namespace.js +216 -0
- package/out/utils/net/http-response.d.ts +94 -0
- package/out/utils/net/http-response.d.ts.map +1 -0
- package/out/utils/net/http-response.js +53 -0
- package/out/utils/net/net.d.ts +123 -0
- package/out/utils/net/net.d.ts.map +1 -0
- package/out/utils/net/net.js +223 -0
- package/out/utils/plural/plural.d.ts +21 -0
- package/out/utils/plural/plural.d.ts.map +1 -0
- package/out/utils/plural/plural.js +25 -0
- package/out/utils/util/util.d.ts +39 -0
- package/out/utils/util/util.d.ts.map +1 -0
- package/out/utils/util/util.js +63 -0
- package/package.json +24 -6
- package/src/constant/core/core.ts +23 -0
- package/src/constant/http-status-message/http-status-message.ts +20 -0
- package/src/constant/index.ts +2 -0
- package/src/context/index.ts +112 -0
- package/src/environment/environment.ts +13 -0
- package/src/error/http-error/http-error.ts +43 -0
- package/src/error/index.ts +2 -0
- package/src/error/runtime-error/runtime-error.ts +14 -0
- package/src/ibizsys.ts +48 -0
- package/src/index.ts +10 -0
- package/src/install.ts +17 -0
- package/src/interface/i-environment/i-environment.ts +72 -0
- package/src/interface/index.ts +2 -0
- package/src/interface/org-data/org-data.ts +42 -0
- package/src/types.ts +54 -0
- package/src/utils/index.ts +6 -0
- package/src/utils/interceptor/interceptor.ts +35 -0
- package/src/utils/namespace/namespace.ts +244 -0
- package/src/utils/net/http-response.ts +113 -0
- package/src/utils/net/net.ts +254 -0
- package/src/utils/plural/plural.ts +27 -0
- package/src/utils/util/util.ts +78 -0
- package/out/interface/i-context/i-context.d.ts +0 -12
- package/out/interface/i-context/i-context.d.ts.map +0 -1
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
/* eslint-disable no-param-reassign */
|
|
2
|
+
/* eslint-disable no-constructor-return */
|
|
3
|
+
/* eslint-disable no-underscore-dangle */
|
|
4
|
+
/* eslint-disable max-classes-per-file */
|
|
5
|
+
|
|
6
|
+
import { clone } from 'lodash-es';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* 上下文代理处理
|
|
10
|
+
*
|
|
11
|
+
* @author chitanda
|
|
12
|
+
* @date 2022-07-14 10:07:45
|
|
13
|
+
* @class IBizContextProxyHandle
|
|
14
|
+
* @implements {ProxyHandler<IBizContext>}
|
|
15
|
+
*/
|
|
16
|
+
export class IBizContextProxyHandle implements ProxyHandler<IBizContext> {
|
|
17
|
+
set(target: IBizContext, p: string | symbol, value: unknown): boolean {
|
|
18
|
+
target.context[p] = value;
|
|
19
|
+
return true;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
get(target: IBizContext, p: string | symbol, _receiver: unknown): unknown {
|
|
23
|
+
if (target[p] !== undefined) {
|
|
24
|
+
return target[p];
|
|
25
|
+
}
|
|
26
|
+
if (target.context[p] !== undefined) {
|
|
27
|
+
return target.context[p];
|
|
28
|
+
}
|
|
29
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
30
|
+
if ((target as any)._parent && (target as any)._parent[p] !== undefined) {
|
|
31
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
32
|
+
return (target as any)._parent[p];
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* 上下文处理类
|
|
39
|
+
*
|
|
40
|
+
* @author chitanda
|
|
41
|
+
* @date 2022-07-14 10:07:24
|
|
42
|
+
* @export
|
|
43
|
+
* @class IBizContext
|
|
44
|
+
*/
|
|
45
|
+
export class IBizContext implements IContext {
|
|
46
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
47
|
+
[key: string | symbol]: any;
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* 父上下文
|
|
51
|
+
*
|
|
52
|
+
* @author chitanda
|
|
53
|
+
* @date 2022-07-14 10:07:06
|
|
54
|
+
* @protected
|
|
55
|
+
* @type {(IBizContext | null)}
|
|
56
|
+
*/
|
|
57
|
+
protected _parent: IContext | null = null;
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Creates an instance of IBizContext.
|
|
61
|
+
*
|
|
62
|
+
* @author chitanda
|
|
63
|
+
* @date 2022-07-14 10:07:15
|
|
64
|
+
* @param {IContext} [context={}] 自身的上下文
|
|
65
|
+
* @param {IBizContext} [parent]
|
|
66
|
+
*/
|
|
67
|
+
constructor(public context: IContext = {}, parent?: IBizContext) {
|
|
68
|
+
if (parent) {
|
|
69
|
+
this._parent = parent;
|
|
70
|
+
}
|
|
71
|
+
return this.createProxy();
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* 创建代理
|
|
76
|
+
*
|
|
77
|
+
* @author chitanda
|
|
78
|
+
* @date 2022-07-14 11:07:37
|
|
79
|
+
* @protected
|
|
80
|
+
* @return {*} {IBizContext}
|
|
81
|
+
*/
|
|
82
|
+
protected createProxy(): IBizContext {
|
|
83
|
+
return new Proxy(this, new IBizContextProxyHandle());
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* 获取所有上下文参数,无多层级默认合并
|
|
88
|
+
*
|
|
89
|
+
* @author chitanda
|
|
90
|
+
* @date 2022-09-28 14:09:20
|
|
91
|
+
* @return {*} {IContext}
|
|
92
|
+
*/
|
|
93
|
+
getContext(): IContext {
|
|
94
|
+
if (this.parent) {
|
|
95
|
+
const ctx = this.parent.getContext();
|
|
96
|
+
Object.assign(ctx, clone(this.context));
|
|
97
|
+
return ctx;
|
|
98
|
+
}
|
|
99
|
+
return clone(this.context);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* 销毁上下文,避免内存泄漏
|
|
104
|
+
*
|
|
105
|
+
* @author chitanda
|
|
106
|
+
* @date 2022-07-14 11:07:45
|
|
107
|
+
*/
|
|
108
|
+
destroy(): void {
|
|
109
|
+
this.context = {};
|
|
110
|
+
this._parent = null;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { IEnvironment } from '../interface';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* 环境变量
|
|
5
|
+
*/
|
|
6
|
+
export const Environment: IEnvironment = {
|
|
7
|
+
baseUrl: '',
|
|
8
|
+
remoteModelUrl: '/remotemodel',
|
|
9
|
+
assetsUrl: './assets',
|
|
10
|
+
dcSystem: '',
|
|
11
|
+
ExportFile: '/ibizutil/download',
|
|
12
|
+
UploadFile: '/ibizutil/upload',
|
|
13
|
+
};
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { AxiosError, AxiosResponse } from 'axios';
|
|
2
|
+
import { HttpStatusMessageConst } from '../../constant';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* 请求异常
|
|
6
|
+
*
|
|
7
|
+
* @author chitanda
|
|
8
|
+
* @date 2022-09-18 17:09:10
|
|
9
|
+
* @export
|
|
10
|
+
* @class HttpError
|
|
11
|
+
* @implements {Error}
|
|
12
|
+
*/
|
|
13
|
+
export class HttpError implements Error {
|
|
14
|
+
name: string = 'HttpError';
|
|
15
|
+
|
|
16
|
+
message: string;
|
|
17
|
+
|
|
18
|
+
status: number;
|
|
19
|
+
|
|
20
|
+
response?: AxiosResponse;
|
|
21
|
+
|
|
22
|
+
constructor(err: AxiosError) {
|
|
23
|
+
const res = err.response;
|
|
24
|
+
this.response = err.response;
|
|
25
|
+
if (res) {
|
|
26
|
+
if (res.data) {
|
|
27
|
+
this.message = (res.data as IData).message;
|
|
28
|
+
} else {
|
|
29
|
+
this.message = res.statusText;
|
|
30
|
+
}
|
|
31
|
+
if (!this.message) {
|
|
32
|
+
this.message = HttpStatusMessageConst[res.status];
|
|
33
|
+
}
|
|
34
|
+
if (!this.message) {
|
|
35
|
+
this.message = '网络异常,请稍后重试!';
|
|
36
|
+
}
|
|
37
|
+
this.status = res.status;
|
|
38
|
+
} else {
|
|
39
|
+
this.message = err.message;
|
|
40
|
+
this.status = 500;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 运行时异常
|
|
3
|
+
*
|
|
4
|
+
* @author lxm
|
|
5
|
+
* @date 2022-09-21 18:09:09
|
|
6
|
+
* @export
|
|
7
|
+
* @class RuntimeError
|
|
8
|
+
* @implements {Error}
|
|
9
|
+
*/
|
|
10
|
+
export class RuntimeError implements Error {
|
|
11
|
+
name: string = 'Runtime Error';
|
|
12
|
+
|
|
13
|
+
constructor(public message: string) {}
|
|
14
|
+
}
|
package/src/ibizsys.ts
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { Environment } from './environment/environment';
|
|
2
|
+
import { OrgData } from './interface';
|
|
3
|
+
import { Net } from './utils';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* 全局对象
|
|
7
|
+
*
|
|
8
|
+
* @author chitanda
|
|
9
|
+
* @date 2022-07-19 16:07:50
|
|
10
|
+
* @export
|
|
11
|
+
* @class IBizSys
|
|
12
|
+
*/
|
|
13
|
+
export class IBizSys {
|
|
14
|
+
/**
|
|
15
|
+
* 环境变量
|
|
16
|
+
*
|
|
17
|
+
* @author chitanda
|
|
18
|
+
* @date 2022-07-19 18:07:04
|
|
19
|
+
*/
|
|
20
|
+
env = Environment;
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* 网络请求工具类
|
|
24
|
+
*
|
|
25
|
+
* @author chitanda
|
|
26
|
+
* @date 2022-07-19 17:07:56
|
|
27
|
+
* @type {Net}
|
|
28
|
+
*/
|
|
29
|
+
net: Net = new Net();
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* sass 模式下的中心系统标识
|
|
33
|
+
*
|
|
34
|
+
* @author chitanda
|
|
35
|
+
* @date 2022-07-19 18:07:23
|
|
36
|
+
* @type {string}
|
|
37
|
+
*/
|
|
38
|
+
orgData?: OrgData;
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* 应用数据
|
|
42
|
+
*
|
|
43
|
+
* @author chitanda
|
|
44
|
+
* @date 2022-07-20 19:07:22
|
|
45
|
+
* @type {IData}
|
|
46
|
+
*/
|
|
47
|
+
appData?: IData;
|
|
48
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import './types';
|
|
2
|
+
|
|
3
|
+
export * from './constant';
|
|
4
|
+
export { IBizContext, IBizContextProxyHandle } from './context';
|
|
5
|
+
export { Environment } from './environment/environment';
|
|
6
|
+
export * from './error';
|
|
7
|
+
export * from './interface';
|
|
8
|
+
export * from './utils';
|
|
9
|
+
export { IBizSys } from './ibizsys';
|
|
10
|
+
export { install } from './install';
|
package/src/install.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { IBizSys } from './ibizsys';
|
|
2
|
+
import { Interceptor } from './utils';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* 初始化全局对象
|
|
6
|
+
*
|
|
7
|
+
* @author chitanda
|
|
8
|
+
* @date 2022-07-19 17:07:37
|
|
9
|
+
* @export
|
|
10
|
+
*/
|
|
11
|
+
export function install(): void {
|
|
12
|
+
if (window.ibiz) {
|
|
13
|
+
throw new Error('ibiz 已经存在, 无需重复安装');
|
|
14
|
+
}
|
|
15
|
+
window.ibiz = new IBizSys();
|
|
16
|
+
new Interceptor();
|
|
17
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 配置参数
|
|
3
|
+
*
|
|
4
|
+
* @author chitanda
|
|
5
|
+
* @date 2022-07-19 18:07:29
|
|
6
|
+
* @export
|
|
7
|
+
* @interface IEnvironment
|
|
8
|
+
*/
|
|
9
|
+
export interface IEnvironment {
|
|
10
|
+
/**
|
|
11
|
+
* 命名空间
|
|
12
|
+
*
|
|
13
|
+
* @author chitanda
|
|
14
|
+
* @date 2022-09-06 11:09:32
|
|
15
|
+
* @type {string}
|
|
16
|
+
*/
|
|
17
|
+
namespace?: string;
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* 请求根路径
|
|
21
|
+
*
|
|
22
|
+
* @author chitanda
|
|
23
|
+
* @date 2022-07-19 18:07:58
|
|
24
|
+
* @type {string}
|
|
25
|
+
*/
|
|
26
|
+
baseUrl: string;
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* 远程模型路径
|
|
30
|
+
*
|
|
31
|
+
* @author chitanda
|
|
32
|
+
* @date 2022-09-22 18:09:25
|
|
33
|
+
* @type {string}
|
|
34
|
+
*/
|
|
35
|
+
remoteModelUrl: string;
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* 资源文件根路径
|
|
39
|
+
*
|
|
40
|
+
* @author lxm
|
|
41
|
+
* @date 2022-08-25 14:08:08
|
|
42
|
+
* @type {string}
|
|
43
|
+
*/
|
|
44
|
+
assetsUrl: string;
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* 中心系统标识
|
|
48
|
+
*
|
|
49
|
+
* @author chitanda
|
|
50
|
+
* @date 2022-08-22 23:08:46
|
|
51
|
+
* @type {string}
|
|
52
|
+
*/
|
|
53
|
+
dcSystem: string;
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* 文件导出
|
|
57
|
+
*
|
|
58
|
+
* @author chitanda
|
|
59
|
+
* @date 2022-08-22 23:08:46
|
|
60
|
+
* @type {string}
|
|
61
|
+
*/
|
|
62
|
+
ExportFile: string;
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* 文件上传
|
|
66
|
+
*
|
|
67
|
+
* @author chitanda
|
|
68
|
+
* @date 2022-08-22 23:08:46
|
|
69
|
+
* @type {string}
|
|
70
|
+
*/
|
|
71
|
+
UploadFile: string;
|
|
72
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 组织数据
|
|
3
|
+
*
|
|
4
|
+
* @author chitanda
|
|
5
|
+
* @date 2022-07-20 18:07:59
|
|
6
|
+
* @export
|
|
7
|
+
* @interface OrgData
|
|
8
|
+
*/
|
|
9
|
+
export interface OrgData {
|
|
10
|
+
/**
|
|
11
|
+
* 组织标识
|
|
12
|
+
*
|
|
13
|
+
* @author chitanda
|
|
14
|
+
* @date 2022-07-20 18:07:17
|
|
15
|
+
* @type {string}
|
|
16
|
+
*/
|
|
17
|
+
orgid: string;
|
|
18
|
+
/**
|
|
19
|
+
* 组织名称
|
|
20
|
+
*
|
|
21
|
+
* @author chitanda
|
|
22
|
+
* @date 2022-07-20 18:07:31
|
|
23
|
+
* @type {string}
|
|
24
|
+
*/
|
|
25
|
+
orgname: string;
|
|
26
|
+
/**
|
|
27
|
+
* 中心系统标识
|
|
28
|
+
*
|
|
29
|
+
* @author chitanda
|
|
30
|
+
* @date 2022-07-20 18:07:56
|
|
31
|
+
* @type {string}
|
|
32
|
+
*/
|
|
33
|
+
dcsystemid: string;
|
|
34
|
+
/**
|
|
35
|
+
* 系统标识
|
|
36
|
+
*
|
|
37
|
+
* @author chitanda
|
|
38
|
+
* @date 2022-07-20 18:07:47
|
|
39
|
+
* @type {string}
|
|
40
|
+
*/
|
|
41
|
+
systemid: string;
|
|
42
|
+
}
|
package/src/types.ts
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
|
+
import { IBizSys } from './ibizsys';
|
|
3
|
+
|
|
4
|
+
declare global {
|
|
5
|
+
const ibiz: IBizSys;
|
|
6
|
+
|
|
7
|
+
interface Window {
|
|
8
|
+
ibiz: IBizSys;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* 上下文
|
|
13
|
+
*
|
|
14
|
+
* @author chitanda
|
|
15
|
+
* @date 2022-07-14 15:07:52
|
|
16
|
+
* @interface IContext
|
|
17
|
+
*/
|
|
18
|
+
interface IContext {
|
|
19
|
+
[key: string | symbol]: any;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* 参数
|
|
24
|
+
*
|
|
25
|
+
* @author chitanda
|
|
26
|
+
* @date 2022-07-14 15:07:57
|
|
27
|
+
* @interface IParams
|
|
28
|
+
*/
|
|
29
|
+
interface IParams {
|
|
30
|
+
[key: string | symbol]: any;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* 数据
|
|
35
|
+
*
|
|
36
|
+
* @author chitanda
|
|
37
|
+
* @date 2022-07-14 15:07:31
|
|
38
|
+
* @interface IData
|
|
39
|
+
*/
|
|
40
|
+
interface IData {
|
|
41
|
+
[key: string | symbol]: any;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* 任意对象结构
|
|
46
|
+
*
|
|
47
|
+
* @author chitanda
|
|
48
|
+
* @date 2022-09-21 15:09:30
|
|
49
|
+
* @interface IObject
|
|
50
|
+
*/
|
|
51
|
+
interface IObject {
|
|
52
|
+
[key: string | symbol]: any;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { Interceptor } from './interceptor/interceptor';
|
|
2
|
+
export { Namespace } from './namespace/namespace';
|
|
3
|
+
export { IHttpResponse, HttpResponse } from './net/http-response';
|
|
4
|
+
export { Net } from './net/net';
|
|
5
|
+
export { plural, pluralLower } from './plural/plural';
|
|
6
|
+
export * from './util/util';
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import axios from 'axios';
|
|
2
|
+
import { getToken } from '../util/util';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* 默认请求拦截器
|
|
6
|
+
*
|
|
7
|
+
* @author chitanda
|
|
8
|
+
* @date 2022-07-20 18:07:11
|
|
9
|
+
* @export
|
|
10
|
+
* @class Interceptor
|
|
11
|
+
*/
|
|
12
|
+
export class Interceptor {
|
|
13
|
+
constructor() {
|
|
14
|
+
this.init();
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
protected init(): void {
|
|
18
|
+
axios.interceptors.request.use(config => {
|
|
19
|
+
if (!config.headers) {
|
|
20
|
+
config.headers = {};
|
|
21
|
+
}
|
|
22
|
+
config.headers.Authorization = `Bearer ${getToken()}`;
|
|
23
|
+
const { orgData } = ibiz;
|
|
24
|
+
if (orgData) {
|
|
25
|
+
if (orgData.systemid) {
|
|
26
|
+
config.headers.srfsystemid = orgData.systemid;
|
|
27
|
+
}
|
|
28
|
+
if (orgData.orgid) {
|
|
29
|
+
config.headers.srforgid = orgData.orgid;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
return config;
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
}
|