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,628 @@
|
|
|
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>
|