@ibiz-template/core 0.0.1-alpha.5 → 0.0.1-beta.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/dist/system/index.system.js +1 -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 +4 -0
- package/out/constant/index.d.ts.map +1 -1
- package/out/constant/index.js +4 -0
- package/out/constant/login-mode/login-mode.d.ts +23 -0
- package/out/constant/login-mode/login-mode.d.ts.map +1 -0
- package/out/constant/login-mode/login-mode.js +24 -0
- package/out/constant/menu-permission-mode/menu-permission-mode.d.ts +23 -0
- package/out/constant/menu-permission-mode/menu-permission-mode.d.ts.map +1 -0
- package/out/constant/menu-permission-mode/menu-permission-mode.js +24 -0
- package/out/constant/util/util.d.ts +5 -0
- package/out/constant/util/util.d.ts.map +1 -0
- package/out/constant/util/util.js +5 -0
- package/out/context/index.d.ts +2 -39
- package/out/context/index.d.ts.map +1 -1
- package/out/context/index.js +33 -64
- package/out/environment/environment.d.ts.map +1 -1
- package/out/environment/environment.js +11 -2
- package/out/error/http-error/http-error.d.ts.map +1 -1
- package/out/error/http-error/http-error.js +7 -0
- package/out/factory-center.d.ts +11 -0
- package/out/factory-center.d.ts.map +1 -0
- package/out/factory-center.js +10 -0
- package/out/ibizsys.d.ts +8 -1
- package/out/ibizsys.d.ts.map +1 -1
- package/out/ibizsys.js +8 -1
- package/out/index.d.ts +2 -1
- package/out/index.d.ts.map +1 -1
- package/out/index.js +2 -1
- package/out/install.d.ts.map +1 -1
- package/out/install.js +4 -2
- package/out/interface/click-outside/click-outside.d.ts +70 -0
- package/out/interface/click-outside/click-outside.d.ts.map +1 -0
- package/out/interface/click-outside/click-outside.js +1 -0
- package/out/interface/i-environment/i-environment.d.ts +72 -4
- package/out/interface/i-environment/i-environment.d.ts.map +1 -1
- package/out/interface/index.d.ts +1 -0
- package/out/interface/index.d.ts.map +1 -1
- package/out/interface/index.js +1 -1
- package/out/types.d.ts +10 -0
- package/out/types.d.ts.map +1 -1
- package/out/utils/click-outside/click-outside.d.ts +14 -0
- package/out/utils/click-outside/click-outside.d.ts.map +1 -0
- package/out/utils/click-outside/click-outside.js +85 -0
- package/out/utils/color/color.d.ts +13 -0
- package/out/utils/color/color.d.ts.map +1 -0
- package/out/utils/color/color.js +76 -0
- package/out/utils/download-file/download-file.d.ts +21 -0
- package/out/utils/download-file/download-file.d.ts.map +1 -0
- package/out/utils/download-file/download-file.js +87 -0
- package/out/utils/event/event.d.ts +34 -0
- package/out/utils/event/event.d.ts.map +1 -0
- package/out/utils/event/event.js +60 -0
- package/out/utils/index.d.ts +7 -1
- package/out/utils/index.d.ts.map +1 -1
- package/out/utils/index.js +7 -1
- package/out/utils/interceptor/core-interceptor.d.ts +15 -0
- package/out/utils/interceptor/core-interceptor.d.ts.map +1 -0
- package/out/utils/interceptor/core-interceptor.js +30 -0
- package/out/utils/interceptor/index.d.ts +3 -0
- package/out/utils/interceptor/index.d.ts.map +1 -0
- package/out/utils/interceptor/index.js +2 -0
- package/out/utils/interceptor/interceptor.d.ts +74 -3
- package/out/utils/interceptor/interceptor.d.ts.map +1 -1
- package/out/utils/interceptor/interceptor.js +73 -22
- package/out/utils/logger/logger.d.ts +3 -0
- package/out/utils/logger/logger.d.ts.map +1 -0
- package/out/utils/logger/logger.js +2 -0
- package/out/utils/net/http-response.d.ts +4 -9
- package/out/utils/net/http-response.d.ts.map +1 -1
- package/out/utils/net/http-response.js +0 -7
- package/out/utils/net/net.d.ts +82 -31
- package/out/utils/net/net.d.ts.map +1 -1
- package/out/utils/net/net.js +109 -40
- package/out/utils/url-helper/url-helper.d.ts +51 -0
- package/out/utils/url-helper/url-helper.d.ts.map +1 -0
- package/out/utils/url-helper/url-helper.js +59 -0
- package/out/utils/util/util.d.ts +20 -4
- package/out/utils/util/util.d.ts.map +1 -1
- package/out/utils/util/util.js +59 -5
- package/package.json +21 -9
- package/src/constant/http-status-message/http-status-message.ts +20 -0
- package/src/constant/index.ts +4 -0
- package/src/constant/login-mode/login-mode.ts +23 -0
- package/src/constant/menu-permission-mode/menu-permission-mode.ts +23 -0
- package/src/constant/util/util.ts +5 -0
- package/src/context/index.ts +34 -68
- package/src/environment/environment.ts +11 -2
- package/src/error/http-error/http-error.ts +7 -0
- package/src/factory-center.ts +9 -0
- package/src/ibizsys.ts +9 -1
- package/src/index.ts +2 -1
- package/src/install.ts +4 -2
- package/src/interface/click-outside/click-outside.ts +71 -0
- package/src/interface/i-environment/i-environment.ts +81 -4
- package/src/interface/index.ts +1 -0
- package/src/types.ts +10 -0
- package/src/utils/click-outside/click-outside.ts +110 -0
- package/src/utils/color/color.ts +84 -0
- package/src/utils/download-file/download-file.ts +88 -0
- package/src/utils/event/event.ts +77 -0
- package/src/utils/index.ts +7 -1
- package/src/utils/interceptor/core-interceptor.ts +35 -0
- package/src/utils/interceptor/index.ts +2 -0
- package/src/utils/interceptor/interceptor.ts +109 -22
- package/src/utils/logger/logger.ts +3 -0
- package/src/utils/net/http-response.ts +6 -9
- package/src/utils/net/net.ts +144 -51
- package/src/utils/url-helper/url-helper.ts +62 -0
- package/src/utils/util/util.ts +72 -14
package/out/utils/net/net.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import axios from 'axios';
|
|
2
|
+
import { merge } from 'lodash-es';
|
|
2
3
|
import { stringify } from 'qs';
|
|
3
4
|
import { notNilEmpty } from 'qx-util';
|
|
4
5
|
import { HttpError } from '../../error';
|
|
@@ -13,45 +14,99 @@ import { HttpError } from '../../error';
|
|
|
13
14
|
export class Net {
|
|
14
15
|
/**
|
|
15
16
|
* Creates an instance of Net.
|
|
16
|
-
*
|
|
17
|
-
* @
|
|
18
|
-
* @
|
|
19
|
-
* @param {string} [prefix] 请求前缀
|
|
17
|
+
* @author lxm
|
|
18
|
+
* @date 2022-10-27 16:10:05
|
|
19
|
+
* @param {CreateAxiosDefaults} [config] 创建实例用的默认配置
|
|
20
20
|
*/
|
|
21
|
-
constructor(
|
|
21
|
+
constructor(config) {
|
|
22
22
|
/**
|
|
23
|
-
*
|
|
23
|
+
* 注册的拦截器
|
|
24
24
|
*
|
|
25
|
-
* @author
|
|
26
|
-
* @date 2022-
|
|
27
|
-
* @
|
|
28
|
-
* @type {string}
|
|
25
|
+
* @author lxm
|
|
26
|
+
* @date 2022-10-27 17:10:18
|
|
27
|
+
* @type {Map<string, Interceptor>}
|
|
29
28
|
*/
|
|
30
|
-
this.
|
|
31
|
-
|
|
32
|
-
|
|
29
|
+
this.interceptors = new Map();
|
|
30
|
+
this.instance = axios.create(config);
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* 添加拦截器
|
|
34
|
+
*
|
|
35
|
+
* @author lxm
|
|
36
|
+
* @date 2022-10-27 17:10:42
|
|
37
|
+
* @param {string} name 唯一标识
|
|
38
|
+
* @param {Interceptor} interceptor 拦截器
|
|
39
|
+
*/
|
|
40
|
+
addInterceptor(name, interceptor) {
|
|
41
|
+
interceptor.use(this.instance);
|
|
42
|
+
this.interceptors.set(name, interceptor);
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* 删除拦截器
|
|
46
|
+
*
|
|
47
|
+
* @author lxm
|
|
48
|
+
* @date 2022-10-27 17:10:27
|
|
49
|
+
* @param {string} name 唯一标识
|
|
50
|
+
*/
|
|
51
|
+
removeInterceptor(name) {
|
|
52
|
+
const interceptor = this.interceptors.get(name);
|
|
53
|
+
if (interceptor) {
|
|
54
|
+
interceptor.eject(this.instance);
|
|
55
|
+
this.interceptors.delete(name);
|
|
33
56
|
}
|
|
34
57
|
}
|
|
35
|
-
|
|
36
|
-
|
|
58
|
+
/**
|
|
59
|
+
* 预置config,绑定动态的配置
|
|
60
|
+
*
|
|
61
|
+
* @author lxm
|
|
62
|
+
* @date 2022-10-27 16:10:48
|
|
63
|
+
* @readonly
|
|
64
|
+
* @protected
|
|
65
|
+
* @type {AxiosRequestConfig}
|
|
66
|
+
*/
|
|
67
|
+
get presetConfig() {
|
|
68
|
+
return {
|
|
69
|
+
// 请求前缀路径
|
|
70
|
+
baseURL: this.instance.defaults.baseURL || ibiz.env.baseUrl,
|
|
71
|
+
headers: {
|
|
72
|
+
'Content-Type': 'application/json;charset=UTF-8',
|
|
73
|
+
Accept: 'application/json',
|
|
74
|
+
},
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* 从左到右递归合并配置参数(内置第一个合并的预置参数)
|
|
79
|
+
*
|
|
80
|
+
* @author lxm
|
|
81
|
+
* @date 2022-10-27 16:10:09
|
|
82
|
+
* @protected
|
|
83
|
+
* @param {...AxiosRequestConfig[]} configs
|
|
84
|
+
* @returns {*}
|
|
85
|
+
*/
|
|
86
|
+
mergeConfig(...configs) {
|
|
87
|
+
if (configs.length === 0) {
|
|
88
|
+
return this.presetConfig;
|
|
89
|
+
}
|
|
90
|
+
return merge(this.presetConfig, ...configs);
|
|
37
91
|
}
|
|
38
92
|
/**
|
|
39
93
|
* Post 请求
|
|
40
94
|
*
|
|
41
95
|
* @author chitanda
|
|
42
|
-
* @date 2022-
|
|
96
|
+
* @date 2022-10-19 11:10:30
|
|
43
97
|
* @param {string} url
|
|
98
|
+
* @param {IData} data
|
|
44
99
|
* @param {IParams} [params={}]
|
|
100
|
+
* @param {RawAxiosRequestHeaders} [headers={}]
|
|
45
101
|
* @return {*} {Promise<IHttpResponse>}
|
|
46
102
|
*/
|
|
47
103
|
async post(url, data, params = {}, headers = {}) {
|
|
48
104
|
url = this.handleAppPresetParam(url, params);
|
|
49
105
|
try {
|
|
50
|
-
const response = await
|
|
106
|
+
const response = await this.request(url, {
|
|
51
107
|
method: 'post',
|
|
52
|
-
url,
|
|
53
108
|
data,
|
|
54
|
-
headers
|
|
109
|
+
headers,
|
|
55
110
|
});
|
|
56
111
|
return this.doResponseResult(response);
|
|
57
112
|
}
|
|
@@ -63,9 +118,11 @@ export class Net {
|
|
|
63
118
|
* Get 请求
|
|
64
119
|
*
|
|
65
120
|
* @author chitanda
|
|
66
|
-
* @date 2022-
|
|
121
|
+
* @date 2022-10-19 11:10:24
|
|
67
122
|
* @param {string} url
|
|
68
123
|
* @param {IParams} [params={}]
|
|
124
|
+
* @param {RawAxiosRequestHeaders} [headers={}]
|
|
125
|
+
* @param {IParams} [option={}]
|
|
69
126
|
* @return {*} {Promise<IHttpResponse>}
|
|
70
127
|
*/
|
|
71
128
|
async get(url, params = {}, headers = {}, option = {}) {
|
|
@@ -75,7 +132,7 @@ export class Net {
|
|
|
75
132
|
// }
|
|
76
133
|
url = this.attachUrlParam(url, params);
|
|
77
134
|
try {
|
|
78
|
-
const response = await
|
|
135
|
+
const response = await this.request(url, merge({ method: 'get', headers }, option));
|
|
79
136
|
return this.doResponseResult(response);
|
|
80
137
|
}
|
|
81
138
|
catch (error) {
|
|
@@ -86,15 +143,16 @@ export class Net {
|
|
|
86
143
|
* Delete 请求
|
|
87
144
|
*
|
|
88
145
|
* @author chitanda
|
|
89
|
-
* @date 2022-
|
|
146
|
+
* @date 2022-10-19 11:10:17
|
|
90
147
|
* @param {string} url
|
|
91
148
|
* @param {IParams} [params]
|
|
149
|
+
* @param {RawAxiosRequestHeaders} [headers={}]
|
|
92
150
|
* @return {*} {Promise<IHttpResponse>}
|
|
93
151
|
*/
|
|
94
152
|
async delete(url, params, headers = {}) {
|
|
95
153
|
url = this.handleAppPresetParam(url, params);
|
|
96
154
|
try {
|
|
97
|
-
const response = await
|
|
155
|
+
const response = await this.request(url, { method: 'delete', headers });
|
|
98
156
|
return this.doResponseResult(response);
|
|
99
157
|
}
|
|
100
158
|
catch (error) {
|
|
@@ -105,15 +163,21 @@ export class Net {
|
|
|
105
163
|
* Put 请求
|
|
106
164
|
*
|
|
107
165
|
* @author chitanda
|
|
108
|
-
* @date 2022-
|
|
166
|
+
* @date 2022-10-19 11:10:11
|
|
109
167
|
* @param {string} url
|
|
110
168
|
* @param {IData} data
|
|
169
|
+
* @param {IParams} [params={}]
|
|
170
|
+
* @param {RawAxiosRequestHeaders} [headers={}]
|
|
111
171
|
* @return {*} {Promise<IHttpResponse>}
|
|
112
172
|
*/
|
|
113
173
|
async put(url, data, params = {}, headers = {}) {
|
|
114
174
|
url = this.handleAppPresetParam(url, params);
|
|
115
175
|
try {
|
|
116
|
-
const response = await
|
|
176
|
+
const response = await this.request(url, {
|
|
177
|
+
method: 'put',
|
|
178
|
+
data,
|
|
179
|
+
headers,
|
|
180
|
+
});
|
|
117
181
|
return this.doResponseResult(response);
|
|
118
182
|
}
|
|
119
183
|
catch (error) {
|
|
@@ -126,12 +190,12 @@ export class Net {
|
|
|
126
190
|
* @author chitanda
|
|
127
191
|
* @date 2022-07-14 15:07:15
|
|
128
192
|
* @param {string} url
|
|
129
|
-
* @param {
|
|
193
|
+
* @param {RawAxiosRequestHeaders} [headers={}]
|
|
130
194
|
* @return {*} {Promise<IHttpResponse>}
|
|
131
195
|
*/
|
|
132
196
|
async getModel(url, headers = {}) {
|
|
133
197
|
try {
|
|
134
|
-
const response = await
|
|
198
|
+
const response = await this.instance.get(url, {
|
|
135
199
|
headers,
|
|
136
200
|
});
|
|
137
201
|
return this.doResponseResult(response);
|
|
@@ -140,6 +204,24 @@ export class Net {
|
|
|
140
204
|
throw new HttpError(error);
|
|
141
205
|
}
|
|
142
206
|
}
|
|
207
|
+
/**
|
|
208
|
+
* 基础请求方法,会合并预置配置
|
|
209
|
+
*
|
|
210
|
+
* @author lxm
|
|
211
|
+
* @date 2022-10-27 14:10:06
|
|
212
|
+
* @param {string} url
|
|
213
|
+
* @param {AxiosRequestConfig} [config={}]
|
|
214
|
+
* @returns {*} {Promise<IHttpResponse>}
|
|
215
|
+
*/
|
|
216
|
+
async request(url, config = {}) {
|
|
217
|
+
try {
|
|
218
|
+
const response = await this.instance.request(this.mergeConfig({ url }, config));
|
|
219
|
+
return this.doResponseResult(response);
|
|
220
|
+
}
|
|
221
|
+
catch (error) {
|
|
222
|
+
throw new HttpError(error);
|
|
223
|
+
}
|
|
224
|
+
}
|
|
143
225
|
/**
|
|
144
226
|
* 统一处理请求返回
|
|
145
227
|
*
|
|
@@ -190,7 +272,6 @@ export class Net {
|
|
|
190
272
|
* @return {*} {string}
|
|
191
273
|
*/
|
|
192
274
|
attachUrlParam(url, params) {
|
|
193
|
-
url = this.attachUrl(url);
|
|
194
275
|
const strParams = stringify(params);
|
|
195
276
|
if (notNilEmpty(strParams)) {
|
|
196
277
|
if (url.endsWith('?')) {
|
|
@@ -208,16 +289,4 @@ export class Net {
|
|
|
208
289
|
}
|
|
209
290
|
return url;
|
|
210
291
|
}
|
|
211
|
-
/**
|
|
212
|
-
* 处理 url 参数
|
|
213
|
-
*
|
|
214
|
-
* @author chitanda
|
|
215
|
-
* @date 2022-07-20 20:07:17
|
|
216
|
-
* @private
|
|
217
|
-
* @param {string} url
|
|
218
|
-
* @return {*} {string}
|
|
219
|
-
*/
|
|
220
|
-
attachUrl(url) {
|
|
221
|
-
return `${this.prefix}${url}`;
|
|
222
|
-
}
|
|
223
292
|
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 路径解析助手
|
|
3
|
+
*
|
|
4
|
+
* @author lxm
|
|
5
|
+
* @date 2022-10-11 14:10:12
|
|
6
|
+
* @export
|
|
7
|
+
* @class UrlHelper
|
|
8
|
+
*/
|
|
9
|
+
export declare class UrlHelper {
|
|
10
|
+
/**
|
|
11
|
+
* 路由路径前面的基础路径
|
|
12
|
+
* 如:http://172.16.103.120:30061/portalwebapp/#/index/appportalview?params=123
|
|
13
|
+
* 返回:http://172.16.103.120:30061/portalwebapp/#
|
|
14
|
+
*
|
|
15
|
+
* @author lxm
|
|
16
|
+
* @date 2022-10-11 20:10:29
|
|
17
|
+
* @returns {*}
|
|
18
|
+
*/
|
|
19
|
+
static get routeBase(): string;
|
|
20
|
+
/**
|
|
21
|
+
* 应用的的基础路径
|
|
22
|
+
* 如:http://172.16.103.120:30061/portalwebapp/#/index/appportalview?params=123
|
|
23
|
+
* 返回:http://172.16.103.120:30061/portalwebapp
|
|
24
|
+
*
|
|
25
|
+
* @author lxm
|
|
26
|
+
* @date 2022-10-11 20:10:29
|
|
27
|
+
* @returns {*}
|
|
28
|
+
*/
|
|
29
|
+
static get appBase(): string;
|
|
30
|
+
/**
|
|
31
|
+
* #开始到末尾,即路由地址
|
|
32
|
+
* 如:http://172.16.103.120:30061/portalwebapp/#/index/appportalview?params=123
|
|
33
|
+
* 返回:/index/appportalview?params=123
|
|
34
|
+
*
|
|
35
|
+
* @author lxm
|
|
36
|
+
* @date 2022-10-11 16:10:40
|
|
37
|
+
* @returns {*}
|
|
38
|
+
*/
|
|
39
|
+
static get routePath(): string;
|
|
40
|
+
/**
|
|
41
|
+
* 当前地址的全路径,包含域名和参数
|
|
42
|
+
* 如:http://172.16.103.120:30061/portalwebapp/#/index/appportalview?params=123
|
|
43
|
+
*
|
|
44
|
+
* @author lxm
|
|
45
|
+
* @date 2022-10-11 21:10:39
|
|
46
|
+
* @readonly
|
|
47
|
+
* @static
|
|
48
|
+
*/
|
|
49
|
+
static get fullPath(): string;
|
|
50
|
+
}
|
|
51
|
+
//# sourceMappingURL=url-helper.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"url-helper.d.ts","sourceRoot":"","sources":["../../../src/utils/url-helper/url-helper.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,qBAAa,SAAS;IACpB;;;;;;;;OAQG;IACH,MAAM,KAAK,SAAS,WAEnB;IAED;;;;;;;;OAQG;IACH,MAAM,KAAK,OAAO,WAGjB;IAED;;;;;;;;OAQG;IACH,MAAM,KAAK,SAAS,WAEnB;IAED;;;;;;;;OAQG;IACH,MAAM,KAAK,QAAQ,WAElB;CACF"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 路径解析助手
|
|
3
|
+
*
|
|
4
|
+
* @author lxm
|
|
5
|
+
* @date 2022-10-11 14:10:12
|
|
6
|
+
* @export
|
|
7
|
+
* @class UrlHelper
|
|
8
|
+
*/
|
|
9
|
+
export class UrlHelper {
|
|
10
|
+
/**
|
|
11
|
+
* 路由路径前面的基础路径
|
|
12
|
+
* 如:http://172.16.103.120:30061/portalwebapp/#/index/appportalview?params=123
|
|
13
|
+
* 返回:http://172.16.103.120:30061/portalwebapp/#
|
|
14
|
+
*
|
|
15
|
+
* @author lxm
|
|
16
|
+
* @date 2022-10-11 20:10:29
|
|
17
|
+
* @returns {*}
|
|
18
|
+
*/
|
|
19
|
+
static get routeBase() {
|
|
20
|
+
return `${this.appBase}/#`;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* 应用的的基础路径
|
|
24
|
+
* 如:http://172.16.103.120:30061/portalwebapp/#/index/appportalview?params=123
|
|
25
|
+
* 返回:http://172.16.103.120:30061/portalwebapp
|
|
26
|
+
*
|
|
27
|
+
* @author lxm
|
|
28
|
+
* @date 2022-10-11 20:10:29
|
|
29
|
+
* @returns {*}
|
|
30
|
+
*/
|
|
31
|
+
static get appBase() {
|
|
32
|
+
const { origin, pathname } = window.location;
|
|
33
|
+
return `${origin}${pathname}`.replace(/\/$/, '');
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* #开始到末尾,即路由地址
|
|
37
|
+
* 如:http://172.16.103.120:30061/portalwebapp/#/index/appportalview?params=123
|
|
38
|
+
* 返回:/index/appportalview?params=123
|
|
39
|
+
*
|
|
40
|
+
* @author lxm
|
|
41
|
+
* @date 2022-10-11 16:10:40
|
|
42
|
+
* @returns {*}
|
|
43
|
+
*/
|
|
44
|
+
static get routePath() {
|
|
45
|
+
return window.location.hash.replace('#', '');
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* 当前地址的全路径,包含域名和参数
|
|
49
|
+
* 如:http://172.16.103.120:30061/portalwebapp/#/index/appportalview?params=123
|
|
50
|
+
*
|
|
51
|
+
* @author lxm
|
|
52
|
+
* @date 2022-10-11 21:10:39
|
|
53
|
+
* @readonly
|
|
54
|
+
* @static
|
|
55
|
+
*/
|
|
56
|
+
static get fullPath() {
|
|
57
|
+
return window.location.href;
|
|
58
|
+
}
|
|
59
|
+
}
|
package/out/utils/util/util.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { DebounceSettings } from 'lodash-es';
|
|
2
1
|
/**
|
|
3
2
|
* 获取认证令牌
|
|
4
3
|
*
|
|
@@ -20,7 +19,8 @@ export declare function getToken(): string | null;
|
|
|
20
19
|
*/
|
|
21
20
|
export declare function isOverlap(arr1: any[], arr2: any[]): boolean;
|
|
22
21
|
/**
|
|
23
|
-
*
|
|
22
|
+
* 防抖并合并每次的参数,
|
|
23
|
+
* 最后一次才会执行
|
|
24
24
|
*
|
|
25
25
|
* @author lxm
|
|
26
26
|
* @date 2022-09-20 21:09:53
|
|
@@ -32,8 +32,24 @@ export declare function isOverlap(arr1: any[], arr2: any[]): boolean;
|
|
|
32
32
|
* newParams: Parameters<T>,
|
|
33
33
|
* ) => Parameters<T>} mergeFunc 合并的回调函数
|
|
34
34
|
* @param {number} [wait] 防抖的延迟毫秒数
|
|
35
|
-
* @param {DebounceSettings} [options] 防抖函数的额外参数
|
|
36
35
|
* @returns {*}
|
|
37
36
|
*/
|
|
38
|
-
export declare function debounceAndMerge<T extends (...args: any[]) => any>(func: T, mergeFunc: (oldParams: Parameters<T>, newParams: Parameters<T>) => Parameters<T>, wait?: number
|
|
37
|
+
export declare function debounceAndMerge<T extends (...args: any[]) => any>(func: T, mergeFunc: (oldParams: Parameters<T>, newParams: Parameters<T>) => Parameters<T>, wait?: number): (...args: Parameters<T>) => any;
|
|
38
|
+
/**
|
|
39
|
+
* 防抖并合并每次的参数,最后一次才会执行
|
|
40
|
+
* 绑定方法为异步方法,给每次调用返回最终执行那次的结果
|
|
41
|
+
*
|
|
42
|
+
* @author lxm
|
|
43
|
+
* @date 2022-09-20 21:09:53
|
|
44
|
+
* @export
|
|
45
|
+
* @template T
|
|
46
|
+
* @param {T} func 要防抖的函数
|
|
47
|
+
* @param {(
|
|
48
|
+
* oldParams: Parameters<T>,
|
|
49
|
+
* newParams: Parameters<T>,
|
|
50
|
+
* ) => Parameters<T>} mergeFunc 合并的回调函数
|
|
51
|
+
* @param {number} [wait] 防抖的延迟毫秒数
|
|
52
|
+
* @returns {*}
|
|
53
|
+
*/
|
|
54
|
+
export declare function debounceAndAsyncMerge<T extends (...args: any[]) => Promise<any>>(func: T, mergeFunc: (oldParams: Parameters<T>, newParams: Parameters<T>) => Parameters<T>, wait?: number): T;
|
|
39
55
|
//# sourceMappingURL=util.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"util.d.ts","sourceRoot":"","sources":["../../../src/utils/util/util.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"util.d.ts","sourceRoot":"","sources":["../../../src/utils/util/util.ts"],"names":[],"mappings":"AAKA;;;;;;;GAOG;AACH,wBAAgB,QAAQ,IAAI,MAAM,GAAG,IAAI,CAExC;AAED;;;;;;;;;GASG;AACH,wBAAgB,SAAS,CAAC,IAAI,EAAE,GAAG,EAAE,EAAE,IAAI,EAAE,GAAG,EAAE,GAAG,OAAO,CAG3D;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,gBAAgB,CAAC,CAAC,SAAS,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,EAChE,IAAI,EAAE,CAAC,EACP,SAAS,EAAE,CACT,SAAS,EAAE,UAAU,CAAC,CAAC,CAAC,EACxB,SAAS,EAAE,UAAU,CAAC,CAAC,CAAC,KACrB,UAAU,CAAC,CAAC,CAAC,EAClB,IAAI,CAAC,EAAE,MAAM,aASI,WAAW,CAAC,CAAC,SAS/B;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,qBAAqB,CACnC,CAAC,SAAS,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,OAAO,CAAC,GAAG,CAAC,EAE1C,IAAI,EAAE,CAAC,EACP,SAAS,EAAE,CACT,SAAS,EAAE,UAAU,CAAC,CAAC,CAAC,EACxB,SAAS,EAAE,UAAU,CAAC,CAAC,CAAC,KACrB,UAAU,CAAC,CAAC,CAAC,EAClB,IAAI,CAAC,EAAE,MAAM,GACZ,CAAC,CAoCH"}
|
package/out/utils/util/util.js
CHANGED
|
@@ -25,10 +25,11 @@ export function getToken() {
|
|
|
25
25
|
*/
|
|
26
26
|
export function isOverlap(arr1, arr2) {
|
|
27
27
|
const newArr = Array.from(new Set([...arr1, ...arr2]));
|
|
28
|
-
return newArr.length
|
|
28
|
+
return newArr.length !== arr1.length + arr2.length;
|
|
29
29
|
}
|
|
30
30
|
/**
|
|
31
|
-
*
|
|
31
|
+
* 防抖并合并每次的参数,
|
|
32
|
+
* 最后一次才会执行
|
|
32
33
|
*
|
|
33
34
|
* @author lxm
|
|
34
35
|
* @date 2022-09-20 21:09:53
|
|
@@ -40,17 +41,16 @@ export function isOverlap(arr1, arr2) {
|
|
|
40
41
|
* newParams: Parameters<T>,
|
|
41
42
|
* ) => Parameters<T>} mergeFunc 合并的回调函数
|
|
42
43
|
* @param {number} [wait] 防抖的延迟毫秒数
|
|
43
|
-
* @param {DebounceSettings} [options] 防抖函数的额外参数
|
|
44
44
|
* @returns {*}
|
|
45
45
|
*/
|
|
46
|
-
export function debounceAndMerge(func, mergeFunc, wait
|
|
46
|
+
export function debounceAndMerge(func, mergeFunc, wait) {
|
|
47
47
|
// 缓存上一次的函数参数
|
|
48
48
|
let oldParams;
|
|
49
49
|
const debounceFunc = debounce((...params) => {
|
|
50
50
|
// 防抖函数执行的时候清空缓存参数
|
|
51
51
|
oldParams = undefined;
|
|
52
52
|
return func(...params);
|
|
53
|
-
}, wait
|
|
53
|
+
}, wait);
|
|
54
54
|
return (...args) => {
|
|
55
55
|
// 合并参数,并把参数缓存到oldParams里,用新参数调用防抖函数
|
|
56
56
|
let newParams = args;
|
|
@@ -61,3 +61,57 @@ export function debounceAndMerge(func, mergeFunc, wait, options) {
|
|
|
61
61
|
return debounceFunc(...newParams);
|
|
62
62
|
};
|
|
63
63
|
}
|
|
64
|
+
/**
|
|
65
|
+
* 防抖并合并每次的参数,最后一次才会执行
|
|
66
|
+
* 绑定方法为异步方法,给每次调用返回最终执行那次的结果
|
|
67
|
+
*
|
|
68
|
+
* @author lxm
|
|
69
|
+
* @date 2022-09-20 21:09:53
|
|
70
|
+
* @export
|
|
71
|
+
* @template T
|
|
72
|
+
* @param {T} func 要防抖的函数
|
|
73
|
+
* @param {(
|
|
74
|
+
* oldParams: Parameters<T>,
|
|
75
|
+
* newParams: Parameters<T>,
|
|
76
|
+
* ) => Parameters<T>} mergeFunc 合并的回调函数
|
|
77
|
+
* @param {number} [wait] 防抖的延迟毫秒数
|
|
78
|
+
* @returns {*}
|
|
79
|
+
*/
|
|
80
|
+
export function debounceAndAsyncMerge(func, mergeFunc, wait) {
|
|
81
|
+
// 缓存上一次的函数参数
|
|
82
|
+
let oldParams;
|
|
83
|
+
let promises = [];
|
|
84
|
+
const debounceFunc = debounce(async (...params) => {
|
|
85
|
+
// 防抖函数执行的时候清空缓存参数
|
|
86
|
+
oldParams = undefined;
|
|
87
|
+
try {
|
|
88
|
+
const result = await func(...params);
|
|
89
|
+
promises.forEach(promise => {
|
|
90
|
+
promise.resolve(result);
|
|
91
|
+
});
|
|
92
|
+
promises = [];
|
|
93
|
+
return result;
|
|
94
|
+
}
|
|
95
|
+
catch (error) {
|
|
96
|
+
promises.forEach(promise => {
|
|
97
|
+
promise.reject(error);
|
|
98
|
+
});
|
|
99
|
+
promises = [];
|
|
100
|
+
}
|
|
101
|
+
}, wait);
|
|
102
|
+
const fun = async (...args) => {
|
|
103
|
+
// 合并参数,并把参数缓存到oldParams里,用新参数调用防抖函数
|
|
104
|
+
let newParams = args;
|
|
105
|
+
if (oldParams) {
|
|
106
|
+
newParams = mergeFunc(oldParams, newParams);
|
|
107
|
+
}
|
|
108
|
+
oldParams = newParams;
|
|
109
|
+
// 执行防抖函数
|
|
110
|
+
debounceFunc(...newParams);
|
|
111
|
+
return new Promise((resolve, reject) => {
|
|
112
|
+
// 阻塞当前调用,当防抖函数被执行后返回
|
|
113
|
+
promises.push({ resolve, reject });
|
|
114
|
+
});
|
|
115
|
+
};
|
|
116
|
+
return fun;
|
|
117
|
+
}
|
package/package.json
CHANGED
|
@@ -1,37 +1,49 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ibiz-template/core",
|
|
3
|
-
"version": "0.0.1-
|
|
3
|
+
"version": "0.0.1-beta.1",
|
|
4
4
|
"description": "核心包",
|
|
5
|
+
"type": "module",
|
|
5
6
|
"main": "out/index.js",
|
|
6
7
|
"types": "out/index.d.ts",
|
|
8
|
+
"system": "./dist/system/index.system.js",
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "https://gitee.com/iBizModeling/ibiz-template.git"
|
|
12
|
+
},
|
|
7
13
|
"files": [
|
|
14
|
+
"dist",
|
|
8
15
|
"out",
|
|
9
16
|
"src"
|
|
10
17
|
],
|
|
11
18
|
"scripts": {
|
|
12
19
|
"dev": "tsc --watch",
|
|
13
|
-
"build": "npm run lint && npm run clean && tsc --build",
|
|
20
|
+
"build": "npm run lint && npm run clean && npm run build:rollup && tsc --build",
|
|
21
|
+
"build:rollup": "rollup -c",
|
|
14
22
|
"lint": "eslint 'src/**/*.ts'",
|
|
15
23
|
"lint:fix": "eslint --fix 'src/**/*.ts'",
|
|
16
|
-
"clean": "rimraf out",
|
|
24
|
+
"clean": "rimraf out dist",
|
|
17
25
|
"test": "jest",
|
|
18
|
-
"
|
|
19
|
-
"publish:
|
|
26
|
+
"prepublish": "npm run build",
|
|
27
|
+
"publish:next": "npm publish --access public --tag next",
|
|
28
|
+
"publish:npm": "npm publish --access public"
|
|
20
29
|
},
|
|
21
30
|
"author": "chitanda",
|
|
22
31
|
"license": "MIT",
|
|
23
32
|
"dependencies": {
|
|
24
|
-
"axios": "^
|
|
33
|
+
"axios": "^1.1.3",
|
|
34
|
+
"loglevel": "^1.8.0",
|
|
25
35
|
"pluralize": "^8.0.0",
|
|
26
36
|
"qs": "^6.11.0"
|
|
27
37
|
},
|
|
28
38
|
"devDependencies": {
|
|
29
39
|
"@types/pluralize": "^0.0.29",
|
|
30
40
|
"@types/qs": "^6.9.7",
|
|
31
|
-
"
|
|
41
|
+
"lodash-es": "^4.17.21",
|
|
42
|
+
"qx-util": "^0.4.4"
|
|
32
43
|
},
|
|
33
44
|
"peerDependencies": {
|
|
34
|
-
"
|
|
45
|
+
"lodash-es": "^4.17.21",
|
|
46
|
+
"qx-util": "^0.4.4"
|
|
35
47
|
},
|
|
36
|
-
"gitHead": "
|
|
48
|
+
"gitHead": "9514cbc720208af6160c67bc43e822262274da1f"
|
|
37
49
|
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 请求状态码文本
|
|
3
|
+
*/
|
|
4
|
+
export const HttpStatusMessageConst: Record<number, string> = {
|
|
5
|
+
200: '服务器成功返回请求的数据。',
|
|
6
|
+
201: '新建或修改数据成功。',
|
|
7
|
+
202: '一个请求已经进入后台排队(异步任务)。',
|
|
8
|
+
204: '删除数据成功。',
|
|
9
|
+
400: '发出的请求有错误,服务器没有进行新建或修改数据的操作。',
|
|
10
|
+
401: '用户没有权限(令牌、用户名、密码错误)。',
|
|
11
|
+
403: '用户得到授权,但是访问是被禁止的。',
|
|
12
|
+
404: '发出的请求针对的是不存在的记录,服务器没有进行操作。',
|
|
13
|
+
406: '请求的格式不可得。',
|
|
14
|
+
410: '请求的资源被永久删除,且不会再得到的。',
|
|
15
|
+
422: '当创建一个对象时,发生一个验证错误。',
|
|
16
|
+
500: '服务器发生错误,请检查服务器。',
|
|
17
|
+
502: '网关错误。',
|
|
18
|
+
503: '服务不可用,服务器暂时过载或维护。',
|
|
19
|
+
504: '网关超时。',
|
|
20
|
+
};
|
package/src/constant/index.ts
CHANGED
|
@@ -1 +1,5 @@
|
|
|
1
1
|
export { CoreConst } from './core/core';
|
|
2
|
+
export * from './util/util';
|
|
3
|
+
export { HttpStatusMessageConst } from './http-status-message/http-status-message';
|
|
4
|
+
export { LoginMode } from './login-mode/login-mode';
|
|
5
|
+
export { MenuPermissionMode } from './menu-permission-mode/menu-permission-mode';
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/* eslint-disable no-shadow */
|
|
2
|
+
/**
|
|
3
|
+
* 登录模式
|
|
4
|
+
*
|
|
5
|
+
* @author lxm
|
|
6
|
+
* @date 2022-10-12 14:10:56
|
|
7
|
+
* @export
|
|
8
|
+
* @enum {number}
|
|
9
|
+
*/
|
|
10
|
+
export enum LoginMode {
|
|
11
|
+
/**
|
|
12
|
+
* 默认标准登录
|
|
13
|
+
*/
|
|
14
|
+
DEFAULT = 'DEFAULT',
|
|
15
|
+
/**
|
|
16
|
+
* 自定义登录
|
|
17
|
+
*/
|
|
18
|
+
CUSTOM = 'CUSTOM',
|
|
19
|
+
/**
|
|
20
|
+
* 中央认证登录
|
|
21
|
+
*/
|
|
22
|
+
CAS = 'CAS',
|
|
23
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/* eslint-disable no-shadow */
|
|
2
|
+
/**
|
|
3
|
+
* 菜单权限校验模式
|
|
4
|
+
*
|
|
5
|
+
* @author lxm
|
|
6
|
+
* @date 2022-10-12 14:10:56
|
|
7
|
+
* @export
|
|
8
|
+
* @enum {number}
|
|
9
|
+
*/
|
|
10
|
+
export enum MenuPermissionMode {
|
|
11
|
+
/**
|
|
12
|
+
* 混合模式(默认)
|
|
13
|
+
*/
|
|
14
|
+
MIXIN = 'MIXIN',
|
|
15
|
+
/**
|
|
16
|
+
* 统一资源模式
|
|
17
|
+
*/
|
|
18
|
+
RESOURCE = 'RESOURCE',
|
|
19
|
+
/**
|
|
20
|
+
* RT模式
|
|
21
|
+
*/
|
|
22
|
+
RT = 'RT',
|
|
23
|
+
}
|