vue2-client 1.22.2 → 1.22.3
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/.claude/settings.local.json +30 -30
- package/.env.his +19 -19
- package/.eslintrc.js +74 -74
- package/.history/.eslintrc_20260521171150.js +74 -0
- package/.history/.eslintrc_20260521171213.js +74 -0
- package/.history/src/base-client/components/common/HIS/HAddNativeForm/HAddNativeForm_20260601154443.vue +726 -0
- package/.history/src/base-client/components/common/HIS/HAddNativeForm/HAddNativeForm_20260601154700.vue +478 -0
- package/.history/src/base-client/components/common/HIS/HButtons/HButtons_20260512175435.vue +706 -0
- package/.history/src/base-client/components/common/HIS/HButtons/HButtons_20260512175450.vue +694 -0
- package/.history/src/base-client/components/common/HIS/HButtons/HButtons_20260611152602.vue +755 -0
- package/.history/src/base-client/components/common/HIS/HForm/HForm_20260513145941.vue +524 -0
- package/.history/src/base-client/components/common/HIS/HForm/HForm_20260513153133.vue +731 -0
- package/.history/src/base-client/components/common/HIS/HForm/HForm_20260513160316.vue +525 -0
- package/.history/src/base-client/components/common/HIS/HForm/HForm_20260601144150.vue +1046 -0
- package/.history/src/base-client/components/common/HIS/HFormTable/HFormTable_20260310142713.vue +512 -0
- package/.history/src/base-client/components/common/HIS/HFormTable/HFormTable_20260310145118.vue +511 -0
- package/.history/src/base-client/components/common/HIS/HFormTable/HFormTable_20260311094834.vue +696 -0
- package/.history/src/base-client/components/common/HIS/HFormTable/HFormTable_20260320143028.vue +693 -0
- package/.history/src/base-client/components/common/HIS/HFormTable/HFormTable_20260409101450.vue +677 -0
- package/.history/src/base-client/components/common/HIS/HTab/HTab_20260508164645.vue +758 -0
- package/.history/src/base-client/components/common/HIS/HTab/HTab_20260508164714.vue +693 -0
- package/.history/src/base-client/components/common/HIS/HTab/HTab_20260508171651.vue +716 -0
- package/.history/src/base-client/components/common/HIS/HTab/HTab_20260509133717.vue +695 -0
- package/.history/src/base-client/components/common/HIS/HTab/HTab_20260509171115.vue +664 -0
- package/.history/src/base-client/components/common/XAddNativeForm/XAddNativeForm_20260513140637.vue +1455 -0
- package/.history/src/base-client/components/common/XAddNativeForm/XAddNativeForm_20260513140935.vue +1441 -0
- package/.history/src/base-client/components/common/XAddNativeForm/XAddNativeForm_20260513150818.vue +1441 -0
- package/.history/src/base-client/components/common/XAddNativeForm/XAddNativeForm_20260513153119.vue +1442 -0
- package/.history/src/base-client/components/common/XAddNativeForm/XAddNativeForm_20260513153126.vue +1486 -0
- package/.history/src/base-client/components/common/XForm/XFormItem_20260513140854.vue +1607 -0
- package/.history/src/base-client/components/common/XMarkdownViewer/XMarkdownViewer_20260519140403.vue +643 -0
- package/.history/src/base-client/components/common/XMarkdownViewer/XMarkdownViewer_20260519140829.vue +628 -0
- package/.history/src/base-client/components/common/XMarkdownViewer/demo_20260519142824.vue +104 -0
- package/.history/src/base-client/components/common/XMarkdownViewer/demo_20260519143155.vue +102 -0
- package/.history/src/base-client/components/common/XReportGrid/XReport_20260309171231.vue +1241 -0
- package/.history/src/base-client/components/common/XReportGrid/XReport_20260309171441.vue +1223 -0
- package/.history/src/base-client/components/his/HAi/HAi_20260612174826.vue +472 -0
- package/.history/src/base-client/components/his/HAi/HAi_20260612175839.vue +538 -0
- package/.history/src/base-client/components/his/HAi/HAi_20260615103331.vue +650 -0
- package/.history/src/base-client/components/his/XHDescriptions/XHDescriptions_20260424134504.vue +1469 -0
- package/.history/src/base-client/components/his/XSidebar/XSidebar_20260610171133.vue +788 -0
- package/.history/src/base-client/components/his/XSidebar/XSidebar_20260610171151.vue +780 -0
- package/.history/src/base-client/components/his/XTransfer/XTransfer_20260511170841.vue +585 -0
- package/.history/src/base-client/components/his/XTransfer/XTransfer_20260511171138.vue +787 -0
- package/.history/src/base-client/components/his/XTransfer/XTransfer_20260512141830.vue +739 -0
- package/.history/src/components/STable/index_20260409155138.js +806 -0
- package/.history/src/components/STable/index_20260409155218.js +814 -0
- package/.history/src/expression/core/Expression_20260305164427.js +1371 -0
- package/.history/src/expression/core/Expression_20260305170258.js +1358 -0
- package/.history/src/expression/core/Program_20260305111830.js +944 -0
- package/.history/src/expression/core/Program_20260305112041.js +931 -0
- package/.history/src/logic/LogicRunner_20260304154306.js +170 -0
- package/.history/src/logic/LogicRunner_20260304155553.js +112 -0
- package/.history/src/logic/LogicRunner_20260305105834.js +112 -0
- package/.history/src/logic/LogicRunner_20260305112718.js +129 -0
- package/.history/src/logic/LogicRunner_20260305182436.js +133 -0
- package/.history/src/logic/LogicRunner_20260306151301.js +213 -0
- package/.history/src/logic/LogicRunner_20260306152419.js +213 -0
- package/.history/src/logic/plugins/common/DateTools_20260305154159.js +61 -0
- package/.history/src/logic/plugins/common/DateTools_20260305154217.js +44 -0
- package/.history/src/logic/plugins/common/DateTools_20260305161014.js +44 -0
- package/.history/src/logic/plugins/common/HttpTools_20260305164352.js +80 -0
- package/.history/src/logic/plugins/common/HttpTools_20260305170258.js +75 -0
- package/.history/src/logic/plugins/common/HttpTools_20260305171634.js +75 -0
- package/.history/src/logic/plugins/common/HttpTools_20260306152419.js +72 -0
- package/.history/src/services/api/restTools_20260427142149.js +245 -0
- package/.history/src/services/api/restTools_20260427142853.js +230 -0
- package/.history/src/services/api/restTools_20260519135558.js +230 -0
- package/.history/src/services/api/restTools_20260519140825.js +230 -0
- package/.history/src/services/api/restTools_20260519151223.js +230 -0
- package/.history/src/utils/indexedDB_20260306150918.js +593 -0
- package/.history/src/utils/indexedDB_20260306151301.js +586 -0
- package/.idea/af-vue2-client.iml +9 -0
- package/.idea/codeStyles/Project.xml +62 -0
- package/.idea/codeStyles/codeStyleConfig.xml +5 -0
- package/.idea/misc.xml +6 -0
- package/.idea/modules.xml +1 -1
- package/Components.md +60 -60
- package/index.js +31 -31
- package/jest-transform-stub.js +8 -8
- package/jest.setup.js +7 -7
- package/package.json +1 -1
- package/preview-input-box.html +180 -0
- package/src/assets/img/querySlotDemo.svg +15 -15
- package/src/base-client/components/common/AmapMarker/AmapPointRendering.vue +120 -120
- package/src/base-client/components/common/CitySelect/index.js +3 -3
- package/src/base-client/components/common/CitySelect/index.md +109 -109
- package/src/base-client/components/common/FormGroupEdit/index.js +3 -3
- package/src/base-client/components/common/FormGroupEdit/index.md +43 -43
- package/src/base-client/components/common/HIS/HButtons/HButtons.vue +55 -1
- package/src/base-client/components/common/HIS/HForm/HForm.vue +1186 -1186
- package/src/base-client/components/common/HIS/HTab/HTab.vue +88 -1
- package/src/base-client/components/common/JSONToTree/jsontotree.vue +271 -271
- package/src/base-client/components/common/PersonSetting/index.js +3 -3
- package/src/base-client/components/common/Tree/index.js +2 -2
- package/src/base-client/components/common/Upload/index.js +3 -3
- package/src/base-client/components/common/XAddNativeForm/index.md +146 -146
- package/src/base-client/components/common/XAddReport/XAddReport.vue +16 -1
- package/src/base-client/components/common/XCard/XCard.vue +64 -64
- package/src/base-client/components/common/XDataDrawer/XDataDrawer.vue +180 -180
- package/src/base-client/components/common/XDataDrawer/index.js +3 -3
- package/src/base-client/components/common/XDataDrawer/index.md +41 -41
- package/src/base-client/components/common/XDescriptions/index.js +3 -3
- package/src/base-client/components/common/XDescriptions/index.md +382 -382
- package/src/base-client/components/common/XForm/index.md +178 -178
- package/src/base-client/components/common/XInput/XInput.vue +32 -1
- package/src/base-client/components/common/XInspectionDetailDrawer/index.vue +1 -1
- package/src/base-client/components/common/XMarkdownViewer/demo.vue +102 -102
- package/src/base-client/components/common/XStepView/XStepView.vue +252 -252
- package/src/base-client/components/common/XStepView/index.js +3 -3
- package/src/base-client/components/common/XStepView/index.md +31 -31
- package/src/base-client/components/common/XTable/index.md +255 -255
- package/src/base-client/components/his/HAi/HAi.vue +1177 -436
- package/src/base-client/components/his/XList/XList.vue +337 -58
- package/src/base-client/components/his/XSidebar/XSidebar.vue +36 -12
- package/src/base-client/components/his/XTransfer/index.md +327 -327
- package/src/base-client/components/system/DictionaryDetailsView/DictionaryDetailsView.vue +232 -232
- package/src/base-client/plugins/Config.js +19 -19
- package/src/base-client/plugins/tabs-page-plugin.js +39 -39
- package/src/components/Charts/Bar.vue +62 -62
- package/src/components/Charts/ChartCard.vue +134 -134
- package/src/components/Charts/Liquid.vue +67 -67
- package/src/components/Charts/MiniArea.vue +39 -39
- package/src/components/Charts/MiniBar.vue +39 -39
- package/src/components/Charts/MiniProgress.vue +75 -75
- package/src/components/Charts/MiniSmoothArea.vue +40 -40
- package/src/components/Charts/Radar.vue +68 -68
- package/src/components/Charts/RankList.vue +77 -77
- package/src/components/Charts/TagCloud.vue +113 -113
- package/src/components/Charts/TransferBar.vue +64 -64
- package/src/components/Charts/Trend.vue +82 -82
- package/src/components/Charts/chart.less +12 -12
- package/src/components/Charts/smooth.area.less +13 -13
- package/src/components/NumberInfo/NumberInfo.vue +54 -54
- package/src/components/NumberInfo/index.js +3 -3
- package/src/components/NumberInfo/index.less +54 -54
- package/src/components/NumberInfo/index.md +43 -43
- package/src/components/STable/index.js +953 -953
- package/src/components/card/ChartCard.vue +79 -79
- package/src/components/chart/Bar.vue +60 -60
- package/src/components/chart/MiniArea.vue +67 -67
- package/src/components/chart/MiniBar.vue +59 -59
- package/src/components/chart/MiniProgress.vue +57 -57
- package/src/components/chart/Radar.vue +80 -80
- package/src/components/chart/RankingList.vue +60 -60
- package/src/components/chart/Trend.vue +79 -79
- package/src/components/chart/index.less +9 -9
- package/src/components/checkbox/ColorCheckbox.vue +157 -157
- package/src/components/input/IInput.vue +66 -66
- package/src/components/menu/SideMenu.vue +75 -75
- package/src/components/menu/menu.js +273 -273
- package/src/components/tool/AStepItem.vue +60 -60
- package/src/layouts/CommonLayout.vue +56 -56
- package/src/lib.js +1 -1
- package/src/mock/extend/index.js +84 -84
- package/src/mock/goods/index.js +108 -108
- package/src/pages/dashboard/workplace/WorkPlace.vue +141 -141
- package/src/pages/system/dictionary/index.vue +44 -44
- package/src/pages/system/monitor/loginInfor/index.vue +37 -37
- package/src/pages/system/monitor/operLog/index.vue +37 -37
- package/src/services/api/cas.js +79 -79
- package/src/store/modules/setting.js +119 -119
- package/src/utils/errorCode.js +6 -6
- package//350/277/201/347/247/273/346/227/245/345/277/227.md +15 -15
- package/.idea/MarsCodeWorkspaceAppSettings.xml +0 -7
- package/.idea/google-java-format.xml +0 -6
- package/.idea/inspectionProfiles/Project_Default.xml +0 -24
- package/.idea/jsLinters/eslint.xml +0 -6
- package/.idea/vue2-client.iml +0 -12
- package/.vscode/settings.json +0 -28
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 前端 Logic 用 HTTP 请求插件。
|
|
3
|
+
* 提供 post、get 方法,均返回 Promise,供表达式执行器在调用处自动等待。
|
|
4
|
+
* 使用项目统一的 request/restTools,走 axios 拦截器与认证。
|
|
5
|
+
*/
|
|
6
|
+
import { post as postRequest, get as getRequest } from '@vue2-client/services/api/restTools'
|
|
7
|
+
|
|
8
|
+
export default class HttpTools {
|
|
9
|
+
static instance
|
|
10
|
+
|
|
11
|
+
constructor () {
|
|
12
|
+
if (HttpTools.instance) {
|
|
13
|
+
return HttpTools.instance
|
|
14
|
+
}
|
|
15
|
+
HttpTools.instance = this
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
static getInstance () {
|
|
19
|
+
if (!HttpTools.instance) {
|
|
20
|
+
HttpTools.instance = new HttpTools()
|
|
21
|
+
}
|
|
22
|
+
return HttpTools.instance
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* POST 请求,返回 Promise<响应体>(即 response.data)
|
|
27
|
+
* @param {string} url 请求地址,如 '/hai-api/suggest-by-complaint' 或 '/api/af-his/logic/xxx'
|
|
28
|
+
* @param {Object} body 请求体(JSON),会作为 request body 发送
|
|
29
|
+
* @param {Object} [config] 可选,axios 配置,如 { dedupe: false }
|
|
30
|
+
* @param {AbortSignal} [config.abortSignal] 可选的 abortSignal(从 plugins 传入)
|
|
31
|
+
* @returns {Promise<*>} 解析为响应体(通常为 JSON 对象)
|
|
32
|
+
*/
|
|
33
|
+
post (url, body, config) {
|
|
34
|
+
const options = { ...config }
|
|
35
|
+
const abortSignal = options.abortSignal
|
|
36
|
+
console.log('[HttpTools.post] abortSignal:', abortSignal, 'aborted:', abortSignal?.aborted)
|
|
37
|
+
|
|
38
|
+
// 如果已经 abort 了,直接抛出错误
|
|
39
|
+
if (abortSignal?.aborted) {
|
|
40
|
+
const error = new Error('请求已被取消')
|
|
41
|
+
error.name = 'AbortError'
|
|
42
|
+
return Promise.reject(error)
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// 从 options 中移除 abortSignal,避免传递给 axios 时出现问题
|
|
46
|
+
delete options.abortSignal
|
|
47
|
+
|
|
48
|
+
if (abortSignal) {
|
|
49
|
+
options.signal = abortSignal
|
|
50
|
+
}
|
|
51
|
+
return postRequest(url, body || {}, options)
|
|
52
|
+
.then(res => res && res.data !== undefined ? res.data : res)
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* GET 请求,返回 Promise<响应体>(即 response.data)
|
|
57
|
+
* @param {string} url 请求地址
|
|
58
|
+
* @param {Object} [params] 查询参数
|
|
59
|
+
* @param {Object} [config] 可选,axios 配置
|
|
60
|
+
* @param {AbortSignal} [config.abortSignal] 可选的 abortSignal(从 plugins 传入)
|
|
61
|
+
* @returns {Promise<*>} 解析为响应体
|
|
62
|
+
*/
|
|
63
|
+
get (url, params, config) {
|
|
64
|
+
const options = { ...config }
|
|
65
|
+
const abortSignal = options.abortSignal
|
|
66
|
+
|
|
67
|
+
delete options.abortSignal
|
|
68
|
+
|
|
69
|
+
if (abortSignal) {
|
|
70
|
+
options.signal = abortSignal
|
|
71
|
+
}
|
|
72
|
+
return getRequest(url, params, options)
|
|
73
|
+
.then(res => res && res.data !== undefined ? res.data : res)
|
|
74
|
+
}
|
|
75
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 前端 Logic 用 HTTP 请求插件。
|
|
3
|
+
* 提供 post、get 方法,均返回 Promise,供表达式执行器在调用处自动等待。
|
|
4
|
+
* 使用项目统一的 request/restTools,走 axios 拦截器与认证。
|
|
5
|
+
*/
|
|
6
|
+
import { post as postRequest, get as getRequest } from '@vue2-client/services/api/restTools'
|
|
7
|
+
|
|
8
|
+
export default class HttpTools {
|
|
9
|
+
static instance
|
|
10
|
+
|
|
11
|
+
constructor () {
|
|
12
|
+
if (HttpTools.instance) {
|
|
13
|
+
return HttpTools.instance
|
|
14
|
+
}
|
|
15
|
+
HttpTools.instance = this
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
static getInstance () {
|
|
19
|
+
if (!HttpTools.instance) {
|
|
20
|
+
HttpTools.instance = new HttpTools()
|
|
21
|
+
}
|
|
22
|
+
return HttpTools.instance
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* POST 请求,返回 Promise<响应体>(即 response.data)
|
|
27
|
+
* @param {string} url 请求地址,如 '/hai-api/suggest-by-complaint' 或 '/api/af-his/logic/xxx'
|
|
28
|
+
* @param {Object} body 请求体(JSON),会作为 request body 发送
|
|
29
|
+
* @param {Object} [config] 可选,axios 配置,如 { dedupe: false }
|
|
30
|
+
* @param {AbortSignal} [config.abortSignal] 可选的 abortSignal(从 plugins 传入)
|
|
31
|
+
* @returns {Promise<*>} 解析为响应体(通常为 JSON 对象)
|
|
32
|
+
*/
|
|
33
|
+
post (url, body, config) {
|
|
34
|
+
const options = { ...config }
|
|
35
|
+
const abortSignal = options.abortSignal
|
|
36
|
+
console.log('[HttpTools.post] abortSignal:', abortSignal, 'aborted:', abortSignal?.aborted)
|
|
37
|
+
|
|
38
|
+
// 如果已经 abort 了,直接抛出错误
|
|
39
|
+
if (abortSignal?.aborted) {
|
|
40
|
+
const error = new Error('请求已被取消')
|
|
41
|
+
error.name = 'AbortError'
|
|
42
|
+
return Promise.reject(error)
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// 从 options 中移除 abortSignal,避免传递给 axios 时出现问题
|
|
46
|
+
delete options.abortSignal
|
|
47
|
+
|
|
48
|
+
if (abortSignal) {
|
|
49
|
+
options.signal = abortSignal
|
|
50
|
+
}
|
|
51
|
+
return postRequest(url, body || {}, options)
|
|
52
|
+
.then(res => res && res.data !== undefined ? res.data : res)
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* GET 请求,返回 Promise<响应体>(即 response.data)
|
|
57
|
+
* @param {string} url 请求地址
|
|
58
|
+
* @param {Object} [params] 查询参数
|
|
59
|
+
* @param {Object} [config] 可选,axios 配置
|
|
60
|
+
* @param {AbortSignal} [config.abortSignal] 可选的 abortSignal(从 plugins 传入)
|
|
61
|
+
* @returns {Promise<*>} 解析为响应体
|
|
62
|
+
*/
|
|
63
|
+
get (url, params, config) {
|
|
64
|
+
const options = { ...config }
|
|
65
|
+
const abortSignal = options.abortSignal
|
|
66
|
+
|
|
67
|
+
delete options.abortSignal
|
|
68
|
+
|
|
69
|
+
if (abortSignal) {
|
|
70
|
+
options.signal = abortSignal
|
|
71
|
+
}
|
|
72
|
+
return getRequest(url, params, options)
|
|
73
|
+
.then(res => res && res.data !== undefined ? res.data : res)
|
|
74
|
+
}
|
|
75
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 前端 Logic 用 HTTP 请求插件。
|
|
3
|
+
* 提供 post、get 方法,均返回 Promise,供表达式执行器在调用处自动等待。
|
|
4
|
+
* 使用项目统一的 request/restTools,走 axios 拦截器与认证。
|
|
5
|
+
*/
|
|
6
|
+
import { post as postRequest, get as getRequest } from '@vue2-client/services/api/restTools'
|
|
7
|
+
import LogicRunner from '../../LogicRunner'
|
|
8
|
+
|
|
9
|
+
export default class HttpTools {
|
|
10
|
+
static instance
|
|
11
|
+
|
|
12
|
+
constructor () {
|
|
13
|
+
if (HttpTools.instance) {
|
|
14
|
+
return HttpTools.instance
|
|
15
|
+
}
|
|
16
|
+
HttpTools.instance = this
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
static getInstance () {
|
|
20
|
+
if (!HttpTools.instance) {
|
|
21
|
+
HttpTools.instance = new HttpTools()
|
|
22
|
+
}
|
|
23
|
+
return HttpTools.instance
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* POST 请求,返回 Promise<响应体>(即 response.data)
|
|
28
|
+
* @param {string} url 请求地址,如 '/hai-api/suggest-by-complaint' 或 '/api/af-his/logic/xxx'
|
|
29
|
+
* @param {Object} body 请求体(JSON),会作为 request body 发送
|
|
30
|
+
* @param {Object} [config] 可选,axios 配置,如 { dedupe: false }
|
|
31
|
+
* @returns {Promise<*>} 解析为响应体(通常为 JSON 对象)
|
|
32
|
+
*/
|
|
33
|
+
post (url, body, config) {
|
|
34
|
+
// 优先使用传入的 abortSignal(来自 plugins.abortSignal)
|
|
35
|
+
// 如果没有传入,则尝试从 LogicRunner 获取当前请求的 abortSignal
|
|
36
|
+
let abortSignal = config?.signal
|
|
37
|
+
if (!abortSignal && config?.abortSignal) {
|
|
38
|
+
abortSignal = config.abortSignal
|
|
39
|
+
}
|
|
40
|
+
if (!abortSignal) {
|
|
41
|
+
abortSignal = LogicRunner.getCurrentAbortSignal()
|
|
42
|
+
}
|
|
43
|
+
console.log('[HttpTools.post] signal 状态:', abortSignal ? `aborted: ${abortSignal.aborted}` : 'null')
|
|
44
|
+
// 禁用去重,确保 abortSignal 正确传递到 HTTP 请求
|
|
45
|
+
const finalConfig = { ...config, signal: abortSignal, dedupe: false }
|
|
46
|
+
return postRequest(url, body || {}, finalConfig)
|
|
47
|
+
.then(res => res && res.data !== undefined ? res.data : res)
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* GET 请求,返回 Promise<响应体>(即 response.data)
|
|
52
|
+
* @param {string} url 请求地址
|
|
53
|
+
* @param {Object} [params] 查询参数
|
|
54
|
+
* @param {Object} [config] 可选,axios 配置
|
|
55
|
+
* @returns {Promise<*>} 解析为响应体
|
|
56
|
+
*/
|
|
57
|
+
get (url, params, config) {
|
|
58
|
+
// 优先使用传入的 abortSignal(来自 plugins.abortSignal)
|
|
59
|
+
// 如果没有传入,则尝试从 LogicRunner 获取当前请求的 abortSignal
|
|
60
|
+
let abortSignal = config?.signal
|
|
61
|
+
if (!abortSignal && config?.abortSignal) {
|
|
62
|
+
abortSignal = config.abortSignal
|
|
63
|
+
}
|
|
64
|
+
if (!abortSignal) {
|
|
65
|
+
abortSignal = LogicRunner.getCurrentAbortSignal()
|
|
66
|
+
}
|
|
67
|
+
// 禁用去重,确保 abortSignal 正确传递到 HTTP 请求
|
|
68
|
+
const finalConfig = { ...config, signal: abortSignal, dedupe: false }
|
|
69
|
+
return getRequest(url, params, finalConfig)
|
|
70
|
+
.then(res => res && res.data !== undefined ? res.data : res)
|
|
71
|
+
}
|
|
72
|
+
}
|
|
@@ -0,0 +1,245 @@
|
|
|
1
|
+
import { getSystemVersion, METHOD, request } from '@vue2-client/utils/request'
|
|
2
|
+
import { ACCESS_TOKEN, V4_ACCESS_TOKEN } from '@vue2-client/store/mutation-types'
|
|
3
|
+
import { showGlobalLoading, hideGlobalLoading } from '@vue2-client/composables/useGlobalLoading'
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* GET请求
|
|
7
|
+
* @param url 请求地址
|
|
8
|
+
* @param parameter 路径参数
|
|
9
|
+
* @returns {Promise<AxiosResponse<T>>}
|
|
10
|
+
*/
|
|
11
|
+
function get (url, parameter) {
|
|
12
|
+
return request(url, METHOD.GET, parameter)
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* POST请求
|
|
17
|
+
* @param url 请求地址
|
|
18
|
+
* @param parameter 请求参数
|
|
19
|
+
* @param config 配置项
|
|
20
|
+
* @param {boolean|string} config.globalLoading - 是否显示全局 Loading,可传入字符串作为提示文字
|
|
21
|
+
* @param {boolean} config.dedupe - 是否启用请求去重(POST 默认开启,设为 false 可关闭)
|
|
22
|
+
* @param {string} config.dedupeStrategy - 去重策略:'reject'(拒绝,默认)或 'reuse'(复用结果)
|
|
23
|
+
* @returns {Promise<AxiosResponse<T>>}
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* // 表单提交 - 默认拒绝重复(防止重复提交)
|
|
27
|
+
* post('/api/save', formData)
|
|
28
|
+
*
|
|
29
|
+
* // 下拉框数据 - 复用结果(多处同时请求共享结果)
|
|
30
|
+
* post('/api/options', params, { dedupe: true, dedupeStrategy: 'reuse' })
|
|
31
|
+
*
|
|
32
|
+
* // 列表查询 - 关闭去重(允许重复查询)
|
|
33
|
+
* post('/api/list', params, { dedupe: false })
|
|
34
|
+
*/
|
|
35
|
+
function post (url, parameter, config = {}) {
|
|
36
|
+
// 兼容 config 为 null 的情况
|
|
37
|
+
const safeConfig = config || {}
|
|
38
|
+
const { globalLoading, ...axiosConfig } = safeConfig
|
|
39
|
+
|
|
40
|
+
// 全局 Loading - 请求开始时显示
|
|
41
|
+
if (globalLoading) {
|
|
42
|
+
showGlobalLoading(globalLoading)
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// 发起请求
|
|
46
|
+
return request(url, METHOD.POST, parameter, axiosConfig)
|
|
47
|
+
.finally(() => {
|
|
48
|
+
// 请求结束时隐藏全局 Loading
|
|
49
|
+
if (globalLoading) {
|
|
50
|
+
hideGlobalLoading()
|
|
51
|
+
}
|
|
52
|
+
})
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* POST请求(按服务名)
|
|
57
|
+
*/
|
|
58
|
+
function postByServiceName (url, parameter, serviceName = process.env.VUE_APP_SYSTEM_NAME, isDev, config = {}) {
|
|
59
|
+
if (url.startsWith('api/') || url.startsWith('/api/')) {
|
|
60
|
+
return request(url, METHOD.POST, parameter, config)
|
|
61
|
+
}
|
|
62
|
+
let apiPre = '/api/'
|
|
63
|
+
if (isDev) {
|
|
64
|
+
apiPre = '/devApi/'
|
|
65
|
+
}
|
|
66
|
+
if (!url.startsWith('/')) {
|
|
67
|
+
url = '/' + url
|
|
68
|
+
}
|
|
69
|
+
url = apiPre + serviceName + url
|
|
70
|
+
return request(url, METHOD.POST, parameter, config)
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* DELETE请求
|
|
75
|
+
* @param url 请求地址
|
|
76
|
+
* @param parameter 请求参数
|
|
77
|
+
* @param config
|
|
78
|
+
* @returns {Promise<AxiosResponse<T>>}
|
|
79
|
+
*/
|
|
80
|
+
function del (url, parameter, config = {}) {
|
|
81
|
+
return request(url, METHOD.DELETE, parameter, config)
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* PUT请求
|
|
86
|
+
* @param url 请求地址
|
|
87
|
+
* @param parameter 请求参数
|
|
88
|
+
* @param config
|
|
89
|
+
* @returns {Promise<AxiosResponse<T>>}
|
|
90
|
+
*/
|
|
91
|
+
function put (url, parameter, config = {}) {
|
|
92
|
+
return request(url, METHOD.PUT, parameter, config)
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* 封装 EventSource 请求函数
|
|
97
|
+
* @param {string} url - 请求地址
|
|
98
|
+
* @param {Object} options - 请求选项(包括 method, headers, body 等)
|
|
99
|
+
* @param {Function} onDataUpdate - 数据更新回调,每次接收到新的数据都会调用
|
|
100
|
+
* @param {Function} onError - 错误处理回调
|
|
101
|
+
* @param {Function} onComplete - 请求完成回调(流正常结束)
|
|
102
|
+
* @returns {Function} - 用于取消请求的函数
|
|
103
|
+
*/
|
|
104
|
+
function startEventStreamPOST (url, params, headers = {}, onDataUpdate, onError, onComplete, serviceName = process.env.VUE_APP_SYSTEM_NAME) {
|
|
105
|
+
return startEventStream(url, params, headers, onDataUpdate, onError, onComplete, serviceName, 'POST')
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* EventSource 请求
|
|
110
|
+
*/
|
|
111
|
+
function startEventStream (url, params, headers = {}, onDataUpdate, onError, onComplete, serviceName = process.env.VUE_APP_SYSTEM_NAME, method = 'GET') {
|
|
112
|
+
let isStopped = false
|
|
113
|
+
let requestCount = 0
|
|
114
|
+
|
|
115
|
+
if (!(url.startsWith('api/') || url.startsWith('/api/') || url.startsWith('http'))) {
|
|
116
|
+
if (!url.startsWith('/')) {
|
|
117
|
+
url = '/' + url
|
|
118
|
+
}
|
|
119
|
+
url = '/api/' + serviceName + url
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
console.log(`[EventStream] 开始新的请求: ${url}`, { params, headers, method })
|
|
123
|
+
|
|
124
|
+
const controller = new AbortController()
|
|
125
|
+
const { signal } = controller
|
|
126
|
+
const token = localStorage.getItem(ACCESS_TOKEN)
|
|
127
|
+
|
|
128
|
+
if (token) {
|
|
129
|
+
const compatible = getSystemVersion()
|
|
130
|
+
if (compatible === 'V4') {
|
|
131
|
+
headers[V4_ACCESS_TOKEN] = token
|
|
132
|
+
} else {
|
|
133
|
+
headers[ACCESS_TOKEN] = token
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
fetch(url, {
|
|
138
|
+
method: method,
|
|
139
|
+
headers: {
|
|
140
|
+
...headers,
|
|
141
|
+
'Content-Type': 'application/json',
|
|
142
|
+
Accept: 'text/event-stream',
|
|
143
|
+
'Cache-Control': 'no-cache',
|
|
144
|
+
Connection: 'keep-alive'
|
|
145
|
+
},
|
|
146
|
+
body: JSON.stringify(params),
|
|
147
|
+
signal
|
|
148
|
+
}).then(response => {
|
|
149
|
+
// console.log('[EventStream] 响应状态:', response.status)
|
|
150
|
+
// console.log('[EventStream] 响应类型:', response.type)
|
|
151
|
+
// console.log('[EventStream] Content-Type:', response.headers.get('content-type'))
|
|
152
|
+
|
|
153
|
+
if (!response.ok) {
|
|
154
|
+
throw new Error(`HTTP error! status: ${response.status}`)
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
requestCount++
|
|
158
|
+
console.log(`[EventStream] 请求已打开 (第${requestCount}次): ${url}`)
|
|
159
|
+
|
|
160
|
+
const reader = response.body.getReader()
|
|
161
|
+
const decoder = new TextDecoder()
|
|
162
|
+
let buffer = ''
|
|
163
|
+
|
|
164
|
+
function processStream () {
|
|
165
|
+
if (isStopped) return
|
|
166
|
+
|
|
167
|
+
reader.read().then(({ done, value }) => {
|
|
168
|
+
if (done) {
|
|
169
|
+
console.log(`[EventStream] 流读取完成: ${url}`)
|
|
170
|
+
// 处理 buffer 中可能残留的最后一行数据
|
|
171
|
+
if (buffer && buffer.trim()) {
|
|
172
|
+
const currentData = buffer.trim()
|
|
173
|
+
if (currentData === '[DONE]') {
|
|
174
|
+
buffer = ''
|
|
175
|
+
} else {
|
|
176
|
+
try {
|
|
177
|
+
const parsedData = JSON.parse(currentData)
|
|
178
|
+
onDataUpdate?.(parsedData, currentEvent === 'sourceInfo' ? 'sourceInfo' : 'data')
|
|
179
|
+
} catch (e) {
|
|
180
|
+
onDataUpdate?.(currentData, currentEvent === 'sourceInfo' ? 'sourceInfo' : 'data')
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
buffer = ''
|
|
185
|
+
if (!isStopped) {
|
|
186
|
+
isStopped = true
|
|
187
|
+
onComplete?.()
|
|
188
|
+
}
|
|
189
|
+
return
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
// console.log('[EventStream] 收到原始数据, length:', value ? value.length : 0)
|
|
193
|
+
const chunk = decoder.decode(value, { stream: true })
|
|
194
|
+
// console.log('[EventStream] 收到原始数据:', chunk)
|
|
195
|
+
buffer += chunk
|
|
196
|
+
|
|
197
|
+
const lines = buffer.split('\n')
|
|
198
|
+
buffer = lines.pop()
|
|
199
|
+
|
|
200
|
+
let currentEvent = null
|
|
201
|
+
|
|
202
|
+
for (const line of lines) {
|
|
203
|
+
if (line.startsWith('event: ')) {
|
|
204
|
+
currentEvent = line.slice(7)
|
|
205
|
+
} else if (line.startsWith('data: ')) {
|
|
206
|
+
const currentData = line.slice(6)
|
|
207
|
+
if (currentData === '[DONE]') continue
|
|
208
|
+
try {
|
|
209
|
+
const parsedData = JSON.parse(currentData)
|
|
210
|
+
const dataType = currentEvent === 'additionalInfo' ? 'additionalInfo' : (currentEvent === 'sourceInfo' ? 'sourceInfo' : 'data')
|
|
211
|
+
onDataUpdate?.(parsedData, dataType)
|
|
212
|
+
} catch (e) {
|
|
213
|
+
onDataUpdate?.(currentData, currentEvent === 'sourceInfo' ? 'sourceInfo' : 'data')
|
|
214
|
+
}
|
|
215
|
+
currentEvent = null
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
processStream()
|
|
220
|
+
}).catch(error => {
|
|
221
|
+
console.error(`[EventStream] 流读取错误: ${url}`, error)
|
|
222
|
+
if (!isStopped) {
|
|
223
|
+
isStopped = true
|
|
224
|
+
onError?.(error)
|
|
225
|
+
}
|
|
226
|
+
})
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
processStream()
|
|
230
|
+
}).catch(error => {
|
|
231
|
+
console.error(`[EventStream] 请求错误: ${url}`, error)
|
|
232
|
+
if (!isStopped) {
|
|
233
|
+
isStopped = true
|
|
234
|
+
onError?.(error)
|
|
235
|
+
}
|
|
236
|
+
})
|
|
237
|
+
|
|
238
|
+
return () => {
|
|
239
|
+
isStopped = true
|
|
240
|
+
controller.abort()
|
|
241
|
+
console.log('连接已关闭')
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
export { get, post, del, put, postByServiceName, startEventStream, startEventStreamPOST }
|
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
import { getSystemVersion, METHOD, request } from '@vue2-client/utils/request'
|
|
2
|
+
import { ACCESS_TOKEN, V4_ACCESS_TOKEN } from '@vue2-client/store/mutation-types'
|
|
3
|
+
import { showGlobalLoading, hideGlobalLoading } from '@vue2-client/composables/useGlobalLoading'
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* GET请求
|
|
7
|
+
* @param url 请求地址
|
|
8
|
+
* @param parameter 路径参数
|
|
9
|
+
* @returns {Promise<AxiosResponse<T>>}
|
|
10
|
+
*/
|
|
11
|
+
function get (url, parameter) {
|
|
12
|
+
return request(url, METHOD.GET, parameter)
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* POST请求
|
|
17
|
+
* @param url 请求地址
|
|
18
|
+
* @param parameter 请求参数
|
|
19
|
+
* @param config 配置项
|
|
20
|
+
* @param {boolean|string} config.globalLoading - 是否显示全局 Loading,可传入字符串作为提示文字
|
|
21
|
+
* @param {boolean} config.dedupe - 是否启用请求去重(POST 默认开启,设为 false 可关闭)
|
|
22
|
+
* @param {string} config.dedupeStrategy - 去重策略:'reject'(拒绝,默认)或 'reuse'(复用结果)
|
|
23
|
+
* @returns {Promise<AxiosResponse<T>>}
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* // 表单提交 - 默认拒绝重复(防止重复提交)
|
|
27
|
+
* post('/api/save', formData)
|
|
28
|
+
*
|
|
29
|
+
* // 下拉框数据 - 复用结果(多处同时请求共享结果)
|
|
30
|
+
* post('/api/options', params, { dedupe: true, dedupeStrategy: 'reuse' })
|
|
31
|
+
*
|
|
32
|
+
* // 列表查询 - 关闭去重(允许重复查询)
|
|
33
|
+
* post('/api/list', params, { dedupe: false })
|
|
34
|
+
*/
|
|
35
|
+
function post (url, parameter, config = {}) {
|
|
36
|
+
// 兼容 config 为 null 的情况
|
|
37
|
+
const safeConfig = config || {}
|
|
38
|
+
const { globalLoading, ...axiosConfig } = safeConfig
|
|
39
|
+
|
|
40
|
+
// 全局 Loading - 请求开始时显示
|
|
41
|
+
if (globalLoading) {
|
|
42
|
+
showGlobalLoading(globalLoading)
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// 发起请求
|
|
46
|
+
return request(url, METHOD.POST, parameter, axiosConfig)
|
|
47
|
+
.finally(() => {
|
|
48
|
+
// 请求结束时隐藏全局 Loading
|
|
49
|
+
if (globalLoading) {
|
|
50
|
+
hideGlobalLoading()
|
|
51
|
+
}
|
|
52
|
+
})
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* POST请求(按服务名)
|
|
57
|
+
*/
|
|
58
|
+
function postByServiceName (url, parameter, serviceName = process.env.VUE_APP_SYSTEM_NAME, isDev, config = {}) {
|
|
59
|
+
if (url.startsWith('api/') || url.startsWith('/api/')) {
|
|
60
|
+
return request(url, METHOD.POST, parameter, config)
|
|
61
|
+
}
|
|
62
|
+
let apiPre = '/api/'
|
|
63
|
+
if (isDev) {
|
|
64
|
+
apiPre = '/devApi/'
|
|
65
|
+
}
|
|
66
|
+
if (!url.startsWith('/')) {
|
|
67
|
+
url = '/' + url
|
|
68
|
+
}
|
|
69
|
+
url = apiPre + serviceName + url
|
|
70
|
+
return request(url, METHOD.POST, parameter, config)
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* DELETE请求
|
|
75
|
+
* @param url 请求地址
|
|
76
|
+
* @param parameter 请求参数
|
|
77
|
+
* @param config
|
|
78
|
+
* @returns {Promise<AxiosResponse<T>>}
|
|
79
|
+
*/
|
|
80
|
+
function del (url, parameter, config = {}) {
|
|
81
|
+
return request(url, METHOD.DELETE, parameter, config)
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* PUT请求
|
|
86
|
+
* @param url 请求地址
|
|
87
|
+
* @param parameter 请求参数
|
|
88
|
+
* @param config
|
|
89
|
+
* @returns {Promise<AxiosResponse<T>>}
|
|
90
|
+
*/
|
|
91
|
+
function put (url, parameter, config = {}) {
|
|
92
|
+
return request(url, METHOD.PUT, parameter, config)
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* 封装 EventSource 请求函数
|
|
97
|
+
* @param {string} url - 请求地址
|
|
98
|
+
* @param {Object} options - 请求选项(包括 method, headers, body 等)
|
|
99
|
+
* @param {Function} onDataUpdate - 数据更新回调,每次接收到新的数据都会调用
|
|
100
|
+
* @param {Function} onError - 错误处理回调
|
|
101
|
+
* @param {Function} onComplete - 请求完成回调(流正常结束)
|
|
102
|
+
* @returns {Function} - 用于取消请求的函数
|
|
103
|
+
*/
|
|
104
|
+
function startEventStreamPOST (url, params, headers = {}, onDataUpdate, onError, onComplete, serviceName = process.env.VUE_APP_SYSTEM_NAME) {
|
|
105
|
+
return startEventStream(url, params, headers, onDataUpdate, onError, onComplete, serviceName, 'POST')
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* EventSource 请求
|
|
110
|
+
*/
|
|
111
|
+
function startEventStream (url, params, headers = {}, onDataUpdate, onError, onComplete, serviceName = process.env.VUE_APP_SYSTEM_NAME, method = 'GET') {
|
|
112
|
+
let isStopped = false
|
|
113
|
+
let requestCount = 0
|
|
114
|
+
|
|
115
|
+
if (!(url.startsWith('api/') || url.startsWith('/api/') || url.startsWith('http'))) {
|
|
116
|
+
if (!url.startsWith('/')) {
|
|
117
|
+
url = '/' + url
|
|
118
|
+
}
|
|
119
|
+
url = '/api/' + serviceName + url
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
console.log(`[EventStream] 开始新的请求: ${url}`, { params, headers, method })
|
|
123
|
+
|
|
124
|
+
const controller = new AbortController()
|
|
125
|
+
const { signal } = controller
|
|
126
|
+
const token = localStorage.getItem(ACCESS_TOKEN)
|
|
127
|
+
|
|
128
|
+
if (token) {
|
|
129
|
+
const compatible = getSystemVersion()
|
|
130
|
+
if (compatible === 'V4') {
|
|
131
|
+
headers[V4_ACCESS_TOKEN] = token
|
|
132
|
+
} else {
|
|
133
|
+
headers[ACCESS_TOKEN] = token
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
fetch(url, {
|
|
138
|
+
method: method,
|
|
139
|
+
headers: {
|
|
140
|
+
...headers,
|
|
141
|
+
'Content-Type': 'application/json',
|
|
142
|
+
Accept: 'text/event-stream',
|
|
143
|
+
'Cache-Control': 'no-cache',
|
|
144
|
+
Connection: 'keep-alive'
|
|
145
|
+
},
|
|
146
|
+
body: JSON.stringify(params),
|
|
147
|
+
signal
|
|
148
|
+
}).then(response => {
|
|
149
|
+
// console.log('[EventStream] 响应状态:', response.status)
|
|
150
|
+
// console.log('[EventStream] 响应类型:', response.type)
|
|
151
|
+
// console.log('[EventStream] Content-Type:', response.headers.get('content-type'))
|
|
152
|
+
|
|
153
|
+
if (!response.ok) {
|
|
154
|
+
throw new Error(`HTTP error! status: ${response.status}`)
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
requestCount++
|
|
158
|
+
console.log(`[EventStream] 请求已打开 (第${requestCount}次): ${url}`)
|
|
159
|
+
|
|
160
|
+
const reader = response.body.getReader()
|
|
161
|
+
const decoder = new TextDecoder()
|
|
162
|
+
let buffer = ''
|
|
163
|
+
|
|
164
|
+
function processStream () {
|
|
165
|
+
if (isStopped) return
|
|
166
|
+
|
|
167
|
+
reader.read().then(({ done, value }) => {
|
|
168
|
+
if (done) {
|
|
169
|
+
console.log(`[EventStream] 流读取完成: ${url}`)
|
|
170
|
+
if (!isStopped) {
|
|
171
|
+
isStopped = true
|
|
172
|
+
onComplete?.()
|
|
173
|
+
}
|
|
174
|
+
return
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
// console.log('[EventStream] 收到原始数据, length:', value ? value.length : 0)
|
|
178
|
+
const chunk = decoder.decode(value, { stream: true })
|
|
179
|
+
// console.log('[EventStream] 收到原始数据:', chunk)
|
|
180
|
+
buffer += chunk
|
|
181
|
+
|
|
182
|
+
const lines = buffer.split('\n')
|
|
183
|
+
buffer = lines.pop()
|
|
184
|
+
|
|
185
|
+
let currentEvent = null
|
|
186
|
+
|
|
187
|
+
for (const line of lines) {
|
|
188
|
+
if (line.startsWith('event: ')) {
|
|
189
|
+
currentEvent = line.slice(7)
|
|
190
|
+
} else if (line.startsWith('data: ')) {
|
|
191
|
+
const currentData = line.slice(6)
|
|
192
|
+
if (currentData === '[DONE]') continue
|
|
193
|
+
try {
|
|
194
|
+
const parsedData = JSON.parse(currentData)
|
|
195
|
+
const dataType = currentEvent === 'additionalInfo' ? 'additionalInfo' : (currentEvent === 'sourceInfo' ? 'sourceInfo' : 'data')
|
|
196
|
+
onDataUpdate?.(parsedData, dataType)
|
|
197
|
+
} catch (e) {
|
|
198
|
+
onDataUpdate?.(currentData, currentEvent === 'sourceInfo' ? 'sourceInfo' : 'data')
|
|
199
|
+
}
|
|
200
|
+
currentEvent = null
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
processStream()
|
|
205
|
+
}).catch(error => {
|
|
206
|
+
console.error(`[EventStream] 流读取错误: ${url}`, error)
|
|
207
|
+
if (!isStopped) {
|
|
208
|
+
isStopped = true
|
|
209
|
+
onError?.(error)
|
|
210
|
+
}
|
|
211
|
+
})
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
processStream()
|
|
215
|
+
}).catch(error => {
|
|
216
|
+
console.error(`[EventStream] 请求错误: ${url}`, error)
|
|
217
|
+
if (!isStopped) {
|
|
218
|
+
isStopped = true
|
|
219
|
+
onError?.(error)
|
|
220
|
+
}
|
|
221
|
+
})
|
|
222
|
+
|
|
223
|
+
return () => {
|
|
224
|
+
isStopped = true
|
|
225
|
+
controller.abort()
|
|
226
|
+
console.log('连接已关闭')
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
export { get, post, del, put, postByServiceName, startEventStream, startEventStreamPOST }
|