[代码优化]AI: 回显写作类型切换之前的数据

pull/482/head
hhhero 2024-07-13 08:50:30 +08:00
parent bb17651915
commit d266b99e9e
1 changed files with 14 additions and 6 deletions

View File

@ -27,12 +27,12 @@
<div class="flex flex-col" v-bind="$attrs"> <div class="flex flex-col" v-bind="$attrs">
<!-- tab --> <!-- tab -->
<div class="w-full pt-2 bg-[#f5f7f9] flex justify-center"> <div class="w-full pt-2 bg-[#f5f7f9] flex justify-center">
<div <div class="w-[303px] rounded-full bg-[#DDDFE3] p-1 z-10">
class="w-[303px] rounded-full bg-[#DDDFE3] p-1 z-10"
>
<div <div
class="flex items-center relative after:content-[''] after:block after:bg-white after:h-[30px] after:w-1/2 after:absolute after:top-0 after:left-0 after:transition-transform after:rounded-full" class="flex items-center relative after:content-[''] after:block after:bg-white after:h-[30px] after:w-1/2 after:absolute after:top-0 after:left-0 after:transition-transform after:rounded-full"
:class="selectedTab === AiWriteTypeEnum.REPLY && 'after:transform after:translate-x-[100%]'" :class="
selectedTab === AiWriteTypeEnum.REPLY && 'after:transform after:translate-x-[100%]'
"
> >
<ReuseTab <ReuseTab
v-for="tab in tabs" v-for="tab in tabs"
@ -179,10 +179,18 @@ const initData: WriteVO = {
} }
const formData = ref<WriteVO>({ ...initData }) const formData = ref<WriteVO>({ ...initData })
/** 用来记录切换之前所填写的数据,切换的时候给赋值回来 **/
const recordFormData = {} as Record<AiWriteTypeEnum, WriteVO>
/** 切换tab **/ /** 切换tab **/
const switchTab = (value: TabType) => { const switchTab = (value: TabType) => {
selectedTab.value = value if (value !== selectedTab.value) {
formData.value = { ...initData } //
recordFormData[selectedTab.value] = formData.value
selectedTab.value = value
//
formData.value = { ...initData, ...recordFormData[value] }
}
} }
/** 提交写作 */ /** 提交写作 */