feat: 对话,图片404 闪屏问题

This commit is contained in:
shaohuzhang1 2023-12-26 12:04:24 +08:00
parent a7704c3a8a
commit 1ecce3bc84
2 changed files with 40 additions and 2 deletions

View File

@ -63,7 +63,7 @@
</div>
<el-card v-else shadow="always" class="dialog-card">
<MdPreview ref="editorRef" editorId="preview-only" :modelValue="item.answer_text" />
<MdRenderer :source="item.answer_text"></MdRenderer>
</el-card>
<div class="flex-between mt-8" v-if="log">
<LogOperationButton :data="item" :applicationId="appId" />
@ -136,7 +136,7 @@ import { ChatManagement, type chatType } from '@/api/type/application'
import { randomId } from '@/utils/utils'
import useStore from '@/stores'
import { MdPreview } from 'md-editor-v3'
import MdRenderer from '@/components/markdown-renderer/MdRenderer.vue'
defineOptions({ name: 'AiChat' })
const route = useRoute()
const {

View File

@ -0,0 +1,38 @@
<template>
<MdPreview
ref="editorRef"
editorId="preview-only"
:modelValue="item"
v-for="item in md_view_list"
/>
</template>
<script setup lang="ts">
import { computed } from 'vue'
import { MdPreview } from 'md-editor-v3'
const props = withDefaults(defineProps<{ source?: string; inner_suffix?: boolean }>(), {
source: ''
})
const md_view_list = computed(() => {
const temp_source = props.source
const temp_md_img_list = temp_source.match(/(!\[.*?\]\(img\/.*?\){.*?})|(!\[.*?\]\(img\/.*?\))/g)
const md_img_list = temp_md_img_list ? temp_md_img_list.filter((i) => i) : []
const split_img_value = temp_source
.split(/(!\[.*?\]\(img\/.*?\){.*?})|(!\[.*?\]\(img\/.*?\))/g)
.filter((item) => item !== undefined)
.filter((item) => !md_img_list?.includes(item))
const result = Array.from(
{ length: md_img_list.length + split_img_value.length },
(v, i) => i
).map((index) => {
if (index % 2 == 0) {
return split_img_value[Math.floor(index / 2)]
} else {
return md_img_list[Math.floor(index / 2)]
}
})
return result
})
</script>
<style lang="scss" scoped></style>