营销:完善商城装修

1. 拆分页面设计用的属性修改接口
2. 增加模板的页面保存
3. 增加唯一名称校验
4. 增加页面编辑器,默认选中组件判断

(cherry picked from commit 881c4f3a29)
This commit is contained in:
owen 2023-10-31 16:01:22 +08:00 committed by shizhong
parent d172595f14
commit 97a94cd29f
5 changed files with 88 additions and 14 deletions

View File

@ -33,3 +33,13 @@ export const updateDiyPage = async (data: DiyPageVO) => {
export const deleteDiyPage = async (id: number) => { export const deleteDiyPage = async (id: number) => {
return await request.delete({ url: `/promotion/diy-page/delete?id=` + id }) return await request.delete({ url: `/promotion/diy-page/delete?id=` + id })
} }
// 获得装修页面属性
export const getDiyPageProperty = async (id: number) => {
return await request.get({ url: `/promotion/diy-page/get-property?id=` + id })
}
// 更新装修页面属性
export const updateDiyPageProperty = async (data: DiyPageVO) => {
return await request.put({ url: `/promotion/diy-page/update-property`, data })
}

View File

@ -1,4 +1,5 @@
import request from '@/config/axios' import request from '@/config/axios'
import { DiyPageVO } from '@/api/mall/promotion/diy/page'
export interface DiyTemplateVO { export interface DiyTemplateVO {
id?: number id?: number
@ -10,6 +11,10 @@ export interface DiyTemplateVO {
property: string property: string
} }
export interface DiyTemplatePropertyVO extends DiyTemplateVO {
pages: DiyPageVO[]
}
// 查询装修模板列表 // 查询装修模板列表
export const getDiyTemplatePage = async (params: any) => { export const getDiyTemplatePage = async (params: any) => {
return await request.get({ url: `/promotion/diy-template/page`, params }) return await request.get({ url: `/promotion/diy-template/page`, params })
@ -39,3 +44,15 @@ export const deleteDiyTemplate = async (id: number) => {
export const useDiyTemplate = async (id: number) => { export const useDiyTemplate = async (id: number) => {
return await request.put({ url: `/promotion/diy-template/use?id=` + id }) return await request.put({ url: `/promotion/diy-template/use?id=` + id })
} }
// 获得装修模板属性
export const getDiyTemplateProperty = async (id: number) => {
return await request.get<DiyTemplatePropertyVO>({
url: `/promotion/diy-template/get-property?id=` + id
})
}
// 更新装修模板属性
export const updateDiyTemplateProperty = async (data: DiyTemplateVO) => {
return await request.put({ url: `/promotion/diy-template/update-property`, data })
}

View File

@ -59,7 +59,7 @@
}" }"
> >
<draggable <draggable
class="drag-area page-prop-area" class="page-prop-area drag-area"
v-model="pageComponents" v-model="pageComponents"
item-key="index" item-key="index"
:animation="200" :animation="200"
@ -200,18 +200,25 @@ const navigationBarComponent = ref<DiyComponent<any>>(cloneDeep(NAVIGATION_BAR_C
const tabBarComponent = ref<DiyComponent<any>>(cloneDeep(TAB_BAR_COMPONENT)) const tabBarComponent = ref<DiyComponent<any>>(cloneDeep(TAB_BAR_COMPONENT))
// //
const selectedComponent = ref<DiyComponent<any>>(unref(pageConfigComponent)) const selectedComponent = ref<DiyComponent<any>>()
// //
const selectedComponentIndex = ref<number>(-1) const selectedComponentIndex = ref<number>(-1)
// //
const pageComponents = ref<DiyComponent<any>[]>([]) const pageComponents = ref<DiyComponent<any>[]>([])
// //
const props = defineProps<{ const props = defineProps<{
// Json
modelValue: string | PageConfig modelValue: string | PageConfig
//
title: string title: string
libs: DiyComponentLibrary[] // //
libs: DiyComponentLibrary[]
//
showNavigationBar: boolean showNavigationBar: boolean
//
showTabBar: boolean showTabBar: boolean
//
showPageConfig: boolean
}>() }>()
// //
@ -255,6 +262,8 @@ const handleSave = () => {
// //
const handlePageSelected = (event: any) => { const handlePageSelected = (event: any) => {
if (!props.showPageConfig) return
// page-prop-area // page-prop-area
if (includes(event?.target?.classList, 'page-prop-area')) { if (includes(event?.target?.classList, 'page-prop-area')) {
handleComponentSelected(unref(pageConfigComponent)) handleComponentSelected(unref(pageConfigComponent))
@ -351,6 +360,22 @@ const handlePreview = () => {
message.warning('开发中~') message.warning('开发中~')
emits('preview') emits('preview')
} }
//
const setDefaultSelectedComponent = () => {
if (props.showPageConfig) {
selectedComponent.value = unref(pageConfigComponent)
} else if (props.showNavigationBar) {
selectedComponent.value = unref(navigationBarComponent)
} else if (props.showTabBar) {
selectedComponent.value = unref(tabBarComponent)
}
}
watch(
() => [props.showPageConfig, props.showNavigationBar, props.showTabBar],
() => setDefaultSelectedComponent()
)
onMounted(() => setDefaultSelectedComponent())
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>
.editor { .editor {

View File

@ -4,6 +4,7 @@
v-model="formData.property" v-model="formData.property"
:title="formData.name" :title="formData.name"
:libs="componentLibs" :libs="componentLibs"
:show-page-config="true"
:show-navigation-bar="true" :show-navigation-bar="true"
:show-tab-bar="false" :show-tab-bar="false"
@save="submitForm" @save="submitForm"
@ -51,7 +52,7 @@ const formRef = ref() // 表单 Ref
const getPageDetail = async (id: any) => { const getPageDetail = async (id: any) => {
formLoading.value = true formLoading.value = true
try { try {
formData.value = await DiyPageApi.getDiyPage(id) formData.value = await DiyPageApi.getDiyPageProperty(id)
} finally { } finally {
formLoading.value = false formLoading.value = false
} }
@ -63,7 +64,7 @@ const submitForm = async () => {
// //
formLoading.value = true formLoading.value = true
try { try {
await DiyPageApi.updateDiyPage(unref(formData)!) await DiyPageApi.updateDiyPageProperty(unref(formData)!)
message.success('保存成功') message.success('保存成功')
} finally { } finally {
formLoading.value = false formLoading.value = false

View File

@ -1,11 +1,12 @@
<template> <template>
<DiyEditor <DiyEditor
v-if="formData && !formLoading" v-if="formData && !formLoading"
v-model="formData.property" v-model="currentFormData!.property"
:title="templateItems[selectedTemplateItem].name" :title="templateItems[selectedTemplateItem].name"
:libs="libs" :libs="libs"
:show-page-config="selectedTemplateItem !== 0"
:show-tab-bar="selectedTemplateItem === 0" :show-tab-bar="selectedTemplateItem === 0"
:show-navigation-bar="selectedTemplateItem > 0" :show-navigation-bar="selectedTemplateItem !== 0"
@save="submitForm" @save="submitForm"
> >
<template #toolBarLeft> <template #toolBarLeft>
@ -25,6 +26,7 @@
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import * as DiyTemplateApi from '@/api/mall/promotion/diy/template' 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 { useTagsViewStore } from '@/store/modules/tagsView'
import { DiyComponentLibrary } from '@/components/DiyEditor/util' import { DiyComponentLibrary } from '@/components/DiyEditor/util'
@ -42,14 +44,17 @@ const templateItems = reactive([
const message = useMessage() // const message = useMessage() //
const formLoading = ref(false) // 12 const formLoading = ref(false) // 12
const formData = ref<DiyTemplateApi.DiyTemplateVO>() const formData = ref<DiyTemplateApi.DiyTemplatePropertyVO>()
const formRef = ref() // Ref const formRef = ref() // Ref
//
const currentFormData = ref<DiyTemplateApi.DiyTemplatePropertyVO | DiyPageApi.DiyPageVO>()
// //
const getPageDetail = async (id: any) => { const getPageDetail = async (id: any) => {
formLoading.value = true formLoading.value = true
try { try {
formData.value = await DiyTemplateApi.getDiyTemplate(id) formData.value = await DiyTemplateApi.getDiyTemplateProperty(id)
currentFormData.value = formData.value
} finally { } finally {
formLoading.value = false formLoading.value = false
} }
@ -82,12 +87,21 @@ const pageLibs = [
] as DiyComponentLibrary[] ] as DiyComponentLibrary[]
// //
const libs = ref<DiyComponentLibrary[]>(templateLibs) const libs = ref<DiyComponentLibrary[]>(templateLibs)
//
const handleTemplateItemChange = () => { const handleTemplateItemChange = () => {
//
if (selectedTemplateItem.value === 0) { if (selectedTemplateItem.value === 0) {
libs.value = templateLibs libs.value = templateLibs
} else { currentFormData.value = formData.value
libs.value = pageLibs return
} }
//
libs.value = pageLibs
currentFormData.value = formData.value!.pages.find(
(page: DiyPageApi.DiyPageVO) => page.name === templateItems[selectedTemplateItem.value].name
)
console.log(currentFormData.value)
} }
// //
@ -97,7 +111,13 @@ const submitForm = async () => {
// //
formLoading.value = true formLoading.value = true
try { try {
await DiyTemplateApi.updateDiyTemplate(unref(formData)!) if (selectedTemplateItem.value === 0) {
//
await DiyTemplateApi.updateDiyTemplateProperty(unref(formData)!)
} else {
//
await DiyPageApi.updateDiyPageProperty(unref(currentFormData)!)
}
message.success('保存成功') message.success('保存成功')
} finally { } finally {
formLoading.value = false formLoading.value = false
@ -113,8 +133,9 @@ const resetForm = () => {
usedTime: undefined, usedTime: undefined,
remark: '', remark: '',
previewImageUrls: [], previewImageUrls: [],
property: '' property: '',
} as DiyTemplateApi.DiyTemplateVO pages: []
} as DiyTemplateApi.DiyTemplatePropertyVO
formRef.value?.resetFields() formRef.value?.resetFields()
} }