Commit 3cf73794 by lijiabin

【需求 25171】fix: 编辑文章时抽屉表单未渲染导致回显丢失,改为子表单挂载后再回填

parent 0a5e9a57
...@@ -128,6 +128,7 @@ import WangEditor from '@/components/common/WangEditor/index.vue' ...@@ -128,6 +128,7 @@ import WangEditor from '@/components/common/WangEditor/index.vue'
import { ArticleTypeEnum, ReleaseStatusTypeEnum, articleTypeListOptions } from '@/constants' import { ArticleTypeEnum, ReleaseStatusTypeEnum, articleTypeListOptions } from '@/constants'
import { useResetData } from '@/hooks' import { useResetData } from '@/hooks'
import { addOrUpdateArticle, addOrUpdatePractice, getArticleDetail } from '@/api' import { addOrUpdateArticle, addOrUpdatePractice, getArticleDetail } from '@/api'
import type { ArticleItemDto } from '@/api'
import { useRouter, useRoute } from 'vue-router' import { useRouter, useRoute } from 'vue-router'
import { push } from 'notivue' import { push } from 'notivue'
import BackButton from '@/components/common/BackButton/index.vue' import BackButton from '@/components/common/BackButton/index.vue'
...@@ -162,6 +163,16 @@ const [sharedForm, resetSharedForm] = useResetData({ ...@@ -162,6 +163,16 @@ const [sharedForm, resetSharedForm] = useResetData({
// 每个类型自己的表单组件,字段/校验/提交数据都在对应组件里,这里只认 ArticleTypeFormExpose 这个接口 // 每个类型自己的表单组件,字段/校验/提交数据都在对应组件里,这里只认 ArticleTypeFormExpose 这个接口
const subFormRef = useTemplateRef<ArticleTypeFormExpose>('subFormRef') const subFormRef = useTemplateRef<ArticleTypeFormExpose>('subFormRef')
// el-drawer 的内容要第一次打开时才会渲染,编辑回显时子表单可能还没挂载(subFormRef 是 null),
// 直接 setEchoData 会被静默跳过。先把详情存着,等子表单挂载出来再回填
let pendingEchoData: ArticleItemDto | null = null
watch(subFormRef, (form) => {
if (form && pendingEchoData) {
form.setEchoData(pendingEchoData)
pendingEchoData = null
}
})
// 打开抽屉 // 打开抽屉
const openDrawer = () => { const openDrawer = () => {
drawerVisible.value = true drawerVisible.value = true
...@@ -220,6 +231,7 @@ onActivated(async () => { ...@@ -220,6 +231,7 @@ onActivated(async () => {
editorKey.value++ editorKey.value++
resetSharedForm() resetSharedForm()
subFormRef.value?.reset() subFormRef.value?.reset()
pendingEchoData = null
await nextTick() await nextTick()
if (!isEdit.value) return if (!isEdit.value) return
...@@ -232,7 +244,11 @@ onActivated(async () => { ...@@ -232,7 +244,11 @@ onActivated(async () => {
title: data.title, title: data.title,
content: data.content, content: data.content,
} }
subFormRef.value?.setEchoData(data) if (subFormRef.value) {
subFormRef.value.setEchoData(data)
} else {
pendingEchoData = data
}
}) })
</script> </script>
......
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