【代码优化】AI:绘图 index.vue 代码梳理 50%(ImageDetail.vue)

pull/476/MERGE
YunaiV 2024-07-09 09:13:10 +08:00
parent 749e44081e
commit ac46a37638
3 changed files with 37 additions and 48 deletions

View File

@ -1,5 +1,5 @@
<template> <template>
<div ref="messageContainer" class="h-100% overflow-y relative"> <div ref="messageContainer" class="h-100% overflow-y-auto relative">
<div class="chat-list" v-for="(item, index) in list" :key="index"> <div class="chat-list" v-for="(item, index) in list" :key="index">
<!-- 靠左 messagesystemassistant 类型 --> <!-- 靠左 messagesystemassistant 类型 -->
<div class="left-message message-item" v-if="item.type !== 'user'"> <div class="left-message message-item" v-if="item.type !== 'user'">
@ -101,13 +101,12 @@ const emits = defineEmits(['onDeleteSuccess', 'onRefresh', 'onEdit']) // 定义
/** 滚动到底部 */ /** 滚动到底部 */
const scrollToBottom = async (isIgnore?: boolean) => { const scrollToBottom = async (isIgnore?: boolean) => {
// 使 nextTick dom // 使 nextTick dom
await nextTick(() => { await nextTick()
if (isIgnore || !isScrolling.value) { if (isIgnore || !isScrolling.value) {
messageContainer.value.scrollTop = messageContainer.value.scrollTop =
messageContainer.value.scrollHeight - messageContainer.value.offsetHeight messageContainer.value.scrollHeight - messageContainer.value.offsetHeight
} }
})
} }
function handleScroll() { function handleScroll() {

View File

@ -394,7 +394,6 @@ const doSendMessage = async (content: string) => {
} as ChatMessageVO) } as ChatMessageVO)
} }
// TODO @fan= =
/** 真正执行【发送】消息操作 */ /** 真正执行【发送】消息操作 */
const doSendMessageStream = async (userMessage: ChatMessageVO) => { const doSendMessageStream = async (userMessage: ChatMessageVO) => {
// AbortController 便 // AbortController 便
@ -421,9 +420,8 @@ const doSendMessageStream = async (userMessage: ChatMessageVO) => {
createTime: new Date() createTime: new Date()
} as ChatMessageVO) } as ChatMessageVO)
// 1.2 // 1.2
nextTick(async () => { await nextTick()
await scrollToBottom() // await scrollToBottom() //
})
// 1.3 // 1.3
textRoll() textRoll()

View File

@ -7,52 +7,49 @@
> >
<!-- 图片 --> <!-- 图片 -->
<div class="item"> <div class="item">
<!-- <div class="header">-->
<!-- <div>图片</div>-->
<!-- <div>-->
<!-- </div>-->
<!-- </div>-->
<div class="body"> <div class="body">
<!-- TODO @fan: 要不这里只展示图片不用 ImageCard --> <el-image
<ImageCard :image-detail="imageDetail" /> class="image"
:src="detail?.picUrl"
:preview-src-list="[detail.picUrl]"
preview-teleported
/>
</div> </div>
</div> </div>
<!-- 时间 --> <!-- 时间 -->
<div class="item"> <div class="item">
<div class="tip">时间</div> <div class="tip">时间</div>
<div class="body"> <div class="body">
<div>提交时间{{ imageDetail.createTime }}</div> <div>提交时间{{ detail.createTime }}</div>
<div>生成时间{{ imageDetail.finishTime }}</div> <div>生成时间{{ detail.finishTime }}</div>
</div> </div>
</div> </div>
<!-- 模型 --> <!-- 模型 -->
<div class="item"> <div class="item">
<div class="tip">模型</div> <div class="tip">模型</div>
<div class="body"> <div class="body"> {{ detail.model }}({{ detail.height }}x{{ detail.width }}) </div>
{{ imageDetail.model }}({{ imageDetail.height }}x{{ imageDetail.width }})
</div>
</div> </div>
<!-- 提示词 --> <!-- 提示词 -->
<div class="item"> <div class="item">
<div class="tip">提示词</div> <div class="tip">提示词</div>
<div class="body"> <div class="body">
{{ imageDetail.prompt }} {{ detail.prompt }}
</div> </div>
</div> </div>
<!-- 地址 --> <!-- 地址 -->
<div class="item"> <div class="item">
<div class="tip">图片地址</div> <div class="tip">图片地址</div>
<div class="body"> <div class="body">
{{ imageDetail.picUrl }} {{ detail.picUrl }}
</div> </div>
</div> </div>
<!-- 风格 --> <!-- 风格 -->
<div class="item" v-if="imageDetail?.options?.style"> <div class="item" v-if="detail?.options?.style">
<div class="tip">风格</div> <div class="tip">风格</div>
<div class="body"> <div class="body">
<!-- TODO @fan貌似需要把 imageStyleList 搞到 api/image/index.ts 枚举起来 --> <!-- TODO @fan貌似需要把 imageStyleList 搞到 api/image/index.ts 枚举起来 -->
<!-- TODO @fan这里的展示可能需要按照平台做区分 --> <!-- TODO @fan这里的展示可能需要按照平台做区分 -->
{{ imageDetail?.options?.style }} {{ detail?.options?.style }}
</div> </div>
</div> </div>
</el-drawer> </el-drawer>
@ -63,7 +60,7 @@ import { ImageApi, ImageVO } from '@/api/ai/image'
import ImageCard from './ImageCard.vue' import ImageCard from './ImageCard.vue'
const showDrawer = ref<boolean>(false) // const showDrawer = ref<boolean>(false) //
const imageDetail = ref<ImageVO>({} as ImageVO) // const detail = ref<ImageVO>({} as ImageVO) //
const props = defineProps({ const props = defineProps({
show: { show: {
@ -77,35 +74,30 @@ const props = defineProps({
} }
}) })
/** 抽屉 - close */ /** 关闭抽屉 */
const handleDrawerClose = async () => { const handleDrawerClose = async () => {
emits('handleDrawerClose') emits('handleDrawerClose')
} }
/** 获取 - 图片 detail */ /** 监听 drawer 是否打开 */
const getImageDetail = async (id) => {
//
imageDetail.value = await ImageApi.getImageMy(id)
}
/** 任务 - detail */
const handleTaskDetail = async () => {
showDrawer.value = true
}
// watch show
const { show } = toRefs(props) const { show } = toRefs(props)
watch(show, async (newValue, oldValue) => { watch(show, async (newValue, oldValue) => {
showDrawer.value = newValue as boolean showDrawer.value = newValue as boolean
}) })
// watch id
/** 获取图片详情 */
const getImageDetail = async (id: number) => {
detail.value = await ImageApi.getImageMy(id)
}
/** 监听 id 变化,加载最新图片详情 */
const { id } = toRefs(props) const { id } = toRefs(props)
watch(id, async (newVal, oldVal) => { watch(id, async (newVal, oldVal) => {
if (newVal) { if (newVal) {
await getImageDetail(newVal) await getImageDetail(newVal)
} }
}) })
//
const emits = defineEmits(['handleDrawerClose']) const emits = defineEmits(['handleDrawerClose'])
</script> </script>
<style scoped lang="scss"> <style scoped lang="scss">