askbot-dragon 1.6.32 → 1.6.33

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "askbot-dragon",
3
- "version": "1.6.32",
3
+ "version": "1.6.33",
4
4
  "scripts": {
5
5
  "serve": "vue-cli-service serve",
6
6
  "build": "vue-cli-service build",
@@ -9,6 +9,8 @@
9
9
  "dependencies": {
10
10
  },
11
11
  "devDependencies": {
12
+ "marked": "^4.0.0",
13
+ "highlight.js": "^11.11.1",
12
14
  "audio-loader": "^1.0.3",
13
15
  "core-js": "^3.6.5",
14
16
  "install": "^0.13.0",
@@ -774,16 +774,6 @@ export default {
774
774
  // Math.hypot()计算参数的平方根
775
775
  return Math.hypot(stop.x - start.x, stop.y - start.y);
776
776
  },
777
- setupCanvas (canvas, width, height) {
778
- const dpr = 1;
779
- // const rect = canvas.getBoundingClientRect();
780
- canvas.width = width
781
- canvas.height = height
782
- const ctx = canvas.getContext('2d');
783
- console.log(canvas.width, canvas.height, dpr, this.scale);
784
- ctx?.scale(dpr, dpr);
785
- return ctx;
786
- },
787
777
  changeScale (value) {
788
778
  if (value == 'zoom') {
789
779
  this.handScale = 'auto'
@@ -1,334 +1,889 @@
1
1
  <template>
2
2
  <div @click="lookImage">
3
- <vue-markdown class="mark_down" :source="typedContent" :ref="'markdown' + msgId">
4
- </vue-markdown>
5
- <div v-if="showPreview">
6
- <img-view :url-list="imgList" @closeViewer="closeViewer"></img-view>
7
- </div>
3
+ <div class="think" v-if="hasThinkValue">
4
+ <p class="think_title" :style="{ height: showThink ? '32px' : '20px' }" @click="showThink = !showThink">
5
+ <span class="think_title_left">
6
+ <i class="iconfont guoran-icon-deepseek"></i>
7
+ {{ $t('dragonCommon.deeplyPondered') }}
8
+ <span v-if="!isHistory">({{ $t('dragonCommon.time') }} {{ filterTime(thinkTimeNum) }})</span>
9
+ </span>
10
+ <span class="think_title_right" :class="showThink ? '' : 'hide_think_title'">
11
+ <i class="iconfont guoran-jiantouxiangshang"></i>
12
+ </span>
13
+ </p>
14
+ <div class="think_content" :class="showThink ? '' : 'hide_think'" v-html="parseThinkVal">
15
+ </div>
16
+ </div>
17
+ <!-- <vue-markdown
18
+ class="mark_down"
19
+ :source="typedContent"
20
+ :ref="'markdown' + msgId"
21
+ @click.native="clickMarkDown"
22
+ :plugins="plugins"
23
+ >
24
+ </vue-markdown> -->
25
+ <!-- v-show="hasContent" -->
26
+ <div
27
+ class="mark_down"
28
+ v-html="markParseText"
29
+ ref="markDown"
30
+ @click="clickMarkDown">
31
+ </div>
32
+ <!-- <div v-show="!hasThinkValue && !hasContent" class="blinking-cursor"></div> -->
33
+ <div v-if="showPreview">
34
+ <img-view :url-list="imgList" @closeViewer="closeViewer"></img-view>
35
+ </div>
8
36
  </div>
9
-
10
- </template>
11
- <script>
12
- import VueMarkdown from 'vue-markdown';
13
- import ImgView from "./imgView";
14
- // import Typed from "typed.js";
15
-
16
- export default {
37
+
38
+ </template>
39
+
40
+ <script>
41
+ /* eslint-disable */
42
+ import VueMarkdown from 'vue-markdown';
43
+ import ImgView from "./imgView";
44
+ // import Typed from "typed.js";
45
+ import hljs from 'highlight.js';
46
+ import 'highlight.js/styles/default.css';
47
+ import { v4 as uuidv4 } from "uuid";
48
+ const marked = require("marked")
49
+ export default {
17
50
  name: "markDownText",
18
51
  data() {
19
- return {
20
- typedContent: "",
21
- typingSpeed: 15,
22
- showPreview: false,
23
- imgList: [],
24
- isManualScroll: false,
25
- }
52
+ return {
53
+ eventSource: null,
54
+ plugins: [
55
+
56
+ ],
57
+ typedContent: "",
58
+ typingSpeed: 15,
59
+ showPreview: false,
60
+ imgList: [],
61
+ isManualScroll: false,
62
+ hasThinkValue: false,
63
+ chainThinkValue: "",
64
+ showThink: true,
65
+ streamThinkValueAddFlag: false,
66
+ timer: null,
67
+ generatingString: "",
68
+ generatingThinkString: "",
69
+ streamEnd: false,
70
+ thinkCount: 0,
71
+ thinkTimer: null,
72
+ thinkTimeNum: 0,
73
+ thinkEnd: true,
74
+ signSetFlag: false,
75
+ // 重试地址
76
+ retryUrl: "",
77
+ }
26
78
  },
27
79
  props: {
28
- chainValues: {
29
- type: String,
30
- default: ""
31
- },
32
- msgId: {
33
- type: String,
34
- default: ""
35
- },
36
- isHistory: {
37
- type: Boolean,
38
- default: false
39
- },
40
- streamRequestUrl: {
41
- type: String,
42
- default: ""
43
- },
44
- whetherRequestStream: {
45
- type: Boolean,
46
- default: false
47
- }
80
+ chainValues: {
81
+ type: String,
82
+ default: ""
83
+ },
84
+ msgId: {
85
+ type: String,
86
+ default: ""
87
+ },
88
+ isHistory: {
89
+ type: Boolean,
90
+ default: false
91
+ },
92
+ streamRequestUrl: {
93
+ type: String,
94
+ default: ""
95
+ },
96
+ whetherRequestStream: {
97
+ type: Boolean,
98
+ default: false
99
+ }
100
+ },
101
+ computed: {
102
+ hasContent() {
103
+ if (!this.markParseText) return false; // 如果 markParseText 为空,返回 false
104
+ const tempDiv = document.createElement("div");
105
+ tempDiv.innerHTML = this.markParseText;
106
+ const textContent = tempDiv.textContent || tempDiv.innerText || "";
107
+ return textContent.trim() !== ""; // 如果文本内容不为空,返回 true
108
+ },
109
+ markParseText() {
110
+ const regex = /```json\n{"content":"/g
111
+ const regex2 = /```json\n{\n "content": "/g
112
+ let str = this.typedContent
113
+ str = str.replace(regex, "")
114
+ str = str.replace(regex2, "")
115
+ str = str.replaceAll("\\n", "\n")
116
+ // 处理特殊情况,标题前的多个换行符补充一个空行
117
+ str = str.replaceAll("\n\n ###", "<p> <p/>\n ###")
118
+ let markdown = marked.marked(str, {
119
+ breaks: true
120
+ })
121
+ return this.parseCode(markdown)
122
+ },
123
+ parseThinkVal() {
124
+ let str = this.chainThinkValue;
125
+ str = str.replaceAll("\\n", "\n")
126
+ str = str.replaceAll("\n", "<br>")
127
+ return this.parseCode(str)
128
+ }
48
129
  },
49
130
  components: {
50
- ImgView,
51
- VueMarkdown
131
+ ImgView,
132
+ VueMarkdown
52
133
  },
53
134
  mounted() {
54
- this.$nextTick(() => {
55
- console.log("this.askMassageStream: ", this.askMassageStream);
56
- console.log("this.whetherRequestStream: ", this.whetherRequestStream);
57
- console.log("this.streamRequestUrl: ", this.streamRequestUrl);
58
- console.log("this.isHistory: ", this.isHistory);
59
- if (this.isHistory) {
60
- if (this.whetherRequestStream) {
61
- console.log("71 新版 真 流 打字 效果");
62
- window.addEventListener('wheel', this.handleScroll, true);
63
- this.streamInfo(this.streamRequestUrl);
64
- } else {
65
- this.typedContent = this.chainValues
66
- console.log(JSON.parse(JSON.stringify(this.typedContent)));
67
-
68
- }
69
-
70
- } else {
71
- console.log("78 pre 新版 真 流 打字 效果");
72
- // 新版 真 流 打字 效果
73
- if (this.askMassageStream && this.whetherRequestStream && this.streamRequestUrl) {
74
- console.log("81 新版 真 流 打字 效果");
75
- window.addEventListener('wheel', this.handleScroll, true);
76
- this.streamInfo(this.streamRequestUrl);
77
- } else {
78
- this.$emit("sseOtherInfo", this.msgId, "start", "");
79
- // 旧版 模拟 流 打字 效果
80
- this.typedContent = this.chainValues
81
- // this.startTypingEffect();
82
- }
83
- }
84
- })
135
+ this.$nextTick(() => {
136
+ console.log("this.askMassageStream: ", this.askMassageStream);
137
+ console.log("this.whetherRequestStream: ", this.whetherRequestStream);
138
+ console.log("this.streamRequestUrl: ", this.streamRequestUrl);
139
+ console.log("this.isHistory: ", this.isHistory);
140
+ if (this.isHistory) {
141
+ if (this.whetherRequestStream) {
142
+ console.log("71 新版 真 流 打字 效果");
143
+ window.addEventListener('wheel', this.handleScroll, true);
144
+ this.streamInfo(this.streamRequestUrl);
145
+ } else {
146
+ this.typedContent = this.filterThinkVal(this.chainValues);
147
+ this.$nextTick(() =>{
148
+ this.appendCopyBtn()
149
+ })
150
+ }
151
+ } else {
152
+ console.log("78 pre 新版 真 流 打字 效果");
153
+ // 新版 真 流 打字 效果
154
+ if (this.askMassageStream && this.whetherRequestStream && this.streamRequestUrl) {
155
+ console.log("81 新版 真 流 打字 效果");
156
+ window.addEventListener('wheel', this.handleScroll, true);
157
+ this.streamInfo(this.streamRequestUrl);
158
+ } else {
159
+ console.log("markdowncopy 旧版 模拟 流 打字 效果 sseOtherInfo");
160
+ this.$emit("sseOtherInfo", this.msgId, "start", "");
161
+ this.$emit("sseOtherInfo", this.msgId, "hideloading", "");
162
+ // 旧版 模拟 流 打字 效果
163
+ this.typedContent = this.filterThinkVal(this.chainValues);
164
+ this.$nextTick(() =>{
165
+ this.appendCopyBtn()
166
+ })
167
+ }
168
+ }
169
+ })
85
170
  },
86
171
  methods: {
87
- // 打字效果已在MarkdownText文件中处理
88
- // typeNewWriter(text, keyId, msg) {
89
- // setTimeout(() => {
90
- // let ref = 'msgTyped' + keyId;
91
- // const el = this.$refs[ref][0];
92
- // new Typed(el, {
93
- // strings: [text],
94
- // typeSpeed: 15,
95
- // showCursor: false,
96
- // onComplete: () => {
97
- // msg.isHistory = true
98
- // this.$emit('openFirstPreview', msg)
99
- // this.typingSuccess()
100
- // },
101
- // })
102
- // }, 500)
103
- // },
104
- handleScroll() {
105
- console.log("this.isManualScroll = true;");
106
- this.isManualScroll = true;
107
- window.removeEventListener('wheel', this.handleScroll, true);
108
- },
109
- scrollMarkdown(){
110
- !this.isManualScroll && this.$nextTick(() => {
111
- const element = document.getElementById('el_id_markdown_' + this.msgId);
112
- if (element) {
113
- element.scrollIntoView({ behavior: 'smooth', block: 'start' });
114
- }
115
- });
116
- },
117
- streamInfo(url){
118
- // 通知消息列表,当前还未建立sse,先不出空消息
119
- this.$emit("sseOtherInfo", this.msgId, "init", "");
120
-
121
- const eventSource = new EventSource(url);
122
- let tempString = "";
123
- let generatingString = "";
124
- let timer = null;
125
- let images = [];
126
- let matched = [];
127
- let recommendItems = [];
128
- let isfirstStr = false;
129
- const backslashOrNRegex = /\n/;
130
- eventSource.onmessage = (event) => {
131
- const data = JSON.parse(event.data);
132
- if (event.lastEventId === 'finish') { // 不能删除 finish
133
- console.log("finish+++++");
134
- } else if (event.lastEventId === '[DONE]') {
135
- let DONETmier = setInterval(() => {
136
- // 在所有文本内容打字效果完毕后 展示底部图片 文件 推荐等
137
- if (generatingString == "") {
138
- if (images.length != 0) {
139
- setTimeout(() => {
140
- this.$emit("sseOtherInfo", this.msgId,"images", images);
141
- this.scrollMarkdown();
142
- }, 50);
172
+ closeMessageStream() {
173
+ this.eventSource.close();
174
+ setTimeout(() => {
175
+ let str = this.typedContent + this.generatingString
176
+ this.$set(this, "typedContent", str)
177
+ this.generatingString = "";
178
+ let str2 = this.filterText(this.chainThinkValue + this.generatingThinkString)
179
+ this.$set(this, "chainThinkValue", str2)
180
+ this.generatingThinkString = "";
181
+ this.closeTimeOut()
182
+ clearInterval(this.thinkTimer)
183
+ this.thinkTimer = null
184
+ this.thinkEnd = true
185
+ this.removeLoadingNode()
186
+ this.$emit("streamCallback", this.typedContent)
187
+ this.$emit("sseOtherInfo", this.msgId, "start", "");
188
+ }, 200);
189
+ },
190
+ filterTime(time) {
191
+ if (time < 60) {
192
+ return time + " 秒";
193
+ } else {
194
+ return Math.floor(time / 60) + " 分 " + time % 60 + " 秒";
195
+ }
196
+ },
197
+ // 处理历史记录中的 <think> 标签
198
+ filterThinkVal(text) {
199
+ // 用于匹配 <think> 标签的正则表达式
200
+ this.hasThinkValue = false;
201
+ this.chainThinkValue = "";
202
+ const thinkStartRegex = /<think>/;
203
+ // const thinkEndRegex = /<\/think>/;
204
+ const thinkEndRegex = /<\/think>/g;
205
+ // 查找第一个 <think> 标签的位置
206
+ const startIndex = text.search(thinkStartRegex);
207
+ if (startIndex === -1) {
208
+ // 如果没有找到 <think> 标签,直接返回原始文本和空内容
209
+ return text.replaceAll("\\n", "\n")
210
+ }
211
+ // 从第一个 <think> 标签之后开始查找最后一个 </think> 标签
212
+ let endIndex = -1;
213
+ let match;
214
+ // 循环查找所有匹配项
215
+ while ((match = thinkEndRegex.exec(text)) !== null) {
216
+ endIndex = match.index;
217
+ }
218
+ if (endIndex !== -1) {
219
+ console.log(`最后一个 </think> 的起始位置是: ${endIndex}`);
220
+ // 提取 <think> 标签中的内容
221
+ let thinkVal = text.slice(startIndex + '<think>'.length, endIndex);
222
+ // 从原始文本中剔除 <think> 标签及其中的内容
223
+ let typedContent = text.slice(0, startIndex) + text.slice(endIndex);
224
+ this.hasThinkValue = true;
225
+ this.chainThinkValue = thinkVal.replaceAll("<think>", "").replaceAll("</think>", "<br/>");
226
+ this.chainThinkValue = this.filterText(this.chainThinkValue)
227
+ return typedContent.replaceAll("\\n", "\n");
228
+ } else {
229
+ // text.replaceAll("\\n", "\n")
230
+ this.hasThinkValue = true;
231
+ this.chainThinkValue = text.replaceAll("<think>", "").replaceAll("</think>", "<br/>");
232
+ return ""
233
+ }
234
+ },
235
+ filterText(str) {
236
+ /* eslint-disable */
237
+ const regex = /\{\n "functionCall": \{/s
238
+ str = str.replace(regex, "")
239
+ str = str.replaceAll("```json", "")
240
+ return str
241
+ },
242
+ // 处理流式消息中的 <think> 标签
243
+ streamFilterThinkValue() {
244
+
245
+ },
246
+ // 打字效果已在MarkdownText文件中处理
247
+ typeNewWriter(text, keyId, msg) {
248
+ // setTimeout(() => {
249
+ // let ref = 'msgTyped' + keyId;
250
+ // const el = this.$refs[ref][0];
251
+ // new Typed(el, {
252
+ // strings: [text],
253
+ // typeSpeed: 15,
254
+ // showCursor: false,
255
+ // onComplete: () => {
256
+ // msg.isHistory = true
257
+ // this.$emit('openFirstPreview', msg)
258
+ // this.typingSuccess()
259
+ // },
260
+ // })
261
+ // }, 500)
262
+ },
263
+ handleScroll() {
264
+ console.log("this.isManualScroll = true;");
265
+ this.isManualScroll = true;
266
+ window.removeEventListener('wheel', this.handleScroll, true);
267
+ },
268
+ scrollMarkdown() {
269
+ !this.isManualScroll && this.$nextTick(() => {
270
+ let container = document.getElementById("list");
271
+ if (container) {
272
+ let scrollHeight = container.scrollHeight;
273
+ container.scrollTop = scrollHeight;
143
274
  }
144
- if (matched.length != 0) {
145
- setTimeout(() => {
146
- this.$emit("sseOtherInfo", this.msgId, "matched", matched);
147
- this.scrollMarkdown();
148
- }, 100);
275
+ });
276
+ },
277
+ streamInfo(url) {
278
+ // 通知消息列表,当前还未建立sse,先不出空消息
279
+ if(this.retryUrl == ""){
280
+ this.$emit("sseOtherInfo", this.msgId, "init", "");
281
+ }
282
+ this.$emit("answerDocKnowledgeFn");
283
+ this.eventSource = new EventSource(url);
284
+ this.$emit("streamStatus", true, this.msgId);
285
+ this.$set(this, 'showThink', true);
286
+ this.signSetFlag = false;
287
+ this.thinkEnd = false
288
+ let tempString = "";
289
+ // let generatingString = "";
290
+ // let timer = null;
291
+ let images = [];
292
+ let matched = [];
293
+ let recommendItems = [];
294
+ let isFirstStr = true;
295
+ const backslashOrNRegex = /[\\n]/; // 不能替换为 /\n/,会导致格式解析错误,在处理方法末尾做了修改
296
+ // 如果只有一次推送、并且推送字符串中带有 n
297
+ let isOnlyOnce = 0; // 标记是否只有一次推送
298
+ let hasN = false; // 标记是否有 n
299
+ const thinkStartRegex = /<think>/;
300
+ const thinkEndRegex = /<\/think>/
301
+ this.eventSource.onmessage = (event) => {
302
+ const data = JSON.parse(event.data);
303
+ if (event.lastEventId === 'finish') { // 不能删除 finish
304
+ console.log("finish+++++");
305
+ } else if (event.lastEventId === '[DONE]') {
306
+ this.streamEnd = true;
307
+ // 只有一次推送,且推送字符串中带有 n
308
+ // 用于特殊情况(只有一次内容推送 且 含有 n)
309
+ if (isOnlyOnce == 1 && hasN) {
310
+ this.$emit("answerDocKnowledgeFn");
311
+ let repStr = tempString.replace(/\\n/g, '\n');
312
+ this.$set(this, "typedContent", repStr);
313
+ this.scrollMarkdown();
314
+ }
315
+ let DONETmier = setInterval(() => {
316
+ // 在所有文本内容打字效果完毕后 展示底部图片 文件 推荐等
317
+ if (this.generatingString == "") {
318
+ if (images.length != 0) {
319
+ setTimeout(() => {
320
+ this.$emit("sseOtherInfo", this.msgId, "images", images);
321
+ this.scrollMarkdown();
322
+ }, 50);
323
+ }
324
+ if (matched.length != 0) {
325
+ setTimeout(() => {
326
+ this.$emit("sseOtherInfo", this.msgId, "matched", matched);
327
+ this.scrollMarkdown();
328
+ }, 100);
329
+ }
330
+ if (recommendItems.length != 0) {
331
+ setTimeout(() => {
332
+ this.$emit("sseOtherInfo", this.msgId, "recommendItems", recommendItems);
333
+ this.scrollMarkdown();
334
+ }, 150);
335
+ }
336
+ this.closeTimeOut()
337
+ clearInterval(DONETmier);
338
+ if(this.thinkTimer != null) {
339
+ clearInterval(this.thinkTimer)
340
+ this.thinkTimer = null
341
+ this.thinkEnd = true
342
+ }
343
+ this.$emit("streamCallback", this.typedContent)
344
+ this.$emit("streamStatus", false, this.msgId);
345
+ this.appendCopyBtn()
346
+ this.removeLoadingNode()
347
+ this.$emit("sseOtherInfo", this.msgId, "start", "");
348
+ }
349
+
350
+ }, 100);
351
+ this.eventSource.close();
352
+ // 重试地址不为空,说明需要重试
353
+ console.log("需要重试 this.retryUrl: ", this.retryUrl);
354
+ if (this.retryUrl != "") {
355
+ console.log("this.retryUrl: ", this.retryUrl);
356
+ this.streamInfo(this.retryUrl);
357
+ // 将重试地址清空,用于在收到结束标识并结束后 判断是否需要重试
358
+ this.retryUrl = "";
359
+ this.$emit("sseOtherInfo", this.msgId, "changeHeaderStyleValue", this.$t('common.modelgeneration'));
360
+ }
361
+ } else if (event.lastEventId === 'matched') {
362
+ matched = data;
363
+ } else if (event.lastEventId === 'images') {
364
+ images = data;
365
+ } else if (event.lastEventId === 'recommendItems') {
366
+ recommendItems = data;
367
+ } else if (event.lastEventId === 'retry') {
368
+ this.retryUrl = data.content;
369
+ } else if (event.lastEventId === 'source') {
370
+ this.$emit("changedHeadStatusValue", this.msgId, data);
371
+ } else {
372
+ // console.log("start event.lastEventId: ", event.lastEventId);
373
+ // 设置当前知识答案id,用于loading取消和展示
374
+ this.$emit("sseOtherInfo", this.msgId, "start", "");
375
+ if(thinkStartRegex.test(data.content) && thinkEndRegex.test(data.content)) {
376
+ this.hasThinkValue = true;
377
+ this.thinkCount = 0
378
+ this.ThinkTime()
379
+ } else {
380
+ // 最终根据规则是以最后一个 </think> 标识当前深度思考结束,开始正常添加数据到 typedContent
381
+ if (thinkStartRegex.test(data.content)) {
382
+ if (this.thinkCount == 0) {
383
+ this.thinkCount = 0
384
+ } else {
385
+ this.thinkCount += 1;
386
+ }
387
+ this.hasThinkValue = true;
388
+ this.ThinkTime()
389
+ // this.streamThinkValueAddFlag = true;
390
+ }
391
+ if (thinkEndRegex.test(data.content)) {
392
+ this.thinkCount -= 1;
393
+ // this.streamThinkValueAddFlag = false;
394
+ }
395
+ }
396
+ // 字符串中存在特定字符,本次接收消息暂不展示
397
+ if (backslashOrNRegex.test(data.content) && !this.hasThinkValue) {
398
+ tempString += data.content;
399
+ // 用于特殊情况(只有一次内容推送 且 含有 n)
400
+ isOnlyOnce++;
401
+ hasN = true;
402
+ } else {
403
+ if (data.content.trim() != "") {
404
+ isOnlyOnce++;
405
+ }
406
+ // 此处判断的逻辑是识别到了深度思考 结束,开始处理回复的内容数据,关闭掉深度思考的手动计时,并收起深度思考的内容
407
+ let repStr = tempString.replace(/\\n/g, '\n');
408
+ if (this.hasThinkValue && this.thinkCount == 0) {
409
+ this.generatingThinkString = this.generatingThinkString + repStr + data.content;
410
+ this.thinkEnd = false
411
+ this.ThinkTime()
412
+ } else {
413
+ let str = data.content
414
+ if (thinkEndRegex.test(data.content)) {
415
+ let arr = data.content.split("</think>")
416
+ this.generatingThinkString = this.generatingThinkString + arr[0]
417
+ str = arr[1]
418
+ }
419
+ this.generatingString = this.generatingString + repStr + str;
420
+ }
421
+ tempString = "";
422
+ if (isFirstStr) {
423
+ isFirstStr = false;
424
+ this.timer = 0;
425
+ this.openTimeOutSetVal()
426
+ }
427
+ }
149
428
  }
150
- if (recommendItems.length != 0) {
151
- setTimeout(() => {
152
- this.$emit("sseOtherInfo", this.msgId, "recommendItems", recommendItems);
153
- this.scrollMarkdown();
154
- }, 150);
429
+ };
430
+ this.eventSource.onerror = (err) => {
431
+ this.typedContent += `\n${this.$t("dragonCommon.eventSourceError")}\n`;
432
+ this.closeTimeOut()
433
+ this.$emit("streamStatus", false, this.msgId);
434
+ this.$emit("streamErrorCallBack", this.msgId);
435
+ this.$emit("streamCallback", this.typedContent)
436
+ if(this.eventSource) {
437
+ try {
438
+ this.eventSource.close();
439
+ } catch (e) {
440
+ console.error('EventSource close failed:', e);
441
+ }
155
442
  }
156
- clearInterval(timer);
157
- clearInterval(DONETmier);
158
- }
159
- }, 100);
160
- eventSource.close();
161
- } else if (event.lastEventId === 'matched') {
162
- matched = data;
163
- } else if (event.lastEventId === 'images') {
164
- images = data;
165
- } else if (event.lastEventId === 'recommendItems') {
166
- recommendItems = data;
167
- } else {
168
- // 设置当前知识答案id,用于loading取消和展示
169
- this.$emit("sseOtherInfo", this.msgId, "start", "");
170
- // 字符串中存在特定字符,本次接收消息暂不展示
171
- if (backslashOrNRegex.test(data.content)) {
172
- tempString += data.content;
173
- } else {
174
- if (!isfirstStr) {
175
- isfirstStr = true;
176
- timer = setInterval(() => {
177
- if (generatingString != "") {
178
- this.$set(this, "typedContent", this.typedContent + generatingString.charAt(0))
179
- generatingString = generatingString.slice(1)
180
- this.scrollMarkdown();
181
- }
443
+ setTimeout(() => {
444
+ this.removeLoadingNode()
445
+ }, 200);
446
+ };
447
+ },
448
+ openTimeOutSetVal() {
449
+ if (this.timer != null) {
450
+ this.timer = setTimeout(() => {
451
+ this.closeThinkContent(this)
452
+ // 先把深度思考的值 push 完成后再执行正常内容的 push,最终以正常内容的值为空判断为本轮打字效果结束
453
+ if (this.generatingThinkString != "") {
454
+ let str = this.filterText(this.chainThinkValue + this.generatingThinkString.charAt(0))
455
+ this.$set(this, "chainThinkValue", str)
456
+ this.generatingThinkString = this.generatingThinkString.slice(1)
457
+ this.scrollMarkdown();
458
+ } else if (this.generatingString != "") {
459
+ this.$set(this, "typedContent", this.typedContent + this.generatingString.charAt(0))
460
+ this.generatingString = this.generatingString.slice(1)
461
+ this.scrollMarkdown();
462
+ if(this.thinkTimer != null) {
463
+ clearInterval(this.thinkTimer)
464
+ this.thinkTimer = null
465
+ this.thinkEnd = true
466
+ }
467
+ }
468
+ this.openTimeOutSetVal()
182
469
  }, 20);
183
- this.$emit("answerDocKnowledgeFn");
184
- }
185
- let repStr = tempString.replace(/\\n/g, '\n');
186
- generatingString = generatingString + repStr + data.content;
187
- tempString = "";
188
470
  }
189
- }
190
- };
191
-
192
- eventSource.onerror = function(err) {
193
- console.error('EventSource failed:', err);
194
- this.typedContent += '\nError receiving data from server.\n';
195
- eventSource.close();
196
- };
197
- },
198
- startTypingEffect() {
199
- // 使用正则表达式将 HTML 内容按 <table> 标签分割
200
- const segments = this.chainValues.split(/(<\/?table[\s\S]*?>[\s\S]*?<\/table>)/i);
201
- console.log("segments: ", segments);
202
-
203
- let segmentIndex = 0;
204
- let i = 0;
205
- const processNextSegment = () => {
206
- if (segmentIndex >= segments.length) {
207
- this.$emit('openFirstPreview')
208
- this.$emit('typingSuccess');
209
- return;
210
- }
211
- const segment = segments[segmentIndex];
212
- if (/^<\/?table[\s\S]*?>[\s\S]*?<\/table>$/i.test(segment)) {
213
- // 如果当前段是 <table> 标签,直接添加到 typedContent 中
214
- this.typedContent += segment;
215
- segmentIndex++;
216
- processNextSegment();
217
- } else {
218
- i = 0;
219
- const updateContent = () => {
220
- if (i < segment.length) {
221
- this.typedContent += segment.charAt(i);
222
- i++;
223
- // 使用 requestAnimationFrame 替代 setInterval,防止卡顿
224
- requestAnimationFrame(updateContent);
225
- } else {
226
- segmentIndex++;
227
- processNextSegment();
228
- }
471
+ },
472
+ closeTimeOut() {
473
+ clearTimeout(this.timer);
474
+ this.timer = null;
475
+ },
476
+ ThinkTime() {
477
+ if(this.thinkTimer == null) {
478
+ this.thinkTimer = setInterval(() => {
479
+ this.thinkTimeNum += 1;
480
+ }, 1000)
481
+ }
482
+ },
483
+ startTypingEffect() {
484
+ // 使用正则表达式将 HTML 内容按 <table> 标签分割
485
+ const segments = this.chainValues.split(/(<\/?table[\s\S]*?>[\s\S]*?<\/table>)/i);
486
+ console.log("segments: ", segments);
487
+
488
+ let segmentIndex = 0;
489
+ let i = 0;
490
+ const processNextSegment = () => {
491
+ if (segmentIndex >= segments.length) {
492
+ this.$emit('openFirstPreview')
493
+ this.$emit('typingSuccess');
494
+ return;
495
+ }
496
+ const segment = segments[segmentIndex];
497
+ if (/^<\/?table[\s\S]*?>[\s\S]*?<\/table>$/i.test(segment)) {
498
+ // 如果当前段是 <table> 标签,直接添加到 typedContent 中
499
+ this.typedContent += segment;
500
+ segmentIndex++;
501
+ processNextSegment();
502
+ } else {
503
+ i = 0;
504
+ const updateContent = () => {
505
+ if (i < segment.length) {
506
+ this.typedContent += segment.charAt(i);
507
+ i++;
508
+ // 使用 requestAnimationFrame 替代 setInterval,防止卡顿
509
+ requestAnimationFrame(updateContent);
510
+ } else {
511
+ segmentIndex++;
512
+ processNextSegment();
513
+ }
514
+ };
515
+ updateContent();
516
+ }
229
517
  };
230
- updateContent();
231
- }
232
- };
233
- processNextSegment();
234
- },
235
-
236
- lookImage(e) {
237
- let previewImageUrl = ""
238
- console.log('e.target', e.target)
239
- if (e.target.localName == 'img') {
240
- previewImageUrl = e.target.currentSrc;
241
- this.showPreview = true;
518
+ processNextSegment();
519
+ },
520
+
521
+ lookImage(e) {
522
+ let previewImageUrl = ""
523
+ console.log('e.target', e.target)
524
+ if (e.target.localName == 'img') {
525
+ previewImageUrl = e.target.currentSrc;
526
+ this.showPreview = true;
527
+ let richtext = JSON.parse(JSON.stringify(this.typedContent))
528
+ this.imgList = [];
529
+ richtext.replace(/<img [^>]*src=['"]([^'"]+)[^>]*>/g, (match, capture) => {
530
+ this.imgList.push(capture);
531
+ });
532
+ /*当前点击的图片作为第一个图片*/
533
+ let index = this.imgList.indexOf(previewImageUrl);
534
+ this.imgList.splice(index, 1);
535
+ this.imgList.unshift(previewImageUrl);
536
+ }
537
+
538
+ },
539
+ closeViewer() {
540
+ this.showPreview = false;
541
+ },
542
+ clickMarkDown(e) {
543
+ if (e.target.tagName == "A") {
544
+ window.open(e.target.href, "_blank")
545
+ e.stopPropagation()
546
+ e.preventDefault()
547
+ return false
548
+ }
549
+ },
550
+ closeThinkContent: _.debounce(function (that) {
551
+ if (that.thinkEnd && that.generatingThinkString == "" && !that.signSetFlag) {
552
+ that.showThink = false;
553
+ // 标识已经自动关闭过一次深度思考内容,不再影响手动打开的效果
554
+ that.signSetFlag = true;
555
+ }
556
+ }, 500),
557
+ parseCode(markDownText) {
558
+ const parser = new DOMParser();
559
+ const doc = parser.parseFromString(markDownText, 'text/html');
560
+ doc.querySelectorAll('pre code').forEach((block) => {
561
+ hljs.highlightBlock(block);
562
+ });
563
+ doc.querySelectorAll('a').forEach((block) => {
564
+ block.setAttribute('target', '_blank');
565
+ block.setAttribute('rel', 'noopener noreferrer');
566
+ });
567
+ let node = this.getLastNode(doc)
568
+ if (node && !this.isHistory) {
569
+ let loading = document.createElement('span')
570
+ loading.classList.add("loading-circle")
571
+ loading.id = "loading-circle"
572
+ this.removeLoadingNode()
573
+ node.appendChild(loading)
574
+ }
575
+ return doc.documentElement.outerHTML
576
+ },
577
+ removeLoadingNode() {
578
+ let old = document.getElementById("loading-circle")
579
+ if(old) old.remove()
580
+ },
581
+ getLastNode(node) {
582
+ let filterList = ["STRONG", "BR", "SPAN", "I", "EM", "B", "A"]
583
+ if(node.lastElementChild && !filterList.includes(node.lastElementChild.tagName)) {
584
+ return this.getLastNode(node.lastElementChild)
585
+ } else {
586
+ return node
587
+ }
588
+ },
589
+ appendCopyBtn() {
590
+ let doc = this.$refs.markDown.$el ? this.$refs.markDown.$el : this.$refs.markDown
591
+ let codeList = doc.querySelectorAll('pre code')
592
+ codeList.forEach(ele =>{
593
+ let list = ele.getElementsByClassName("code_copy_btn")
594
+ if(list.length == 0 && ele.classList.contains("hljs")) {
595
+ let text = ele.innerText
596
+ let btnId = uuidv4();
597
+ let copy = document.createElement('div')
598
+ copy.classList.add("code_copy_btn")
599
+ copy.setAttribute('id', btnId)
600
+ copy.style.display = 'flex'
601
+ let i = document.createElement('i')
602
+ i.classList.add("iconfont")
603
+ i.classList.add("guoran-tongyichicun-fuzhi")
604
+ let span = document.createElement('span')
605
+ span.innerText = this.$t("dragonCommon.copy")
606
+ copy.append(i)
607
+ copy.append(span)
608
+ copy.onclick = () =>{
609
+ let fn = () =>{
610
+ let id = copy.getAttribute("id")
611
+ copy.style.display = "none"
612
+ let cs = document.getElementById(id + "success")
613
+ if(cs) {
614
+ cs.style.display = "flex"
615
+ }
616
+ setTimeout(() =>{
617
+ cs && (cs.style.display = "none")
618
+ copy.style.display = "flex"
619
+ }, 2000)
620
+ }
621
+ if (navigator.clipboard) {
622
+ // 使用 Clipboard API 进行复制
623
+ navigator.clipboard.writeText(text).then(() => { fn()})
624
+ .catch((error) => {
625
+ // 如果 Clipboard API 失败,尝试使用传统方法
626
+ this.fallbackCopyTextToClipboard(text, fn, () =>{
627
+ this.$message.error(this.$t("dragonCommon.copyError"))
628
+ });
629
+ });
630
+ } else {
631
+ this.fallbackCopyTextToClipboard(text, fn, () =>{
632
+ this.$message.error(this.$t("dragonCommon.copyError"))
633
+ });
634
+ }
635
+ }
636
+ ele.append(copy)
637
+ let copySuccess = document.createElement('div')
638
+ copySuccess.classList.add("code_copy_btn")
639
+ copySuccess.setAttribute('id', btnId + 'success')
640
+ copySuccess.style.display = 'none'
641
+ let csI = document.createElement('i')
642
+ csI.classList.add("el-icon-check")
643
+ let csSpan = document.createElement('span')
644
+ csSpan.innerText = this.$t("dragonCommon.copySuccess")
645
+ copySuccess.append(csI)
646
+ copySuccess.append(csSpan)
647
+ ele.append(copySuccess)
648
+ }
649
+ })
650
+ },
651
+ fallbackCopyTextToClipboard(text, success, fail) {
652
+ // 创建一个临时的 input 元素
653
+ const textArea = document.createElement('textarea');
654
+ textArea.value = text;
655
+ // 使 textarea 不在屏幕上显示
656
+ textArea.style.position = 'fixed';
657
+ textArea.style.top = 0;
658
+ textArea.style.left = 0;
659
+ textArea.style.width = '2em';
660
+ textArea.style.height = '2em';
661
+ textArea.style.padding = 0;
662
+ textArea.style.border = 'none';
663
+ textArea.style.outline = 'none';
664
+ textArea.style.boxShadow = 'none';
665
+ textArea.style.background = 'transparent';
666
+
667
+ // 将 textarea 添加到文档中
668
+ document.body.appendChild(textArea);
669
+ textArea.focus();
670
+ textArea.select();
671
+
672
+ try {
673
+ // 执行复制命令
674
+ const successful = document.execCommand('copy');
675
+ if (successful) {
676
+ success()
677
+ } else {
678
+ fail()
679
+ }
680
+ } catch (err) {
681
+ fail()
682
+ }
683
+ // 移除临时的 textarea
684
+ document.body.removeChild(textArea);
685
+ },
686
+ },
687
+ beforeDestroy() {
688
+ if (this.eventSource) {
689
+ this.eventSource.close();
242
690
  }
243
- let richtext = JSON.parse(JSON.stringify(this.typedContent))
244
- this.imgList = [];
245
- richtext.replace(/<img [^>]*src=['"]([^'"]+)[^>]*>/g, (match, capture) => {
246
- this.imgList.push(capture);
247
- });
248
- /*当前点击的图片作为第一个图片*/
249
- let index = this.imgList.indexOf(previewImageUrl);
250
- this.imgList.splice(index, 1);
251
- this.imgList.unshift(previewImageUrl);
252
- },
253
- closeViewer() {
254
- this.showPreview = false;
255
- }
256
691
  }
257
- };
258
- </script>
259
-
260
- <style scoped lang="less">
261
- .mark_down {
692
+ };
693
+ </script>
694
+
695
+ <style scoped lang="less">
696
+ .blinking-cursor {
697
+ display: inline-block;
698
+ width: 2px;
699
+ height: 1em;
700
+ background-color: black;
701
+ animation: blink 1s steps(2, start) infinite;
702
+ }
703
+
704
+ @keyframes blink {
705
+ 0%, 100% {
706
+ opacity: 1;
707
+ }
708
+ 50% {
709
+ opacity: 0;
710
+ }
711
+ }
712
+ .think {
713
+ padding: 10px;
714
+ background: #f2f5ff;
715
+ border-radius: 8px;
716
+ margin-bottom: 12px;
717
+
718
+ .think_content {
719
+ height: auto;
720
+ white-space: pre-wrap;
721
+ transition: all 2s ease;
722
+
723
+ /deep/ br {
724
+ line-height: 10px !important;
725
+ }
726
+ }
727
+
728
+ .hide_think {
729
+ height: 0px;
730
+ overflow: hidden;
731
+ transition: all 2s ease;
732
+ }
733
+
734
+ .think_title {
735
+ width: 100%;
736
+ height: 20px;
737
+ display: flex;
738
+ align-items: center;
739
+ justify-content: space-between;
740
+ cursor: pointer;
741
+
742
+ .think_title_left {
743
+ display: flex;
744
+ align-items: center;
745
+
746
+ i {
747
+ font-size: 18px;
748
+ }
749
+
750
+ .guoran-icon-deepseek {
751
+ font-size: 18px;
752
+ }
753
+ }
754
+
755
+ .think_title_right {
756
+ font-size: 18px;
757
+ color: #366aff;
758
+ }
759
+
760
+ .hide_think_title {
761
+ transform: rotate(180deg);
762
+ }
763
+ }
764
+ }
765
+
766
+ .mark_down {
262
767
  line-height: 24px;
263
768
  overflow-x: auto;
769
+
770
+ /deep/code {
771
+ font-family: Microsoft Yahei, Helvetica Neue, Helvetica, Arial, sans-serif !important;
772
+ white-space: pre-wrap;
773
+ font-size: 16px;
774
+ position: relative;
775
+ .code_copy_btn {
776
+ position: absolute;
777
+ right: 10px;
778
+ top: 10px;
779
+ display: flex;
780
+ align-items: center;
781
+ padding: 3px 12px;
782
+ background: #EEF1FF;
783
+ cursor: pointer;
784
+ font-size: 14px;
785
+ border-radius: 25px;
786
+ i {
787
+ font-size: 14px;
788
+ margin-right: 6px;
789
+ }
790
+ }
791
+ }
792
+
793
+ /deep/ pre {
794
+ // code {
795
+ // background: #F3F3F3 !important;
796
+ // color: #444 !important;
797
+ // }
798
+ .language-undefined {
799
+ background: #FFFFFF;
800
+ color: #000;
801
+ }
802
+ }
803
+
264
804
  /deep/p {
265
- margin-bottom: 14px;
266
- font-size: 16px;
805
+ margin-bottom: 7px;
806
+ font-size: 16px;
267
807
  }
268
-
808
+
269
809
  /deep/p:only-child {
270
- margin: 0 !important;
810
+ margin: 0 !important;
271
811
  }
272
-
812
+
273
813
  /deep/p:last-child {
274
- margin-bottom: 0 !important;
814
+ margin-bottom: 0 !important;
275
815
  }
276
-
816
+
277
817
  /deep/ul {
278
- margin-bottom: 16px;
279
- list-style: disc;
280
- padding-left: 40px;
281
-
282
- li {
283
- margin: 7px 0 !important;
284
- font-size: 16px;
285
- // padding-left: 40px;
286
-
287
- }
818
+ margin-bottom: 7px;
819
+ list-style: disc;
820
+ padding-left: 40px;
821
+
822
+ li {
823
+ margin: 7px 0 !important;
824
+ font-size: 16px;
825
+ // padding-left: 40px;
826
+ }
288
827
  }
289
-
828
+
290
829
  /deep/ ol {
291
- list-style: auto;
292
- padding-left: 40px;
293
-
294
- li {
295
- margin: 7px 0 !important;
296
- font-size: 16px;
297
- // padding-left: 40px;
298
- }
830
+ list-style: auto;
831
+ padding-left: 40px;
832
+
833
+ li {
834
+ margin: 7px 0 !important;
835
+ font-size: 16px;
836
+ // padding-left: 40px;
837
+ }
299
838
  }
300
-
839
+
301
840
  /deep/img {
302
- max-width: 400px;
841
+ max-width: 400px;
303
842
  }
304
-
843
+
305
844
  /deep/h3,
306
845
  /deep/h2,
307
846
  /deep/h1,
308
847
  /deep/h4,
309
848
  /deep/h5,
310
849
  /deep/h6 {
311
- color: #000000;
312
- font-weight: 500;
313
- line-height: 26px;
850
+ color: #000000;
851
+ font-weight: 500;
852
+ line-height: 26px;
853
+ margin: 7px 0;
854
+ }
855
+
856
+ /deep/h6 {
857
+ font-size: 12px;
858
+ }
859
+
860
+ /deep/h5 {
861
+ font-size: 14px;
862
+ }
863
+
864
+ /deep/h4 {
865
+ font-size: 16px;
314
866
  }
315
-
867
+
316
868
  /deep/h3 {
317
- font-size: 20px;
869
+ font-size: 20px;
318
870
  }
319
-
871
+
320
872
  /deep/h2 {
321
- font-size: 22px;
873
+ font-size: 22px;
322
874
  }
323
-
875
+
324
876
  /deep/h1 {
325
- font-size: 24px;
877
+ font-size: 24px;
326
878
  }
327
-
328
- /deep/h3 {
329
- font-size: 20px;
879
+
880
+ // /deep/h3 {
881
+ // font-size: 20px;
882
+ // }
883
+
884
+ /deep/hr {
885
+ margin: 16px 0;
330
886
  }
331
-
332
887
 
333
888
  /deep/ table {
334
889
  border-spacing: 0;
@@ -337,6 +892,7 @@
337
892
  border: solid 1px #e0e6f7;
338
893
  min-width: 800px;
339
894
  overflow-x: auto;
895
+ margin: 16px 0;
340
896
  }
341
897
 
342
898
  /deep/ th {
@@ -354,5 +910,31 @@
354
910
  min-width: 100px;
355
911
  }
356
912
  }
913
+
914
+ /* 圆圈的样式 */
915
+ /deep/.loading-circle {
916
+ width: 8px;
917
+ height: 8px;
918
+ display: inline-block;
919
+ border-radius: 50%;
920
+ background-color: #366aff;
921
+ animation: loading 2s infinite ease-in-out;
922
+ margin: 0 8px;
923
+ /* 动画控制 */
924
+ }
925
+
926
+ /* 放大缩小的动画 */
927
+ @keyframes loading {
928
+
929
+ 0%,
930
+ 100% {
931
+ transform: scale(1);
932
+ /* 原始大小 */
933
+ }
934
+
935
+ 50% {
936
+ transform: scale(1.5);
937
+ /* 放大 */
938
+ }
939
+ }
357
940
  </style>
358
-
@@ -789,15 +789,6 @@ export default {
789
789
  // Math.hypot()计算参数的平方根
790
790
  return Math.hypot(stop.x - start.x, stop.y - start.y);
791
791
  },
792
- setupCanvas (canvas, width, height) {
793
- const dpr = 1;
794
- // const rect = canvas.getBoundingClientRect();
795
- canvas.width = width
796
- canvas.height = height
797
- const ctx = canvas.getContext('2d');
798
- ctx?.scale(dpr, dpr);
799
- return ctx;
800
- },
801
792
  changeScale (value) {
802
793
  if (value == 'zoom') {
803
794
  this.handScale = 'auto'
@@ -57,7 +57,10 @@
57
57
  "botService": "机器人",
58
58
  "willServeYou": "将为您服务",
59
59
  "check": "查看",
60
- "clickme": "点我"
60
+ "clickme": "点我",
61
+ "copyError": "无法复制到剪贴板!",
62
+ "copy": "复制",
63
+ "copySuccess": "已复制"
61
64
  },
62
65
  "common": {
63
66
  "submit": "提交",
@@ -57,7 +57,10 @@
57
57
  "botService": "Bot",
58
58
  "willServeYou": "will serve you",
59
59
  "check": "Check",
60
- "clickme": "Click me"
60
+ "clickme": "Click me",
61
+ "copyError": "Unable to copy to clipboard!",
62
+ "copy": "Copy",
63
+ "copySuccess": "Copied"
61
64
  },
62
65
  "common": {
63
66
  "submit": "Submit",