diff --git a/src/api/mall/promotion/diy/page.ts b/src/api/mall/promotion/diy/page.ts index 255015d2..1cd34282 100644 --- a/src/api/mall/promotion/diy/page.ts +++ b/src/api/mall/promotion/diy/page.ts @@ -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 }) +} diff --git a/src/api/mall/promotion/diy/template.ts b/src/api/mall/promotion/diy/template.ts index 72eea41c..f8d4bc80 100644 --- a/src/api/mall/promotion/diy/template.ts +++ b/src/api/mall/promotion/diy/template.ts @@ -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({ + 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 }) +} diff --git a/src/components/DiyEditor/index.vue b/src/components/DiyEditor/index.vue index 520cd497..f0fed316 100644 --- a/src/components/DiyEditor/index.vue +++ b/src/components/DiyEditor/index.vue @@ -59,7 +59,7 @@ }" > >(cloneDeep(NAVIGATION_BAR_C const tabBarComponent = ref>(cloneDeep(TAB_BAR_COMPONENT)) // 选中的组件,默认选中顶部导航栏 -const selectedComponent = ref>(unref(pageConfigComponent)) +const selectedComponent = ref>() // 选中的组件索引 const selectedComponentIndex = ref(-1) // 组件列表 const pageComponents = ref[]>([]) // 定义属性 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())