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,628 +0,0 @@
|
|
|
1
|
-
<template>
|
|
2
|
-
<div class="x-markdown-viewer-wrapper">
|
|
3
|
-
<div
|
|
4
|
-
v-if="showControlButton"
|
|
5
|
-
class="stream-control-bar"
|
|
6
|
-
>
|
|
7
|
-
<a-button
|
|
8
|
-
class="stream-btn"
|
|
9
|
-
:class="buttonClass"
|
|
10
|
-
@click="handleButtonClick"
|
|
11
|
-
>
|
|
12
|
-
<a-icon :type="getButtonIcon()" />
|
|
13
|
-
<span class="btn-text">{{ getButtonText() }}</span>
|
|
14
|
-
</a-button>
|
|
15
|
-
</div>
|
|
16
|
-
<div ref="containerRef" class="x-markdown-viewer">
|
|
17
|
-
<template v-for="(seg, idx) in segments">
|
|
18
|
-
<div
|
|
19
|
-
v-if="seg.type === 'md'"
|
|
20
|
-
:key="`md-${idx}`"
|
|
21
|
-
class="markdown-body"
|
|
22
|
-
v-html="renderMd(seg.content)"
|
|
23
|
-
/>
|
|
24
|
-
<XList
|
|
25
|
-
v-else-if="seg.type === 'component' && seg.componentType === 'x-list'"
|
|
26
|
-
:key="`xlist-${idx}`"
|
|
27
|
-
:queryParamsName="seg.configName"
|
|
28
|
-
:initialData="seg.data"
|
|
29
|
-
/>
|
|
30
|
-
</template>
|
|
31
|
-
</div>
|
|
32
|
-
</div>
|
|
33
|
-
</template>
|
|
34
|
-
|
|
35
|
-
<script>
|
|
36
|
-
import { marked } from 'marked'
|
|
37
|
-
import { parseMarkdownWithJsonBlocks } from './parseMarkdownWithJsonBlocks'
|
|
38
|
-
import XList from '@vue2-client/base-client/components/his/XList/XList.vue'
|
|
39
|
-
import { startEventStreamPOST } from '@vue2-client/services/api/restTools'
|
|
40
|
-
import { getConfigByName } from '@vue2-client/services/api/common'
|
|
41
|
-
import moment from 'moment/moment'
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* HTML 转义,防止 XSS
|
|
45
|
-
*/
|
|
46
|
-
function escapeHtml (s) {
|
|
47
|
-
if (s == null) return ''
|
|
48
|
-
return String(s)
|
|
49
|
-
.replace(/&/g, '&')
|
|
50
|
-
.replace(/</g, '<')
|
|
51
|
-
.replace(/>/g, '>')
|
|
52
|
-
.replace(/"/g, '"')
|
|
53
|
-
.replace(/'/g, ''')
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
* 标准化 markdown 输入,支持多种格式
|
|
58
|
-
*/
|
|
59
|
-
function normalizeMdInput (v, onWarn) {
|
|
60
|
-
if (typeof v === 'string') return v === '[object Object]' ? '' : v
|
|
61
|
-
if (v && typeof v === 'object') {
|
|
62
|
-
if (typeof v.default === 'string') return v.default
|
|
63
|
-
if (typeof v.content === 'string') return v.content
|
|
64
|
-
if (typeof onWarn === 'function') onWarn(v)
|
|
65
|
-
return ''
|
|
66
|
-
}
|
|
67
|
-
const s = v == null ? '' : String(v)
|
|
68
|
-
return s === '[object Object]' ? '' : s
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
/**
|
|
72
|
-
* 判断是否为 Blob/File 对象
|
|
73
|
-
*/
|
|
74
|
-
function isBlobLike (v) {
|
|
75
|
-
if (!v || typeof v !== 'object') return false
|
|
76
|
-
return typeof v.size === 'number' && typeof v.type === 'string' && (typeof v.text === 'function' || typeof FileReader !== 'undefined')
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
/**
|
|
80
|
-
* 将 Blob 读取为文本
|
|
81
|
-
*/
|
|
82
|
-
function readBlobAsText (blob) {
|
|
83
|
-
if (blob && typeof blob.text === 'function') return blob.text()
|
|
84
|
-
return new Promise((resolve, reject) => {
|
|
85
|
-
try {
|
|
86
|
-
const reader = new FileReader()
|
|
87
|
-
reader.onload = () => resolve(reader.result == null ? '' : String(reader.result))
|
|
88
|
-
reader.onerror = () => reject(reader.error || new Error('read file error'))
|
|
89
|
-
reader.readAsText(blob)
|
|
90
|
-
} catch (e) {
|
|
91
|
-
reject(e)
|
|
92
|
-
}
|
|
93
|
-
})
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
export default {
|
|
97
|
-
name: 'XMarkdownViewer',
|
|
98
|
-
components: { XList },
|
|
99
|
-
props: {
|
|
100
|
-
/**
|
|
101
|
-
* Markdown 文本(推荐使用 markdown;value 用于兼容 v-model/旧写法)
|
|
102
|
-
*/
|
|
103
|
-
markdown: {
|
|
104
|
-
type: [String, Object],
|
|
105
|
-
default: ''
|
|
106
|
-
},
|
|
107
|
-
value: {
|
|
108
|
-
type: [String, Object],
|
|
109
|
-
default: ''
|
|
110
|
-
},
|
|
111
|
-
/**
|
|
112
|
-
* 是否允许 Markdown 中的原始 HTML 被解析渲染
|
|
113
|
-
*/
|
|
114
|
-
allowHtml: {
|
|
115
|
-
type: Boolean,
|
|
116
|
-
default: false
|
|
117
|
-
},
|
|
118
|
-
/**
|
|
119
|
-
* marked 解析参数覆盖
|
|
120
|
-
*/
|
|
121
|
-
markedOptions: {
|
|
122
|
-
type: Object,
|
|
123
|
-
default: () => ({})
|
|
124
|
-
},
|
|
125
|
-
/**
|
|
126
|
-
* 纯数组 JSON 代码块时默认的 x-list 配置名
|
|
127
|
-
*/
|
|
128
|
-
defaultXListConfigName: {
|
|
129
|
-
type: String,
|
|
130
|
-
default: ''
|
|
131
|
-
},
|
|
132
|
-
/**
|
|
133
|
-
* 是否显示控制按钮
|
|
134
|
-
*/
|
|
135
|
-
showControlButton: {
|
|
136
|
-
type: Boolean,
|
|
137
|
-
default: true
|
|
138
|
-
},
|
|
139
|
-
/**
|
|
140
|
-
* 按钮配置名称(用于从配置中心获取按钮文字等配置)
|
|
141
|
-
*/
|
|
142
|
-
queryParamsName: {
|
|
143
|
-
type: String,
|
|
144
|
-
default: ''
|
|
145
|
-
},
|
|
146
|
-
/**
|
|
147
|
-
* 服务名
|
|
148
|
-
*/
|
|
149
|
-
serviceName: {
|
|
150
|
-
type: String,
|
|
151
|
-
default: process.env.VUE_APP_SYSTEM_NAME
|
|
152
|
-
}
|
|
153
|
-
},
|
|
154
|
-
emits: {
|
|
155
|
-
'start-stream': null,
|
|
156
|
-
'stop-stream': null,
|
|
157
|
-
'configEnd': null
|
|
158
|
-
},
|
|
159
|
-
data () {
|
|
160
|
-
return {
|
|
161
|
-
/**
|
|
162
|
-
* 通过实例方法 receiveMarkdown() 写入的 md 内容
|
|
163
|
-
*/
|
|
164
|
-
internalMarkdown: null,
|
|
165
|
-
/**
|
|
166
|
-
* 容器 DOM 引用
|
|
167
|
-
*/
|
|
168
|
-
containerRef: null,
|
|
169
|
-
/**
|
|
170
|
-
* 是否正在流式输出
|
|
171
|
-
*/
|
|
172
|
-
isStreaming: false,
|
|
173
|
-
/**
|
|
174
|
-
* 流是否已结束
|
|
175
|
-
*/
|
|
176
|
-
streamEnded: false,
|
|
177
|
-
/**
|
|
178
|
-
* 按钮配置(从配置中心加载,无默认值)
|
|
179
|
-
*/
|
|
180
|
-
buttonConfig: {},
|
|
181
|
-
/**
|
|
182
|
-
* 环境变量
|
|
183
|
-
*/
|
|
184
|
-
env: process.env.NODE_ENV || 'production',
|
|
185
|
-
/**
|
|
186
|
-
* 是否始终显示按钮
|
|
187
|
-
*/
|
|
188
|
-
showButtonInitially: true,
|
|
189
|
-
/**
|
|
190
|
-
* 配置是否已加载完成
|
|
191
|
-
*/
|
|
192
|
-
// eslint-disable-next-line vue/no-reserved-keys
|
|
193
|
-
configEndEmitted: false,
|
|
194
|
-
/**
|
|
195
|
-
* 配置结束 Promise
|
|
196
|
-
*/
|
|
197
|
-
// eslint-disable-next-line vue/no-reserved-keys
|
|
198
|
-
configEndPromise: null,
|
|
199
|
-
/**
|
|
200
|
-
* 配置结束 resolve 函数
|
|
201
|
-
*/
|
|
202
|
-
// eslint-disable-next-line vue/no-reserved-keys
|
|
203
|
-
configEndResolve: null
|
|
204
|
-
}
|
|
205
|
-
},
|
|
206
|
-
/**
|
|
207
|
-
* 监听按钮配置名称变化,自动加载配置
|
|
208
|
-
*/
|
|
209
|
-
watch: {
|
|
210
|
-
queryParamsName: {
|
|
211
|
-
immediate: true,
|
|
212
|
-
handler (newVal) {
|
|
213
|
-
this.loadButtonConfig(newVal)
|
|
214
|
-
},
|
|
215
|
-
deep: true
|
|
216
|
-
}
|
|
217
|
-
},
|
|
218
|
-
computed: {
|
|
219
|
-
buttonClass() {
|
|
220
|
-
return {
|
|
221
|
-
'is-streaming': this.isStreaming
|
|
222
|
-
}
|
|
223
|
-
},
|
|
224
|
-
normalizedMd () {
|
|
225
|
-
if (this.internalMarkdown !== null && this.internalMarkdown !== undefined) {
|
|
226
|
-
return normalizeMdInput(this.internalMarkdown, v => {
|
|
227
|
-
console.warn('[XMarkdownViewer] internalMarkdown 期望是字符串,但收到对象:', v)
|
|
228
|
-
})
|
|
229
|
-
}
|
|
230
|
-
const v = (this.markdown != null && this.markdown !== '') ? this.markdown : (this.value || '')
|
|
231
|
-
return normalizeMdInput(v, vv => {
|
|
232
|
-
console.warn('[XMarkdownViewer] markdown/value 期望是字符串,但收到对象:', vv)
|
|
233
|
-
})
|
|
234
|
-
},
|
|
235
|
-
segments () {
|
|
236
|
-
return parseMarkdownWithJsonBlocks(this.normalizedMd, {
|
|
237
|
-
defaultXListConfigName: this.defaultXListConfigName || undefined
|
|
238
|
-
})
|
|
239
|
-
}
|
|
240
|
-
},
|
|
241
|
-
methods: {
|
|
242
|
-
/**
|
|
243
|
-
* 初始化按钮配置
|
|
244
|
-
*/
|
|
245
|
-
initButtonConfig(parameter) {
|
|
246
|
-
this.configEndEmitted = false
|
|
247
|
-
this.configEndPromise = new Promise(resolve => { this.configEndResolve = resolve })
|
|
248
|
-
if (!parameter) {
|
|
249
|
-
this._emitConfigEnd()
|
|
250
|
-
return
|
|
251
|
-
}
|
|
252
|
-
this.loadButtonConfig(parameter)
|
|
253
|
-
},
|
|
254
|
-
/**
|
|
255
|
-
* 配置加载结束后发出事件
|
|
256
|
-
*/
|
|
257
|
-
_emitConfigEnd () {
|
|
258
|
-
if (this.configEndEmitted) return
|
|
259
|
-
this.configEndEmitted = true
|
|
260
|
-
if (this.configEndResolve) {
|
|
261
|
-
this.configEndResolve()
|
|
262
|
-
this.configEndResolve = null
|
|
263
|
-
}
|
|
264
|
-
this.$emit('configEnd')
|
|
265
|
-
},
|
|
266
|
-
/**
|
|
267
|
-
* 等待配置结束的异步方法
|
|
268
|
-
*/
|
|
269
|
-
waitConfigEnd () {
|
|
270
|
-
if (this.configEndEmitted) return Promise.resolve()
|
|
271
|
-
return this.configEndPromise || Promise.resolve()
|
|
272
|
-
},
|
|
273
|
-
/**
|
|
274
|
-
* 通过组件实例接收 md 文件
|
|
275
|
-
*/
|
|
276
|
-
async receiveMarkdown (file) {
|
|
277
|
-
if (!isBlobLike(file)) {
|
|
278
|
-
console.warn('[XMarkdownViewer] receiveMarkdown 仅支持 File/Blob,但收到:', file)
|
|
279
|
-
this.internalMarkdown = ''
|
|
280
|
-
return ''
|
|
281
|
-
}
|
|
282
|
-
const text = await readBlobAsText(file)
|
|
283
|
-
this.internalMarkdown = text
|
|
284
|
-
return text
|
|
285
|
-
},
|
|
286
|
-
/**
|
|
287
|
-
* 接收字符串格式的 markdown 内容
|
|
288
|
-
*/
|
|
289
|
-
receiveMarkdownString (markdownText) {
|
|
290
|
-
if (typeof markdownText !== 'string') {
|
|
291
|
-
console.warn('[XMarkdownViewer] receiveMarkdownString 期望接收字符串,但收到:', markdownText)
|
|
292
|
-
this.internalMarkdown = ''
|
|
293
|
-
return ''
|
|
294
|
-
}
|
|
295
|
-
this.internalMarkdown = markdownText
|
|
296
|
-
return markdownText
|
|
297
|
-
},
|
|
298
|
-
/**
|
|
299
|
-
* receiveMarkdown 的别名
|
|
300
|
-
*/
|
|
301
|
-
async receiveFile (file) {
|
|
302
|
-
return await this.receiveMarkdown(file)
|
|
303
|
-
},
|
|
304
|
-
/**
|
|
305
|
-
* 清除通过 receiveMarkdown() 写入的内容
|
|
306
|
-
*/
|
|
307
|
-
clearReceivedMarkdown () {
|
|
308
|
-
this.internalMarkdown = null
|
|
309
|
-
},
|
|
310
|
-
/**
|
|
311
|
-
* 渲染 Markdown
|
|
312
|
-
*/
|
|
313
|
-
renderMd (text) {
|
|
314
|
-
const s = this.allowHtml ? (text || '') : escapeHtml(text || '')
|
|
315
|
-
try {
|
|
316
|
-
return marked.parse(s, {
|
|
317
|
-
breaks: true,
|
|
318
|
-
gfm: true,
|
|
319
|
-
headerIds: false,
|
|
320
|
-
mangle: false,
|
|
321
|
-
...this.markedOptions
|
|
322
|
-
})
|
|
323
|
-
} catch (e) {
|
|
324
|
-
console.error('[XMarkdownViewer] Markdown 渲染错误:', e)
|
|
325
|
-
return s
|
|
326
|
-
}
|
|
327
|
-
},
|
|
328
|
-
/**
|
|
329
|
-
* 调用 AI 流式接口
|
|
330
|
-
*/
|
|
331
|
-
callAiStream (userMessage, options = {}) {
|
|
332
|
-
const {
|
|
333
|
-
chatId = this._aiChatId || (this._aiChatId = moment().format('YYYYMMDDHHmmss')),
|
|
334
|
-
model = '',
|
|
335
|
-
prompt = '',
|
|
336
|
-
useContext = true,
|
|
337
|
-
onChunk,
|
|
338
|
-
onEnd,
|
|
339
|
-
onError
|
|
340
|
-
} = options
|
|
341
|
-
|
|
342
|
-
let currentContent = ''
|
|
343
|
-
let stopConnection = null
|
|
344
|
-
|
|
345
|
-
this.isStreaming = true
|
|
346
|
-
this.streamEnded = false
|
|
347
|
-
|
|
348
|
-
stopConnection = startEventStreamPOST(
|
|
349
|
-
'/his-web/api/af-his/ai/chat/stream',
|
|
350
|
-
{
|
|
351
|
-
userMessage,
|
|
352
|
-
chatId,
|
|
353
|
-
model,
|
|
354
|
-
prompt,
|
|
355
|
-
useContext
|
|
356
|
-
},
|
|
357
|
-
{},
|
|
358
|
-
(data, type) => {
|
|
359
|
-
if (type === 'additionalInfo' || type === 'sourceInfo') {
|
|
360
|
-
return
|
|
361
|
-
}
|
|
362
|
-
let textChunk = ''
|
|
363
|
-
if (typeof data === 'object' && data !== null) {
|
|
364
|
-
const choices = data.choices
|
|
365
|
-
if (Array.isArray(choices) && choices.length > 0) {
|
|
366
|
-
const delta = choices[0].delta
|
|
367
|
-
if (delta && typeof delta.content === 'string') {
|
|
368
|
-
textChunk = delta.content
|
|
369
|
-
}
|
|
370
|
-
}
|
|
371
|
-
} else if (typeof data === 'string') {
|
|
372
|
-
textChunk = data
|
|
373
|
-
}
|
|
374
|
-
|
|
375
|
-
if (textChunk) {
|
|
376
|
-
currentContent += textChunk
|
|
377
|
-
// 同步更新 internalMarkdown 以触发视图更新
|
|
378
|
-
this.internalMarkdown = currentContent
|
|
379
|
-
onChunk?.(textChunk, currentContent)
|
|
380
|
-
this.scrollToBottom()
|
|
381
|
-
}
|
|
382
|
-
},
|
|
383
|
-
(error) => {
|
|
384
|
-
this.isStreaming = false
|
|
385
|
-
this.streamEnded = true
|
|
386
|
-
onError?.(error.message || '请求失败')
|
|
387
|
-
},
|
|
388
|
-
() => {
|
|
389
|
-
this.isStreaming = false
|
|
390
|
-
this.streamEnded = true
|
|
391
|
-
onEnd?.(currentContent)
|
|
392
|
-
this.scrollToBottom()
|
|
393
|
-
}
|
|
394
|
-
)
|
|
395
|
-
|
|
396
|
-
this._currentStreamConnection = {
|
|
397
|
-
stop: () => {
|
|
398
|
-
stopConnection?.()
|
|
399
|
-
},
|
|
400
|
-
getContent: () => currentContent
|
|
401
|
-
}
|
|
402
|
-
|
|
403
|
-
return this._currentStreamConnection
|
|
404
|
-
},
|
|
405
|
-
/**
|
|
406
|
-
* 停止当前的流式请求
|
|
407
|
-
*/
|
|
408
|
-
stopStream() {
|
|
409
|
-
this._currentStreamConnection?.stop()
|
|
410
|
-
this.isStreaming = false
|
|
411
|
-
this.streamEnded = true
|
|
412
|
-
},
|
|
413
|
-
/**
|
|
414
|
-
* 处理按钮点击
|
|
415
|
-
*/
|
|
416
|
-
handleButtonClick() {
|
|
417
|
-
if (this.buttonConfig.eventDisabled) {
|
|
418
|
-
return
|
|
419
|
-
}
|
|
420
|
-
|
|
421
|
-
if (this.isStreaming) {
|
|
422
|
-
this.stopStream()
|
|
423
|
-
this.$emit('stop-stream')
|
|
424
|
-
} else {
|
|
425
|
-
this.streamEnded = false
|
|
426
|
-
const startEvent = this.buttonConfig.startClickEventName || 'start-stream'
|
|
427
|
-
console.log('[XMarkdownViewer] 触发开始事件:', startEvent)
|
|
428
|
-
this.$emit(startEvent)
|
|
429
|
-
}
|
|
430
|
-
},
|
|
431
|
-
/**
|
|
432
|
-
* 获取当前累积的内容
|
|
433
|
-
*/
|
|
434
|
-
getStreamContent() {
|
|
435
|
-
return this._currentStreamConnection?.getContent() || ''
|
|
436
|
-
},
|
|
437
|
-
/**
|
|
438
|
-
* 滚动到底部
|
|
439
|
-
*/
|
|
440
|
-
scrollToBottom() {
|
|
441
|
-
if (this.$refs.containerRef) {
|
|
442
|
-
this.$nextTick(() => {
|
|
443
|
-
const container = this.$refs.containerRef
|
|
444
|
-
container.scrollTop = container.scrollHeight
|
|
445
|
-
})
|
|
446
|
-
}
|
|
447
|
-
},
|
|
448
|
-
/**
|
|
449
|
-
* 重置流状态
|
|
450
|
-
*/
|
|
451
|
-
resetStreamState() {
|
|
452
|
-
this.isStreaming = false
|
|
453
|
-
this.streamEnded = false
|
|
454
|
-
},
|
|
455
|
-
/**
|
|
456
|
-
* 加载按钮配置
|
|
457
|
-
*/
|
|
458
|
-
loadButtonConfig(configName) {
|
|
459
|
-
if (!configName) {
|
|
460
|
-
console.warn('[XMarkdownViewer] queryParamsName 为空,跳过加载')
|
|
461
|
-
this._emitConfigEnd()
|
|
462
|
-
return
|
|
463
|
-
}
|
|
464
|
-
console.log('[XMarkdownViewer] 开始加载按钮配置:', configName)
|
|
465
|
-
|
|
466
|
-
// 优先使用传入的 serviceName,否则使用 'af-his' 确保获取到正确的配置
|
|
467
|
-
const serviceName = this.serviceName || 'af-his'
|
|
468
|
-
console.log('[XMarkdownViewer] 使用服务名:', serviceName)
|
|
469
|
-
|
|
470
|
-
getConfigByName(configName, serviceName, (res) => {
|
|
471
|
-
console.log('[XMarkdownViewer] 配置加载回调, res:', res)
|
|
472
|
-
if (!res) {
|
|
473
|
-
console.warn('[XMarkdownViewer] 按钮配置未找到:', configName)
|
|
474
|
-
this._emitConfigEnd()
|
|
475
|
-
return
|
|
476
|
-
}
|
|
477
|
-
console.log('[XMarkdownViewer] 应用配置:', res)
|
|
478
|
-
this.buttonConfig = {
|
|
479
|
-
...res
|
|
480
|
-
}
|
|
481
|
-
if (typeof res.showButtonInitially === 'boolean') {
|
|
482
|
-
this.showButtonInitially = res.showButtonInitially
|
|
483
|
-
}
|
|
484
|
-
console.log('[XMarkdownViewer] buttonConfig 已更新:', this.buttonConfig)
|
|
485
|
-
this._emitConfigEnd()
|
|
486
|
-
}, this.env === 'dev')
|
|
487
|
-
},
|
|
488
|
-
/**
|
|
489
|
-
* 获取按钮图标
|
|
490
|
-
*/
|
|
491
|
-
getButtonIcon() {
|
|
492
|
-
if (this.isStreaming) {
|
|
493
|
-
return this.buttonConfig.stopIcon || 'pause-circle'
|
|
494
|
-
} else if (this.streamEnded) {
|
|
495
|
-
return this.buttonConfig.stoppedIcon || 'check-circle'
|
|
496
|
-
} else {
|
|
497
|
-
return this.buttonConfig.startIcon || 'play-circle'
|
|
498
|
-
}
|
|
499
|
-
},
|
|
500
|
-
/**
|
|
501
|
-
* 获取按钮文字
|
|
502
|
-
*/
|
|
503
|
-
getButtonText() {
|
|
504
|
-
if (this.isStreaming) {
|
|
505
|
-
return this.buttonConfig.stopText || '停止'
|
|
506
|
-
} else if (this.streamEnded) {
|
|
507
|
-
return this.buttonConfig.startText || '开始'
|
|
508
|
-
} else {
|
|
509
|
-
return this.buttonConfig.startText || '开始'
|
|
510
|
-
}
|
|
511
|
-
}
|
|
512
|
-
},
|
|
513
|
-
mounted() {
|
|
514
|
-
this.containerRef = this.$refs.containerRef
|
|
515
|
-
}
|
|
516
|
-
}
|
|
517
|
-
</script>
|
|
518
|
-
|
|
519
|
-
<style lang="less" scoped>
|
|
520
|
-
.x-markdown-viewer-wrapper {
|
|
521
|
-
width: 100%;
|
|
522
|
-
display: flex;
|
|
523
|
-
flex-direction: column;
|
|
524
|
-
opacity: 1;
|
|
525
|
-
background: #FFFFFF;
|
|
526
|
-
box-sizing: border-box;
|
|
527
|
-
border: 1px solid #E5E9F0;
|
|
528
|
-
padding: 5px;
|
|
529
|
-
|
|
530
|
-
.stream-control-bar {
|
|
531
|
-
display: flex;
|
|
532
|
-
justify-content: flex-end;
|
|
533
|
-
padding: 5px;
|
|
534
|
-
margin-bottom: 5px;
|
|
535
|
-
border-bottom: 1px solid #e8e8e8;
|
|
536
|
-
|
|
537
|
-
.stream-btn {
|
|
538
|
-
display: inline-flex;
|
|
539
|
-
align-items: center;
|
|
540
|
-
justify-content: center;
|
|
541
|
-
gap: 6px;
|
|
542
|
-
width: 110px;
|
|
543
|
-
height: 32px;
|
|
544
|
-
padding: 0;
|
|
545
|
-
font-family: "Source Han Sans";
|
|
546
|
-
font-size: 16px;
|
|
547
|
-
font-weight: normal;
|
|
548
|
-
letter-spacing: 0em;
|
|
549
|
-
line-height: normal;
|
|
550
|
-
font-feature-settings: "kern" on;
|
|
551
|
-
color: #5D5C5C;
|
|
552
|
-
opacity: 1;
|
|
553
|
-
background: #FFFFFF;
|
|
554
|
-
border: 1px solid #9499A0;
|
|
555
|
-
border-radius: 6px;
|
|
556
|
-
box-sizing: border-box;
|
|
557
|
-
margin-right: 5px;
|
|
558
|
-
|
|
559
|
-
&.is-streaming {
|
|
560
|
-
background: #fff2f0;
|
|
561
|
-
border-color: #ff4d4f;
|
|
562
|
-
color: #ff4d4f;
|
|
563
|
-
|
|
564
|
-
&:hover {
|
|
565
|
-
background: #fff1f0;
|
|
566
|
-
border-color: #ff7875;
|
|
567
|
-
color: #ff7875;
|
|
568
|
-
}
|
|
569
|
-
}
|
|
570
|
-
|
|
571
|
-
}
|
|
572
|
-
}
|
|
573
|
-
|
|
574
|
-
.x-markdown-viewer {
|
|
575
|
-
width: 100%;
|
|
576
|
-
max-height: 350px;
|
|
577
|
-
overflow-y: auto;
|
|
578
|
-
overflow-x: hidden;
|
|
579
|
-
}
|
|
580
|
-
}
|
|
581
|
-
|
|
582
|
-
.markdown-body {
|
|
583
|
-
font-family: "Source Han Sans";
|
|
584
|
-
font-size: 16px;
|
|
585
|
-
font-weight: normal;
|
|
586
|
-
line-height: normal;
|
|
587
|
-
text-align: justify;
|
|
588
|
-
letter-spacing: 0em;
|
|
589
|
-
font-feature-settings: "kern" on;
|
|
590
|
-
color: #313131;
|
|
591
|
-
word-break: break-word;
|
|
592
|
-
}
|
|
593
|
-
|
|
594
|
-
.markdown-body h1,
|
|
595
|
-
.markdown-body h2,
|
|
596
|
-
.markdown-body h3,
|
|
597
|
-
.markdown-body h4,
|
|
598
|
-
.markdown-body h5,
|
|
599
|
-
.markdown-body h6 {
|
|
600
|
-
margin-top: 16px;
|
|
601
|
-
margin-bottom: 8px;
|
|
602
|
-
font-weight: 600;
|
|
603
|
-
}
|
|
604
|
-
|
|
605
|
-
.markdown-body p {
|
|
606
|
-
margin: 0 0 12px;
|
|
607
|
-
}
|
|
608
|
-
|
|
609
|
-
.markdown-body ul,
|
|
610
|
-
.markdown-body ol {
|
|
611
|
-
padding-left: 2em;
|
|
612
|
-
margin: 0 0 12px;
|
|
613
|
-
}
|
|
614
|
-
|
|
615
|
-
.markdown-body pre {
|
|
616
|
-
background-color: #f6f8fa;
|
|
617
|
-
border-radius: 6px;
|
|
618
|
-
padding: 12px;
|
|
619
|
-
overflow: auto;
|
|
620
|
-
}
|
|
621
|
-
|
|
622
|
-
.markdown-body code {
|
|
623
|
-
background-color: #f6f8fa;
|
|
624
|
-
border-radius: 3px;
|
|
625
|
-
padding: 0.2em 0.4em;
|
|
626
|
-
font-size: 85%;
|
|
627
|
-
}
|
|
628
|
-
</style>
|