营销:完善商城装修
1. 拆分页面设计用的属性修改接口 2. 增加模板的页面保存 3. 增加唯一名称校验 4. 增加页面编辑器,默认选中组件判断
This commit is contained in:
parent
c1534bf168
commit
881c4f3a29
@ -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 })
|
||||||
|
}
|
||||||
|
@ -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 })
|
||||||
|
}
|
||||||
|
@ -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 {
|
||||||
|
@ -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
|
||||||
|
@ -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) // 表单的加载中:1)修改时的数据加载;2)提交的按钮禁用
|
const formLoading = ref(false) // 表单的加载中:1)修改时的数据加载;2)提交的按钮禁用
|
||||||
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()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user