营销:完善商城装修
1. 拆分页面设计用的属性修改接口
2. 增加模板的页面保存
3. 增加唯一名称校验
4. 增加页面编辑器,默认选中组件判断
(cherry picked from commit 881c4f3a29
)
This commit is contained in:
parent
d172595f14
commit
97a94cd29f
@ -33,3 +33,13 @@ export const updateDiyPage = async (data: DiyPageVO) => {
|
||||
export const deleteDiyPage = async (id: number) => {
|
||||
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 })
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
import request from '@/config/axios'
|
||||
import { DiyPageVO } from '@/api/mall/promotion/diy/page'
|
||||
|
||||
export interface DiyTemplateVO {
|
||||
id?: number
|
||||
@ -10,6 +11,10 @@ export interface DiyTemplateVO {
|
||||
property: string
|
||||
}
|
||||
|
||||
export interface DiyTemplatePropertyVO extends DiyTemplateVO {
|
||||
pages: DiyPageVO[]
|
||||
}
|
||||
|
||||
// 查询装修模板列表
|
||||
export const getDiyTemplatePage = async (params: any) => {
|
||||
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) => {
|
||||
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 })
|
||||
}
|
||||
|
@ -59,7 +59,7 @@
|
||||
}"
|
||||
>
|
||||
<draggable
|
||||
class="drag-area page-prop-area"
|
||||
class="page-prop-area drag-area"
|
||||
v-model="pageComponents"
|
||||
item-key="index"
|
||||
: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 selectedComponent = ref<DiyComponent<any>>(unref(pageConfigComponent))
|
||||
const selectedComponent = ref<DiyComponent<any>>()
|
||||
// 选中的组件索引
|
||||
const selectedComponentIndex = ref<number>(-1)
|
||||
// 组件列表
|
||||
const pageComponents = ref<DiyComponent<any>[]>([])
|
||||
// 定义属性
|
||||
const props = defineProps<{
|
||||
// 页面配置,支持Json字符串
|
||||
modelValue: string | PageConfig
|
||||
// 标题
|
||||
title: string
|
||||
libs: DiyComponentLibrary[] // 组件库
|
||||
// 组件库
|
||||
libs: DiyComponentLibrary[]
|
||||
// 是否显示顶部导航栏
|
||||
showNavigationBar: boolean
|
||||
// 是否显示底部导航菜单
|
||||
showTabBar: boolean
|
||||
// 是否显示页面配置
|
||||
showPageConfig: boolean
|
||||
}>()
|
||||
|
||||
// 监听传入的页面配置
|
||||
@ -255,6 +262,8 @@ const handleSave = () => {
|
||||
|
||||
// 处理页面选中:显示属性表单
|
||||
const handlePageSelected = (event: any) => {
|
||||
if (!props.showPageConfig) return
|
||||
|
||||
// 配置了样式 page-prop-area 的元素,才显示页面设置
|
||||
if (includes(event?.target?.classList, 'page-prop-area')) {
|
||||
handleComponentSelected(unref(pageConfigComponent))
|
||||
@ -351,6 +360,22 @@ const handlePreview = () => {
|
||||
message.warning('开发中~')
|
||||
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>
|
||||
<style lang="scss" scoped>
|
||||
.editor {
|
||||
|
@ -4,6 +4,7 @@
|
||||
v-model="formData.property"
|
||||
:title="formData.name"
|
||||
:libs="componentLibs"
|
||||
:show-page-config="true"
|
||||
:show-navigation-bar="true"
|
||||
:show-tab-bar="false"
|
||||
@save="submitForm"
|
||||
@ -51,7 +52,7 @@ const formRef = ref() // 表单 Ref
|
||||
const getPageDetail = async (id: any) => {
|
||||
formLoading.value = true
|
||||
try {
|
||||
formData.value = await DiyPageApi.getDiyPage(id)
|
||||
formData.value = await DiyPageApi.getDiyPageProperty(id)
|
||||
} finally {
|
||||
formLoading.value = false
|
||||
}
|
||||
@ -63,7 +64,7 @@ const submitForm = async () => {
|
||||
// 提交请求
|
||||
formLoading.value = true
|
||||
try {
|
||||
await DiyPageApi.updateDiyPage(unref(formData)!)
|
||||
await DiyPageApi.updateDiyPageProperty(unref(formData)!)
|
||||
message.success('保存成功')
|
||||
} finally {
|
||||
formLoading.value = false
|
||||
|
@ -1,11 +1,12 @@
|
||||
<template>
|
||||
<DiyEditor
|
||||
v-if="formData && !formLoading"
|
||||
v-model="formData.property"
|
||||
v-model="currentFormData!.property"
|
||||
:title="templateItems[selectedTemplateItem].name"
|
||||
:libs="libs"
|
||||
:show-page-config="selectedTemplateItem !== 0"
|
||||
:show-tab-bar="selectedTemplateItem === 0"
|
||||
:show-navigation-bar="selectedTemplateItem > 0"
|
||||
:show-navigation-bar="selectedTemplateItem !== 0"
|
||||
@save="submitForm"
|
||||
>
|
||||
<template #toolBarLeft>
|
||||
@ -25,6 +26,7 @@
|
||||
</template>
|
||||
<script setup lang="ts">
|
||||
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 } from '@/components/DiyEditor/util'
|
||||
|
||||
@ -42,14 +44,17 @@ const templateItems = reactive([
|
||||
const message = useMessage() // 消息弹窗
|
||||
|
||||
const formLoading = ref(false) // 表单的加载中:1)修改时的数据加载;2)提交的按钮禁用
|
||||
const formData = ref<DiyTemplateApi.DiyTemplateVO>()
|
||||
const formData = ref<DiyTemplateApi.DiyTemplatePropertyVO>()
|
||||
const formRef = ref() // 表单 Ref
|
||||
// 当前编辑的属性
|
||||
const currentFormData = ref<DiyTemplateApi.DiyTemplatePropertyVO | DiyPageApi.DiyPageVO>()
|
||||
|
||||
// 获取详情
|
||||
const getPageDetail = async (id: any) => {
|
||||
formLoading.value = true
|
||||
try {
|
||||
formData.value = await DiyTemplateApi.getDiyTemplate(id)
|
||||
formData.value = await DiyTemplateApi.getDiyTemplateProperty(id)
|
||||
currentFormData.value = formData.value
|
||||
} finally {
|
||||
formLoading.value = false
|
||||
}
|
||||
@ -82,12 +87,21 @@ const pageLibs = [
|
||||
] as DiyComponentLibrary[]
|
||||
// 当前组件库
|
||||
const libs = ref<DiyComponentLibrary[]>(templateLibs)
|
||||
// 模板选项切换
|
||||
const handleTemplateItemChange = () => {
|
||||
// 编辑模板
|
||||
if (selectedTemplateItem.value === 0) {
|
||||
libs.value = templateLibs
|
||||
} else {
|
||||
libs.value = pageLibs
|
||||
currentFormData.value = formData.value
|
||||
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
|
||||
try {
|
||||
await DiyTemplateApi.updateDiyTemplate(unref(formData)!)
|
||||
if (selectedTemplateItem.value === 0) {
|
||||
// 提交模板属性
|
||||
await DiyTemplateApi.updateDiyTemplateProperty(unref(formData)!)
|
||||
} else {
|
||||
// 提交页面属性
|
||||
await DiyPageApi.updateDiyPageProperty(unref(currentFormData)!)
|
||||
}
|
||||
message.success('保存成功')
|
||||
} finally {
|
||||
formLoading.value = false
|
||||
@ -113,8 +133,9 @@ const resetForm = () => {
|
||||
usedTime: undefined,
|
||||
remark: '',
|
||||
previewImageUrls: [],
|
||||
property: ''
|
||||
} as DiyTemplateApi.DiyTemplateVO
|
||||
property: '',
|
||||
pages: []
|
||||
} as DiyTemplateApi.DiyTemplatePropertyVO
|
||||
formRef.value?.resetFields()
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user