2022-09-06 03:51:36 +00:00
|
|
|
<template>
|
2022-09-06 10:42:24 +00:00
|
|
|
<div class="decoration-pages min-w-[1100px]">
|
2024-08-28 16:24:01 +00:00
|
|
|
<div class="flex flex-1 h-full justify-between">
|
|
|
|
|
<el-card
|
|
|
|
|
shadow="never"
|
|
|
|
|
class="!border-none flex scroll-view-content"
|
|
|
|
|
:body-style="{ 'padding-right': 0 }"
|
|
|
|
|
>
|
2022-09-06 10:42:24 +00:00
|
|
|
<Menu v-model="activeMenu" :menus="menus" />
|
2024-08-28 16:24:01 +00:00
|
|
|
</el-card>
|
|
|
|
|
|
|
|
|
|
<preview
|
|
|
|
|
class="flex-1 scroll-view-content"
|
|
|
|
|
v-model="selectWidgetIndex"
|
|
|
|
|
@updatePageData="updatePageData"
|
|
|
|
|
:pageData="getPageData"
|
|
|
|
|
:pageMeta="getPageMeta"
|
|
|
|
|
/>
|
|
|
|
|
|
|
|
|
|
<attr-setting
|
|
|
|
|
class="w-[560px] scroll-view-content"
|
|
|
|
|
:widget="getSelectWidget"
|
|
|
|
|
@update:content="updateContent"
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
2022-09-15 11:02:09 +00:00
|
|
|
<footer-btns class="mt-4" :fixed="false" v-perms="['decorate:pages:save']">
|
2022-09-06 03:51:36 +00:00
|
|
|
<el-button type="primary" @click="setData">保存</el-button>
|
|
|
|
|
</footer-btns>
|
|
|
|
|
</div>
|
|
|
|
|
</template>
|
2022-09-20 02:58:38 +00:00
|
|
|
<script lang="ts" setup name="decorationPages">
|
2024-08-28 16:24:01 +00:00
|
|
|
import { getDecoratePages, setDecoratePages } from '@/api/decoration'
|
|
|
|
|
import { getNonDuplicateID } from '@/utils/util'
|
|
|
|
|
|
|
|
|
|
import AttrSetting from '../component/pages/attr-setting.vue'
|
2022-09-06 03:51:36 +00:00
|
|
|
import Menu from '../component/pages/menu.vue'
|
|
|
|
|
import Preview from '../component/pages/preview.vue'
|
|
|
|
|
import widgets from '../component/widgets'
|
2024-08-28 16:24:01 +00:00
|
|
|
|
2022-09-06 03:51:36 +00:00
|
|
|
enum pagesTypeEnum {
|
|
|
|
|
HOME = '1',
|
|
|
|
|
USER = '2',
|
|
|
|
|
SERVICE = '3'
|
|
|
|
|
}
|
|
|
|
|
|
2024-08-28 16:24:01 +00:00
|
|
|
const updatePageData = (value: any) => {
|
|
|
|
|
menus[activeMenu.value].pageData = [...value]
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-06 03:51:36 +00:00
|
|
|
const generatePageData = (widgetNames: string[]) => {
|
2022-09-14 08:41:39 +00:00
|
|
|
return widgetNames.map((widgetName) => {
|
|
|
|
|
const options = {
|
|
|
|
|
id: getNonDuplicateID(),
|
|
|
|
|
...(widgets[widgetName]?.options() || {})
|
|
|
|
|
}
|
|
|
|
|
return options
|
|
|
|
|
})
|
2022-09-06 03:51:36 +00:00
|
|
|
}
|
|
|
|
|
|
2024-08-28 16:24:01 +00:00
|
|
|
const updateContent = (content: any) => {
|
|
|
|
|
if (menus[activeMenu.value]?.pageData) {
|
|
|
|
|
menus[activeMenu.value].pageData[selectWidgetIndex.value].content = content
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-06 03:51:36 +00:00
|
|
|
const menus: Record<
|
|
|
|
|
string,
|
|
|
|
|
{
|
|
|
|
|
id: number
|
|
|
|
|
name: string
|
2024-08-28 16:24:01 +00:00
|
|
|
pageMeta?: any
|
2022-09-06 03:51:36 +00:00
|
|
|
pageData: any[]
|
|
|
|
|
}
|
|
|
|
|
> = reactive({
|
|
|
|
|
[pagesTypeEnum.HOME]: {
|
|
|
|
|
id: 1,
|
2024-08-28 16:24:01 +00:00
|
|
|
type: 1,
|
2022-10-13 08:08:31 +00:00
|
|
|
name: '首页装修',
|
2024-08-28 16:24:01 +00:00
|
|
|
pageMeta: generatePageData(['page-meta']),
|
2022-09-14 08:41:39 +00:00
|
|
|
pageData: generatePageData(['search', 'banner', 'nav', 'news'])
|
2022-09-06 03:51:36 +00:00
|
|
|
},
|
|
|
|
|
[pagesTypeEnum.USER]: {
|
|
|
|
|
id: 2,
|
2024-08-28 16:24:01 +00:00
|
|
|
type: 2,
|
2022-09-06 03:51:36 +00:00
|
|
|
name: '个人中心',
|
2024-08-28 16:24:01 +00:00
|
|
|
pageMeta: generatePageData(['page-meta']),
|
2022-09-06 10:42:24 +00:00
|
|
|
pageData: generatePageData(['user-info', 'my-service', 'user-banner'])
|
2022-09-06 03:51:36 +00:00
|
|
|
},
|
|
|
|
|
[pagesTypeEnum.SERVICE]: {
|
|
|
|
|
id: 3,
|
2024-08-28 16:24:01 +00:00
|
|
|
type: 3,
|
2022-09-06 03:51:36 +00:00
|
|
|
name: '客服设置',
|
2024-08-28 16:24:01 +00:00
|
|
|
pageMeta: null,
|
2022-09-06 10:42:24 +00:00
|
|
|
pageData: generatePageData(['customer-service'])
|
2022-09-06 03:51:36 +00:00
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
|
2024-08-28 16:24:01 +00:00
|
|
|
const activeMenu = ref<string>('1')
|
|
|
|
|
const selectWidgetIndex = ref<number>(-1)
|
2022-09-06 03:51:36 +00:00
|
|
|
const getPageData = computed(() => {
|
|
|
|
|
return menus[activeMenu.value]?.pageData ?? []
|
|
|
|
|
})
|
2024-08-28 16:24:01 +00:00
|
|
|
const getPageMeta = computed(() => {
|
|
|
|
|
return menus[activeMenu.value]?.pageMeta ?? null
|
|
|
|
|
})
|
2022-09-06 03:51:36 +00:00
|
|
|
const getSelectWidget = computed(() => {
|
2024-08-28 16:24:01 +00:00
|
|
|
if (selectWidgetIndex.value === -1) {
|
|
|
|
|
return menus[activeMenu.value]?.pageMeta[0] ?? ''
|
|
|
|
|
} else {
|
|
|
|
|
return menus[activeMenu.value]?.pageData[selectWidgetIndex.value] ?? ''
|
|
|
|
|
}
|
2022-09-06 03:51:36 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
|
|
const getData = async () => {
|
|
|
|
|
const data = await getDecoratePages({ id: activeMenu.value })
|
2024-08-28 16:24:01 +00:00
|
|
|
menus[String(data.id)].pageData = JSON.parse(data.data)
|
|
|
|
|
menus[String(data.id)].pageMeta = data?.meta ? JSON.parse(data?.meta) : null
|
2022-09-06 03:51:36 +00:00
|
|
|
}
|
2022-09-14 08:41:39 +00:00
|
|
|
|
2022-09-06 03:51:36 +00:00
|
|
|
const setData = async () => {
|
2024-08-28 16:24:01 +00:00
|
|
|
const data = menus[activeMenu.value]
|
2022-09-06 06:17:20 +00:00
|
|
|
await setDecoratePages({
|
2024-08-28 16:24:01 +00:00
|
|
|
...data,
|
|
|
|
|
data: JSON.stringify(data.pageData),
|
|
|
|
|
meta: data?.pageMeta ? JSON.stringify(data?.pageMeta) : null
|
2022-09-06 06:17:20 +00:00
|
|
|
})
|
|
|
|
|
getData()
|
2022-09-06 03:51:36 +00:00
|
|
|
}
|
|
|
|
|
watch(
|
|
|
|
|
activeMenu,
|
|
|
|
|
() => {
|
|
|
|
|
selectWidgetIndex.value = getPageData.value.findIndex((item) => !item.disabled)
|
2022-09-06 06:17:20 +00:00
|
|
|
getData()
|
2022-09-06 03:51:36 +00:00
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
immediate: true
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
</script>
|
|
|
|
|
<style lang="scss" scoped>
|
2024-08-28 16:24:01 +00:00
|
|
|
$scroll-height: calc(100vh - var(--navbar-height) - 74px);
|
2022-09-06 03:51:36 +00:00
|
|
|
.decoration-pages {
|
2024-08-28 16:24:01 +00:00
|
|
|
height: $scroll-height;
|
2022-09-06 03:51:36 +00:00
|
|
|
@apply flex flex-col;
|
2024-08-28 16:24:01 +00:00
|
|
|
.scroll-view-content {
|
|
|
|
|
height: calc($scroll-height - 60px);
|
|
|
|
|
}
|
2022-09-06 03:51:36 +00:00
|
|
|
}
|
|
|
|
|
</style>
|