askbot-dragon 1.7.66-beta → 1.7.68-beta

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