@ibiz-template/core 0.0.1-alpha.2 → 0.0.1-alpha.22
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 +3 -0
- package/out/constant/index.d.ts.map +1 -1
- package/out/constant/index.js +3 -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/context/index.d.ts +2 -39
- package/out/context/index.d.ts.map +1 -1
- package/out/context/index.js +34 -65
- package/out/environment/environment.d.ts.map +1 -1
- package/out/environment/environment.js +7 -1
- package/out/error/http-error/http-error.d.ts +18 -0
- package/out/error/http-error/http-error.d.ts.map +1 -0
- package/out/error/http-error/http-error.js +36 -0
- package/out/error/index.d.ts +3 -0
- package/out/error/index.d.ts.map +1 -0
- package/out/error/index.js +2 -0
- package/out/error/runtime-error/runtime-error.d.ts +15 -0
- package/out/error/runtime-error/runtime-error.d.ts.map +1 -0
- package/out/error/runtime-error/runtime-error.js +15 -0
- package/out/index.d.ts +2 -1
- package/out/index.d.ts.map +1 -1
- package/out/index.js +2 -1
- package/out/interface/i-environment/i-environment.d.ts +41 -0
- package/out/interface/i-environment/i-environment.d.ts.map +1 -1
- package/out/types.d.ts +10 -0
- package/out/types.d.ts.map +1 -1
- package/out/utils/index.d.ts +1 -0
- package/out/utils/index.d.ts.map +1 -1
- package/out/utils/index.js +1 -0
- package/out/utils/net/http-response.d.ts +1 -1
- package/out/utils/net/http-response.d.ts.map +1 -1
- package/out/utils/net/net.d.ts +1 -1
- package/out/utils/net/net.d.ts.map +1 -1
- package/out/utils/net/net.js +45 -19
- package/out/utils/plural/plural.js +1 -1
- 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 +29 -0
- package/out/utils/util/util.d.ts.map +1 -1
- package/out/utils/util/util.js +50 -0
- package/package.json +15 -6
- package/src/constant/http-status-message/http-status-message.ts +20 -0
- package/src/constant/index.ts +3 -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/context/index.ts +35 -69
- package/src/environment/environment.ts +7 -1
- package/src/error/http-error/http-error.ts +43 -0
- package/src/error/index.ts +2 -0
- package/src/error/runtime-error/runtime-error.ts +14 -0
- package/src/index.ts +2 -1
- package/src/interface/i-environment/i-environment.ts +47 -0
- package/src/types.ts +11 -0
- package/src/utils/index.ts +1 -0
- package/src/utils/net/http-response.ts +1 -1
- package/src/utils/net/net.ts +45 -23
- package/src/utils/plural/plural.ts +1 -1
- package/src/utils/url-helper/url-helper.ts +62 -0
- package/src/utils/util/util.ts +64 -0
package/src/index.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import './types';
|
|
2
2
|
|
|
3
3
|
export * from './constant';
|
|
4
|
-
export { IBizContext
|
|
4
|
+
export { IBizContext } from './context';
|
|
5
5
|
export { Environment } from './environment/environment';
|
|
6
|
+
export * from './error';
|
|
6
7
|
export * from './interface';
|
|
7
8
|
export * from './utils';
|
|
8
9
|
export { IBizSys } from './ibizsys';
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { LoginMode, MenuPermissionMode } from '../../constant';
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
4
|
* 配置参数
|
|
3
5
|
*
|
|
@@ -25,6 +27,33 @@ export interface IEnvironment {
|
|
|
25
27
|
*/
|
|
26
28
|
baseUrl: string;
|
|
27
29
|
|
|
30
|
+
/**
|
|
31
|
+
* 登录模式
|
|
32
|
+
*
|
|
33
|
+
* @author lxm
|
|
34
|
+
* @date 2022-10-12 14:10:51
|
|
35
|
+
* @type {LoginMode}
|
|
36
|
+
*/
|
|
37
|
+
loginMode: LoginMode;
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* 中央认证登录地址
|
|
41
|
+
*
|
|
42
|
+
* @author lxm
|
|
43
|
+
* @date 2022-10-11 12:10:21
|
|
44
|
+
* @type {string}
|
|
45
|
+
*/
|
|
46
|
+
casLoginUrl: string;
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* 远程模型路径
|
|
50
|
+
*
|
|
51
|
+
* @author chitanda
|
|
52
|
+
* @date 2022-09-22 18:09:25
|
|
53
|
+
* @type {string}
|
|
54
|
+
*/
|
|
55
|
+
remoteModelUrl: string;
|
|
56
|
+
|
|
28
57
|
/**
|
|
29
58
|
* 资源文件根路径
|
|
30
59
|
*
|
|
@@ -60,4 +89,22 @@ export interface IEnvironment {
|
|
|
60
89
|
* @type {string}
|
|
61
90
|
*/
|
|
62
91
|
UploadFile: string;
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* 是否启用权限校验(默认true)
|
|
95
|
+
*
|
|
96
|
+
* @author lxm
|
|
97
|
+
* @date 2022-10-12 18:10:25
|
|
98
|
+
* @type {boolean}
|
|
99
|
+
*/
|
|
100
|
+
enablePermission: boolean;
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* 菜单权限校验模式(默认MIXIN)
|
|
104
|
+
*
|
|
105
|
+
* @author lxm
|
|
106
|
+
* @date 2022-10-12 18:10:27
|
|
107
|
+
* @type {MenuPermissionMode}
|
|
108
|
+
*/
|
|
109
|
+
menuPermissionMode: MenuPermissionMode;
|
|
63
110
|
}
|
package/src/types.ts
CHANGED
|
@@ -40,4 +40,15 @@ declare global {
|
|
|
40
40
|
interface IData {
|
|
41
41
|
[key: string | symbol]: any;
|
|
42
42
|
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* 任意对象结构
|
|
46
|
+
*
|
|
47
|
+
* @author chitanda
|
|
48
|
+
* @date 2022-09-21 15:09:30
|
|
49
|
+
* @interface IObject
|
|
50
|
+
*/
|
|
51
|
+
interface IObject {
|
|
52
|
+
[key: string | symbol]: any;
|
|
53
|
+
}
|
|
43
54
|
}
|
package/src/utils/index.ts
CHANGED
package/src/utils/net/net.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import axios, { AxiosRequestHeaders, AxiosResponse } from 'axios';
|
|
1
|
+
import axios, { AxiosError, AxiosRequestHeaders, AxiosResponse } from 'axios';
|
|
2
2
|
import { stringify } from 'qs';
|
|
3
3
|
import { notNilEmpty } from 'qx-util';
|
|
4
|
+
import { HttpError } from '../../error';
|
|
4
5
|
import { IHttpResponse } from './http-response';
|
|
5
6
|
|
|
6
7
|
/**
|
|
@@ -55,17 +56,21 @@ export class Net {
|
|
|
55
56
|
headers: AxiosRequestHeaders = {},
|
|
56
57
|
): Promise<IHttpResponse> {
|
|
57
58
|
url = this.handleAppPresetParam(url, params);
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
59
|
+
try {
|
|
60
|
+
const response = await axios({
|
|
61
|
+
method: 'post',
|
|
62
|
+
url,
|
|
63
|
+
data,
|
|
64
|
+
headers: {
|
|
65
|
+
'Content-Type': 'application/json;charset=UTF-8',
|
|
66
|
+
Accept: 'application/json',
|
|
67
|
+
...headers,
|
|
68
|
+
},
|
|
69
|
+
});
|
|
70
|
+
return this.doResponseResult(response);
|
|
71
|
+
} catch (error) {
|
|
72
|
+
throw new HttpError(error as AxiosError);
|
|
73
|
+
}
|
|
69
74
|
}
|
|
70
75
|
|
|
71
76
|
/**
|
|
@@ -88,8 +93,12 @@ export class Net {
|
|
|
88
93
|
// delete params.srfparentdata;
|
|
89
94
|
// }
|
|
90
95
|
url = this.attachUrlParam(url, params);
|
|
91
|
-
|
|
92
|
-
|
|
96
|
+
try {
|
|
97
|
+
const response = await axios.get(url, { headers, ...option });
|
|
98
|
+
return this.doResponseResult(response);
|
|
99
|
+
} catch (error) {
|
|
100
|
+
throw new HttpError(error as AxiosError);
|
|
101
|
+
}
|
|
93
102
|
}
|
|
94
103
|
|
|
95
104
|
/**
|
|
@@ -107,8 +116,12 @@ export class Net {
|
|
|
107
116
|
headers: AxiosRequestHeaders = {},
|
|
108
117
|
): Promise<IHttpResponse> {
|
|
109
118
|
url = this.handleAppPresetParam(url, params);
|
|
110
|
-
|
|
111
|
-
|
|
119
|
+
try {
|
|
120
|
+
const response = await axios.delete(url, { headers });
|
|
121
|
+
return this.doResponseResult(response);
|
|
122
|
+
} catch (error) {
|
|
123
|
+
throw new HttpError(error as AxiosError);
|
|
124
|
+
}
|
|
112
125
|
}
|
|
113
126
|
|
|
114
127
|
/**
|
|
@@ -123,11 +136,16 @@ export class Net {
|
|
|
123
136
|
async put(
|
|
124
137
|
url: string,
|
|
125
138
|
data: IData,
|
|
139
|
+
params: IParams = {},
|
|
126
140
|
headers: AxiosRequestHeaders = {},
|
|
127
141
|
): Promise<IHttpResponse> {
|
|
128
|
-
url = this.handleAppPresetParam(url,
|
|
129
|
-
|
|
130
|
-
|
|
142
|
+
url = this.handleAppPresetParam(url, params);
|
|
143
|
+
try {
|
|
144
|
+
const response = await axios.put(url, data, { headers });
|
|
145
|
+
return this.doResponseResult(response);
|
|
146
|
+
} catch (error) {
|
|
147
|
+
throw new HttpError(error as AxiosError);
|
|
148
|
+
}
|
|
131
149
|
}
|
|
132
150
|
|
|
133
151
|
/**
|
|
@@ -143,10 +161,14 @@ export class Net {
|
|
|
143
161
|
url: string,
|
|
144
162
|
headers: AxiosRequestHeaders = {},
|
|
145
163
|
): Promise<IHttpResponse> {
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
164
|
+
try {
|
|
165
|
+
const response = await axios.get(url, {
|
|
166
|
+
headers,
|
|
167
|
+
});
|
|
168
|
+
return this.doResponseResult(response);
|
|
169
|
+
} catch (error) {
|
|
170
|
+
throw new HttpError(error as AxiosError);
|
|
171
|
+
}
|
|
150
172
|
}
|
|
151
173
|
|
|
152
174
|
/**
|
|
@@ -0,0 +1,62 @@
|
|
|
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
|
+
* 应用的的基础路径
|
|
25
|
+
* 如:http://172.16.103.120:30061/portalwebapp/#/index/appportalview?params=123
|
|
26
|
+
* 返回:http://172.16.103.120:30061/portalwebapp
|
|
27
|
+
*
|
|
28
|
+
* @author lxm
|
|
29
|
+
* @date 2022-10-11 20:10:29
|
|
30
|
+
* @returns {*}
|
|
31
|
+
*/
|
|
32
|
+
static get appBase() {
|
|
33
|
+
const { origin, pathname } = window.location;
|
|
34
|
+
return `${origin}${pathname}`.replace(/\/$/, '');
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* #开始到末尾,即路由地址
|
|
39
|
+
* 如:http://172.16.103.120:30061/portalwebapp/#/index/appportalview?params=123
|
|
40
|
+
* 返回:/index/appportalview?params=123
|
|
41
|
+
*
|
|
42
|
+
* @author lxm
|
|
43
|
+
* @date 2022-10-11 16:10:40
|
|
44
|
+
* @returns {*}
|
|
45
|
+
*/
|
|
46
|
+
static get routePath() {
|
|
47
|
+
return window.location.hash.replace('#', '');
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* 当前地址的全路径,包含域名和参数
|
|
52
|
+
* 如:http://172.16.103.120:30061/portalwebapp/#/index/appportalview?params=123
|
|
53
|
+
*
|
|
54
|
+
* @author lxm
|
|
55
|
+
* @date 2022-10-11 21:10:39
|
|
56
|
+
* @readonly
|
|
57
|
+
* @static
|
|
58
|
+
*/
|
|
59
|
+
static get fullPath() {
|
|
60
|
+
return window.location.href;
|
|
61
|
+
}
|
|
62
|
+
}
|
package/src/utils/util/util.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
|
+
import { debounce, DebounceSettings } from 'lodash-es';
|
|
1
3
|
import { getCookie } from 'qx-util';
|
|
2
4
|
import { CoreConst } from '../../constant';
|
|
3
5
|
|
|
@@ -12,3 +14,65 @@ import { CoreConst } from '../../constant';
|
|
|
12
14
|
export function getToken(): string | null {
|
|
13
15
|
return getCookie(CoreConst.TOKEN);
|
|
14
16
|
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* 判断两个数组是否有相同的元素
|
|
20
|
+
*
|
|
21
|
+
* @author lxm
|
|
22
|
+
* @date 2022-09-20 19:09:29
|
|
23
|
+
* @export
|
|
24
|
+
* @param {any[]} arr1
|
|
25
|
+
* @param {any[]} arr2
|
|
26
|
+
* @returns {*} {boolean}
|
|
27
|
+
*/
|
|
28
|
+
export function isOverlap(arr1: any[], arr2: any[]): boolean {
|
|
29
|
+
const newArr = Array.from(new Set([...arr1, ...arr2]));
|
|
30
|
+
return newArr.length !== arr1.length + arr2.length;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* 防抖并合并每次的参数
|
|
35
|
+
*
|
|
36
|
+
* @author lxm
|
|
37
|
+
* @date 2022-09-20 21:09:53
|
|
38
|
+
* @export
|
|
39
|
+
* @template T
|
|
40
|
+
* @param {T} func 要防抖的函数
|
|
41
|
+
* @param {(
|
|
42
|
+
* oldParams: Parameters<T>,
|
|
43
|
+
* newParams: Parameters<T>,
|
|
44
|
+
* ) => Parameters<T>} mergeFunc 合并的回调函数
|
|
45
|
+
* @param {number} [wait] 防抖的延迟毫秒数
|
|
46
|
+
* @param {DebounceSettings} [options] 防抖函数的额外参数
|
|
47
|
+
* @returns {*}
|
|
48
|
+
*/
|
|
49
|
+
export function debounceAndMerge<T extends (...args: any[]) => any>(
|
|
50
|
+
func: T,
|
|
51
|
+
mergeFunc: (
|
|
52
|
+
oldParams: Parameters<T>,
|
|
53
|
+
newParams: Parameters<T>,
|
|
54
|
+
) => Parameters<T>,
|
|
55
|
+
wait?: number,
|
|
56
|
+
options?: DebounceSettings,
|
|
57
|
+
) {
|
|
58
|
+
// 缓存上一次的函数参数
|
|
59
|
+
let oldParams: Parameters<T> | undefined;
|
|
60
|
+
const debounceFunc = debounce(
|
|
61
|
+
(...params: Parameters<T>) => {
|
|
62
|
+
// 防抖函数执行的时候清空缓存参数
|
|
63
|
+
oldParams = undefined;
|
|
64
|
+
return func(...params);
|
|
65
|
+
},
|
|
66
|
+
wait,
|
|
67
|
+
options,
|
|
68
|
+
);
|
|
69
|
+
return (...args: Parameters<T>) => {
|
|
70
|
+
// 合并参数,并把参数缓存到oldParams里,用新参数调用防抖函数
|
|
71
|
+
let newParams = args;
|
|
72
|
+
if (oldParams) {
|
|
73
|
+
newParams = mergeFunc(oldParams, newParams);
|
|
74
|
+
}
|
|
75
|
+
oldParams = newParams;
|
|
76
|
+
return debounceFunc(...newParams);
|
|
77
|
+
};
|
|
78
|
+
}
|