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

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 (40) hide show
  1. package/out/context/index.js +3 -3
  2. package/out/environment/environment.d.ts.map +1 -1
  3. package/out/environment/environment.js +5 -1
  4. package/out/ibizsys.d.ts +0 -7
  5. package/out/ibizsys.d.ts.map +1 -1
  6. package/out/ibizsys.js +1 -9
  7. package/out/index.d.ts +0 -1
  8. package/out/index.d.ts.map +1 -1
  9. package/out/index.js +0 -1
  10. package/out/install.d.ts.map +1 -1
  11. package/out/install.js +3 -2
  12. package/out/interface/i-environment/i-environment.d.ts +40 -1
  13. package/out/interface/i-environment/i-environment.d.ts.map +1 -1
  14. package/out/utils/index.d.ts +5 -2
  15. package/out/utils/index.d.ts.map +1 -1
  16. package/out/utils/index.js +4 -1
  17. package/out/utils/namespace/namespace.d.ts +148 -0
  18. package/out/utils/namespace/namespace.d.ts.map +1 -0
  19. package/out/utils/namespace/namespace.js +216 -0
  20. package/out/utils/net/http-response.d.ts +94 -0
  21. package/out/utils/net/http-response.d.ts.map +1 -0
  22. package/out/utils/net/http-response.js +53 -0
  23. package/out/utils/net/net.d.ts +16 -34
  24. package/out/utils/net/net.d.ts.map +1 -1
  25. package/out/utils/net/net.js +16 -13
  26. package/out/utils/plural/plural.d.ts +21 -0
  27. package/out/utils/plural/plural.d.ts.map +1 -0
  28. package/out/utils/plural/plural.js +25 -0
  29. package/package.json +13 -9
  30. package/src/context/index.ts +3 -3
  31. package/src/environment/environment.ts +5 -1
  32. package/src/ibizsys.ts +1 -10
  33. package/src/index.ts +0 -2
  34. package/src/install.ts +3 -2
  35. package/src/interface/i-environment/i-environment.ts +45 -2
  36. package/src/utils/index.ts +5 -2
  37. package/src/utils/namespace/namespace.ts +244 -0
  38. package/src/utils/net/http-response.ts +113 -0
  39. package/src/utils/net/net.ts +26 -40
  40. package/src/utils/plural/plural.ts +27 -0
@@ -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
+ }
@@ -1,27 +1,7 @@
1
1
  import axios, { AxiosRequestHeaders, AxiosResponse } from 'axios';
2
2
  import { stringify } from 'qs';
3
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
- }
4
+ import { IHttpResponse } from './http-response';
25
5
 
26
6
  /**
27
7
  * 全局请求工具类
@@ -40,7 +20,11 @@ export class Net {
40
20
  * @protected
41
21
  * @type {string}
42
22
  */
43
- protected prefix: string = '';
23
+ protected _prefix: string = '';
24
+
25
+ get prefix(): string {
26
+ return this._prefix || ibiz.env.baseUrl;
27
+ }
44
28
 
45
29
  /**
46
30
  * Creates an instance of Net.
@@ -51,7 +35,7 @@ export class Net {
51
35
  */
52
36
  constructor(prefix?: string) {
53
37
  if (prefix) {
54
- this.prefix = prefix;
38
+ this._prefix = prefix;
55
39
  }
56
40
  }
57
41
 
@@ -62,14 +46,14 @@ export class Net {
62
46
  * @date 2022-07-14 15:07:01
63
47
  * @param {string} url
64
48
  * @param {IParams} [params={}]
65
- * @return {*} {Promise<NetResponse>}
49
+ * @return {*} {Promise<IHttpResponse>}
66
50
  */
67
51
  async post(
68
52
  url: string,
69
53
  data: IData,
70
54
  params: IParams = {},
71
55
  headers: AxiosRequestHeaders = {},
72
- ): Promise<NetResponse> {
56
+ ): Promise<IHttpResponse> {
73
57
  url = this.handleAppPresetParam(url, params);
74
58
  const response = await axios({
75
59
  method: 'post',
@@ -91,19 +75,20 @@ export class Net {
91
75
  * @date 2022-07-14 15:07:08
92
76
  * @param {string} url
93
77
  * @param {IParams} [params={}]
94
- * @return {*} {Promise<NetResponse>}
78
+ * @return {*} {Promise<IHttpResponse>}
95
79
  */
96
80
  async get(
97
81
  url: string,
98
82
  params: IParams = {},
99
83
  headers: AxiosRequestHeaders = {},
100
- ): Promise<NetResponse> {
84
+ option: IParams = {},
85
+ ): Promise<IHttpResponse> {
101
86
  // if (params.srfparentdata) {
102
87
  // Object.assign(params, params.srfparentdata);
103
88
  // delete params.srfparentdata;
104
89
  // }
105
90
  url = this.attachUrlParam(url, params);
106
- const response = await axios.get(url, { headers });
91
+ const response = await axios.get(url, { headers, ...option });
107
92
  return this.doResponseResult(response);
108
93
  }
109
94
 
@@ -114,13 +99,13 @@ export class Net {
114
99
  * @date 2022-07-14 15:07:43
115
100
  * @param {string} url
116
101
  * @param {IParams} [params]
117
- * @return {*} {Promise<NetResponse>}
102
+ * @return {*} {Promise<IHttpResponse>}
118
103
  */
119
104
  async delete(
120
105
  url: string,
121
106
  params?: IParams,
122
107
  headers: AxiosRequestHeaders = {},
123
- ): Promise<NetResponse> {
108
+ ): Promise<IHttpResponse> {
124
109
  url = this.handleAppPresetParam(url, params);
125
110
  const response = await axios.delete(url, { headers });
126
111
  return this.doResponseResult(response);
@@ -132,16 +117,17 @@ export class Net {
132
117
  * @author chitanda
133
118
  * @date 2022-07-14 15:07:49
134
119
  * @param {string} url
135
- * @param {IParams} params
136
- * @return {*} {Promise<NetResponse>}
120
+ * @param {IData} data
121
+ * @return {*} {Promise<IHttpResponse>}
137
122
  */
138
123
  async put(
139
124
  url: string,
140
- params: IParams,
125
+ data: IData,
126
+ params: IParams = {},
141
127
  headers: AxiosRequestHeaders = {},
142
- ): Promise<NetResponse> {
128
+ ): Promise<IHttpResponse> {
143
129
  url = this.handleAppPresetParam(url, params);
144
- const response = await axios.put(url, params, { headers });
130
+ const response = await axios.put(url, data, { headers });
145
131
  return this.doResponseResult(response);
146
132
  }
147
133
 
@@ -152,12 +138,12 @@ export class Net {
152
138
  * @date 2022-07-14 15:07:15
153
139
  * @param {string} url
154
140
  * @param {AxiosRequestHeaders} [headers={}]
155
- * @return {*} {Promise<NetResponse>}
141
+ * @return {*} {Promise<IHttpResponse>}
156
142
  */
157
143
  async getModel(
158
144
  url: string,
159
145
  headers: AxiosRequestHeaders = {},
160
- ): Promise<NetResponse> {
146
+ ): Promise<IHttpResponse> {
161
147
  const response = await axios.get(url, {
162
148
  headers,
163
149
  });
@@ -171,10 +157,10 @@ export class Net {
171
157
  * @date 2022-07-14 16:07:23
172
158
  * @private
173
159
  * @param {AxiosResponse} response
174
- * @return {*} {NetResponse}
160
+ * @return {*} {IHttpResponse}
175
161
  */
176
- private doResponseResult(response: AxiosResponse): NetResponse {
177
- const res = response as NetResponse;
162
+ private doResponseResult(response: AxiosResponse): IHttpResponse {
163
+ const res = response as IHttpResponse;
178
164
  if (res.status >= 200 && res.status <= 299) {
179
165
  res.ok = true;
180
166
  }
@@ -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
+ }