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

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>
<div class="flex items-center gap-8px">
<Icon :icon="selectedComponent.icon" color="gray" />
<span>{{ selectedComponent.name }}</span>
<Icon :icon="selectedComponent?.icon" color="gray" />
<span>{{ selectedComponent?.name }}</span>
</div>
</template>
<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"
>
<component
:is="selectedComponent.id + 'Property'"
:is="selectedComponent?.id + 'Property'"
v-model="selectedComponent.property"
/>
</el-scrollbar>
@ -306,9 +306,12 @@ const handleDeleteComponent = (index: number) => {
//
const emits = defineEmits(['reset', 'preview', 'save', 'update:modelValue'])
//
const reload = inject<() => void>('reload')
//
const handleReset = () => {
message.warning('开发中~')
if (reload) reload()
emits('reset')
}
//

View File

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

View File

@ -8,6 +8,7 @@
:show-tab-bar="selectedTemplateItem === 0"
:show-navigation-bar="selectedTemplateItem !== 0"
@save="submitForm"
@reset="handleEditorReset"
>
<template #toolBarLeft>
<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 { useTagsViewStore } from '@/store/modules/tagsView'
import { DiyComponentLibrary, PAGE_LIBS } from '@/components/DiyEditor/util'
import { toNumber } from 'lodash-es'
/** 装修模板表单 */
defineOptions({ name: 'DiyTemplateDecorate' })
@ -115,17 +117,43 @@ const resetForm = () => {
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 { delView } = useTagsViewStore() //
const route = useRoute()
onMounted(() => {
onMounted(async () => {
resetForm()
if (!route.params.id) {
if (!currentRoute.value.params.id) {
message.warning('参数错误,页面编号不能为空!')
delView(unref(currentRoute))
return
}
getPageDetail(route.params.id)
//
await getPageDetail(currentRoute.value.params.id)
//
recoverPageIndex()
})
</script>