vue2-client 1.22.3 → 1.22.4
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/.env.his +19 -19
- package/.idea/.name +1 -0
- package/.idea/MarsCodeWorkspaceAppSettings.xml +8 -0
- package/.idea/deployment.xml +14 -0
- package/.idea/gradle.xml +7 -0
- package/.idea/inspectionProfiles/Project_Default.xml +6 -0
- package/.idea/libraries/contour_plot.xml +9 -0
- package/.idea/material_theme_project_new.xml +18 -0
- package/.idea/misc.xml +87 -5
- package/package.json +1 -1
- package/src/base-client/components/common/HIS/HForm/HForm.vue +1186 -1186
- package/src/base-client/components/common/XMarkdownViewer/demo.vue +102 -102
- package/src/base-client/components/his/HAi/HAi.vue +1177 -1177
- package/src/base-client/components/his/XTransfer/index.md +327 -327
- package/src/base-client/plugins/GetLoginInfoService.js +4 -4
- package/src/utils/login.js +11 -11
- package/.history/.eslintrc_20260521171150.js +0 -74
- package/.history/.eslintrc_20260521171213.js +0 -74
- package/.history/src/base-client/components/common/HIS/HAddNativeForm/HAddNativeForm_20260601154443.vue +0 -726
- package/.history/src/base-client/components/common/HIS/HAddNativeForm/HAddNativeForm_20260601154700.vue +0 -478
- package/.history/src/base-client/components/common/HIS/HButtons/HButtons_20260512175435.vue +0 -706
- package/.history/src/base-client/components/common/HIS/HButtons/HButtons_20260512175450.vue +0 -694
- package/.history/src/base-client/components/common/HIS/HButtons/HButtons_20260611152602.vue +0 -755
- package/.history/src/base-client/components/common/HIS/HForm/HForm_20260513145941.vue +0 -524
- package/.history/src/base-client/components/common/HIS/HForm/HForm_20260513153133.vue +0 -731
- package/.history/src/base-client/components/common/HIS/HForm/HForm_20260513160316.vue +0 -525
- package/.history/src/base-client/components/common/HIS/HForm/HForm_20260601144150.vue +0 -1046
- package/.history/src/base-client/components/common/HIS/HFormTable/HFormTable_20260310142713.vue +0 -512
- package/.history/src/base-client/components/common/HIS/HFormTable/HFormTable_20260310145118.vue +0 -511
- package/.history/src/base-client/components/common/HIS/HFormTable/HFormTable_20260311094834.vue +0 -696
- package/.history/src/base-client/components/common/HIS/HFormTable/HFormTable_20260320143028.vue +0 -693
- package/.history/src/base-client/components/common/HIS/HFormTable/HFormTable_20260409101450.vue +0 -677
- package/.history/src/base-client/components/common/HIS/HTab/HTab_20260508164645.vue +0 -758
- package/.history/src/base-client/components/common/HIS/HTab/HTab_20260508164714.vue +0 -693
- package/.history/src/base-client/components/common/HIS/HTab/HTab_20260508171651.vue +0 -716
- package/.history/src/base-client/components/common/HIS/HTab/HTab_20260509133717.vue +0 -695
- package/.history/src/base-client/components/common/HIS/HTab/HTab_20260509171115.vue +0 -664
- package/.history/src/base-client/components/common/XAddNativeForm/XAddNativeForm_20260513140637.vue +0 -1455
- package/.history/src/base-client/components/common/XAddNativeForm/XAddNativeForm_20260513140935.vue +0 -1441
- package/.history/src/base-client/components/common/XAddNativeForm/XAddNativeForm_20260513150818.vue +0 -1441
- package/.history/src/base-client/components/common/XAddNativeForm/XAddNativeForm_20260513153119.vue +0 -1442
- package/.history/src/base-client/components/common/XAddNativeForm/XAddNativeForm_20260513153126.vue +0 -1486
- package/.history/src/base-client/components/common/XForm/XFormItem_20260513140854.vue +0 -1607
- package/.history/src/base-client/components/common/XMarkdownViewer/XMarkdownViewer_20260519140403.vue +0 -643
- package/.history/src/base-client/components/common/XMarkdownViewer/XMarkdownViewer_20260519140829.vue +0 -628
- package/.history/src/base-client/components/common/XMarkdownViewer/demo_20260519142824.vue +0 -104
- package/.history/src/base-client/components/common/XMarkdownViewer/demo_20260519143155.vue +0 -102
- package/.history/src/base-client/components/common/XReportGrid/XReport_20260309171231.vue +0 -1241
- package/.history/src/base-client/components/common/XReportGrid/XReport_20260309171441.vue +0 -1223
- package/.history/src/base-client/components/his/HAi/HAi_20260612174826.vue +0 -472
- package/.history/src/base-client/components/his/HAi/HAi_20260612175839.vue +0 -538
- package/.history/src/base-client/components/his/HAi/HAi_20260615103331.vue +0 -650
- package/.history/src/base-client/components/his/XHDescriptions/XHDescriptions_20260424134504.vue +0 -1469
- package/.history/src/base-client/components/his/XSidebar/XSidebar_20260610171133.vue +0 -788
- package/.history/src/base-client/components/his/XSidebar/XSidebar_20260610171151.vue +0 -780
- package/.history/src/base-client/components/his/XTransfer/XTransfer_20260511170841.vue +0 -585
- package/.history/src/base-client/components/his/XTransfer/XTransfer_20260511171138.vue +0 -787
- package/.history/src/base-client/components/his/XTransfer/XTransfer_20260512141830.vue +0 -739
- package/.history/src/components/STable/index_20260409155138.js +0 -806
- package/.history/src/components/STable/index_20260409155218.js +0 -814
- package/.history/src/expression/core/Expression_20260305164427.js +0 -1371
- package/.history/src/expression/core/Expression_20260305170258.js +0 -1358
- package/.history/src/expression/core/Program_20260305111830.js +0 -944
- package/.history/src/expression/core/Program_20260305112041.js +0 -931
- package/.history/src/logic/LogicRunner_20260304154306.js +0 -170
- package/.history/src/logic/LogicRunner_20260304155553.js +0 -112
- package/.history/src/logic/LogicRunner_20260305105834.js +0 -112
- package/.history/src/logic/LogicRunner_20260305112718.js +0 -129
- package/.history/src/logic/LogicRunner_20260305182436.js +0 -133
- package/.history/src/logic/LogicRunner_20260306151301.js +0 -213
- package/.history/src/logic/LogicRunner_20260306152419.js +0 -213
- package/.history/src/logic/plugins/common/DateTools_20260305154159.js +0 -61
- package/.history/src/logic/plugins/common/DateTools_20260305154217.js +0 -44
- package/.history/src/logic/plugins/common/DateTools_20260305161014.js +0 -44
- package/.history/src/logic/plugins/common/HttpTools_20260305164352.js +0 -80
- package/.history/src/logic/plugins/common/HttpTools_20260305170258.js +0 -75
- package/.history/src/logic/plugins/common/HttpTools_20260305171634.js +0 -75
- package/.history/src/logic/plugins/common/HttpTools_20260306152419.js +0 -72
- package/.history/src/services/api/restTools_20260427142149.js +0 -245
- package/.history/src/services/api/restTools_20260427142853.js +0 -230
- package/.history/src/services/api/restTools_20260519135558.js +0 -230
- package/.history/src/services/api/restTools_20260519140825.js +0 -230
- package/.history/src/services/api/restTools_20260519151223.js +0 -230
- package/.history/src/utils/indexedDB_20260306150918.js +0 -593
- package/.history/src/utils/indexedDB_20260306151301.js +0 -586
- package/.idea/codeStyles/Project.xml +0 -62
- package/.idea/codeStyles/codeStyleConfig.xml +0 -5
- package/preview-input-box.html +0 -180
|
@@ -1,230 +0,0 @@
|
|
|
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 }
|
|
@@ -1,230 +0,0 @@
|
|
|
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 }
|
|
@@ -1,230 +0,0 @@
|
|
|
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 }
|