Skip to content

Commit eec3a21

Browse files
committed
营销:完善装修编辑器重置功能
1 parent 9128fa9 commit eec3a21

File tree

3 files changed

+51
-9
lines changed

3 files changed

+51
-9
lines changed

src/components/DiyEditor/index.vue

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,16 +102,16 @@
102102
<!-- 组件名称 -->
103103
<template #header>
104104
<div class="flex items-center gap-8px">
105-
<Icon :icon="selectedComponent.icon" color="gray" />
106-
<span>{{ selectedComponent.name }}</span>
105+
<Icon :icon="selectedComponent?.icon" color="gray" />
106+
<span>{{ selectedComponent?.name }}</span>
107107
</div>
108108
</template>
109109
<el-scrollbar
110110
class="m-[calc(0px-var(--el-card-padding))]"
111111
view-class="p-[var(--el-card-padding)] p-b-[calc(var(--el-card-padding)+var(--el-card-padding))] property"
112112
>
113113
<component
114-
:is="selectedComponent.id + 'Property'"
114+
:is="selectedComponent?.id + 'Property'"
115115
v-model="selectedComponent.property"
116116
/>
117117
</el-scrollbar>
@@ -306,9 +306,12 @@ const handleDeleteComponent = (index: number) => {
306306
307307
// 工具栏操作
308308
const emits = defineEmits(['reset', 'preview', 'save', 'update:modelValue'])
309+
310+
// 注入无感刷新页面函数
311+
const reload = inject<() => void>('reload')
309312
// 重置
310313
const handleReset = () => {
311-
message.warning('开发中~')
314+
if (reload) reload()
312315
emits('reset')
313316
}
314317
// 预览

src/layout/components/AppView.vue

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,17 @@ const getCaches = computed((): string[] => {
2020
})
2121
2222
const tagsView = computed(() => appStore.getTagsView)
23+
24+
//region 无感刷新
25+
const routerAlive = ref(true)
26+
// 无感刷新,防止出现页面闪烁白屏
27+
const reload = () => {
28+
routerAlive.value = false
29+
nextTick(() => (routerAlive.value = true))
30+
}
31+
// 为组件后代提供刷新方法
32+
provide('reload', reload)
33+
//endregion
2334
</script>
2435

2536
<template>
@@ -49,7 +60,7 @@ const tagsView = computed(() => appStore.getTagsView)
4960
}
5061
]"
5162
>
52-
<router-view>
63+
<router-view v-if="routerAlive">
5364
<template #default="{ Component, route }">
5465
<keep-alive :include="getCaches">
5566
<component :is="Component" :key="route.fullPath" />

src/views/mall/promotion/diy/template/decorate.vue

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
:show-tab-bar="selectedTemplateItem === 0"
99
:show-navigation-bar="selectedTemplateItem !== 0"
1010
@save="submitForm"
11+
@reset="handleEditorReset"
1112
>
1213
<template #toolBarLeft>
1314
<el-radio-group
@@ -29,6 +30,7 @@ import * as DiyTemplateApi from '@/api/mall/promotion/diy/template'
2930
import * as DiyPageApi from '@/api/mall/promotion/diy/page'
3031
import { useTagsViewStore } from '@/store/modules/tagsView'
3132
import { DiyComponentLibrary, PAGE_LIBS } from '@/components/DiyEditor/util'
33+
import { toNumber } from 'lodash-es'
3234
3335
/** 装修模板表单 */
3436
defineOptions({ name: 'DiyTemplateDecorate' })
@@ -115,17 +117,43 @@ const resetForm = () => {
115117
formRef.value?.resetFields()
116118
}
117119
120+
// 重置时记录当前编辑的页面
121+
const handleEditorReset = () => storePageIndex()
122+
123+
//#region 无感刷新
124+
// 记录标识
125+
const DIY_PAGE_INDEX_KEY = 'diy_page_index'
126+
// 1. 记录
127+
const storePageIndex = () =>
128+
sessionStorage.setItem(DIY_PAGE_INDEX_KEY, `${selectedTemplateItem.value}`)
129+
// 2. 恢复
130+
const recoverPageIndex = () => {
131+
// 恢复重置前的页面,默认是第一个页面
132+
const pageIndex = toNumber(sessionStorage.getItem(DIY_PAGE_INDEX_KEY)) || 0
133+
// 移除标记
134+
sessionStorage.removeItem(DIY_PAGE_INDEX_KEY)
135+
// 切换页面
136+
if (pageIndex !== selectedTemplateItem.value) {
137+
selectedTemplateItem.value = pageIndex
138+
handleTemplateItemChange()
139+
}
140+
}
141+
//#endregion
142+
118143
/** 初始化 **/
119144
const { currentRoute } = useRouter() // 路由
120145
const { delView } = useTagsViewStore() // 视图操作
121-
const route = useRoute()
122-
onMounted(() => {
146+
onMounted(async () => {
123147
resetForm()
124-
if (!route.params.id) {
148+
if (!currentRoute.value.params.id) {
125149
message.warning('参数错误,页面编号不能为空!')
126150
delView(unref(currentRoute))
127151
return
128152
}
129-
getPageDetail(route.params.id)
153+
154+
// 查询详情
155+
await getPageDetail(currentRoute.value.params.id)
156+
// 恢复重置前的页面
157+
recoverPageIndex()
130158
})
131159
</script>

0 commit comments

Comments
 (0)