@ibiz-template/core 0.0.1-alpha.0 → 0.0.1-alpha.1
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/index.d.ts +2 -0
- package/out/constant/index.d.ts.map +1 -0
- package/out/constant/index.js +1 -0
- package/out/context/index.d.ts +29 -2
- package/out/context/index.d.ts.map +1 -1
- package/out/context/index.js +34 -3
- package/out/environment/environment.d.ts +6 -0
- package/out/environment/environment.d.ts.map +1 -0
- package/out/environment/environment.js +6 -0
- package/out/ibizsys.d.ts +51 -0
- package/out/ibizsys.d.ts.map +1 -0
- package/out/ibizsys.js +37 -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 +15 -0
- package/out/interface/i-environment/i-environment.d.ts +20 -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 +38 -0
- package/out/types.d.ts.map +1 -0
- package/out/types.js +1 -0
- package/out/utils/index.d.ts +4 -0
- package/out/utils/index.d.ts.map +1 -0
- package/out/utils/index.js +3 -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/net/net.d.ts +141 -0
- package/out/utils/net/net.d.ts.map +1 -0
- package/out/utils/net/net.js +194 -0
- package/out/utils/util/util.d.ts +10 -0
- package/out/utils/util/util.d.ts.map +1 -0
- package/out/utils/util/util.js +13 -0
- package/package.json +17 -5
- package/src/constant/core/core.ts +23 -0
- package/src/constant/index.ts +1 -0
- package/src/context/index.ts +93 -0
- package/src/environment/environment.ts +8 -0
- package/src/ibizsys.ts +57 -0
- package/src/index.ts +11 -0
- package/src/install.ts +16 -0
- package/src/interface/i-environment/i-environment.ts +20 -0
- package/src/interface/index.ts +2 -0
- package/src/interface/org-data/org-data.ts +42 -0
- package/src/types.ts +43 -0
- package/src/utils/index.ts +3 -0
- package/src/utils/interceptor/interceptor.ts +35 -0
- package/src/utils/net/net.ts +247 -0
- package/src/utils/util/util.ts +14 -0
- package/out/interface/i-context/i-context.d.ts +0 -12
- package/out/interface/i-context/i-context.d.ts.map +0 -1
package/src/types.ts
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
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
|
+
}
|
|
@@ -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
|
+
}
|
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
import axios, { AxiosRequestHeaders, AxiosResponse } from 'axios';
|
|
2
|
+
import { stringify } from 'qs';
|
|
3
|
+
import { notNilEmpty } from 'qx-util';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* 返回值扩展
|
|
7
|
+
*
|
|
8
|
+
* @author chitanda
|
|
9
|
+
* @date 2022-07-14 16:07:50
|
|
10
|
+
* @export
|
|
11
|
+
* @interface NetResponse
|
|
12
|
+
* @extends {AxiosResponse}
|
|
13
|
+
*/
|
|
14
|
+
export interface NetResponse extends AxiosResponse {
|
|
15
|
+
/**
|
|
16
|
+
* 是否请求成功
|
|
17
|
+
*
|
|
18
|
+
* @description 当状态码为 200-299 时认为成功
|
|
19
|
+
* @author chitanda
|
|
20
|
+
* @date 2022-07-14 16:07:59
|
|
21
|
+
* @type {boolean}
|
|
22
|
+
*/
|
|
23
|
+
ok: boolean;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* 全局请求工具类
|
|
28
|
+
*
|
|
29
|
+
* @author chitanda
|
|
30
|
+
* @date 2022-07-14 15:07:42
|
|
31
|
+
* @export
|
|
32
|
+
* @class Net
|
|
33
|
+
*/
|
|
34
|
+
export class Net {
|
|
35
|
+
/**
|
|
36
|
+
* 标准请求前缀
|
|
37
|
+
*
|
|
38
|
+
* @author chitanda
|
|
39
|
+
* @date 2022-07-21 10:07:48
|
|
40
|
+
* @protected
|
|
41
|
+
* @type {string}
|
|
42
|
+
*/
|
|
43
|
+
protected prefix: string = '';
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Creates an instance of Net.
|
|
47
|
+
*
|
|
48
|
+
* @author chitanda
|
|
49
|
+
* @date 2022-07-21 10:07:27
|
|
50
|
+
* @param {string} [prefix] 请求前缀
|
|
51
|
+
*/
|
|
52
|
+
constructor(prefix?: string) {
|
|
53
|
+
if (prefix) {
|
|
54
|
+
this.prefix = prefix;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Post 请求
|
|
60
|
+
*
|
|
61
|
+
* @author chitanda
|
|
62
|
+
* @date 2022-07-14 15:07:01
|
|
63
|
+
* @param {string} url
|
|
64
|
+
* @param {IParams} [params={}]
|
|
65
|
+
* @return {*} {Promise<NetResponse>}
|
|
66
|
+
*/
|
|
67
|
+
async post(
|
|
68
|
+
url: string,
|
|
69
|
+
data: IData,
|
|
70
|
+
params: IParams = {},
|
|
71
|
+
headers: AxiosRequestHeaders = {},
|
|
72
|
+
): Promise<NetResponse> {
|
|
73
|
+
url = this.handleAppPresetParam(url, params);
|
|
74
|
+
const response = await axios({
|
|
75
|
+
method: 'post',
|
|
76
|
+
url,
|
|
77
|
+
data,
|
|
78
|
+
headers: {
|
|
79
|
+
'Content-Type': 'application/json;charset=UTF-8',
|
|
80
|
+
Accept: 'application/json',
|
|
81
|
+
...headers,
|
|
82
|
+
},
|
|
83
|
+
});
|
|
84
|
+
return this.doResponseResult(response);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Get 请求
|
|
89
|
+
*
|
|
90
|
+
* @author chitanda
|
|
91
|
+
* @date 2022-07-14 15:07:08
|
|
92
|
+
* @param {string} url
|
|
93
|
+
* @param {IParams} [params={}]
|
|
94
|
+
* @return {*} {Promise<NetResponse>}
|
|
95
|
+
*/
|
|
96
|
+
async get(
|
|
97
|
+
url: string,
|
|
98
|
+
params: IParams = {},
|
|
99
|
+
headers: AxiosRequestHeaders = {},
|
|
100
|
+
): Promise<NetResponse> {
|
|
101
|
+
// if (params.srfparentdata) {
|
|
102
|
+
// Object.assign(params, params.srfparentdata);
|
|
103
|
+
// delete params.srfparentdata;
|
|
104
|
+
// }
|
|
105
|
+
url = this.attachUrlParam(url, params);
|
|
106
|
+
const response = await axios.get(url, { headers });
|
|
107
|
+
return this.doResponseResult(response);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Delete 请求
|
|
112
|
+
*
|
|
113
|
+
* @author chitanda
|
|
114
|
+
* @date 2022-07-14 15:07:43
|
|
115
|
+
* @param {string} url
|
|
116
|
+
* @param {IParams} [params]
|
|
117
|
+
* @return {*} {Promise<NetResponse>}
|
|
118
|
+
*/
|
|
119
|
+
async delete(
|
|
120
|
+
url: string,
|
|
121
|
+
params?: IParams,
|
|
122
|
+
headers: AxiosRequestHeaders = {},
|
|
123
|
+
): Promise<NetResponse> {
|
|
124
|
+
url = this.handleAppPresetParam(url, params);
|
|
125
|
+
const response = await axios.delete(url, { headers });
|
|
126
|
+
return this.doResponseResult(response);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* Put 请求
|
|
131
|
+
*
|
|
132
|
+
* @author chitanda
|
|
133
|
+
* @date 2022-07-14 15:07:49
|
|
134
|
+
* @param {string} url
|
|
135
|
+
* @param {IParams} params
|
|
136
|
+
* @return {*} {Promise<NetResponse>}
|
|
137
|
+
*/
|
|
138
|
+
async put(
|
|
139
|
+
url: string,
|
|
140
|
+
params: IParams,
|
|
141
|
+
headers: AxiosRequestHeaders = {},
|
|
142
|
+
): Promise<NetResponse> {
|
|
143
|
+
url = this.handleAppPresetParam(url, params);
|
|
144
|
+
const response = await axios.put(url, params, { headers });
|
|
145
|
+
return this.doResponseResult(response);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* 获取模型数据
|
|
150
|
+
*
|
|
151
|
+
* @author chitanda
|
|
152
|
+
* @date 2022-07-14 15:07:15
|
|
153
|
+
* @param {string} url
|
|
154
|
+
* @param {AxiosRequestHeaders} [headers={}]
|
|
155
|
+
* @return {*} {Promise<NetResponse>}
|
|
156
|
+
*/
|
|
157
|
+
async getModel(
|
|
158
|
+
url: string,
|
|
159
|
+
headers: AxiosRequestHeaders = {},
|
|
160
|
+
): Promise<NetResponse> {
|
|
161
|
+
const response = await axios.get(url, {
|
|
162
|
+
headers,
|
|
163
|
+
});
|
|
164
|
+
return this.doResponseResult(response);
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* 统一处理请求返回
|
|
169
|
+
*
|
|
170
|
+
* @author chitanda
|
|
171
|
+
* @date 2022-07-14 16:07:23
|
|
172
|
+
* @private
|
|
173
|
+
* @param {AxiosResponse} response
|
|
174
|
+
* @return {*} {NetResponse}
|
|
175
|
+
*/
|
|
176
|
+
private doResponseResult(response: AxiosResponse): NetResponse {
|
|
177
|
+
const res = response as NetResponse;
|
|
178
|
+
if (res.status >= 200 && res.status <= 299) {
|
|
179
|
+
res.ok = true;
|
|
180
|
+
}
|
|
181
|
+
return res;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* 处理平台预定义参数
|
|
186
|
+
*
|
|
187
|
+
* @author chitanda
|
|
188
|
+
* @date 2022-07-14 15:07:12
|
|
189
|
+
* @private
|
|
190
|
+
* @param {string} url
|
|
191
|
+
* @param {IParams} [params]
|
|
192
|
+
* @return {*} {string}
|
|
193
|
+
*/
|
|
194
|
+
private handleAppPresetParam(url: string, params?: IParams): string {
|
|
195
|
+
if (params) {
|
|
196
|
+
const keys = Object.keys(params);
|
|
197
|
+
const tempParam: IParams = {};
|
|
198
|
+
keys.forEach((item: string) => {
|
|
199
|
+
if (item.startsWith('srf') && notNilEmpty(params[item])) {
|
|
200
|
+
tempParam[item] = params[item];
|
|
201
|
+
}
|
|
202
|
+
});
|
|
203
|
+
return this.attachUrlParam(url, params);
|
|
204
|
+
}
|
|
205
|
+
return url;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
/**
|
|
209
|
+
* url 附加请求参数
|
|
210
|
+
*
|
|
211
|
+
* @author chitanda
|
|
212
|
+
* @date 2022-07-14 15:07:34
|
|
213
|
+
* @private
|
|
214
|
+
* @param {string} url
|
|
215
|
+
* @param {IParams} params
|
|
216
|
+
* @return {*} {string}
|
|
217
|
+
*/
|
|
218
|
+
private attachUrlParam(url: string, params: IParams): string {
|
|
219
|
+
url = this.attachUrl(url);
|
|
220
|
+
const strParams: string = stringify(params);
|
|
221
|
+
if (notNilEmpty(strParams)) {
|
|
222
|
+
if (url.endsWith('?')) {
|
|
223
|
+
url = `${url}${strParams}`;
|
|
224
|
+
} else if (url.indexOf('?') !== -1 && url.endsWith('&')) {
|
|
225
|
+
url = `${url}${strParams}`;
|
|
226
|
+
} else if (url.indexOf('?') !== -1 && !url.endsWith('&')) {
|
|
227
|
+
url = `${url}&${strParams}`;
|
|
228
|
+
} else {
|
|
229
|
+
url = `${url}?${strParams}`;
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
return url;
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
/**
|
|
236
|
+
* 处理 url 参数
|
|
237
|
+
*
|
|
238
|
+
* @author chitanda
|
|
239
|
+
* @date 2022-07-20 20:07:17
|
|
240
|
+
* @private
|
|
241
|
+
* @param {string} url
|
|
242
|
+
* @return {*} {string}
|
|
243
|
+
*/
|
|
244
|
+
private attachUrl(url: string): string {
|
|
245
|
+
return `${this.prefix}${url}`;
|
|
246
|
+
}
|
|
247
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { getCookie } from 'qx-util';
|
|
2
|
+
import { CoreConst } from '../../constant';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* 获取认证令牌
|
|
6
|
+
*
|
|
7
|
+
* @author chitanda
|
|
8
|
+
* @date 2022-07-20 18:07:39
|
|
9
|
+
* @export
|
|
10
|
+
* @return {*} {(string | null)}
|
|
11
|
+
*/
|
|
12
|
+
export function getToken(): string | null {
|
|
13
|
+
return getCookie(CoreConst.TOKEN);
|
|
14
|
+
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"i-context.d.ts","sourceRoot":"","sources":["../../../src/interface/i-context/i-context.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,MAAM,WAAW,QAAQ;IACvB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,GAAG,CAAC;CAC7B"}
|