@ibiz-template/core 0.0.1-beta.1 → 0.0.1-beta.141

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 (87) hide show
  1. package/dist/system/index.system.js +1 -1
  2. package/out/constant/core/core.d.ts +9 -0
  3. package/out/constant/core/core.d.ts.map +1 -1
  4. package/out/constant/core/core.js +9 -0
  5. package/out/context/index.d.ts +63 -4
  6. package/out/context/index.d.ts.map +1 -1
  7. package/out/context/index.js +73 -3
  8. package/out/environment/environment.d.ts.map +1 -1
  9. package/out/environment/environment.js +6 -0
  10. package/out/error/http-error/http-error.d.ts.map +1 -1
  11. package/out/error/http-error/http-error.js +0 -4
  12. package/out/interface/click-outside/click-outside.d.ts +1 -1
  13. package/out/interface/click-outside/click-outside.d.ts.map +1 -1
  14. package/out/interface/i-environment/i-environment.d.ts +44 -0
  15. package/out/interface/i-environment/i-environment.d.ts.map +1 -1
  16. package/out/types.d.ts +31 -0
  17. package/out/types.d.ts.map +1 -1
  18. package/out/utils/data-type/data-types.d.ts +47 -0
  19. package/out/utils/data-type/data-types.d.ts.map +1 -0
  20. package/out/utils/data-type/data-types.js +96 -0
  21. package/out/utils/download-file/download-file.d.ts +10 -0
  22. package/out/utils/download-file/download-file.d.ts.map +1 -1
  23. package/out/utils/download-file/download-file.js +20 -0
  24. package/out/utils/index.d.ts +6 -0
  25. package/out/utils/index.d.ts.map +1 -1
  26. package/out/utils/index.js +6 -0
  27. package/out/utils/interceptor/core-interceptor.d.ts +1 -2
  28. package/out/utils/interceptor/core-interceptor.d.ts.map +1 -1
  29. package/out/utils/interceptor/core-interceptor.js +12 -7
  30. package/out/utils/interceptor/interceptor.d.ts +6 -6
  31. package/out/utils/interceptor/interceptor.d.ts.map +1 -1
  32. package/out/utils/interceptor/interceptor.js +2 -2
  33. package/out/utils/logger/logger.d.ts +1 -1
  34. package/out/utils/logger/logger.d.ts.map +1 -1
  35. package/out/utils/logger/logger.js +1 -1
  36. package/out/utils/net/http-response.d.ts +1 -3
  37. package/out/utils/net/http-response.d.ts.map +1 -1
  38. package/out/utils/net/net.d.ts +30 -13
  39. package/out/utils/net/net.d.ts.map +1 -1
  40. package/out/utils/net/net.js +37 -11
  41. package/out/utils/plural/plural.d.ts.map +1 -1
  42. package/out/utils/plural/plural.js +2 -0
  43. package/out/utils/string-util/string-util.d.ts +46 -0
  44. package/out/utils/string-util/string-util.d.ts.map +1 -0
  45. package/out/utils/string-util/string-util.js +71 -0
  46. package/out/utils/sync/await-timeout.d.ts +14 -0
  47. package/out/utils/sync/await-timeout.d.ts.map +1 -0
  48. package/out/utils/sync/await-timeout.js +23 -0
  49. package/out/utils/sync/count-latch.d.ts +60 -0
  50. package/out/utils/sync/count-latch.d.ts.map +1 -0
  51. package/out/utils/sync/count-latch.js +90 -0
  52. package/out/utils/sync/index.d.ts +3 -0
  53. package/out/utils/sync/index.d.ts.map +1 -0
  54. package/out/utils/sync/index.js +2 -0
  55. package/out/utils/upload/select-file.d.ts +53 -0
  56. package/out/utils/upload/select-file.d.ts.map +1 -0
  57. package/out/utils/upload/select-file.js +47 -0
  58. package/out/utils/upload/upload-file.d.ts +46 -0
  59. package/out/utils/upload/upload-file.d.ts.map +1 -0
  60. package/out/utils/upload/upload-file.js +151 -0
  61. package/out/utils/util/ie-helper.d.ts +12 -0
  62. package/out/utils/util/ie-helper.d.ts.map +1 -0
  63. package/out/utils/util/ie-helper.js +20 -0
  64. package/package.json +13 -11
  65. package/src/constant/core/core.ts +10 -0
  66. package/src/context/index.ts +115 -5
  67. package/src/environment/environment.ts +6 -0
  68. package/src/error/http-error/http-error.ts +0 -4
  69. package/src/interface/i-environment/i-environment.ts +50 -0
  70. package/src/types.ts +35 -0
  71. package/src/utils/data-type/data-types.ts +99 -0
  72. package/src/utils/download-file/download-file.ts +21 -0
  73. package/src/utils/index.ts +6 -0
  74. package/src/utils/interceptor/core-interceptor.ts +16 -11
  75. package/src/utils/interceptor/interceptor.ts +7 -9
  76. package/src/utils/logger/logger.ts +1 -1
  77. package/src/utils/net/http-response.ts +1 -5
  78. package/src/utils/net/net.ts +45 -22
  79. package/src/utils/plural/plural.ts +3 -0
  80. package/src/utils/string-util/string-util.ts +75 -0
  81. package/src/utils/sync/await-timeout.ts +27 -0
  82. package/src/utils/sync/count-latch.ts +96 -0
  83. package/src/utils/sync/index.ts +2 -0
  84. package/src/utils/upload/select-file.ts +86 -0
  85. package/src/utils/upload/upload-file.ts +207 -0
  86. package/src/utils/util/ie-helper.ts +42 -0
  87. package/LICENSE +0 -21
@@ -1,3 +1,5 @@
1
+ import { clone } from 'ramda';
2
+
1
3
  /**
2
4
  * 上下文处理类
3
5
  *
@@ -10,24 +12,65 @@ export class IBizContext implements IContext {
10
12
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
11
13
  [key: string | symbol]: any;
12
14
 
13
- protected _context!: IContext;
15
+ /**
16
+ * clone 后引用的上下文实例,需要在实例销毁时,同时销毁
17
+ *
18
+ * @author chitanda
19
+ * @date 2023-03-13 16:03:31
20
+ * @protected
21
+ * @type {IBizContext[]}
22
+ */
23
+ protected declare _associationContext: IBizContext[];
24
+
25
+ /**
26
+ * 修改的父上下文
27
+ *
28
+ * @author lxm
29
+ * @date 2022-12-08 18:12:16
30
+ * @protected
31
+ * @type {IData}
32
+ */
33
+ protected declare _context: IData;
34
+
35
+ /**
36
+ * 父的上下文源对象
37
+ *
38
+ * @author lxm
39
+ * @date 2022-12-08 18:12:31
40
+ * @type {IContext}
41
+ */
42
+ declare _parent?: IContext;
14
43
 
15
44
  /**
16
45
  * Creates an instance of IBizContext.
17
46
  *
18
47
  * @author chitanda
19
48
  * @date 2022-07-14 10:07:15
20
- * @param {IContext} [context={}] 自身的上下文
21
- * @param {IBizContext} [parent]
49
+ * @param {IData} [context={}] 自身的上下文
50
+ * @param {IContext} [parent]
22
51
  */
23
52
  // eslint-disable-next-line default-param-last
24
- constructor(context: IContext = {}, parent?: IBizContext) {
53
+ private constructor(context: IData = {}, parent?: IContext) {
54
+ Object.defineProperty(this, '_associationContext', {
55
+ enumerable: false,
56
+ value: [],
57
+ });
58
+
25
59
  if (parent) {
26
60
  // eslint-disable-next-line @typescript-eslint/no-this-alias
27
61
  const self = this;
28
- // 定义私有变量,用于存储父已有上下文,方便覆盖
62
+
63
+ // 定义私有变量,存放父上下文源对象
64
+ Object.defineProperty(this, '_parent', {
65
+ enumerable: false,
66
+ writable: true,
67
+ value: parent,
68
+ });
69
+
70
+ // 定义私有变量,用于存储对父已有上下文的修改。
29
71
  Object.defineProperty(this, '_context', {
30
72
  enumerable: false,
73
+ writable: true,
31
74
  value: {},
32
75
  });
33
76
  // 监控父上下文参数,自身不存在时从父取
@@ -56,4 +99,71 @@ export class IBizContext implements IContext {
56
99
  // 合并给入上下文
57
100
  Object.assign(this, context);
58
101
  }
102
+
103
+ /**
104
+ * 返回自身的上下文,独有的和与父有差异的。
105
+ *
106
+ * @author lxm
107
+ * @date 2022-12-08 17:12:26
108
+ * @returns {*} {IData}
109
+ */
110
+ getOwnContext(): IData {
111
+ const result: IData = {};
112
+ Object.keys(this).forEach(key => {
113
+ // 父没有的,或者修改了父的上下文
114
+ // 父不存在则返回所有自身的属性
115
+ if (
116
+ !this._parent ||
117
+ !Object.prototype.hasOwnProperty.call(this._parent, key) ||
118
+ Object.prototype.hasOwnProperty.call(this._context, key)
119
+ ) {
120
+ result[key] = this[key];
121
+ }
122
+ });
123
+ return result;
124
+ }
125
+
126
+ /**
127
+ * 销毁当前上下文对象
128
+ *
129
+ * @author chitanda
130
+ * @date 2023-03-13 15:03:04
131
+ */
132
+ destroy(): void {
133
+ this._parent = undefined;
134
+ this._context = {};
135
+ this._associationContext.forEach(item => {
136
+ item.destroy();
137
+ });
138
+ }
139
+
140
+ /**
141
+ * 在非视图中,需要断开视图上下文联系时。只能使用 clone 创建新的局部上下文
142
+ *
143
+ * @author chitanda
144
+ * @date 2023-03-13 16:03:13
145
+ * @return {*} {IBizContext}
146
+ */
147
+ clone(): IBizContext {
148
+ const newContext = new IBizContext(
149
+ clone(this.getOwnContext()),
150
+ this._parent,
151
+ );
152
+ this._associationContext.push(newContext);
153
+ return newContext;
154
+ }
155
+
156
+ /**
157
+ * 上下文只有在视图初始化时,调用 create 方法
158
+ *
159
+ * @author chitanda
160
+ * @date 2023-03-13 16:03:32
161
+ * @static
162
+ * @param {IData} [context]
163
+ * @param {IContext} [parent]
164
+ * @return {*} {IContext}
165
+ */
166
+ static create(context?: IData, parent?: IContext): IBizContext {
167
+ return new IBizContext(context, parent);
168
+ }
59
169
  }
@@ -19,4 +19,10 @@ export const Environment: IEnvironment = {
19
19
  loginMode: LoginMode.DEFAULT,
20
20
  menuPermissionMode: MenuPermissionMode.MIXIN,
21
21
  enablePermission: true,
22
+ enableWfAllHistory: false,
23
+ routePlaceholder: '-',
24
+ loginViewName: 'AppLoginView',
25
+ version: '0.0.1',
26
+ favicon: './favicon.ico',
27
+ disableLogout: false,
22
28
  };
@@ -1,5 +1,4 @@
1
1
  import { AxiosError, AxiosResponse } from 'axios';
2
- import { HttpStatusMessageConst } from '../../constant';
3
2
 
4
3
  /**
5
4
  * 请求异常
@@ -28,9 +27,6 @@ export class HttpError implements Error {
28
27
  } else {
29
28
  this.message = res.statusText;
30
29
  }
31
- if (!this.message) {
32
- this.message = HttpStatusMessageConst[res.status];
33
- }
34
30
  if (!this.message) {
35
31
  this.message = '网络异常,请稍后重试!';
36
32
  }
@@ -146,4 +146,54 @@ export interface IEnvironment {
146
146
  * @type {MenuPermissionMode}
147
147
  */
148
148
  menuPermissionMode: MenuPermissionMode;
149
+
150
+ /**
151
+ * 是否让所有工作流history接口走all
152
+ *
153
+ * @type {boolean}
154
+ * @memberof IEnvironment
155
+ */
156
+ enableWfAllHistory: boolean;
157
+
158
+ /**
159
+ * 路由占位符
160
+ *
161
+ * @type {string}
162
+ * @memberof IEnvironment
163
+ */
164
+ routePlaceholder: string;
165
+
166
+ /**
167
+ * 登录页视图组件名称
168
+ *
169
+ * @type {string}
170
+ * @memberof IEnvironment
171
+ */
172
+ loginViewName: string;
173
+
174
+ /**
175
+ * 版本
176
+ *
177
+ * @type {string}
178
+ * @memberof IEnvironment
179
+ */
180
+ version: string;
181
+
182
+ /**
183
+ * 应用图标地址
184
+ *
185
+ * @author chitanda
186
+ * @date 2023-07-17 17:07:23
187
+ * @type {string}
188
+ */
189
+ favicon?: string;
190
+
191
+ /**
192
+ * 是否禁止退出登录
193
+ *
194
+ * @author zhanghengfeng
195
+ * @date 2023-12-18 14:12:55
196
+ * @type {boolean}
197
+ */
198
+ disableLogout: boolean;
149
199
  }
package/src/types.ts CHANGED
@@ -27,6 +27,41 @@ declare global {
27
27
  */
28
28
  interface IContext {
29
29
  [key: string | symbol]: any;
30
+
31
+ /**
32
+ * 沙箱标识
33
+ *
34
+ * @author chitanda
35
+ * @date 2022-07-22 15:07:23
36
+ * @type {string}
37
+ */
38
+ srfsandbox?: string;
39
+
40
+ /**
41
+ * 返回自身的上下文,独有的和与父有差异的
42
+ *
43
+ * @author chitanda
44
+ * @date 2023-03-13 17:03:10
45
+ * @return {*} {IData}
46
+ */
47
+ getOwnContext(): IData;
48
+
49
+ /**
50
+ * 销毁当前上下文
51
+ *
52
+ * @author chitanda
53
+ * @date 2023-03-13 17:03:37
54
+ */
55
+ destroy(): void;
56
+
57
+ /**
58
+ * 克隆当前上下文
59
+ *
60
+ * @author chitanda
61
+ * @date 2023-03-13 17:03:45
62
+ * @return {*} {IContext}
63
+ */
64
+ clone(): IContext;
30
65
  }
31
66
 
32
67
  /**
@@ -0,0 +1,99 @@
1
+ /**
2
+ * 数据类型转换识别工具类
3
+ * @author lxm
4
+ * @date 2023-08-25 04:33:49
5
+ * @export
6
+ * @class DataTypes
7
+ */
8
+ export class DataTypes {
9
+ /**
10
+ * 数字类型映射字符串类型
11
+ * @author lxm
12
+ * @date 2023-08-25 04:49:52
13
+ * @static
14
+ * @type {{ [p: number]: string }}
15
+ */
16
+ static readonly typeMap: { [p: number]: string } = {
17
+ 0: 'UNKNOWN',
18
+ 1: 'BIGINT',
19
+ 2: 'BINARY',
20
+ 3: 'BIT',
21
+ 4: 'CHAR',
22
+ 5: 'DATETIME',
23
+ 6: 'DECIMAL',
24
+ 7: 'FLOAT',
25
+ 8: 'IMAGE',
26
+ 9: 'INT',
27
+ 10: 'MONEY',
28
+ 11: 'NCHAR',
29
+ 12: 'NTEXT',
30
+ 13: 'NVARCHAR',
31
+ 14: 'NUMERIC',
32
+ 15: 'REAL',
33
+ 16: 'SMALLDATETIME',
34
+ 17: 'SMALLINT',
35
+ 18: 'SMALLMONEY',
36
+ 19: 'SQL_VARIANT',
37
+ 20: 'SYSNAME',
38
+ 21: 'TEXT',
39
+ 22: 'TIMESTAMP',
40
+ 23: 'TINYINT',
41
+ 24: 'VARBINARY',
42
+ 25: 'VARCHAR',
43
+ 26: 'UNIQUEIDENTIFIER',
44
+ 27: 'DATE', // 纯日期型
45
+ 28: 'TIME', // 纯时间
46
+ 29: 'BIGDECIMAL', // 大数值
47
+ };
48
+
49
+ /**
50
+ * 是否是数值类型
51
+ * @author lxm
52
+ * @date 2023-08-25 04:53:30
53
+ * @static
54
+ * @param {number} dataType 数据类型(数值)
55
+ * @return {*} {boolean}
56
+ */
57
+ public static isNumber(dataType: number): boolean {
58
+ const numberTypes = [
59
+ 'BIGINT',
60
+ 'BINARY',
61
+ 'DECIMAL',
62
+ 'FLOAT',
63
+ 'INT',
64
+ 'MONEY',
65
+ 'NUMERIC',
66
+ 'REAL',
67
+ 'SMALLINT',
68
+ 'SMALLMONEY',
69
+ 'TINYINT',
70
+ 'VARBINARY',
71
+ ];
72
+ return numberTypes.includes(this.toString(dataType));
73
+ }
74
+
75
+ /**
76
+ * 是否是日期类型数据
77
+ *
78
+ * @static
79
+ * @param {number} dataType
80
+ * @return {*}
81
+ * @memberof DataTypes
82
+ */
83
+ public static isDate(dataType: number): boolean {
84
+ const dateTypes = ['DATETIME', 'SMALLDATETIME', 'DATE', 'TIME'];
85
+ return dateTypes.includes(this.toString(dataType));
86
+ }
87
+
88
+ /**
89
+ * 获取字符串数据类型
90
+ * @author lxm
91
+ * @date 2023-08-25 04:53:58
92
+ * @static
93
+ * @param {number} dataType 数据类型(数值)
94
+ * @return {*} {string}
95
+ */
96
+ public static toString(dataType: number): string {
97
+ return this.typeMap[dataType];
98
+ }
99
+ }
@@ -51,12 +51,33 @@ export function calcMimeByFileName(fileName: string) {
51
51
  case '.tar':
52
52
  mime = 'application/x-tar';
53
53
  break;
54
+ case '.xlsx':
55
+ mime = 'application/vnd.ms-excel';
56
+ break;
54
57
  default:
55
58
  mime = '';
56
59
  }
57
60
  return mime;
58
61
  }
59
62
 
63
+ /**
64
+ * 判断是否是图片格式
65
+ *
66
+ * @author lxm
67
+ * @date 2022-11-21 13:11:23
68
+ * @export
69
+ * @param {string} fileName
70
+ * @returns {*} {boolean}
71
+ */
72
+ export function isImage(fileName: string): boolean {
73
+ const ext = fileName.split('.').pop();
74
+ if (!ext) {
75
+ return false;
76
+ }
77
+ const imageTypes = ['.jpeg', 'jpg', 'gif', 'png', 'bmp', 'svg'];
78
+ return imageTypes.includes(ext);
79
+ }
80
+
60
81
  /**
61
82
  * 纯JS触发下载文件
62
83
  *
@@ -5,8 +5,14 @@ export { IHttpResponse, HttpResponse } from './net/http-response';
5
5
  export { Net } from './net/net';
6
6
  export { plural, pluralLower } from './plural/plural';
7
7
  export * from './util/util';
8
+ export * from './util/ie-helper';
8
9
  export * from './url-helper/url-helper';
9
10
  export * from './event/event';
10
11
  export * from './click-outside/click-outside';
11
12
  export * from './color/color';
12
13
  export * from './download-file/download-file';
14
+ export * from './upload/select-file';
15
+ export * from './upload/upload-file';
16
+ export * from './sync';
17
+ export { StringUtil } from './string-util/string-util';
18
+ export { DataTypes } from './data-type/data-types';
@@ -1,4 +1,3 @@
1
- import { AxiosRequestConfig } from 'axios';
2
1
  import { getToken } from '../util/util';
3
2
  import { Interceptor } from './interceptor';
4
3
 
@@ -12,24 +11,30 @@ import { Interceptor } from './interceptor';
12
11
  * @extends {Interceptor}
13
12
  */
14
13
  export class CoreInterceptor extends Interceptor {
15
- protected async onBeforeRequest(
16
- config: AxiosRequestConfig,
17
- ): Promise<AxiosRequestConfig> {
18
- await super.onBeforeRequest(config);
14
+ protected async onBeforeRequest(config: IData): Promise<IData> {
15
+ config = await super.onBeforeRequest(config);
19
16
 
20
- if (!config.headers) {
21
- config.headers = {};
22
- }
23
- config.headers.Authorization = `Bearer ${getToken()}`;
17
+ const { headers } = config;
18
+
19
+ // Set the access token.
20
+ // headers.set('Authorization', `Bearer ${getToken()}`);
21
+ headers.Authorization = `Bearer ${getToken()}`;
22
+
23
+ // Set the system ID.
24
+ let systemId = ibiz.env.dcSystem;
24
25
  const { orgData } = ibiz;
25
26
  if (orgData) {
26
27
  if (orgData.systemid) {
27
- config.headers.srfsystemid = orgData.systemid;
28
+ systemId = orgData.systemid;
28
29
  }
29
30
  if (orgData.orgid) {
30
- config.headers.srforgid = orgData.orgid;
31
+ // headers.set('srforgid', orgData.orgid);
32
+ headers.srforgid = orgData.orgid;
31
33
  }
32
34
  }
35
+ // headers.set('srfsystemid', systemId);
36
+ headers.srfsystemid = systemId;
37
+
33
38
  return config;
34
39
  }
35
40
  }
@@ -1,5 +1,5 @@
1
1
  /* eslint-disable @typescript-eslint/no-explicit-any */
2
- import { AxiosInstance, AxiosRequestConfig, AxiosResponse } from 'axios';
2
+ import { AxiosInstance, AxiosResponse } from 'axios';
3
3
 
4
4
  /**
5
5
  * 拦截器基类
@@ -36,12 +36,10 @@ export class Interceptor {
36
36
  * @author lxm
37
37
  * @date 2022-10-27 17:10:41
38
38
  * @protected
39
- * @param {AxiosRequestConfig} config
40
- * @returns {*} {Promise<AxiosRequestConfig>}
39
+ * @param {InternalAxiosRequestConfig} config
40
+ * @returns {*} {Promise<InternalAxiosRequestConfig>}
41
41
  */
42
- protected async onBeforeRequest(
43
- config: AxiosRequestConfig,
44
- ): Promise<AxiosRequestConfig> {
42
+ protected async onBeforeRequest(config: IData): Promise<IData> {
45
43
  return config;
46
44
  }
47
45
 
@@ -53,7 +51,7 @@ export class Interceptor {
53
51
  * @protected
54
52
  * @param {*} error
55
53
  */
56
- protected onRequestError(error: any) {
54
+ protected onRequestError(error: Error): Promise<never> {
57
55
  // 处理请求错误
58
56
  return Promise.reject(error);
59
57
  }
@@ -81,7 +79,7 @@ export class Interceptor {
81
79
  * @protected
82
80
  * @param {*} _error
83
81
  */
84
- protected onResponseError(error: any) {
82
+ protected onResponseError(error: Error): Promise<never> {
85
83
  // 处理响应错误
86
84
  return Promise.reject(error);
87
85
  }
@@ -111,7 +109,7 @@ export class Interceptor {
111
109
  * @date 2022-10-27 17:10:27
112
110
  * @param {AxiosInstance} instance
113
111
  */
114
- eject(instance: AxiosInstance) {
112
+ eject(instance: AxiosInstance): void {
115
113
  if (this.requestTag) {
116
114
  instance.interceptors.request.eject(this.requestTag);
117
115
  }
@@ -1,3 +1,3 @@
1
- import * as Logger from 'loglevel';
1
+ import Logger from 'loglevel';
2
2
 
3
3
  export { Logger };
@@ -75,11 +75,7 @@ export class HttpResponse<T = IData> implements IHttpResponse<T> {
75
75
 
76
76
  statusText: string;
77
77
 
78
- headers:
79
- | AxiosResponseHeaders
80
- | Partial<
81
- Record<string, string> & { 'set-cookie'?: string[] | undefined }
82
- > = {};
78
+ headers: AxiosResponseHeaders = {};
83
79
 
84
80
  /**
85
81
  * AxiosResponse 本地仿造时值为空