askbot-dragon 88.0.43 → 88.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. package/npminstall-debug.log +208 -0
  2. package/package.json +14 -14
  3. package/public/index.html +2 -2
  4. package/src/assets/js/obsBrowser.js +3 -2
  5. package/src/components/ActionAlertIframe.vue +1 -0
  6. package/src/components/AiGuide.vue +1 -1
  7. package/src/components/AnswerDocknowledge.vue +167 -54
  8. package/src/components/ConversationContainer.vue +16 -9
  9. package/src/components/MyEditor.vue +1 -1
  10. package/src/components/QwFeedback.vue +2 -1
  11. package/src/components/actionSatisfaction.vue +2 -2
  12. package/src/components/answerRadio.vue +59 -4
  13. package/src/components/assetDetails.vue +1 -1
  14. package/src/components/assetMessage.vue +14 -13
  15. package/src/components/associationIntention.vue +2 -2
  16. package/src/components/fielListView.vue +1 -1
  17. package/src/components/formTemplate.vue +24 -3
  18. package/src/components/intelligentSummary.vue +15 -12
  19. package/src/components/kkview.vue +0 -10
  20. package/src/components/markDownText.vue +798 -55
  21. package/src/components/myPopup.vue +14 -11
  22. package/src/components/pagination.vue +129 -0
  23. package/src/components/pdfPosition.vue +67 -67
  24. package/src/components/popup.vue +8 -7
  25. package/src/components/preview/docView.vue +114 -0
  26. package/src/components/preview/excelView.vue +191 -0
  27. package/src/components/preview/newPositionPreview.vue +385 -0
  28. package/src/components/preview/pdfView.vue +824 -0
  29. package/src/components/previewDoc.vue +1 -0
  30. package/src/components/previewPdf.vue +343 -65
  31. package/src/components/receiverMessagePlatform.vue +24 -20
  32. package/src/components/senderMessagePlatform.vue +19 -11
  33. package/src/components/tree.vue +2 -2
  34. package/src/components/welcomeKnowledgeFile.vue +5 -2
  35. package/src/components/welcomeSuggest.vue +1 -1
  36. package/src/locales/cn.json +99 -0
  37. package/src/locales/en.json +99 -0
  38. package/src/main.js +19 -0
@@ -1,110 +1,808 @@
1
1
  <template>
2
2
  <div @click="lookImage">
3
- <vue-markdown class="mark_down" :source="typedContent" :ref="'markdown' + msgId">
4
- </vue-markdown>
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> -->
5
33
  <div v-if="showPreview">
6
34
  <img-view :url-list="imgList" @closeViewer="closeViewer"></img-view>
7
35
  </div>
8
36
  </div>
37
+
9
38
  </template>
10
39
 
11
40
  <script>
12
- import VueMarkdown from "vue-markdown";
13
- import ImgView from "./imgView.vue";
14
-
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")
15
49
  export default {
16
50
  name: "markDownText",
17
51
  data() {
18
52
  return {
53
+ eventSource: null,
54
+ plugins: [
55
+
56
+ ],
19
57
  typedContent: "",
20
58
  typingSpeed: 15,
21
59
  showPreview: false,
22
60
  imgList: [],
23
- };
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
+ }
24
78
  },
25
79
  props: {
26
80
  chainValues: {
27
81
  type: String,
28
- default: "",
82
+ default: ""
29
83
  },
30
84
  msgId: {
31
85
  type: String,
32
- default: "",
86
+ default: ""
33
87
  },
34
88
  isHistory: {
35
89
  type: Boolean,
36
- default: false,
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
37
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
+ }
38
129
  },
39
130
  components: {
40
131
  ImgView,
41
- VueMarkdown,
132
+ VueMarkdown
42
133
  },
43
134
  mounted() {
44
135
  this.$nextTick(() => {
45
- // let ref = 'markdown' + this.msgId
46
- // const el = this.$refs[ref].$el;
47
- // if (this.isHistory){
48
- // el.innerHTML = this.chainValues;
49
- // } else {
50
- // new Typed(el, {
51
- // strings: [this.chainValues],
52
- // typeSpeed: 30,
53
- // showCursor: false
54
- // })
55
- // }
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);
56
140
  if (this.isHistory) {
57
- this.typedContent = this.chainValues;
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
+ }
58
151
  } else {
59
- this.startTypingEffect();
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
+ }
60
168
  }
61
- });
169
+ })
62
170
  },
63
171
  methods: {
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;
274
+ }
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
+ }
428
+ }
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
+ }
442
+ }
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()
469
+ }, 20);
470
+ }
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
+ },
64
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;
65
489
  let i = 0;
66
- const interval = setInterval(() => {
67
- if (i < this.chainValues.length) {
68
- this.typedContent += this.chainValues.charAt(i);
69
- i++;
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();
70
502
  } else {
71
- clearInterval(interval);
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();
72
516
  }
73
- }, this.typingSpeed);
517
+ };
518
+ processNextSegment();
74
519
  },
520
+
75
521
  lookImage(e) {
76
- let previewImageUrl = "";
77
- console.log("e.target", e.target);
78
- if (e.target.localName == "img") {
522
+ let previewImageUrl = ""
523
+ console.log('e.target', e.target)
524
+ if (e.target.localName == 'img') {
79
525
  previewImageUrl = e.target.currentSrc;
80
526
  this.showPreview = true;
81
- }
82
- let richtext = JSON.parse(JSON.stringify(this.typedContent));
83
- this.imgList = [];
84
- richtext.replace(
85
- /<img [^>]*src=['"]([^'"]+)[^>]*>/g,
86
- (match, capture) => {
527
+ let richtext = JSON.parse(JSON.stringify(this.typedContent))
528
+ this.imgList = [];
529
+ richtext.replace(/<img [^>]*src=['"]([^'"]+)[^>]*>/g, (match, capture) => {
87
530
  this.imgList.push(capture);
88
- }
89
- );
90
- /*当前点击的图片作为第一个图片*/
91
- let index = this.imgList.indexOf(previewImageUrl);
92
- this.imgList.splice(index, 1);
93
- this.imgList.unshift(previewImageUrl);
531
+ });
532
+ /*当前点击的图片作为第一个图片*/
533
+ let index = this.imgList.indexOf(previewImageUrl);
534
+ this.imgList.splice(index, 1);
535
+ this.imgList.unshift(previewImageUrl);
536
+ }
537
+
94
538
  },
95
539
  closeViewer() {
96
540
  this.showPreview = false;
97
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
+ },
98
686
  },
687
+ beforeDestroy() {
688
+ if (this.eventSource) {
689
+ this.eventSource.close();
690
+ }
691
+ }
99
692
  };
100
693
  </script>
101
694
 
102
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
+
103
766
  .mark_down {
104
767
  line-height: 24px;
105
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
+
106
804
  /deep/p {
107
- margin-bottom: 14px;
805
+ margin-bottom: 7px;
108
806
  font-size: 16px;
109
807
  }
110
808
 
@@ -117,7 +815,7 @@ export default {
117
815
  }
118
816
 
119
817
  /deep/ul {
120
- margin-bottom: 16px;
818
+ margin-bottom: 7px;
121
819
  list-style: disc;
122
820
  padding-left: 16px;
123
821
 
@@ -125,7 +823,6 @@ export default {
125
823
  margin: 7px 0 !important;
126
824
  font-size: 16px;
127
825
  // padding-left: 40px;
128
-
129
826
  }
130
827
  }
131
828
 
@@ -153,6 +850,19 @@ export default {
153
850
  color: #000000;
154
851
  font-weight: 500;
155
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;
156
866
  }
157
867
 
158
868
  /deep/h3 {
@@ -167,8 +877,12 @@ export default {
167
877
  font-size: 24px;
168
878
  }
169
879
 
170
- /deep/h3 {
171
- font-size: 20px;
880
+ // /deep/h3 {
881
+ // font-size: 20px;
882
+ // }
883
+
884
+ /deep/hr {
885
+ margin: 16px 0;
172
886
  }
173
887
 
174
888
  /deep/ table {
@@ -178,20 +892,49 @@ export default {
178
892
  border: solid 1px #e0e6f7;
179
893
  min-width: 800px;
180
894
  overflow-x: auto;
895
+ margin: 16px 0;
181
896
  }
897
+
182
898
  /deep/ th {
183
899
  background: #EEF1FF;
184
900
  border: solid 1px #e0e6f7;
185
- padding: 10px;
186
- height: 60px;
901
+ padding: 8px;
902
+ height: 38px;
187
903
  min-width: 100px;
188
904
  }
189
905
 
190
906
  /deep/ td {
191
907
  border: solid 1px #e0e6f7;
192
- padding: 10px;
193
- height: 48px;
908
+ padding: 8px;
909
+ height: 28px;
194
910
  min-width: 100px;
195
911
  }
196
912
  }
197
- </style>
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
+ }
940
+ </style>