@ibiz-template/core 0.0.1-alpha.0 → 0.0.1-alpha.3
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 +36 -5
- package/out/environment/environment.d.ts +6 -0
- package/out/environment/environment.d.ts.map +1 -0
- package/out/environment/environment.js +10 -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 +8 -1
- package/out/index.d.ts.map +1 -1
- package/out/index.js +8 -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 +59 -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 +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 +197 -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 +10 -0
- package/out/utils/util/util.d.ts.map +1 -0
- package/out/utils/util/util.js +13 -0
- package/package.json +22 -6
- 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 +12 -0
- package/src/ibizsys.ts +48 -0
- package/src/index.ts +9 -0
- package/src/install.ts +17 -0
- package/src/interface/i-environment/i-environment.ts +63 -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 +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 +232 -0
- package/src/utils/plural/plural.ts +27 -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
|
@@ -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,244 @@
|
|
|
1
|
+
export const defaultNamespace = 'ibiz';
|
|
2
|
+
const statePrefix = 'is-';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* css bem 命名规则拼接
|
|
6
|
+
* _bem('ibiz', 'layout') => ibiz-layout
|
|
7
|
+
* _bem('ibiz', 'layout', '', 'title') => ibiz-layout__title
|
|
8
|
+
* _bem('ibiz', 'layout', '', '', 'right') => ibiz-layout--right
|
|
9
|
+
* _bem('ibiz', 'layout', '', 'title', 'right') => ibiz-layout__title--right
|
|
10
|
+
* _bem('ibiz', 'layout', 'header', 'title', 'right') => ibiz-layout-header__title--right
|
|
11
|
+
*
|
|
12
|
+
* @author chitanda
|
|
13
|
+
* @date 2022-09-06 11:09:42
|
|
14
|
+
* @param {string} namespace 命名空间
|
|
15
|
+
* @param {string} block 块
|
|
16
|
+
* @param {string} blockSuffix 块后缀
|
|
17
|
+
* @param {string} element 元素
|
|
18
|
+
* @param {string} modifier 修饰符
|
|
19
|
+
* @return {*} {string}
|
|
20
|
+
*/
|
|
21
|
+
function _bem(
|
|
22
|
+
namespace: string,
|
|
23
|
+
block: string,
|
|
24
|
+
blockSuffix?: string,
|
|
25
|
+
element?: string,
|
|
26
|
+
modifier?: string,
|
|
27
|
+
): string {
|
|
28
|
+
let cls = `${namespace}-${block}`;
|
|
29
|
+
if (blockSuffix) {
|
|
30
|
+
cls += `-${blockSuffix}`;
|
|
31
|
+
}
|
|
32
|
+
if (element) {
|
|
33
|
+
cls += `__${element}`;
|
|
34
|
+
}
|
|
35
|
+
if (modifier) {
|
|
36
|
+
cls += `--${modifier}`;
|
|
37
|
+
}
|
|
38
|
+
return cls;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* 全局样式处理命名空间
|
|
43
|
+
*
|
|
44
|
+
* @author chitanda
|
|
45
|
+
* @date 2022-09-06 11:09:50
|
|
46
|
+
* @export
|
|
47
|
+
* @class Namespace
|
|
48
|
+
*/
|
|
49
|
+
export class Namespace {
|
|
50
|
+
/**
|
|
51
|
+
* 命名空间
|
|
52
|
+
*
|
|
53
|
+
* @author chitanda
|
|
54
|
+
* @date 2022-09-06 12:09:01
|
|
55
|
+
* @type {string}
|
|
56
|
+
*/
|
|
57
|
+
namespace: string;
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Creates an instance of Namespace.
|
|
61
|
+
*
|
|
62
|
+
* @author chitanda
|
|
63
|
+
* @date 2022-09-06 12:09:12
|
|
64
|
+
* @param {string} block 当前命名空间的根模块,例如组件的名称
|
|
65
|
+
* @param {string} [namespace] 指定命名空间,未指定使用默认值 ibiz
|
|
66
|
+
*/
|
|
67
|
+
constructor(protected block: string, namespace?: string) {
|
|
68
|
+
this.namespace = namespace || defaultNamespace;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* namespace-block
|
|
73
|
+
* namespace-block-blockSuffix
|
|
74
|
+
*
|
|
75
|
+
* @author chitanda
|
|
76
|
+
* @date 2022-09-06 12:09:08
|
|
77
|
+
* @param {string} [blockSuffix='']
|
|
78
|
+
* @return {*} {string}
|
|
79
|
+
*/
|
|
80
|
+
b(blockSuffix: string = ''): string {
|
|
81
|
+
return _bem(this.namespace, this.block, blockSuffix, '', '');
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* namespace-block__element
|
|
86
|
+
*
|
|
87
|
+
* @author chitanda
|
|
88
|
+
* @date 2022-09-06 12:09:48
|
|
89
|
+
* @param {string} [element]
|
|
90
|
+
* @return {*} {string}
|
|
91
|
+
*/
|
|
92
|
+
e(element?: string): string {
|
|
93
|
+
return element ? _bem(this.namespace, this.block, '', element, '') : '';
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* namespace-block--modifier
|
|
98
|
+
*
|
|
99
|
+
* @author chitanda
|
|
100
|
+
* @date 2022-09-06 12:09:37
|
|
101
|
+
* @param {string} [modifier]
|
|
102
|
+
* @return {*} {string}
|
|
103
|
+
*/
|
|
104
|
+
m(modifier?: string): string {
|
|
105
|
+
return modifier ? _bem(this.namespace, this.block, '', '', modifier) : '';
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* namespace-block-blockSuffix__element
|
|
110
|
+
*
|
|
111
|
+
* @author chitanda
|
|
112
|
+
* @date 2022-09-06 12:09:52
|
|
113
|
+
* @param {string} [blockSuffix]
|
|
114
|
+
* @param {string} [element]
|
|
115
|
+
* @return {*} {string}
|
|
116
|
+
*/
|
|
117
|
+
be(blockSuffix?: string, element?: string): string {
|
|
118
|
+
return blockSuffix && element
|
|
119
|
+
? _bem(this.namespace, this.block, blockSuffix, element, '')
|
|
120
|
+
: '';
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* namespace-block__element--modifier
|
|
125
|
+
*
|
|
126
|
+
* @author chitanda
|
|
127
|
+
* @date 2022-09-06 12:09:19
|
|
128
|
+
* @param {string} [element]
|
|
129
|
+
* @param {string} [modifier]
|
|
130
|
+
* @return {*} {string}
|
|
131
|
+
*/
|
|
132
|
+
em(element?: string, modifier?: string): string {
|
|
133
|
+
return element && modifier
|
|
134
|
+
? _bem(this.namespace, this.block, '', element, modifier)
|
|
135
|
+
: '';
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* namespace-block-blockSuffix--modifier
|
|
140
|
+
*
|
|
141
|
+
* @author chitanda
|
|
142
|
+
* @date 2022-09-06 12:09:59
|
|
143
|
+
* @param {string} [blockSuffix]
|
|
144
|
+
* @param {string} [modifier]
|
|
145
|
+
* @return {*} {string}
|
|
146
|
+
*/
|
|
147
|
+
bm(blockSuffix?: string, modifier?: string): string {
|
|
148
|
+
return blockSuffix && modifier
|
|
149
|
+
? _bem(this.namespace, this.block, blockSuffix, '', modifier)
|
|
150
|
+
: '';
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* namespace-block-blockSuffix__element--modifier
|
|
155
|
+
*
|
|
156
|
+
* @author chitanda
|
|
157
|
+
* @date 2022-09-06 12:09:37
|
|
158
|
+
* @param {string} [blockSuffix]
|
|
159
|
+
* @param {string} [element]
|
|
160
|
+
* @param {string} [modifier]
|
|
161
|
+
* @return {*} {string}
|
|
162
|
+
*/
|
|
163
|
+
bem(blockSuffix?: string, element?: string, modifier?: string): string {
|
|
164
|
+
return blockSuffix && element && modifier
|
|
165
|
+
? _bem(this.namespace, this.block, blockSuffix, element, modifier)
|
|
166
|
+
: '';
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/**
|
|
170
|
+
* 返回状态 class
|
|
171
|
+
*
|
|
172
|
+
* is('loading', false) => '';
|
|
173
|
+
* is('loading', true) => 'is-loading';
|
|
174
|
+
*
|
|
175
|
+
* @author chitanda
|
|
176
|
+
* @date 2022-09-06 12:09:57
|
|
177
|
+
* @param {string} name
|
|
178
|
+
* @param {boolean} [state]
|
|
179
|
+
* @return {*} {string}
|
|
180
|
+
*/
|
|
181
|
+
is(name: string, state?: boolean): string {
|
|
182
|
+
return name && state ? `${statePrefix}${name}` : '';
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/**
|
|
186
|
+
* 生成使用到的 css 变量 style 对象
|
|
187
|
+
*
|
|
188
|
+
* @author chitanda
|
|
189
|
+
* @date 2022-09-06 15:09:41
|
|
190
|
+
* @param {Record<string, string>} object
|
|
191
|
+
* @return {*} {Record<string, string>}
|
|
192
|
+
*/
|
|
193
|
+
cssVar(object: Record<string, string>): Record<string, string> {
|
|
194
|
+
const styles: Record<string, string> = {};
|
|
195
|
+
for (const key in object) {
|
|
196
|
+
if (object[key]) {
|
|
197
|
+
styles[this.cssVarName(key)] = object[key];
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
return styles;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
/**
|
|
204
|
+
* 生成使用到的 css block 变量 style 对象
|
|
205
|
+
*
|
|
206
|
+
* @author chitanda
|
|
207
|
+
* @date 2022-09-06 15:09:03
|
|
208
|
+
* @param {Record<string, string>} object
|
|
209
|
+
* @return {*} {Record<string, string>}
|
|
210
|
+
*/
|
|
211
|
+
cssVarBlock(object: Record<string, string>): Record<string, string> {
|
|
212
|
+
const styles: Record<string, string> = {};
|
|
213
|
+
for (const key in object) {
|
|
214
|
+
if (object[key]) {
|
|
215
|
+
styles[this.cssVarBlockName(key)] = object[key];
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
return styles;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
/**
|
|
222
|
+
* 生成 css var 变量名称
|
|
223
|
+
*
|
|
224
|
+
* @author chitanda
|
|
225
|
+
* @date 2022-09-06 15:09:21
|
|
226
|
+
* @param {string} name
|
|
227
|
+
* @return {*} {string}
|
|
228
|
+
*/
|
|
229
|
+
cssVarName(name: string): string {
|
|
230
|
+
return `--${this.namespace}-${name}`;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
/**
|
|
234
|
+
* 生成块 css var 变量名称
|
|
235
|
+
*
|
|
236
|
+
* @author chitanda
|
|
237
|
+
* @date 2022-09-06 15:09:35
|
|
238
|
+
* @param {string} name
|
|
239
|
+
* @return {*} {string}
|
|
240
|
+
*/
|
|
241
|
+
cssVarBlockName(name: string): string {
|
|
242
|
+
return `--${this.namespace}-${this.block}-${name}`;
|
|
243
|
+
}
|
|
244
|
+
}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import { AxiosRequestConfig, AxiosResponse, AxiosResponseHeaders } from 'axios';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Http请求返回接口
|
|
5
|
+
*
|
|
6
|
+
* @author chitanda
|
|
7
|
+
* @date 2022-08-21 17:08:06
|
|
8
|
+
* @export
|
|
9
|
+
* @interface IHttpResponse
|
|
10
|
+
* @extends {AxiosResponse}
|
|
11
|
+
* @template T
|
|
12
|
+
*/
|
|
13
|
+
export interface IHttpResponse<T = IData> extends AxiosResponse {
|
|
14
|
+
/**
|
|
15
|
+
* 是否请求成功
|
|
16
|
+
*
|
|
17
|
+
* @description 当状态码为 200-299 时认为成功
|
|
18
|
+
* @author chitanda
|
|
19
|
+
* @date 2022-07-14 16:07:59
|
|
20
|
+
* @type {boolean}
|
|
21
|
+
*/
|
|
22
|
+
ok: boolean;
|
|
23
|
+
/**
|
|
24
|
+
* 是否为本地仿造响应
|
|
25
|
+
*
|
|
26
|
+
* @description 只有当值为 true 时, 才认为是本地仿造响应
|
|
27
|
+
* @author chitanda
|
|
28
|
+
* @date 2022-08-18 15:08:44
|
|
29
|
+
* @type {boolean}
|
|
30
|
+
*/
|
|
31
|
+
local?: boolean;
|
|
32
|
+
|
|
33
|
+
data: T;
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* 当前页
|
|
37
|
+
*/
|
|
38
|
+
page?: number;
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* 分页条数
|
|
42
|
+
*/
|
|
43
|
+
size?: number;
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* 总条数
|
|
47
|
+
*/
|
|
48
|
+
total?: number;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* 本地请求仿造响应
|
|
53
|
+
*
|
|
54
|
+
* @author chitanda
|
|
55
|
+
* @date 2022-08-21 17:08:00
|
|
56
|
+
* @export
|
|
57
|
+
* @class HttpResponse
|
|
58
|
+
* @implements {IHttpResponse<T>}
|
|
59
|
+
* @template T
|
|
60
|
+
*/
|
|
61
|
+
export class HttpResponse<T = IData> implements IHttpResponse<T> {
|
|
62
|
+
/**
|
|
63
|
+
* 本地仿造响应
|
|
64
|
+
*
|
|
65
|
+
* @author chitanda
|
|
66
|
+
* @date 2022-08-18 15:08:06
|
|
67
|
+
*/
|
|
68
|
+
local = true;
|
|
69
|
+
|
|
70
|
+
ok = false;
|
|
71
|
+
|
|
72
|
+
data: T;
|
|
73
|
+
|
|
74
|
+
status: number;
|
|
75
|
+
|
|
76
|
+
statusText: string;
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* header 本地仿造时值为空
|
|
80
|
+
*
|
|
81
|
+
* @author chitanda
|
|
82
|
+
* @date 2022-08-18 15:08:46
|
|
83
|
+
* @type {AxiosResponseHeaders}
|
|
84
|
+
*/
|
|
85
|
+
headers: AxiosResponseHeaders = {};
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* AxiosResponse 本地仿造时值为空
|
|
89
|
+
*
|
|
90
|
+
* @author chitanda
|
|
91
|
+
* @date 2022-08-18 15:08:22
|
|
92
|
+
* @type {AxiosRequestConfig<IData>}
|
|
93
|
+
*/
|
|
94
|
+
config: AxiosRequestConfig<IData> = {};
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Creates an instance of HttpResponse.
|
|
98
|
+
*
|
|
99
|
+
* @author chitanda
|
|
100
|
+
* @date 2022-08-18 15:08:11
|
|
101
|
+
* @param {unknown} [data] 返回的数据
|
|
102
|
+
* @param {number} [status] 状态码 (默认为 200)
|
|
103
|
+
* @param {string} [statusText] 状态描述 (默认为空字符)
|
|
104
|
+
*/
|
|
105
|
+
constructor(data?: unknown, status?: number, statusText?: string) {
|
|
106
|
+
this.data = data as T;
|
|
107
|
+
this.status = status || 200;
|
|
108
|
+
this.statusText = statusText || '';
|
|
109
|
+
if (this.status >= 200 && this.status < 300) {
|
|
110
|
+
this.ok = true;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
}
|
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
import axios, { AxiosRequestHeaders, AxiosResponse } from 'axios';
|
|
2
|
+
import { stringify } from 'qs';
|
|
3
|
+
import { notNilEmpty } from 'qx-util';
|
|
4
|
+
import { IHttpResponse } from './http-response';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* 全局请求工具类
|
|
8
|
+
*
|
|
9
|
+
* @author chitanda
|
|
10
|
+
* @date 2022-07-14 15:07:42
|
|
11
|
+
* @export
|
|
12
|
+
* @class Net
|
|
13
|
+
*/
|
|
14
|
+
export class Net {
|
|
15
|
+
/**
|
|
16
|
+
* 标准请求前缀
|
|
17
|
+
*
|
|
18
|
+
* @author chitanda
|
|
19
|
+
* @date 2022-07-21 10:07:48
|
|
20
|
+
* @protected
|
|
21
|
+
* @type {string}
|
|
22
|
+
*/
|
|
23
|
+
protected _prefix: string = '';
|
|
24
|
+
|
|
25
|
+
get prefix(): string {
|
|
26
|
+
return this._prefix || ibiz.env.baseUrl;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Creates an instance of Net.
|
|
31
|
+
*
|
|
32
|
+
* @author chitanda
|
|
33
|
+
* @date 2022-07-21 10:07:27
|
|
34
|
+
* @param {string} [prefix] 请求前缀
|
|
35
|
+
*/
|
|
36
|
+
constructor(prefix?: string) {
|
|
37
|
+
if (prefix) {
|
|
38
|
+
this._prefix = prefix;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Post 请求
|
|
44
|
+
*
|
|
45
|
+
* @author chitanda
|
|
46
|
+
* @date 2022-07-14 15:07:01
|
|
47
|
+
* @param {string} url
|
|
48
|
+
* @param {IParams} [params={}]
|
|
49
|
+
* @return {*} {Promise<IHttpResponse>}
|
|
50
|
+
*/
|
|
51
|
+
async post(
|
|
52
|
+
url: string,
|
|
53
|
+
data: IData,
|
|
54
|
+
params: IParams = {},
|
|
55
|
+
headers: AxiosRequestHeaders = {},
|
|
56
|
+
): Promise<IHttpResponse> {
|
|
57
|
+
url = this.handleAppPresetParam(url, params);
|
|
58
|
+
const response = await axios({
|
|
59
|
+
method: 'post',
|
|
60
|
+
url,
|
|
61
|
+
data,
|
|
62
|
+
headers: {
|
|
63
|
+
'Content-Type': 'application/json;charset=UTF-8',
|
|
64
|
+
Accept: 'application/json',
|
|
65
|
+
...headers,
|
|
66
|
+
},
|
|
67
|
+
});
|
|
68
|
+
return this.doResponseResult(response);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Get 请求
|
|
73
|
+
*
|
|
74
|
+
* @author chitanda
|
|
75
|
+
* @date 2022-07-14 15:07:08
|
|
76
|
+
* @param {string} url
|
|
77
|
+
* @param {IParams} [params={}]
|
|
78
|
+
* @return {*} {Promise<IHttpResponse>}
|
|
79
|
+
*/
|
|
80
|
+
async get(
|
|
81
|
+
url: string,
|
|
82
|
+
params: IParams = {},
|
|
83
|
+
headers: AxiosRequestHeaders = {},
|
|
84
|
+
option: IParams = {},
|
|
85
|
+
): Promise<IHttpResponse> {
|
|
86
|
+
// if (params.srfparentdata) {
|
|
87
|
+
// Object.assign(params, params.srfparentdata);
|
|
88
|
+
// delete params.srfparentdata;
|
|
89
|
+
// }
|
|
90
|
+
url = this.attachUrlParam(url, params);
|
|
91
|
+
const response = await axios.get(url, { headers, ...option });
|
|
92
|
+
return this.doResponseResult(response);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Delete 请求
|
|
97
|
+
*
|
|
98
|
+
* @author chitanda
|
|
99
|
+
* @date 2022-07-14 15:07:43
|
|
100
|
+
* @param {string} url
|
|
101
|
+
* @param {IParams} [params]
|
|
102
|
+
* @return {*} {Promise<IHttpResponse>}
|
|
103
|
+
*/
|
|
104
|
+
async delete(
|
|
105
|
+
url: string,
|
|
106
|
+
params?: IParams,
|
|
107
|
+
headers: AxiosRequestHeaders = {},
|
|
108
|
+
): Promise<IHttpResponse> {
|
|
109
|
+
url = this.handleAppPresetParam(url, params);
|
|
110
|
+
const response = await axios.delete(url, { headers });
|
|
111
|
+
return this.doResponseResult(response);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Put 请求
|
|
116
|
+
*
|
|
117
|
+
* @author chitanda
|
|
118
|
+
* @date 2022-07-14 15:07:49
|
|
119
|
+
* @param {string} url
|
|
120
|
+
* @param {IData} data
|
|
121
|
+
* @return {*} {Promise<IHttpResponse>}
|
|
122
|
+
*/
|
|
123
|
+
async put(
|
|
124
|
+
url: string,
|
|
125
|
+
data: IData,
|
|
126
|
+
headers: AxiosRequestHeaders = {},
|
|
127
|
+
): Promise<IHttpResponse> {
|
|
128
|
+
url = this.handleAppPresetParam(url, data);
|
|
129
|
+
const response = await axios.put(url, data, { headers });
|
|
130
|
+
return this.doResponseResult(response);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* 获取模型数据
|
|
135
|
+
*
|
|
136
|
+
* @author chitanda
|
|
137
|
+
* @date 2022-07-14 15:07:15
|
|
138
|
+
* @param {string} url
|
|
139
|
+
* @param {AxiosRequestHeaders} [headers={}]
|
|
140
|
+
* @return {*} {Promise<IHttpResponse>}
|
|
141
|
+
*/
|
|
142
|
+
async getModel(
|
|
143
|
+
url: string,
|
|
144
|
+
headers: AxiosRequestHeaders = {},
|
|
145
|
+
): Promise<IHttpResponse> {
|
|
146
|
+
const response = await axios.get(url, {
|
|
147
|
+
headers,
|
|
148
|
+
});
|
|
149
|
+
return this.doResponseResult(response);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* 统一处理请求返回
|
|
154
|
+
*
|
|
155
|
+
* @author chitanda
|
|
156
|
+
* @date 2022-07-14 16:07:23
|
|
157
|
+
* @private
|
|
158
|
+
* @param {AxiosResponse} response
|
|
159
|
+
* @return {*} {IHttpResponse}
|
|
160
|
+
*/
|
|
161
|
+
private doResponseResult(response: AxiosResponse): IHttpResponse {
|
|
162
|
+
const res = response as IHttpResponse;
|
|
163
|
+
if (res.status >= 200 && res.status <= 299) {
|
|
164
|
+
res.ok = true;
|
|
165
|
+
}
|
|
166
|
+
return res;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/**
|
|
170
|
+
* 处理平台预定义参数
|
|
171
|
+
*
|
|
172
|
+
* @author chitanda
|
|
173
|
+
* @date 2022-07-14 15:07:12
|
|
174
|
+
* @private
|
|
175
|
+
* @param {string} url
|
|
176
|
+
* @param {IParams} [params]
|
|
177
|
+
* @return {*} {string}
|
|
178
|
+
*/
|
|
179
|
+
private handleAppPresetParam(url: string, params?: IParams): string {
|
|
180
|
+
if (params) {
|
|
181
|
+
const keys = Object.keys(params);
|
|
182
|
+
const tempParam: IParams = {};
|
|
183
|
+
keys.forEach((item: string) => {
|
|
184
|
+
if (item.startsWith('srf') && notNilEmpty(params[item])) {
|
|
185
|
+
tempParam[item] = params[item];
|
|
186
|
+
}
|
|
187
|
+
});
|
|
188
|
+
return this.attachUrlParam(url, params);
|
|
189
|
+
}
|
|
190
|
+
return url;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
/**
|
|
194
|
+
* url 附加请求参数
|
|
195
|
+
*
|
|
196
|
+
* @author chitanda
|
|
197
|
+
* @date 2022-07-14 15:07:34
|
|
198
|
+
* @private
|
|
199
|
+
* @param {string} url
|
|
200
|
+
* @param {IParams} params
|
|
201
|
+
* @return {*} {string}
|
|
202
|
+
*/
|
|
203
|
+
private attachUrlParam(url: string, params: IParams): string {
|
|
204
|
+
url = this.attachUrl(url);
|
|
205
|
+
const strParams: string = stringify(params);
|
|
206
|
+
if (notNilEmpty(strParams)) {
|
|
207
|
+
if (url.endsWith('?')) {
|
|
208
|
+
url = `${url}${strParams}`;
|
|
209
|
+
} else if (url.indexOf('?') !== -1 && url.endsWith('&')) {
|
|
210
|
+
url = `${url}${strParams}`;
|
|
211
|
+
} else if (url.indexOf('?') !== -1 && !url.endsWith('&')) {
|
|
212
|
+
url = `${url}&${strParams}`;
|
|
213
|
+
} else {
|
|
214
|
+
url = `${url}?${strParams}`;
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
return url;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
/**
|
|
221
|
+
* 处理 url 参数
|
|
222
|
+
*
|
|
223
|
+
* @author chitanda
|
|
224
|
+
* @date 2022-07-20 20:07:17
|
|
225
|
+
* @private
|
|
226
|
+
* @param {string} url
|
|
227
|
+
* @return {*} {string}
|
|
228
|
+
*/
|
|
229
|
+
private attachUrl(url: string): string {
|
|
230
|
+
return `${this.prefix}${url}`;
|
|
231
|
+
}
|
|
232
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import pluralize from 'pluralize';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* 英文转复数写法
|
|
5
|
+
*
|
|
6
|
+
* @author chitanda
|
|
7
|
+
* @date 2022-08-25 18:08:41
|
|
8
|
+
* @export
|
|
9
|
+
* @param {string} key
|
|
10
|
+
* @return {*} {string}
|
|
11
|
+
*/
|
|
12
|
+
export function plural(key: string): string {
|
|
13
|
+
return pluralize(key);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* 英文转复数写法并转全小写
|
|
18
|
+
*
|
|
19
|
+
* @author chitanda
|
|
20
|
+
* @date 2022-08-25 18:08:23
|
|
21
|
+
* @export
|
|
22
|
+
* @param {string} key
|
|
23
|
+
* @return {*} {string}
|
|
24
|
+
*/
|
|
25
|
+
export function pluralLower(key: string): string {
|
|
26
|
+
return plural(key).toLowerCase();
|
|
27
|
+
}
|
|
@@ -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"}
|