@ibiz-template/core 0.0.1-alpha.1 → 0.0.1-alpha.13

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.
Files changed (69) hide show
  1. package/out/constant/http-status-message/http-status-message.d.ts +5 -0
  2. package/out/constant/http-status-message/http-status-message.d.ts.map +1 -0
  3. package/out/constant/http-status-message/http-status-message.js +20 -0
  4. package/out/constant/index.d.ts +1 -0
  5. package/out/constant/index.d.ts.map +1 -1
  6. package/out/constant/index.js +1 -0
  7. package/out/context/index.d.ts +10 -2
  8. package/out/context/index.d.ts.map +1 -1
  9. package/out/context/index.js +20 -4
  10. package/out/environment/environment.d.ts.map +1 -1
  11. package/out/environment/environment.js +6 -1
  12. package/out/error/http-error/http-error.d.ts +18 -0
  13. package/out/error/http-error/http-error.d.ts.map +1 -0
  14. package/out/error/http-error/http-error.js +36 -0
  15. package/out/error/index.d.ts +3 -0
  16. package/out/error/index.d.ts.map +1 -0
  17. package/out/error/index.js +2 -0
  18. package/out/error/runtime-error/runtime-error.d.ts +15 -0
  19. package/out/error/runtime-error/runtime-error.d.ts.map +1 -0
  20. package/out/error/runtime-error/runtime-error.js +15 -0
  21. package/out/ibizsys.d.ts +0 -7
  22. package/out/ibizsys.d.ts.map +1 -1
  23. package/out/ibizsys.js +1 -9
  24. package/out/index.d.ts +1 -1
  25. package/out/index.d.ts.map +1 -1
  26. package/out/index.js +1 -1
  27. package/out/install.d.ts.map +1 -1
  28. package/out/install.js +3 -2
  29. package/out/interface/i-environment/i-environment.d.ts +48 -1
  30. package/out/interface/i-environment/i-environment.d.ts.map +1 -1
  31. package/out/types.d.ts +10 -0
  32. package/out/types.d.ts.map +1 -1
  33. package/out/utils/index.d.ts +5 -2
  34. package/out/utils/index.d.ts.map +1 -1
  35. package/out/utils/index.js +4 -1
  36. package/out/utils/namespace/namespace.d.ts +148 -0
  37. package/out/utils/namespace/namespace.d.ts.map +1 -0
  38. package/out/utils/namespace/namespace.js +216 -0
  39. package/out/utils/net/http-response.d.ts +94 -0
  40. package/out/utils/net/http-response.d.ts.map +1 -0
  41. package/out/utils/net/http-response.js +53 -0
  42. package/out/utils/net/net.d.ts +16 -34
  43. package/out/utils/net/net.d.ts.map +1 -1
  44. package/out/utils/net/net.js +57 -28
  45. package/out/utils/plural/plural.d.ts +21 -0
  46. package/out/utils/plural/plural.d.ts.map +1 -0
  47. package/out/utils/plural/plural.js +25 -0
  48. package/out/utils/util/util.d.ts +29 -0
  49. package/out/utils/util/util.d.ts.map +1 -1
  50. package/out/utils/util/util.js +50 -0
  51. package/package.json +19 -9
  52. package/src/constant/http-status-message/http-status-message.ts +20 -0
  53. package/src/constant/index.ts +1 -0
  54. package/src/context/index.ts +24 -5
  55. package/src/environment/environment.ts +6 -1
  56. package/src/error/http-error/http-error.ts +43 -0
  57. package/src/error/index.ts +2 -0
  58. package/src/error/runtime-error/runtime-error.ts +14 -0
  59. package/src/ibizsys.ts +1 -10
  60. package/src/index.ts +1 -2
  61. package/src/install.ts +3 -2
  62. package/src/interface/i-environment/i-environment.ts +54 -2
  63. package/src/types.ts +11 -0
  64. package/src/utils/index.ts +5 -2
  65. package/src/utils/namespace/namespace.ts +244 -0
  66. package/src/utils/net/http-response.ts +113 -0
  67. package/src/utils/net/net.ts +67 -60
  68. package/src/utils/plural/plural.ts +27 -0
  69. package/src/utils/util/util.ts +64 -0
@@ -0,0 +1,216 @@
1
+ export const defaultNamespace = 'ibiz';
2
+ const statePrefix = 'is-';
3
+ /**
4
+ * css bem 命名规则拼接
5
+ * _bem('ibiz', 'layout') => ibiz-layout
6
+ * _bem('ibiz', 'layout', '', 'title') => ibiz-layout__title
7
+ * _bem('ibiz', 'layout', '', '', 'right') => ibiz-layout--right
8
+ * _bem('ibiz', 'layout', '', 'title', 'right') => ibiz-layout__title--right
9
+ * _bem('ibiz', 'layout', 'header', 'title', 'right') => ibiz-layout-header__title--right
10
+ *
11
+ * @author chitanda
12
+ * @date 2022-09-06 11:09:42
13
+ * @param {string} namespace 命名空间
14
+ * @param {string} block 块
15
+ * @param {string} blockSuffix 块后缀
16
+ * @param {string} element 元素
17
+ * @param {string} modifier 修饰符
18
+ * @return {*} {string}
19
+ */
20
+ function _bem(namespace, block, blockSuffix, element, modifier) {
21
+ let cls = `${namespace}-${block}`;
22
+ if (blockSuffix) {
23
+ cls += `-${blockSuffix}`;
24
+ }
25
+ if (element) {
26
+ cls += `__${element}`;
27
+ }
28
+ if (modifier) {
29
+ cls += `--${modifier}`;
30
+ }
31
+ return cls;
32
+ }
33
+ /**
34
+ * 全局样式处理命名空间
35
+ *
36
+ * @author chitanda
37
+ * @date 2022-09-06 11:09:50
38
+ * @export
39
+ * @class Namespace
40
+ */
41
+ export class Namespace {
42
+ /**
43
+ * Creates an instance of Namespace.
44
+ *
45
+ * @author chitanda
46
+ * @date 2022-09-06 12:09:12
47
+ * @param {string} block 当前命名空间的根模块,例如组件的名称
48
+ * @param {string} [namespace] 指定命名空间,未指定使用默认值 ibiz
49
+ */
50
+ constructor(block, namespace) {
51
+ this.block = block;
52
+ this.namespace = namespace || defaultNamespace;
53
+ }
54
+ /**
55
+ * namespace-block
56
+ * namespace-block-blockSuffix
57
+ *
58
+ * @author chitanda
59
+ * @date 2022-09-06 12:09:08
60
+ * @param {string} [blockSuffix='']
61
+ * @return {*} {string}
62
+ */
63
+ b(blockSuffix = '') {
64
+ return _bem(this.namespace, this.block, blockSuffix, '', '');
65
+ }
66
+ /**
67
+ * namespace-block__element
68
+ *
69
+ * @author chitanda
70
+ * @date 2022-09-06 12:09:48
71
+ * @param {string} [element]
72
+ * @return {*} {string}
73
+ */
74
+ e(element) {
75
+ return element ? _bem(this.namespace, this.block, '', element, '') : '';
76
+ }
77
+ /**
78
+ * namespace-block--modifier
79
+ *
80
+ * @author chitanda
81
+ * @date 2022-09-06 12:09:37
82
+ * @param {string} [modifier]
83
+ * @return {*} {string}
84
+ */
85
+ m(modifier) {
86
+ return modifier ? _bem(this.namespace, this.block, '', '', modifier) : '';
87
+ }
88
+ /**
89
+ * namespace-block-blockSuffix__element
90
+ *
91
+ * @author chitanda
92
+ * @date 2022-09-06 12:09:52
93
+ * @param {string} [blockSuffix]
94
+ * @param {string} [element]
95
+ * @return {*} {string}
96
+ */
97
+ be(blockSuffix, element) {
98
+ return blockSuffix && element
99
+ ? _bem(this.namespace, this.block, blockSuffix, element, '')
100
+ : '';
101
+ }
102
+ /**
103
+ * namespace-block__element--modifier
104
+ *
105
+ * @author chitanda
106
+ * @date 2022-09-06 12:09:19
107
+ * @param {string} [element]
108
+ * @param {string} [modifier]
109
+ * @return {*} {string}
110
+ */
111
+ em(element, modifier) {
112
+ return element && modifier
113
+ ? _bem(this.namespace, this.block, '', element, modifier)
114
+ : '';
115
+ }
116
+ /**
117
+ * namespace-block-blockSuffix--modifier
118
+ *
119
+ * @author chitanda
120
+ * @date 2022-09-06 12:09:59
121
+ * @param {string} [blockSuffix]
122
+ * @param {string} [modifier]
123
+ * @return {*} {string}
124
+ */
125
+ bm(blockSuffix, modifier) {
126
+ return blockSuffix && modifier
127
+ ? _bem(this.namespace, this.block, blockSuffix, '', modifier)
128
+ : '';
129
+ }
130
+ /**
131
+ * namespace-block-blockSuffix__element--modifier
132
+ *
133
+ * @author chitanda
134
+ * @date 2022-09-06 12:09:37
135
+ * @param {string} [blockSuffix]
136
+ * @param {string} [element]
137
+ * @param {string} [modifier]
138
+ * @return {*} {string}
139
+ */
140
+ bem(blockSuffix, element, modifier) {
141
+ return blockSuffix && element && modifier
142
+ ? _bem(this.namespace, this.block, blockSuffix, element, modifier)
143
+ : '';
144
+ }
145
+ /**
146
+ * 返回状态 class
147
+ *
148
+ * is('loading', false) => '';
149
+ * is('loading', true) => 'is-loading';
150
+ *
151
+ * @author chitanda
152
+ * @date 2022-09-06 12:09:57
153
+ * @param {string} name
154
+ * @param {boolean} [state]
155
+ * @return {*} {string}
156
+ */
157
+ is(name, state) {
158
+ return name && state ? `${statePrefix}${name}` : '';
159
+ }
160
+ /**
161
+ * 生成使用到的 css 变量 style 对象
162
+ *
163
+ * @author chitanda
164
+ * @date 2022-09-06 15:09:41
165
+ * @param {Record<string, string>} object
166
+ * @return {*} {Record<string, string>}
167
+ */
168
+ cssVar(object) {
169
+ const styles = {};
170
+ for (const key in object) {
171
+ if (object[key]) {
172
+ styles[this.cssVarName(key)] = object[key];
173
+ }
174
+ }
175
+ return styles;
176
+ }
177
+ /**
178
+ * 生成使用到的 css block 变量 style 对象
179
+ *
180
+ * @author chitanda
181
+ * @date 2022-09-06 15:09:03
182
+ * @param {Record<string, string>} object
183
+ * @return {*} {Record<string, string>}
184
+ */
185
+ cssVarBlock(object) {
186
+ const styles = {};
187
+ for (const key in object) {
188
+ if (object[key]) {
189
+ styles[this.cssVarBlockName(key)] = object[key];
190
+ }
191
+ }
192
+ return styles;
193
+ }
194
+ /**
195
+ * 生成 css var 变量名称
196
+ *
197
+ * @author chitanda
198
+ * @date 2022-09-06 15:09:21
199
+ * @param {string} name
200
+ * @return {*} {string}
201
+ */
202
+ cssVarName(name) {
203
+ return `--${this.namespace}-${name}`;
204
+ }
205
+ /**
206
+ * 生成块 css var 变量名称
207
+ *
208
+ * @author chitanda
209
+ * @date 2022-09-06 15:09:35
210
+ * @param {string} name
211
+ * @return {*} {string}
212
+ */
213
+ cssVarBlockName(name) {
214
+ return `--${this.namespace}-${this.block}-${name}`;
215
+ }
216
+ }
@@ -0,0 +1,94 @@
1
+ import { AxiosRequestConfig, AxiosResponse, AxiosResponseHeaders } from 'axios';
2
+ /**
3
+ * Http请求返回接口
4
+ *
5
+ * @author chitanda
6
+ * @date 2022-08-21 17:08:06
7
+ * @export
8
+ * @interface IHttpResponse
9
+ * @extends {AxiosResponse}
10
+ * @template T
11
+ */
12
+ export interface IHttpResponse<T = IData> extends AxiosResponse {
13
+ /**
14
+ * 是否请求成功
15
+ *
16
+ * @description 当状态码为 200-299 时认为成功
17
+ * @author chitanda
18
+ * @date 2022-07-14 16:07:59
19
+ * @type {boolean}
20
+ */
21
+ ok: boolean;
22
+ /**
23
+ * 是否为本地仿造响应
24
+ *
25
+ * @description 只有当值为 true 时, 才认为是本地仿造响应
26
+ * @author chitanda
27
+ * @date 2022-08-18 15:08:44
28
+ * @type {boolean}
29
+ */
30
+ local?: boolean;
31
+ data: T;
32
+ /**
33
+ * 当前页
34
+ */
35
+ page?: number;
36
+ /**
37
+ * 分页条数
38
+ */
39
+ size?: number;
40
+ /**
41
+ * 总条数
42
+ */
43
+ total?: number;
44
+ }
45
+ /**
46
+ * 本地请求仿造响应
47
+ *
48
+ * @author chitanda
49
+ * @date 2022-08-21 17:08:00
50
+ * @export
51
+ * @class HttpResponse
52
+ * @implements {IHttpResponse<T>}
53
+ * @template T
54
+ */
55
+ export declare class HttpResponse<T = IData> implements IHttpResponse<T> {
56
+ /**
57
+ * 本地仿造响应
58
+ *
59
+ * @author chitanda
60
+ * @date 2022-08-18 15:08:06
61
+ */
62
+ local: boolean;
63
+ ok: boolean;
64
+ data: T;
65
+ status: number;
66
+ statusText: string;
67
+ /**
68
+ * header 本地仿造时值为空
69
+ *
70
+ * @author chitanda
71
+ * @date 2022-08-18 15:08:46
72
+ * @type {AxiosResponseHeaders}
73
+ */
74
+ headers: AxiosResponseHeaders;
75
+ /**
76
+ * AxiosResponse 本地仿造时值为空
77
+ *
78
+ * @author chitanda
79
+ * @date 2022-08-18 15:08:22
80
+ * @type {AxiosRequestConfig<IData>}
81
+ */
82
+ config: AxiosRequestConfig<IData>;
83
+ /**
84
+ * Creates an instance of HttpResponse.
85
+ *
86
+ * @author chitanda
87
+ * @date 2022-08-18 15:08:11
88
+ * @param {unknown} [data] 返回的数据
89
+ * @param {number} [status] 状态码 (默认为 200)
90
+ * @param {string} [statusText] 状态描述 (默认为空字符)
91
+ */
92
+ constructor(data?: unknown, status?: number, statusText?: string);
93
+ }
94
+ //# sourceMappingURL=http-response.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"http-response.d.ts","sourceRoot":"","sources":["../../../src/utils/net/http-response.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,aAAa,EAAE,oBAAoB,EAAE,MAAM,OAAO,CAAC;AAEhF;;;;;;;;;GASG;AACH,MAAM,WAAW,aAAa,CAAC,CAAC,GAAG,KAAK,CAAE,SAAQ,aAAa;IAC7D;;;;;;;OAOG;IACH,EAAE,EAAE,OAAO,CAAC;IACZ;;;;;;;OAOG;IACH,KAAK,CAAC,EAAE,OAAO,CAAC;IAEhB,IAAI,EAAE,CAAC,CAAC;IAER;;OAEG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IAEd;;OAEG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IAEd;;OAEG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED;;;;;;;;;GASG;AACH,qBAAa,YAAY,CAAC,CAAC,GAAG,KAAK,CAAE,YAAW,aAAa,CAAC,CAAC,CAAC;IAC9D;;;;;OAKG;IACH,KAAK,UAAQ;IAEb,EAAE,UAAS;IAEX,IAAI,EAAE,CAAC,CAAC;IAER,MAAM,EAAE,MAAM,CAAC;IAEf,UAAU,EAAE,MAAM,CAAC;IAEnB;;;;;;OAMG;IACH,OAAO,EAAE,oBAAoB,CAAM;IAEnC;;;;;;OAMG;IACH,MAAM,EAAE,kBAAkB,CAAC,KAAK,CAAC,CAAM;IAEvC;;;;;;;;OAQG;gBACS,IAAI,CAAC,EAAE,OAAO,EAAE,MAAM,CAAC,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM;CAQjE"}
@@ -0,0 +1,53 @@
1
+ /**
2
+ * 本地请求仿造响应
3
+ *
4
+ * @author chitanda
5
+ * @date 2022-08-21 17:08:00
6
+ * @export
7
+ * @class HttpResponse
8
+ * @implements {IHttpResponse<T>}
9
+ * @template T
10
+ */
11
+ export class HttpResponse {
12
+ /**
13
+ * Creates an instance of HttpResponse.
14
+ *
15
+ * @author chitanda
16
+ * @date 2022-08-18 15:08:11
17
+ * @param {unknown} [data] 返回的数据
18
+ * @param {number} [status] 状态码 (默认为 200)
19
+ * @param {string} [statusText] 状态描述 (默认为空字符)
20
+ */
21
+ constructor(data, status, statusText) {
22
+ /**
23
+ * 本地仿造响应
24
+ *
25
+ * @author chitanda
26
+ * @date 2022-08-18 15:08:06
27
+ */
28
+ this.local = true;
29
+ this.ok = false;
30
+ /**
31
+ * header 本地仿造时值为空
32
+ *
33
+ * @author chitanda
34
+ * @date 2022-08-18 15:08:46
35
+ * @type {AxiosResponseHeaders}
36
+ */
37
+ this.headers = {};
38
+ /**
39
+ * AxiosResponse 本地仿造时值为空
40
+ *
41
+ * @author chitanda
42
+ * @date 2022-08-18 15:08:22
43
+ * @type {AxiosRequestConfig<IData>}
44
+ */
45
+ this.config = {};
46
+ this.data = data;
47
+ this.status = status || 200;
48
+ this.statusText = statusText || '';
49
+ if (this.status >= 200 && this.status < 300) {
50
+ this.ok = true;
51
+ }
52
+ }
53
+ }
@@ -1,24 +1,5 @@
1
- import { AxiosRequestHeaders, AxiosResponse } from 'axios';
2
- /**
3
- * 返回值扩展
4
- *
5
- * @author chitanda
6
- * @date 2022-07-14 16:07:50
7
- * @export
8
- * @interface NetResponse
9
- * @extends {AxiosResponse}
10
- */
11
- export interface NetResponse extends AxiosResponse {
12
- /**
13
- * 是否请求成功
14
- *
15
- * @description 当状态码为 200-299 时认为成功
16
- * @author chitanda
17
- * @date 2022-07-14 16:07:59
18
- * @type {boolean}
19
- */
20
- ok: boolean;
21
- }
1
+ import { AxiosRequestHeaders } from 'axios';
2
+ import { IHttpResponse } from './http-response';
22
3
  /**
23
4
  * 全局请求工具类
24
5
  *
@@ -36,7 +17,8 @@ export declare class Net {
36
17
  * @protected
37
18
  * @type {string}
38
19
  */
39
- protected prefix: string;
20
+ protected _prefix: string;
21
+ get prefix(): string;
40
22
  /**
41
23
  * Creates an instance of Net.
42
24
  *
@@ -52,9 +34,9 @@ export declare class Net {
52
34
  * @date 2022-07-14 15:07:01
53
35
  * @param {string} url
54
36
  * @param {IParams} [params={}]
55
- * @return {*} {Promise<NetResponse>}
37
+ * @return {*} {Promise<IHttpResponse>}
56
38
  */
57
- post(url: string, data: IData, params?: IParams, headers?: AxiosRequestHeaders): Promise<NetResponse>;
39
+ post(url: string, data: IData, params?: IParams, headers?: AxiosRequestHeaders): Promise<IHttpResponse>;
58
40
  /**
59
41
  * Get 请求
60
42
  *
@@ -62,9 +44,9 @@ export declare class Net {
62
44
  * @date 2022-07-14 15:07:08
63
45
  * @param {string} url
64
46
  * @param {IParams} [params={}]
65
- * @return {*} {Promise<NetResponse>}
47
+ * @return {*} {Promise<IHttpResponse>}
66
48
  */
67
- get(url: string, params?: IParams, headers?: AxiosRequestHeaders): Promise<NetResponse>;
49
+ get(url: string, params?: IParams, headers?: AxiosRequestHeaders, option?: IParams): Promise<IHttpResponse>;
68
50
  /**
69
51
  * Delete 请求
70
52
  *
@@ -72,19 +54,19 @@ export declare class Net {
72
54
  * @date 2022-07-14 15:07:43
73
55
  * @param {string} url
74
56
  * @param {IParams} [params]
75
- * @return {*} {Promise<NetResponse>}
57
+ * @return {*} {Promise<IHttpResponse>}
76
58
  */
77
- delete(url: string, params?: IParams, headers?: AxiosRequestHeaders): Promise<NetResponse>;
59
+ delete(url: string, params?: IParams, headers?: AxiosRequestHeaders): Promise<IHttpResponse>;
78
60
  /**
79
61
  * Put 请求
80
62
  *
81
63
  * @author chitanda
82
64
  * @date 2022-07-14 15:07:49
83
65
  * @param {string} url
84
- * @param {IParams} params
85
- * @return {*} {Promise<NetResponse>}
66
+ * @param {IData} data
67
+ * @return {*} {Promise<IHttpResponse>}
86
68
  */
87
- put(url: string, params: IParams, headers?: AxiosRequestHeaders): Promise<NetResponse>;
69
+ put(url: string, data: IData, params?: IParams, headers?: AxiosRequestHeaders): Promise<IHttpResponse>;
88
70
  /**
89
71
  * 获取模型数据
90
72
  *
@@ -92,9 +74,9 @@ export declare class Net {
92
74
  * @date 2022-07-14 15:07:15
93
75
  * @param {string} url
94
76
  * @param {AxiosRequestHeaders} [headers={}]
95
- * @return {*} {Promise<NetResponse>}
77
+ * @return {*} {Promise<IHttpResponse>}
96
78
  */
97
- getModel(url: string, headers?: AxiosRequestHeaders): Promise<NetResponse>;
79
+ getModel(url: string, headers?: AxiosRequestHeaders): Promise<IHttpResponse>;
98
80
  /**
99
81
  * 统一处理请求返回
100
82
  *
@@ -102,7 +84,7 @@ export declare class Net {
102
84
  * @date 2022-07-14 16:07:23
103
85
  * @private
104
86
  * @param {AxiosResponse} response
105
- * @return {*} {NetResponse}
87
+ * @return {*} {IHttpResponse}
106
88
  */
107
89
  private doResponseResult;
108
90
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"net.d.ts","sourceRoot":"","sources":["../../../src/utils/net/net.ts"],"names":[],"mappings":"AAAA,OAAc,EAAE,mBAAmB,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AAIlE;;;;;;;;GAQG;AACH,MAAM,WAAW,WAAY,SAAQ,aAAa;IAChD;;;;;;;OAOG;IACH,EAAE,EAAE,OAAO,CAAC;CACb;AAED;;;;;;;GAOG;AACH,qBAAa,GAAG;IACd;;;;;;;OAOG;IACH,SAAS,CAAC,MAAM,EAAE,MAAM,CAAM;IAE9B;;;;;;OAMG;gBACS,MAAM,CAAC,EAAE,MAAM;IAM3B;;;;;;;;OAQG;IACG,IAAI,CACR,GAAG,EAAE,MAAM,EACX,IAAI,EAAE,KAAK,EACX,MAAM,GAAE,OAAY,EACpB,OAAO,GAAE,mBAAwB,GAChC,OAAO,CAAC,WAAW,CAAC;IAevB;;;;;;;;OAQG;IACG,GAAG,CACP,GAAG,EAAE,MAAM,EACX,MAAM,GAAE,OAAY,EACpB,OAAO,GAAE,mBAAwB,GAChC,OAAO,CAAC,WAAW,CAAC;IAUvB;;;;;;;;OAQG;IACG,MAAM,CACV,GAAG,EAAE,MAAM,EACX,MAAM,CAAC,EAAE,OAAO,EAChB,OAAO,GAAE,mBAAwB,GAChC,OAAO,CAAC,WAAW,CAAC;IAMvB;;;;;;;;OAQG;IACG,GAAG,CACP,GAAG,EAAE,MAAM,EACX,MAAM,EAAE,OAAO,EACf,OAAO,GAAE,mBAAwB,GAChC,OAAO,CAAC,WAAW,CAAC;IAMvB;;;;;;;;OAQG;IACG,QAAQ,CACZ,GAAG,EAAE,MAAM,EACX,OAAO,GAAE,mBAAwB,GAChC,OAAO,CAAC,WAAW,CAAC;IAOvB;;;;;;;;OAQG;IACH,OAAO,CAAC,gBAAgB;IAQxB;;;;;;;;;OASG;IACH,OAAO,CAAC,oBAAoB;IAc5B;;;;;;;;;OASG;IACH,OAAO,CAAC,cAAc;IAiBtB;;;;;;;;OAQG;IACH,OAAO,CAAC,SAAS;CAGlB"}
1
+ {"version":3,"file":"net.d.ts","sourceRoot":"","sources":["../../../src/utils/net/net.ts"],"names":[],"mappings":"AAAA,OAAc,EAAc,mBAAmB,EAAiB,MAAM,OAAO,CAAC;AAI9E,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAEhD;;;;;;;GAOG;AACH,qBAAa,GAAG;IACd;;;;;;;OAOG;IACH,SAAS,CAAC,OAAO,EAAE,MAAM,CAAM;IAE/B,IAAI,MAAM,IAAI,MAAM,CAEnB;IAED;;;;;;OAMG;gBACS,MAAM,CAAC,EAAE,MAAM;IAM3B;;;;;;;;OAQG;IACG,IAAI,CACR,GAAG,EAAE,MAAM,EACX,IAAI,EAAE,KAAK,EACX,MAAM,GAAE,OAAY,EACpB,OAAO,GAAE,mBAAwB,GAChC,OAAO,CAAC,aAAa,CAAC;IAmBzB;;;;;;;;OAQG;IACG,GAAG,CACP,GAAG,EAAE,MAAM,EACX,MAAM,GAAE,OAAY,EACpB,OAAO,GAAE,mBAAwB,EACjC,MAAM,GAAE,OAAY,GACnB,OAAO,CAAC,aAAa,CAAC;IAczB;;;;;;;;OAQG;IACG,MAAM,CACV,GAAG,EAAE,MAAM,EACX,MAAM,CAAC,EAAE,OAAO,EAChB,OAAO,GAAE,mBAAwB,GAChC,OAAO,CAAC,aAAa,CAAC;IAUzB;;;;;;;;OAQG;IACG,GAAG,CACP,GAAG,EAAE,MAAM,EACX,IAAI,EAAE,KAAK,EACX,MAAM,GAAE,OAAY,EACpB,OAAO,GAAE,mBAAwB,GAChC,OAAO,CAAC,aAAa,CAAC;IAUzB;;;;;;;;OAQG;IACG,QAAQ,CACZ,GAAG,EAAE,MAAM,EACX,OAAO,GAAE,mBAAwB,GAChC,OAAO,CAAC,aAAa,CAAC;IAWzB;;;;;;;;OAQG;IACH,OAAO,CAAC,gBAAgB;IAQxB;;;;;;;;;OASG;IACH,OAAO,CAAC,oBAAoB;IAc5B;;;;;;;;;OASG;IACH,OAAO,CAAC,cAAc;IAiBtB;;;;;;;;OAQG;IACH,OAAO,CAAC,SAAS;CAGlB"}
@@ -1,6 +1,7 @@
1
1
  import axios from 'axios';
2
2
  import { stringify } from 'qs';
3
3
  import { notNilEmpty } from 'qx-util';
4
+ import { HttpError } from '../../error';
4
5
  /**
5
6
  * 全局请求工具类
6
7
  *
@@ -26,11 +27,14 @@ export class Net {
26
27
  * @protected
27
28
  * @type {string}
28
29
  */
29
- this.prefix = '';
30
+ this._prefix = '';
30
31
  if (prefix) {
31
- this.prefix = prefix;
32
+ this._prefix = prefix;
32
33
  }
33
34
  }
35
+ get prefix() {
36
+ return this._prefix || ibiz.env.baseUrl;
37
+ }
34
38
  /**
35
39
  * Post 请求
36
40
  *
@@ -38,17 +42,22 @@ export class Net {
38
42
  * @date 2022-07-14 15:07:01
39
43
  * @param {string} url
40
44
  * @param {IParams} [params={}]
41
- * @return {*} {Promise<NetResponse>}
45
+ * @return {*} {Promise<IHttpResponse>}
42
46
  */
43
47
  async post(url, data, params = {}, headers = {}) {
44
48
  url = this.handleAppPresetParam(url, params);
45
- const response = await axios({
46
- method: 'post',
47
- url,
48
- data,
49
- headers: Object.assign({ 'Content-Type': 'application/json;charset=UTF-8', Accept: 'application/json' }, headers),
50
- });
51
- return this.doResponseResult(response);
49
+ try {
50
+ const response = await axios({
51
+ method: 'post',
52
+ url,
53
+ data,
54
+ headers: Object.assign({ 'Content-Type': 'application/json;charset=UTF-8', Accept: 'application/json' }, headers),
55
+ });
56
+ return this.doResponseResult(response);
57
+ }
58
+ catch (error) {
59
+ throw new HttpError(error);
60
+ }
52
61
  }
53
62
  /**
54
63
  * Get 请求
@@ -57,16 +66,21 @@ export class Net {
57
66
  * @date 2022-07-14 15:07:08
58
67
  * @param {string} url
59
68
  * @param {IParams} [params={}]
60
- * @return {*} {Promise<NetResponse>}
69
+ * @return {*} {Promise<IHttpResponse>}
61
70
  */
62
- async get(url, params = {}, headers = {}) {
71
+ async get(url, params = {}, headers = {}, option = {}) {
63
72
  // if (params.srfparentdata) {
64
73
  // Object.assign(params, params.srfparentdata);
65
74
  // delete params.srfparentdata;
66
75
  // }
67
76
  url = this.attachUrlParam(url, params);
68
- const response = await axios.get(url, { headers });
69
- return this.doResponseResult(response);
77
+ try {
78
+ const response = await axios.get(url, Object.assign({ headers }, option));
79
+ return this.doResponseResult(response);
80
+ }
81
+ catch (error) {
82
+ throw new HttpError(error);
83
+ }
70
84
  }
71
85
  /**
72
86
  * Delete 请求
@@ -75,12 +89,17 @@ export class Net {
75
89
  * @date 2022-07-14 15:07:43
76
90
  * @param {string} url
77
91
  * @param {IParams} [params]
78
- * @return {*} {Promise<NetResponse>}
92
+ * @return {*} {Promise<IHttpResponse>}
79
93
  */
80
94
  async delete(url, params, headers = {}) {
81
95
  url = this.handleAppPresetParam(url, params);
82
- const response = await axios.delete(url, { headers });
83
- return this.doResponseResult(response);
96
+ try {
97
+ const response = await axios.delete(url, { headers });
98
+ return this.doResponseResult(response);
99
+ }
100
+ catch (error) {
101
+ throw new HttpError(error);
102
+ }
84
103
  }
85
104
  /**
86
105
  * Put 请求
@@ -88,13 +107,18 @@ export class Net {
88
107
  * @author chitanda
89
108
  * @date 2022-07-14 15:07:49
90
109
  * @param {string} url
91
- * @param {IParams} params
92
- * @return {*} {Promise<NetResponse>}
110
+ * @param {IData} data
111
+ * @return {*} {Promise<IHttpResponse>}
93
112
  */
94
- async put(url, params, headers = {}) {
113
+ async put(url, data, params = {}, headers = {}) {
95
114
  url = this.handleAppPresetParam(url, params);
96
- const response = await axios.put(url, params, { headers });
97
- return this.doResponseResult(response);
115
+ try {
116
+ const response = await axios.put(url, data, { headers });
117
+ return this.doResponseResult(response);
118
+ }
119
+ catch (error) {
120
+ throw new HttpError(error);
121
+ }
98
122
  }
99
123
  /**
100
124
  * 获取模型数据
@@ -103,13 +127,18 @@ export class Net {
103
127
  * @date 2022-07-14 15:07:15
104
128
  * @param {string} url
105
129
  * @param {AxiosRequestHeaders} [headers={}]
106
- * @return {*} {Promise<NetResponse>}
130
+ * @return {*} {Promise<IHttpResponse>}
107
131
  */
108
132
  async getModel(url, headers = {}) {
109
- const response = await axios.get(url, {
110
- headers,
111
- });
112
- return this.doResponseResult(response);
133
+ try {
134
+ const response = await axios.get(url, {
135
+ headers,
136
+ });
137
+ return this.doResponseResult(response);
138
+ }
139
+ catch (error) {
140
+ throw new HttpError(error);
141
+ }
113
142
  }
114
143
  /**
115
144
  * 统一处理请求返回
@@ -118,7 +147,7 @@ export class Net {
118
147
  * @date 2022-07-14 16:07:23
119
148
  * @private
120
149
  * @param {AxiosResponse} response
121
- * @return {*} {NetResponse}
150
+ * @return {*} {IHttpResponse}
122
151
  */
123
152
  doResponseResult(response) {
124
153
  const res = response;
@@ -0,0 +1,21 @@
1
+ /**
2
+ * 英文转复数写法
3
+ *
4
+ * @author chitanda
5
+ * @date 2022-08-25 18:08:41
6
+ * @export
7
+ * @param {string} key
8
+ * @return {*} {string}
9
+ */
10
+ export declare function plural(key: string): string;
11
+ /**
12
+ * 英文转复数写法并转全小写
13
+ *
14
+ * @author chitanda
15
+ * @date 2022-08-25 18:08:23
16
+ * @export
17
+ * @param {string} key
18
+ * @return {*} {string}
19
+ */
20
+ export declare function pluralLower(key: string): string;
21
+ //# sourceMappingURL=plural.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plural.d.ts","sourceRoot":"","sources":["../../../src/utils/plural/plural.ts"],"names":[],"mappings":"AAEA;;;;;;;;GAQG;AACH,wBAAgB,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAE1C;AAED;;;;;;;;GAQG;AACH,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAE/C"}
@@ -0,0 +1,25 @@
1
+ import pluralize from 'pluralize';
2
+ /**
3
+ * 英文转复数写法
4
+ *
5
+ * @author chitanda
6
+ * @date 2022-08-25 18:08:41
7
+ * @export
8
+ * @param {string} key
9
+ * @return {*} {string}
10
+ */
11
+ export function plural(key) {
12
+ return pluralize(key);
13
+ }
14
+ /**
15
+ * 英文转复数写法并转全小写
16
+ *
17
+ * @author chitanda
18
+ * @date 2022-08-25 18:08:23
19
+ * @export
20
+ * @param {string} key
21
+ * @return {*} {string}
22
+ */
23
+ export function pluralLower(key) {
24
+ return plural(key).toLowerCase();
25
+ }