营销:完善装修编辑器重置功能

This commit is contained in:
owen 2023-12-07 16:25:15 +08:00
parent 9128fa98f5
commit eec3a21852
3 changed files with 51 additions and 9 deletions

View File

@ -102,8 +102,8 @@
<!-- 组件名称 --> <!-- 组件名称 -->
<template #header> <template #header>
<div class="flex items-center gap-8px"> <div class="flex items-center gap-8px">
<Icon :icon="selectedComponent.icon" color="gray" /> <Icon :icon="selectedComponent?.icon" color="gray" />
<span>{{ selectedComponent.name }}</span> <span>{{ selectedComponent?.name }}</span>
</div> </div>
</template> </template>
<el-scrollbar <el-scrollbar
@ -111,7 +111,7 @@
view-class="p-[var(--el-card-padding)] p-b-[calc(var(--el-card-padding)+var(--el-card-padding))] property" view-class="p-[var(--el-card-padding)] p-b-[calc(var(--el-card-padding)+var(--el-card-padding))] property"
> >
<component <component
:is="selectedComponent.id + 'Property'" :is="selectedComponent?.id + 'Property'"
v-model="selectedComponent.property" v-model="selectedComponent.property"
/> />
</el-scrollbar> </el-scrollbar>
@ -306,9 +306,12 @@ const handleDeleteComponent = (index: number) => {
// //
const emits = defineEmits(['reset', 'preview', 'save', 'update:modelValue']) const emits = defineEmits(['reset', 'preview', 'save', 'update:modelValue'])
//
const reload = inject<() => void>('reload')
// //
const handleReset = () => { const handleReset = () => {
message.warning('开发中~') if (reload) reload()
emits('reset') emits('reset')
} }
// //

View File

@ -20,6 +20,17 @@ const getCaches = computed((): string[] => {
}) })
const tagsView = computed(() => appStore.getTagsView) const tagsView = computed(() => appStore.getTagsView)
//region
const routerAlive = ref(true)
//
const reload = () => {
routerAlive.value = false
nextTick(() => (routerAlive.value = true))
}
//
provide('reload', reload)
//endregion
</script> </script>
<template> <template>
@ -49,7 +60,7 @@ const tagsView = computed(() => appStore.getTagsView)
} }
]" ]"
> >
<router-view> <router-view v-if="routerAlive">
<template #default="{ Component, route }"> <template #default="{ Component, route }">
<keep-alive :include="getCaches"> <keep-alive :include="getCaches">
<component :is="Component" :key="route.fullPath" /> <component :is="Component" :key="route.fullPath" />

View File

@ -8,6 +8,7 @@
:show-tab-bar="selectedTemplateItem === 0" :show-tab-bar="selectedTemplateItem === 0"
:show-navigation-bar="selectedTemplateItem !== 0" :show-navigation-bar="selectedTemplateItem !== 0"
@save="submitForm" @save="submitForm"
@reset="handleEditorReset"
> >
<template #toolBarLeft> <template #toolBarLeft>
<el-radio-group <el-radio-group
@ -29,6 +30,7 @@ import * as DiyTemplateApi from '@/api/mall/promotion/diy/template'
import * as DiyPageApi from '@/api/mall/promotion/diy/page' import * as DiyPageApi from '@/api/mall/promotion/diy/page'
import { useTagsViewStore } from '@/store/modules/tagsView' import { useTagsViewStore } from '@/store/modules/tagsView'
import { DiyComponentLibrary, PAGE_LIBS } from '@/components/DiyEditor/util' import { DiyComponentLibrary, PAGE_LIBS } from '@/components/DiyEditor/util'
import { toNumber } from 'lodash-es'
/** 装修模板表单 */ /** 装修模板表单 */
defineOptions({ name: 'DiyTemplateDecorate' }) defineOptions({ name: 'DiyTemplateDecorate' })
@ -115,17 +117,43 @@ const resetForm = () => {
formRef.value?.resetFields() formRef.value?.resetFields()
} }
//
const handleEditorReset = () => storePageIndex()
//#region
//
const DIY_PAGE_INDEX_KEY = 'diy_page_index'
// 1.
const storePageIndex = () =>
sessionStorage.setItem(DIY_PAGE_INDEX_KEY, `${selectedTemplateItem.value}`)
// 2.
const recoverPageIndex = () => {
//
const pageIndex = toNumber(sessionStorage.getItem(DIY_PAGE_INDEX_KEY)) || 0
//
sessionStorage.removeItem(DIY_PAGE_INDEX_KEY)
//
if (pageIndex !== selectedTemplateItem.value) {
selectedTemplateItem.value = pageIndex
handleTemplateItemChange()
}
}
//#endregion
/** 初始化 **/ /** 初始化 **/
const { currentRoute } = useRouter() // const { currentRoute } = useRouter() //
const { delView } = useTagsViewStore() // const { delView } = useTagsViewStore() //
const route = useRoute() onMounted(async () => {
onMounted(() => {
resetForm() resetForm()
if (!route.params.id) { if (!currentRoute.value.params.id) {
message.warning('参数错误,页面编号不能为空!') message.warning('参数错误,页面编号不能为空!')
delView(unref(currentRoute)) delView(unref(currentRoute))
return return
} }
getPageDetail(route.params.id)
//
await getPageDetail(currentRoute.value.params.id)
//
recoverPageIndex()
}) })
</script> </script>