@ibiz-template/core 0.1.32 → 0.1.34

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/out/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import './types';
2
+ export * from '@microsoft/fetch-event-source';
2
3
  export * from './command';
3
4
  export * from './constant';
4
5
  export { IBizContext } from './context';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,CAAC;AAEjB,cAAc,WAAW,CAAC;AAC1B,cAAc,YAAY,CAAC;AAC3B,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AACxC,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AACxD,cAAc,SAAS,CAAC;AACxB,cAAc,aAAa,CAAC;AAC5B,cAAc,SAAS,CAAC;AACxB,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,CAAC;AAEjB,cAAc,+BAA+B,CAAC;AAE9C,cAAc,WAAW,CAAC;AAC1B,cAAc,YAAY,CAAC;AAC3B,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AACxC,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AACxD,cAAc,SAAS,CAAC;AACxB,cAAc,aAAa,CAAC;AAC5B,cAAc,SAAS,CAAC;AACxB,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC"}
package/out/index.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import './types';
2
+ export * from '@microsoft/fetch-event-source';
2
3
  export * from './command';
3
4
  export * from './constant';
4
5
  export { IBizContext } from './context';
@@ -0,0 +1,76 @@
1
+ import { IPortalAsyncAction } from '../i-portal-async-action/i-portal-async-action';
2
+ /**
3
+ * AI聊天消息
4
+ *
5
+ * @author chitanda
6
+ * @date 2023-10-10 16:10:29
7
+ * @export
8
+ * @interface IChatMessage
9
+ */
10
+ export interface IChatMessage {
11
+ /**
12
+ * 消息标识
13
+ *
14
+ * @author chitanda
15
+ * @date 2023-09-05 15:09:43
16
+ * @type {string}
17
+ */
18
+ messageid?: string;
19
+ /**
20
+ * 消息名称
21
+ *
22
+ * @author chitanda
23
+ * @date 2023-09-05 15:09:49
24
+ * @type {string}
25
+ */
26
+ messagename?: string;
27
+ /**
28
+ * 消息类型
29
+ *
30
+ * @author chitanda
31
+ * @date 2023-10-10 16:10:21
32
+ * @type {string}
33
+ */
34
+ type?: string;
35
+ /**
36
+ * 消息子类型
37
+ *
38
+ * @author chitanda
39
+ * @date 2023-10-10 16:10:00
40
+ * @type {string}
41
+ */
42
+ subtype?: string;
43
+ /**
44
+ * 消息角色
45
+ *
46
+ * @author chitanda
47
+ * @date 2023-10-10 16:10:32
48
+ * @type {('ASSISTANT' | 'USER' | 'SYSTEM')} 助手 | 用户 | 系统
49
+ */
50
+ role: 'ASSISTANT' | 'USER' | 'SYSTEM';
51
+ /**
52
+ * 内容摘要
53
+ *
54
+ * @author chitanda
55
+ * @date 2023-09-05 15:09:23
56
+ * @type {string}
57
+ */
58
+ content: string;
59
+ /**
60
+ * 消息数据
61
+ *
62
+ * @author chitanda
63
+ * @date 2023-09-05 15:09:55
64
+ * @type {(IPortalAsyncAction | IData | string | unknown)}
65
+ */
66
+ data?: IPortalAsyncAction | IData | string | unknown;
67
+ /**
68
+ * 消息路径
69
+ *
70
+ * @author chitanda
71
+ * @date 2023-09-05 15:09:25
72
+ * @type {string}
73
+ */
74
+ url?: string;
75
+ }
76
+ //# sourceMappingURL=i-chat-message.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"i-chat-message.d.ts","sourceRoot":"","sources":["../../../src/interface/i-chat-message/i-chat-message.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,gDAAgD,CAAC;AAEpF;;;;;;;GAOG;AACH,MAAM,WAAW,YAAY;IAC3B;;;;;;OAMG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IAEnB;;;;;;OAMG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IAErB;;;;;;OAMG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IAEd;;;;;;OAMG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IAEjB;;;;;;OAMG;IACH,IAAI,EAAE,WAAW,GAAG,MAAM,GAAG,QAAQ,CAAC;IAEtC;;;;;;OAMG;IACH,OAAO,EAAE,MAAM,CAAC;IAEhB;;;;;;OAMG;IACH,IAAI,CAAC,EAAE,kBAAkB,GAAG,KAAK,GAAG,MAAM,GAAG,OAAO,CAAC;IAErD;;;;;;OAMG;IACH,GAAG,CAAC,EAAE,MAAM,CAAC;CACd"}
@@ -0,0 +1 @@
1
+ export {};
@@ -23,6 +23,14 @@ export interface IPortalAsyncAction {
23
23
  * @type {string}
24
24
  */
25
25
  actiontype: string;
26
+ /**
27
+ * 作业状态
28
+ *
29
+ * @author chitanda
30
+ * @date 2023-10-10 15:10:59
31
+ * @type {(10 | 20 | 30 | 40)} 未开始 | 执行中 | 已执行 | 执行失败
32
+ */
33
+ actionstate: 10 | 20 | 30 | 40;
26
34
  /**
27
35
  * 异步作业执行结果
28
36
  *
@@ -1 +1 @@
1
- {"version":3,"file":"i-portal-async-action.d.ts","sourceRoot":"","sources":["../../../src/interface/i-portal-async-action/i-portal-async-action.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,MAAM,WAAW,kBAAkB;IACjC;;;;;;OAMG;IACH,YAAY,EAAE,MAAM,CAAC;IAErB;;;;;;OAMG;IACH,UAAU,EAAE,MAAM,CAAC;IAEnB;;;;;;OAMG;IACH,YAAY,CAAC,EAAE,OAAO,CAAC;IAEvB;;;;;;OAMG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAElB;;;;;;OAMG;IACH,sBAAsB,CAAC,EAAE,MAAM,CAAC;IAEhC;;;;;;OAMG;IACH,WAAW,CAAC,EAAE,OAAO,CAAC;IAEtB;;;;;;OAMG;IACH,YAAY,CAAC,EAAE,OAAO,CAAC;IAEvB;;;;;;OAMG;IACH,YAAY,CAAC,EAAE,OAAO,CAAC;IAEvB;;;;;;OAMG;IACH,YAAY,CAAC,EAAE,OAAO,CAAC;CACxB"}
1
+ {"version":3,"file":"i-portal-async-action.d.ts","sourceRoot":"","sources":["../../../src/interface/i-portal-async-action/i-portal-async-action.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,MAAM,WAAW,kBAAkB;IACjC;;;;;;OAMG;IACH,YAAY,EAAE,MAAM,CAAC;IAErB;;;;;;OAMG;IACH,UAAU,EAAE,MAAM,CAAC;IAEnB;;;;;;OAMG;IACH,WAAW,EAAE,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC;IAE/B;;;;;;OAMG;IACH,YAAY,CAAC,EAAE,OAAO,CAAC;IAEvB;;;;;;OAMG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAElB;;;;;;OAMG;IACH,sBAAsB,CAAC,EAAE,MAAM,CAAC;IAEhC;;;;;;OAMG;IACH,WAAW,CAAC,EAAE,OAAO,CAAC;IAEtB;;;;;;OAMG;IACH,YAAY,CAAC,EAAE,OAAO,CAAC;IAEvB;;;;;;OAMG;IACH,YAAY,CAAC,EAAE,OAAO,CAAC;IAEvB;;;;;;OAMG;IACH,YAAY,CAAC,EAAE,OAAO,CAAC;CACxB"}
@@ -1,5 +1,6 @@
1
1
  export * from './click-outside/click-outside';
2
2
  export type { I18n } from './i-18n/i-18n';
3
+ export type { IChatMessage } from './i-chat-message/i-chat-message';
3
4
  export type { IEnvironment } from './i-environment/i-environment';
4
5
  export type { IPortalAsyncAction } from './i-portal-async-action/i-portal-async-action';
5
6
  export type { IPortalMessage } from './i-portal-message/i-portal-message';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/interface/index.ts"],"names":[],"mappings":"AAAA,cAAc,+BAA+B,CAAC;AAC9C,YAAY,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AAC1C,YAAY,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAC;AAClE,YAAY,EAAE,kBAAkB,EAAE,MAAM,+CAA+C,CAAC;AACxF,YAAY,EAAE,cAAc,EAAE,MAAM,qCAAqC,CAAC;AAC1E,YAAY,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/interface/index.ts"],"names":[],"mappings":"AAAA,cAAc,+BAA+B,CAAC;AAC9C,YAAY,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AAC1C,YAAY,EAAE,YAAY,EAAE,MAAM,iCAAiC,CAAC;AACpE,YAAY,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAC;AAClE,YAAY,EAAE,kBAAkB,EAAE,MAAM,+CAA+C,CAAC;AACxF,YAAY,EAAE,cAAc,EAAE,MAAM,qCAAqC,CAAC;AAC1E,YAAY,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC"}
@@ -1,4 +1,5 @@
1
1
  import { RawAxiosRequestHeaders, AxiosResponse, AxiosRequestConfig, AxiosInstance, CreateAxiosDefaults } from 'axios';
2
+ import { FetchEventSourceInit } from '@microsoft/fetch-event-source';
2
3
  import { Interceptor } from '../interceptor/interceptor';
3
4
  import { IHttpResponse } from './http-response';
4
5
  /**
@@ -37,6 +38,7 @@ export declare class Net {
37
38
  * @protected
38
39
  */
39
40
  protected waitRequest: Map<string, Promise<AxiosResponse<any, any>>>;
41
+ protected get baseUrl(): string;
40
42
  /**
41
43
  * Creates an instance of Net.
42
44
  * @author lxm
@@ -165,6 +167,17 @@ export declare class Net {
165
167
  * @return {*}
166
168
  */
167
169
  axios(config: AxiosRequestConfig<IData>): Promise<AxiosResponse>;
170
+ /**
171
+ * 触发 sse 请求
172
+ *
173
+ * @author chitanda
174
+ * @date 2023-10-10 16:10:08
175
+ * @param {string} url
176
+ * @param {IParams} params
177
+ * @param {FetchEventSourceInit} [options={}]
178
+ * @return {*} {Promise<void>}
179
+ */
180
+ sse(url: string, params: IParams, options?: FetchEventSourceInit): Promise<void>;
168
181
  /**
169
182
  * 统一处理请求返回
170
183
  *
@@ -1 +1 @@
1
- {"version":3,"file":"net.d.ts","sourceRoot":"","sources":["../../../src/utils/net/net.ts"],"names":[],"mappings":"AAAA,OAAc,EAEZ,sBAAsB,EACtB,aAAa,EACb,kBAAkB,EAClB,aAAa,EACb,mBAAmB,EACpB,MAAM,OAAO,CAAC;AAMf,OAAO,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AACzD,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAEhD;;;;;;;GAOG;AACH,qBAAa,GAAG;IACd;;;;;;;OAOG;IACH,SAAS,CAAC,QAAQ,EAAE,aAAa,CAAC;IAElC;;;;;;OAMG;IACH,SAAS,CAAC,MAAM,SAA0B;IAE1C;;;;;;;;OAQG;IACH,SAAS,CAAC,WAAW,gDAA6C;IAElE;;;;;OAKG;gBACS,MAAM,CAAC,EAAE,mBAAmB;IAKxC;;;;;;OAMG;IACH,YAAY,EAAE,GAAG,CAAC,MAAM,EAAE,WAAW,CAAC,CAAa;IAEnD;;;;;;;OAOG;IACH,cAAc,CAAC,IAAI,EAAE,MAAM,EAAE,WAAW,EAAE,WAAW,GAAG,IAAI;IAK5D;;;;;;OAMG;IACH,iBAAiB,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI;IAQrC;;;;;;;;OAQG;IACH,SAAS,KAAK,YAAY,IAAI,kBAAkB,CAW/C;IAED;;;;;;;;OAQG;IACH,SAAS,CAAC,WAAW,CAAC,GAAG,OAAO,EAAE,kBAAkB,EAAE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;;;;;;;;;OASG;IACG,MAAM,CACV,GAAG,EAAE,MAAM,EACX,MAAM,CAAC,EAAE,OAAO,EAChB,OAAO,GAAE,sBAA2B,GACnC,OAAO,CAAC,aAAa,CAAC;IAUzB;;;;;;;;;;OAUG;IACG,GAAG,CACP,GAAG,EAAE,MAAM,EACX,IAAI,EAAE,KAAK,EACX,MAAM,GAAE,OAAY,EACpB,OAAO,GAAE,sBAA2B,GACnC,OAAO,CAAC,aAAa,CAAC;IAczB;;;;;;;;OAQG;IACG,QAAQ,CACZ,GAAG,EAAE,MAAM,EACX,OAAO,GAAE,sBAA2B,GACnC,OAAO,CAAC,aAAa,CAAC;IAWzB;;;;;;;;OAQG;IACG,OAAO,CACX,GAAG,EAAE,MAAM,EACX,MAAM,GAAE,kBAAuB,GAC9B,OAAO,CAAC,aAAa,CAAC;IA4BzB;;;;;;;OAOG;IACH,KAAK,CAAC,MAAM,EAAE,kBAAkB,CAAC,KAAK,CAAC,GAAG,OAAO,CAAC,aAAa,CAAC;IAIhE;;;;;;;;;OASG;IACG,GAAG,CACP,GAAG,EAAE,MAAM,EACX,MAAM,EAAE,OAAO,EACf,OAAO,GAAE,oBAAyB,GACjC,OAAO,CAAC,IAAI,CAAC;IA+BhB;;;;;;;;OAQG;IACH,OAAO,CAAC,gBAAgB;IAQxB;;;;;;;;;OASG;IACH,OAAO,CAAC,oBAAoB;IAc5B;;;;;;;;;OASG;IACH,OAAO,CAAC,cAAc;CAevB"}
@@ -1,9 +1,12 @@
1
1
  import axios from 'axios';
2
+ import { fetchEventSource, } from '@microsoft/fetch-event-source';
2
3
  import { merge } from 'lodash-es';
3
4
  import { stringify } from 'qs';
4
5
  import { notNilEmpty } from 'qx-util';
6
+ import { mergeDeepRight } from 'ramda';
5
7
  import { HttpError } from '../../error';
6
8
  import { CoreInterceptor } from '../interceptor';
9
+ import { getToken } from '../util/util';
7
10
  /**
8
11
  * 全局请求工具类
9
12
  *
@@ -13,6 +16,9 @@ import { CoreInterceptor } from '../interceptor';
13
16
  * @class Net
14
17
  */
15
18
  export class Net {
19
+ get baseUrl() {
20
+ return (this.instance.defaults.baseURL || `${ibiz.env.baseUrl}/${ibiz.env.appId}`);
21
+ }
16
22
  /**
17
23
  * Creates an instance of Net.
18
24
  * @author lxm
@@ -87,8 +93,7 @@ export class Net {
87
93
  get presetConfig() {
88
94
  return {
89
95
  // 请求前缀路径
90
- baseURL: this.instance.defaults.baseURL ||
91
- `${ibiz.env.baseUrl}/${ibiz.env.appId}`,
96
+ baseURL: this.baseUrl,
92
97
  headers: {
93
98
  'Content-Type': 'application/json;charset=UTF-8',
94
99
  Accept: 'application/json',
@@ -275,6 +280,43 @@ export class Net {
275
280
  axios(config) {
276
281
  return axios(config);
277
282
  }
283
+ /**
284
+ * 触发 sse 请求
285
+ *
286
+ * @author chitanda
287
+ * @date 2023-10-10 16:10:08
288
+ * @param {string} url
289
+ * @param {IParams} params
290
+ * @param {FetchEventSourceInit} [options={}]
291
+ * @return {*} {Promise<void>}
292
+ */
293
+ async sse(url, params, options = {}) {
294
+ url = this.attachUrlParam(this.baseUrl + url, params);
295
+ if (!options.headers) {
296
+ options.headers = {};
297
+ }
298
+ const headers = options.headers;
299
+ // 补充基本认证信息
300
+ {
301
+ headers.Authorization = `Bearer ${getToken()}`;
302
+ let systemId = ibiz.env.dcSystem;
303
+ const { orgData } = ibiz;
304
+ if (orgData) {
305
+ if (orgData.systemid) {
306
+ systemId = orgData.systemid;
307
+ }
308
+ if (orgData.orgid) {
309
+ headers.srforgid = orgData.orgid;
310
+ }
311
+ }
312
+ headers.srfsystemid = systemId;
313
+ }
314
+ const config = mergeDeepRight({
315
+ openWhenHidden: true,
316
+ method: 'POST',
317
+ }, options);
318
+ await fetchEventSource(url, config);
319
+ }
278
320
  /**
279
321
  * 统一处理请求返回
280
322
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ibiz-template/core",
3
- "version": "0.1.32",
3
+ "version": "0.1.34",
4
4
  "description": "核心包",
5
5
  "type": "module",
6
6
  "main": "out/index.js",
@@ -31,6 +31,7 @@
31
31
  "author": "chitanda",
32
32
  "license": "MIT",
33
33
  "dependencies": {
34
+ "@microsoft/fetch-event-source": "^2.0.1",
34
35
  "axios": "^1.5.1",
35
36
  "lodash-es": "^4.17.21",
36
37
  "loglevel": "^1.8.1",
@@ -49,5 +50,5 @@
49
50
  "qx-util": "^0.4.8",
50
51
  "ramda": "^0.29.0"
51
52
  },
52
- "gitHead": "594d722ab71f8c9e5fa88e685597b221c70e56e0"
53
+ "gitHead": "6b6ab37103623fbc1994241b511829a2013a72c0"
53
54
  }
package/src/index.ts CHANGED
@@ -1,5 +1,7 @@
1
1
  import './types';
2
2
 
3
+ export * from '@microsoft/fetch-event-source';
4
+
3
5
  export * from './command';
4
6
  export * from './constant';
5
7
  export { IBizContext } from './context';
@@ -0,0 +1,83 @@
1
+ import { IPortalAsyncAction } from '../i-portal-async-action/i-portal-async-action';
2
+
3
+ /**
4
+ * AI聊天消息
5
+ *
6
+ * @author chitanda
7
+ * @date 2023-10-10 16:10:29
8
+ * @export
9
+ * @interface IChatMessage
10
+ */
11
+ export interface IChatMessage {
12
+ /**
13
+ * 消息标识
14
+ *
15
+ * @author chitanda
16
+ * @date 2023-09-05 15:09:43
17
+ * @type {string}
18
+ */
19
+ messageid?: string;
20
+
21
+ /**
22
+ * 消息名称
23
+ *
24
+ * @author chitanda
25
+ * @date 2023-09-05 15:09:49
26
+ * @type {string}
27
+ */
28
+ messagename?: string;
29
+
30
+ /**
31
+ * 消息类型
32
+ *
33
+ * @author chitanda
34
+ * @date 2023-10-10 16:10:21
35
+ * @type {string}
36
+ */
37
+ type?: string;
38
+
39
+ /**
40
+ * 消息子类型
41
+ *
42
+ * @author chitanda
43
+ * @date 2023-10-10 16:10:00
44
+ * @type {string}
45
+ */
46
+ subtype?: string;
47
+
48
+ /**
49
+ * 消息角色
50
+ *
51
+ * @author chitanda
52
+ * @date 2023-10-10 16:10:32
53
+ * @type {('ASSISTANT' | 'USER' | 'SYSTEM')} 助手 | 用户 | 系统
54
+ */
55
+ role: 'ASSISTANT' | 'USER' | 'SYSTEM';
56
+
57
+ /**
58
+ * 内容摘要
59
+ *
60
+ * @author chitanda
61
+ * @date 2023-09-05 15:09:23
62
+ * @type {string}
63
+ */
64
+ content: string;
65
+
66
+ /**
67
+ * 消息数据
68
+ *
69
+ * @author chitanda
70
+ * @date 2023-09-05 15:09:55
71
+ * @type {(IPortalAsyncAction | IData | string | unknown)}
72
+ */
73
+ data?: IPortalAsyncAction | IData | string | unknown;
74
+
75
+ /**
76
+ * 消息路径
77
+ *
78
+ * @author chitanda
79
+ * @date 2023-09-05 15:09:25
80
+ * @type {string}
81
+ */
82
+ url?: string;
83
+ }
@@ -25,6 +25,15 @@ export interface IPortalAsyncAction {
25
25
  */
26
26
  actiontype: string;
27
27
 
28
+ /**
29
+ * 作业状态
30
+ *
31
+ * @author chitanda
32
+ * @date 2023-10-10 15:10:59
33
+ * @type {(10 | 20 | 30 | 40)} 未开始 | 执行中 | 已执行 | 执行失败
34
+ */
35
+ actionstate: 10 | 20 | 30 | 40;
36
+
28
37
  /**
29
38
  * 异步作业执行结果
30
39
  *
@@ -1,5 +1,6 @@
1
1
  export * from './click-outside/click-outside';
2
2
  export type { I18n } from './i-18n/i-18n';
3
+ export type { IChatMessage } from './i-chat-message/i-chat-message';
3
4
  export type { IEnvironment } from './i-environment/i-environment';
4
5
  export type { IPortalAsyncAction } from './i-portal-async-action/i-portal-async-action';
5
6
  export type { IPortalMessage } from './i-portal-message/i-portal-message';
@@ -6,13 +6,19 @@ import axios, {
6
6
  AxiosInstance,
7
7
  CreateAxiosDefaults,
8
8
  } from 'axios';
9
+ import {
10
+ FetchEventSourceInit,
11
+ fetchEventSource,
12
+ } from '@microsoft/fetch-event-source';
9
13
  import { merge } from 'lodash-es';
10
14
  import { stringify } from 'qs';
11
15
  import { notNilEmpty } from 'qx-util';
16
+ import { mergeDeepRight } from 'ramda';
12
17
  import { HttpError } from '../../error';
13
18
  import { CoreInterceptor } from '../interceptor';
14
19
  import { Interceptor } from '../interceptor/interceptor';
15
20
  import { IHttpResponse } from './http-response';
21
+ import { getToken } from '../util/util';
16
22
 
17
23
  /**
18
24
  * 全局请求工具类
@@ -53,6 +59,12 @@ export class Net {
53
59
  */
54
60
  protected waitRequest = new Map<string, Promise<AxiosResponse>>();
55
61
 
62
+ protected get baseUrl(): string {
63
+ return (
64
+ this.instance.defaults.baseURL || `${ibiz.env.baseUrl}/${ibiz.env.appId}`
65
+ );
66
+ }
67
+
56
68
  /**
57
69
  * Creates an instance of Net.
58
70
  * @author lxm
@@ -113,9 +125,7 @@ export class Net {
113
125
  protected get presetConfig(): AxiosRequestConfig {
114
126
  return {
115
127
  // 请求前缀路径
116
- baseURL:
117
- this.instance.defaults.baseURL ||
118
- `${ibiz.env.baseUrl}/${ibiz.env.appId}`,
128
+ baseURL: this.baseUrl,
119
129
  headers: {
120
130
  'Content-Type': 'application/json;charset=UTF-8',
121
131
  Accept: 'application/json',
@@ -332,6 +342,51 @@ export class Net {
332
342
  return axios(config);
333
343
  }
334
344
 
345
+ /**
346
+ * 触发 sse 请求
347
+ *
348
+ * @author chitanda
349
+ * @date 2023-10-10 16:10:08
350
+ * @param {string} url
351
+ * @param {IParams} params
352
+ * @param {FetchEventSourceInit} [options={}]
353
+ * @return {*} {Promise<void>}
354
+ */
355
+ async sse(
356
+ url: string,
357
+ params: IParams,
358
+ options: FetchEventSourceInit = {},
359
+ ): Promise<void> {
360
+ url = this.attachUrlParam(this.baseUrl + url, params);
361
+ if (!options.headers) {
362
+ options.headers = {};
363
+ }
364
+ const headers = options.headers!;
365
+ // 补充基本认证信息
366
+ {
367
+ headers.Authorization = `Bearer ${getToken()}`;
368
+ let systemId = ibiz.env.dcSystem;
369
+ const { orgData } = ibiz;
370
+ if (orgData) {
371
+ if (orgData.systemid) {
372
+ systemId = orgData.systemid;
373
+ }
374
+ if (orgData.orgid) {
375
+ headers.srforgid = orgData.orgid;
376
+ }
377
+ }
378
+ headers.srfsystemid = systemId;
379
+ }
380
+ const config = mergeDeepRight(
381
+ {
382
+ openWhenHidden: true,
383
+ method: 'POST',
384
+ },
385
+ options,
386
+ );
387
+ await fetchEventSource(url, config);
388
+ }
389
+
335
390
  /**
336
391
  * 统一处理请求返回
337
392
  *