vue2-client 1.22.19 → 1.22.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 (88) hide show
  1. package/.env.his +19 -19
  2. package/.env.message +19 -19
  3. package/.history/.eslintrc_20260521171150.js +74 -0
  4. package/.history/.eslintrc_20260521171213.js +74 -0
  5. package/.history/src/base-client/components/common/HIS/HAddNativeForm/HAddNativeForm_20260601154443.vue +726 -0
  6. package/.history/src/base-client/components/common/HIS/HAddNativeForm/HAddNativeForm_20260601154700.vue +478 -0
  7. package/.history/src/base-client/components/common/HIS/HButtons/HButtons_20260512175435.vue +706 -0
  8. package/.history/src/base-client/components/common/HIS/HButtons/HButtons_20260512175450.vue +694 -0
  9. package/.history/src/base-client/components/common/HIS/HButtons/HButtons_20260611152602.vue +755 -0
  10. package/.history/src/base-client/components/common/HIS/HForm/HForm_20260513145941.vue +524 -0
  11. package/.history/src/base-client/components/common/HIS/HForm/HForm_20260513153133.vue +731 -0
  12. package/.history/src/base-client/components/common/HIS/HForm/HForm_20260513160316.vue +525 -0
  13. package/.history/src/base-client/components/common/HIS/HForm/HForm_20260601144150.vue +1046 -0
  14. package/.history/src/base-client/components/common/HIS/HFormTable/HFormTable_20260310142713.vue +512 -0
  15. package/.history/src/base-client/components/common/HIS/HFormTable/HFormTable_20260310145118.vue +511 -0
  16. package/.history/src/base-client/components/common/HIS/HFormTable/HFormTable_20260311094834.vue +696 -0
  17. package/.history/src/base-client/components/common/HIS/HFormTable/HFormTable_20260320143028.vue +693 -0
  18. package/.history/src/base-client/components/common/HIS/HFormTable/HFormTable_20260409101450.vue +677 -0
  19. package/.history/src/base-client/components/common/HIS/HTab/HTab_20260625173703.vue +767 -0
  20. package/.history/src/base-client/components/common/HIS/HTab/HTab_20260626112425.vue +803 -0
  21. package/.history/src/base-client/components/common/XAddNativeForm/XAddNativeForm_20260513140637.vue +1455 -0
  22. package/.history/src/base-client/components/common/XAddNativeForm/XAddNativeForm_20260513140935.vue +1441 -0
  23. package/.history/src/base-client/components/common/XAddNativeForm/XAddNativeForm_20260513150818.vue +1441 -0
  24. package/.history/src/base-client/components/common/XAddNativeForm/XAddNativeForm_20260513153119.vue +1442 -0
  25. package/.history/src/base-client/components/common/XAddNativeForm/XAddNativeForm_20260513153126.vue +1486 -0
  26. package/.history/src/base-client/components/common/XForm/XFormItem_20260513140854.vue +1607 -0
  27. package/.history/src/base-client/components/common/XMarkdownViewer/XMarkdownViewer_20260519140403.vue +643 -0
  28. package/.history/src/base-client/components/common/XMarkdownViewer/XMarkdownViewer_20260519140829.vue +628 -0
  29. package/.history/src/base-client/components/common/XMarkdownViewer/demo_20260519142824.vue +104 -0
  30. package/.history/src/base-client/components/common/XMarkdownViewer/demo_20260519143155.vue +102 -0
  31. package/.history/src/base-client/components/common/XReportGrid/XReport_20260309171231.vue +1241 -0
  32. package/.history/src/base-client/components/common/XReportGrid/XReport_20260309171441.vue +1223 -0
  33. package/.history/src/base-client/components/his/HAi/HAi_20260612174826.vue +472 -0
  34. package/.history/src/base-client/components/his/HAi/HAi_20260612175839.vue +538 -0
  35. package/.history/src/base-client/components/his/HAi/HAi_20260615103331.vue +650 -0
  36. package/.history/src/base-client/components/his/HAi/HAi_20260618140214.vue +1396 -0
  37. package/.history/src/base-client/components/his/HAi/HAi_20260618140556.vue +1396 -0
  38. package/.history/src/base-client/components/his/XHDescriptions/XHDescriptions_20260424134504.vue +1469 -0
  39. package/.history/src/base-client/components/his/XSidebar/XSidebar_20260610171133.vue +788 -0
  40. package/.history/src/base-client/components/his/XSidebar/XSidebar_20260610171151.vue +780 -0
  41. package/.history/src/base-client/components/his/XTransfer/XTransfer_20260511170841.vue +585 -0
  42. package/.history/src/base-client/components/his/XTransfer/XTransfer_20260511171138.vue +787 -0
  43. package/.history/src/base-client/components/his/XTransfer/XTransfer_20260512141830.vue +739 -0
  44. package/.history/src/components/STable/index_20260409155138.js +806 -0
  45. package/.history/src/components/STable/index_20260409155218.js +814 -0
  46. package/.history/src/expression/core/Expression_20260305164427.js +1371 -0
  47. package/.history/src/expression/core/Expression_20260305170258.js +1358 -0
  48. package/.history/src/expression/core/Program_20260305111830.js +944 -0
  49. package/.history/src/expression/core/Program_20260305112041.js +931 -0
  50. package/.history/src/logic/LogicRunner_20260304154306.js +170 -0
  51. package/.history/src/logic/LogicRunner_20260304155553.js +112 -0
  52. package/.history/src/logic/LogicRunner_20260305105834.js +112 -0
  53. package/.history/src/logic/LogicRunner_20260305112718.js +129 -0
  54. package/.history/src/logic/LogicRunner_20260305182436.js +133 -0
  55. package/.history/src/logic/LogicRunner_20260306151301.js +213 -0
  56. package/.history/src/logic/LogicRunner_20260306152419.js +213 -0
  57. package/.history/src/logic/plugins/common/DateTools_20260305154159.js +61 -0
  58. package/.history/src/logic/plugins/common/DateTools_20260305154217.js +44 -0
  59. package/.history/src/logic/plugins/common/DateTools_20260305161014.js +44 -0
  60. package/.history/src/logic/plugins/common/HttpTools_20260305164352.js +80 -0
  61. package/.history/src/logic/plugins/common/HttpTools_20260305170258.js +75 -0
  62. package/.history/src/logic/plugins/common/HttpTools_20260305171634.js +75 -0
  63. package/.history/src/logic/plugins/common/HttpTools_20260306152419.js +72 -0
  64. package/.history/src/services/api/restTools_20260427142149.js +245 -0
  65. package/.history/src/services/api/restTools_20260427142853.js +230 -0
  66. package/.history/src/services/api/restTools_20260519135558.js +230 -0
  67. package/.history/src/services/api/restTools_20260519140825.js +230 -0
  68. package/.history/src/services/api/restTools_20260519151223.js +230 -0
  69. package/.history/src/utils/indexedDB_20260306150918.js +593 -0
  70. package/.history/src/utils/indexedDB_20260306151301.js +586 -0
  71. package/.idea/af-vue2-client.iml +4 -7
  72. package/.idea/codeStyles/Project.xml +62 -0
  73. package/.idea/codeStyles/codeStyleConfig.xml +5 -0
  74. package/.idea/misc.xml +6 -0
  75. package/CHANGELOG.md +837 -837
  76. package/package.json +117 -117
  77. package/preview-input-box.html +180 -0
  78. package/src/base-client/components/common/HIS/HForm/HForm.vue +1186 -1186
  79. package/src/base-client/components/common/HIS/HTab/HTab.vue +790 -757
  80. package/src/base-client/components/common/ImagePreviewModal/index.js +3 -3
  81. package/src/base-client/components/common/XMarkdownViewer/demo.vue +102 -102
  82. package/src/base-client/components/his/HAi/HAi.vue +159 -30
  83. package/src/base-client/components/his/XTransfer/index.md +327 -327
  84. package/src/components/MarkdownEditor/demo.vue +300 -300
  85. package/src/components/MarkdownEditor/index.vue +590 -590
  86. package/src/router/async/router.map.js +141 -141
  87. package/src/services/api/restTools.js +1 -1
  88. package/.idea/inspectionProfiles/Project_Default.xml +0 -6
@@ -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 }
@@ -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 }
@@ -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 }