@ibiz-template/core 0.0.1-alpha.2 → 0.0.1-alpha.21

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 (68) hide show
  1. package/dist/system/index-7a803ce4.system.js +1 -0
  2. package/out/constant/http-status-message/http-status-message.d.ts +5 -0
  3. package/out/constant/http-status-message/http-status-message.d.ts.map +1 -0
  4. package/out/constant/http-status-message/http-status-message.js +20 -0
  5. package/out/constant/index.d.ts +3 -0
  6. package/out/constant/index.d.ts.map +1 -1
  7. package/out/constant/index.js +3 -0
  8. package/out/constant/login-mode/login-mode.d.ts +23 -0
  9. package/out/constant/login-mode/login-mode.d.ts.map +1 -0
  10. package/out/constant/login-mode/login-mode.js +24 -0
  11. package/out/constant/menu-permission-mode/menu-permission-mode.d.ts +23 -0
  12. package/out/constant/menu-permission-mode/menu-permission-mode.d.ts.map +1 -0
  13. package/out/constant/menu-permission-mode/menu-permission-mode.js +24 -0
  14. package/out/context/index.d.ts +2 -39
  15. package/out/context/index.d.ts.map +1 -1
  16. package/out/context/index.js +34 -65
  17. package/out/environment/environment.d.ts.map +1 -1
  18. package/out/environment/environment.js +7 -1
  19. package/out/error/http-error/http-error.d.ts +18 -0
  20. package/out/error/http-error/http-error.d.ts.map +1 -0
  21. package/out/error/http-error/http-error.js +36 -0
  22. package/out/error/index.d.ts +3 -0
  23. package/out/error/index.d.ts.map +1 -0
  24. package/out/error/index.js +2 -0
  25. package/out/error/runtime-error/runtime-error.d.ts +15 -0
  26. package/out/error/runtime-error/runtime-error.d.ts.map +1 -0
  27. package/out/error/runtime-error/runtime-error.js +15 -0
  28. package/out/index.d.ts +2 -1
  29. package/out/index.d.ts.map +1 -1
  30. package/out/index.js +2 -1
  31. package/out/interface/i-environment/i-environment.d.ts +41 -0
  32. package/out/interface/i-environment/i-environment.d.ts.map +1 -1
  33. package/out/types.d.ts +10 -0
  34. package/out/types.d.ts.map +1 -1
  35. package/out/utils/index.d.ts +1 -0
  36. package/out/utils/index.d.ts.map +1 -1
  37. package/out/utils/index.js +1 -0
  38. package/out/utils/net/http-response.d.ts +1 -1
  39. package/out/utils/net/http-response.d.ts.map +1 -1
  40. package/out/utils/net/net.d.ts +1 -1
  41. package/out/utils/net/net.d.ts.map +1 -1
  42. package/out/utils/net/net.js +45 -19
  43. package/out/utils/plural/plural.js +1 -1
  44. package/out/utils/url-helper/url-helper.d.ts +51 -0
  45. package/out/utils/url-helper/url-helper.d.ts.map +1 -0
  46. package/out/utils/url-helper/url-helper.js +59 -0
  47. package/out/utils/util/util.d.ts +29 -0
  48. package/out/utils/util/util.d.ts.map +1 -1
  49. package/out/utils/util/util.js +50 -0
  50. package/package.json +15 -6
  51. package/src/constant/http-status-message/http-status-message.ts +20 -0
  52. package/src/constant/index.ts +3 -0
  53. package/src/constant/login-mode/login-mode.ts +23 -0
  54. package/src/constant/menu-permission-mode/menu-permission-mode.ts +23 -0
  55. package/src/context/index.ts +35 -69
  56. package/src/environment/environment.ts +7 -1
  57. package/src/error/http-error/http-error.ts +43 -0
  58. package/src/error/index.ts +2 -0
  59. package/src/error/runtime-error/runtime-error.ts +14 -0
  60. package/src/index.ts +2 -1
  61. package/src/interface/i-environment/i-environment.ts +47 -0
  62. package/src/types.ts +11 -0
  63. package/src/utils/index.ts +1 -0
  64. package/src/utils/net/http-response.ts +1 -1
  65. package/src/utils/net/net.ts +45 -23
  66. package/src/utils/plural/plural.ts +1 -1
  67. package/src/utils/url-helper/url-helper.ts +62 -0
  68. 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, IBizContextProxyHandle } from './context';
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
  }
@@ -4,3 +4,4 @@ export { IHttpResponse, HttpResponse } from './net/http-response';
4
4
  export { Net } from './net/net';
5
5
  export { plural, pluralLower } from './plural/plural';
6
6
  export * from './util/util';
7
+ export * from './url-helper/url-helper';
@@ -28,7 +28,7 @@ export interface IHttpResponse<T = IData> extends AxiosResponse {
28
28
  * @date 2022-08-18 15:08:44
29
29
  * @type {boolean}
30
30
  */
31
- local?: boolean;
31
+ local: boolean;
32
32
 
33
33
  data: T;
34
34
 
@@ -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
- 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);
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
- const response = await axios.get(url, { headers, ...option });
92
- return this.doResponseResult(response);
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
- const response = await axios.delete(url, { headers });
111
- return this.doResponseResult(response);
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, data);
129
- const response = await axios.put(url, data, { headers });
130
- return this.doResponseResult(response);
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
- const response = await axios.get(url, {
147
- headers,
148
- });
149
- return this.doResponseResult(response);
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
  /**
@@ -1,4 +1,4 @@
1
- import * as pluralize from 'pluralize';
1
+ import pluralize from 'pluralize';
2
2
 
3
3
  /**
4
4
  * 英文转复数写法
@@ -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
+ }
@@ -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
+ }