Commit d36fb269 authored by mhw's avatar mhw

预览调整

parent 87e04e1c
<!-- 答案内容预览 -->
<template>
<vue-markdown :source="content" v-highlight class="markdown-body" :id="'myContainer'+index">
<vue-markdown :source="content" v-highlight class="markdown-body">
</vue-markdown>
</template>
......@@ -15,9 +15,10 @@ export default {
data () {
return {
result: undefined
};
},
props: ['content', 'index', 'isSuccess'],
props: ['content'],
components: { VueMarkdown },
computed: {},
......@@ -40,15 +41,15 @@ export default {
},
watch: {
'isSuccess' () {
if (this.isSuccess) {
const anchorTags = document.querySelectorAll(`#myContainer${this.index} a`);
this.preview(anchorTags)
}
}
},
methods: {
isSuccess () {
this.$nextTick(() => {
const anchorTags = Object.values(this.$el.getElementsByTagName('a'));
this.preview(anchorTags)
})
},
preview (anchorTags) {
let that = this
// 遍历并输出链接的 href 属性
......@@ -65,7 +66,6 @@ export default {
if (isFile) { // 判断可预览文件类型
// 阻止默认点击事件
event.preventDefault();
if (tagUrl.indexOf('https') !== -1) {
url = tagUrl.replace(/^https:\/\/[^/]+\//, `https://${window.location.hostname}:${window.location.port}/`);
} else {
......@@ -102,6 +102,7 @@ export default {
}
})
}
}
}
......
......@@ -3,7 +3,7 @@
<div class="box">
<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="content">
......@@ -18,7 +18,7 @@
GPT
</div>
<div class="content">
<contentView :content="item.answer" ref="contentView" :index="index" :isSuccess="isSuccess" />
<contentView :content="item.answer" :ref="'contentView'+item.id" />
</div>
</div>
......@@ -49,7 +49,6 @@ import contentView from '../contentView';
export default {
data () {
return {
isSuccess: false,
templateController: undefined,
isPromptTemplate: true,
inputContent: null,
......@@ -81,6 +80,7 @@ export default {
// 移除监听事件 "share"
this.$bus.$off('isPromptTemplate')
},
methods: {
clear () {
......@@ -90,7 +90,6 @@ export default {
this.myHistory = []
},
submit () {
this.isSuccess = false
this.param.model_name = this.chatForm.model_name
this.param.temperature = this.chatForm.temperature
this.heistoryRotate = this.chatForm.heistoryRotate
......@@ -118,9 +117,11 @@ export default {
'role': 'user',
'content': this.inputContent,
'answer': '',
'excludeReferenceAnswer': ''
'excludeReferenceAnswer': '',
'id': this.generateRandomString(8)
})
this.inputContent = null;
this.myHistory.slice(0, -1).slice(-this.heistoryRotate).forEach((item) => {
......@@ -128,14 +129,18 @@ export default {
})
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()
},
success () {
this.isSuccess = true
setSuccess () {
this.$nextTick(() => {
let nowChat = this.myHistory[this.myHistory.length - 1]
this.$refs['contentView' + nowChat.id][0].isSuccess()
})
},
onmessage (data) {
console.log(data);
let nowChat = this.myHistory[this.myHistory.length - 1]
if (this.chatForm.pattern === '通用智能问答') {
nowChat.answer += data
......@@ -169,6 +174,20 @@ export default {
this.$nextTick(() => {
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