Commit d36fb269 authored by mhw's avatar mhw

预览调整

parent 87e04e1c
<!-- 答案内容预览 --> <!-- 答案内容预览 -->
<template> <template>
<vue-markdown :source="content" v-highlight class="markdown-body" :id="'myContainer'+index"> <vue-markdown :source="content" v-highlight class="markdown-body">
</vue-markdown> </vue-markdown>
</template> </template>
...@@ -15,9 +15,10 @@ export default { ...@@ -15,9 +15,10 @@ export default {
data () { data () {
return { return {
result: undefined result: undefined
}; };
}, },
props: ['content', 'index', 'isSuccess'], props: ['content'],
components: { VueMarkdown }, components: { VueMarkdown },
computed: {}, computed: {},
...@@ -40,15 +41,15 @@ export default { ...@@ -40,15 +41,15 @@ export default {
}, },
watch: { watch: {
'isSuccess' () {
if (this.isSuccess) {
const anchorTags = document.querySelectorAll(`#myContainer${this.index} a`);
this.preview(anchorTags)
}
}
}, },
methods: { methods: {
isSuccess () {
this.$nextTick(() => {
const anchorTags = Object.values(this.$el.getElementsByTagName('a'));
this.preview(anchorTags)
})
},
preview (anchorTags) { preview (anchorTags) {
let that = this let that = this
// 遍历并输出链接的 href 属性 // 遍历并输出链接的 href 属性
...@@ -65,7 +66,6 @@ export default { ...@@ -65,7 +66,6 @@ export default {
if (isFile) { // 判断可预览文件类型 if (isFile) { // 判断可预览文件类型
// 阻止默认点击事件 // 阻止默认点击事件
event.preventDefault(); event.preventDefault();
if (tagUrl.indexOf('https') !== -1) { if (tagUrl.indexOf('https') !== -1) {
url = tagUrl.replace(/^https:\/\/[^/]+\//, `https://${window.location.hostname}:${window.location.port}/`); url = tagUrl.replace(/^https:\/\/[^/]+\//, `https://${window.location.hostname}:${window.location.port}/`);
} else { } else {
...@@ -102,6 +102,7 @@ export default { ...@@ -102,6 +102,7 @@ export default {
} }
}) })
} }
} }
} }
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
<div class="box"> <div class="box">
<div class="contentBox" ref="contentBox" v-if="myHistory.length > 0"> <div class="contentBox" ref="contentBox" v-if="myHistory.length > 0">
<div v-for="(item, index) in myHistory" :key="index"> <div v-for=" item in myHistory" :key="item.id">
<div class="userBox"> <div class="userBox">
<div class="content"> <div class="content">
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
GPT GPT
</div> </div>
<div class="content"> <div class="content">
<contentView :content="item.answer" ref="contentView" :index="index" :isSuccess="isSuccess" /> <contentView :content="item.answer" :ref="'contentView'+item.id" />
</div> </div>
</div> </div>
...@@ -49,7 +49,6 @@ import contentView from '../contentView'; ...@@ -49,7 +49,6 @@ import contentView from '../contentView';
export default { export default {
data () { data () {
return { return {
isSuccess: false,
templateController: undefined, templateController: undefined,
isPromptTemplate: true, isPromptTemplate: true,
inputContent: null, inputContent: null,
...@@ -81,6 +80,7 @@ export default { ...@@ -81,6 +80,7 @@ export default {
// 移除监听事件 "share" // 移除监听事件 "share"
this.$bus.$off('isPromptTemplate') this.$bus.$off('isPromptTemplate')
}, },
methods: { methods: {
clear () { clear () {
...@@ -90,7 +90,6 @@ export default { ...@@ -90,7 +90,6 @@ export default {
this.myHistory = [] this.myHistory = []
}, },
submit () { submit () {
this.isSuccess = false
this.param.model_name = this.chatForm.model_name this.param.model_name = this.chatForm.model_name
this.param.temperature = this.chatForm.temperature this.param.temperature = this.chatForm.temperature
this.heistoryRotate = this.chatForm.heistoryRotate this.heistoryRotate = this.chatForm.heistoryRotate
...@@ -118,9 +117,11 @@ export default { ...@@ -118,9 +117,11 @@ export default {
'role': 'user', 'role': 'user',
'content': this.inputContent, 'content': this.inputContent,
'answer': '', 'answer': '',
'excludeReferenceAnswer': '' 'excludeReferenceAnswer': '',
'id': this.generateRandomString(8)
}) })
this.inputContent = null; this.inputContent = null;
this.myHistory.slice(0, -1).slice(-this.heistoryRotate).forEach((item) => { this.myHistory.slice(0, -1).slice(-this.heistoryRotate).forEach((item) => {
...@@ -128,14 +129,18 @@ export default { ...@@ -128,14 +129,18 @@ export default {
}) })
this.$emit('submit') this.$emit('submit')
let getData = new GetStreaming(apiUrl, this.param, this.onmessage, this.success) let getData = new GetStreaming(apiUrl, this.param, this.onmessage, this.setSuccess)
getData.initeventSource() getData.initeventSource()
}, },
success () { setSuccess () {
this.isSuccess = true this.$nextTick(() => {
let nowChat = this.myHistory[this.myHistory.length - 1]
this.$refs['contentView' + nowChat.id][0].isSuccess()
})
}, },
onmessage (data) { onmessage (data) {
console.log(data);
let nowChat = this.myHistory[this.myHistory.length - 1] let nowChat = this.myHistory[this.myHistory.length - 1]
if (this.chatForm.pattern === '通用智能问答') { if (this.chatForm.pattern === '通用智能问答') {
nowChat.answer += data nowChat.answer += data
...@@ -169,6 +174,20 @@ export default { ...@@ -169,6 +174,20 @@ export default {
this.$nextTick(() => { this.$nextTick(() => {
this.$refs.contentBox.scrollTo(0, this.$refs.contentBox.scrollHeight) this.$refs.contentBox.scrollTo(0, this.$refs.contentBox.scrollHeight)
}) })
},
generateRandomString (length) {
const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
const charactersLength = characters.length;
const randomValues = new Uint32Array(length);
crypto.getRandomValues(randomValues);
let result = '';
for (let i = 0; i < length; i++) {
result += characters.charAt(randomValues[i] % charactersLength);
}
return result;
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment