将装修列表页面去掉直接在菜单栏里面添加按钮跳转到对应的装修页面

This commit is contained in:
77 2024-10-05 11:47:25 +08:00
parent d477567030
commit d83522607b
5 changed files with 500 additions and 144 deletions

View File

@ -249,6 +249,7 @@ watch(
const component = componentConfigs[item.id]
return { ...component, property: item.property }
})
console.log(modelValue,"pageComponents.value")
},
{
immediate: true

View File

@ -469,7 +469,7 @@ const remainingRouter: AppRouteRecordRaw[] = [
]
},
{
path: '/diy',
path: '/diy-template/diy',
name: 'DiyCenter',
meta: { hidden: true },
component: Layout,

View File

@ -1,18 +1,10 @@
<template>
<DiyEditor
v-if="formData && !formLoading"
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"
:preview-url="previewUrl"
@save="submitForm"
@reset="handleEditorReset"
>
<template #toolBarLeft>
<el-radio-group
<DiyEditor v-if="formData && !formLoading" 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"
:preview-url="previewUrl" @save="submitForm" @reset="handleEditorReset">
<template #toolBarLeft>
<!-- <el-radio-group
v-model="selectedTemplateItem"
class="h-full!"
@change="handleTemplateItemChange"
@ -22,146 +14,159 @@
<Icon :icon="item.icon" :size="24" />
</el-radio-button>
</el-tooltip>
</el-radio-group>
</template>
</DiyEditor>
</el-radio-group> -->
</template>
</DiyEditor>
</template>
<script setup lang="ts">
// TODO @ decorate index.vue
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, PAGE_LIBS } from '@/components/DiyEditor/util' // DIY DiyEditor
import { toNumber } from 'lodash-es'
// TODO @ decorate index.vue
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, PAGE_LIBS } from '@/components/DiyEditor/util' // DIY DiyEditor
import { toNumber } from 'lodash-es'
// import { watch } from 'vue';
/** 装修模板表单 */
defineOptions({ name: 'DiyTemplateDecorate' })
/** 装修模板表单 */
defineOptions({ name: 'DiyTemplateDecorate' })
/** 初始化 **/
const { currentRoute } = useRouter() //
const { delView } = useTagsViewStore() //
const route = useRoute();
//
const selectedTemplateItem = ref('0')
// console.log(selectedTemplateItem.value,'selectedTemplateItemselectedTemplateItem')
const templateItems = reactive([
{ name: '基础设置', icon: 'ep:iphone' },
{ name: '首页', icon: 'ep:home-filled' },
{ name: '我的', icon: 'ep:user-filled' }
])
//
const selectedTemplateItem = ref(0)
const templateItems = reactive([
{ name: '基础设置', icon: 'ep:iphone' },
{ name: '首页', icon: 'ep:home-filled' },
{ name: '我的', icon: 'ep:user-filled' }
])
const message = useMessage() //
const message = useMessage() //
const formLoading = ref(false) // 12
const formData = ref<DiyTemplateApi.DiyTemplatePropertyVO>()
const formRef = ref() // Ref
//
const currentFormData = ref<DiyTemplateApi.DiyTemplatePropertyVO | DiyPageApi.DiyPageVO>()
// H5
const previewUrl = ref('')
const formLoading = ref(false) // 12
const formData = ref<DiyTemplateApi.DiyTemplatePropertyVO>()
const formRef = ref() // Ref
//
const currentFormData = ref<DiyTemplateApi.DiyTemplatePropertyVO | DiyPageApi.DiyPageVO>()
// H5
const previewUrl = ref('')
//
const getPageDetail = async (id : any) => {
formLoading.value = true
try {
formData.value = await DiyTemplateApi.getDiyTemplateProperty(id)
currentFormData.value = formData.value
//
const domain = import.meta.env.VITE_MALL_H5_DOMAIN
previewUrl.value = `${domain}/#/pages/index/index?templateId=${formData.value.id}`
} finally {
formLoading.value = false
}
}
//
const getPageDetail = async (id: any) => {
formLoading.value = true
try {
formData.value = await DiyTemplateApi.getDiyTemplateProperty(id)
currentFormData.value = formData.value
//
const templateLibs = [] as DiyComponentLibrary[]
//
const libs = ref<DiyComponentLibrary[]>(templateLibs)
//
const handleTemplateItemChange = () => {
//
// if (selectedTemplateItem.value === 0) {
// libs.value = templateLibs
// currentFormData.value = formData.value
// return
// }
//
const domain = import.meta.env.VITE_MALL_H5_DOMAIN
previewUrl.value = `${domain}/#/pages/index/index?templateId=${formData.value.id}`
} finally {
formLoading.value = false
}
}
//
libs.value = PAGE_LIBS
console.log(formData.value!.pages, 'PAGE_LIBS')
// currentFormData.value = formData.value!.pages.find(
// // (page: DiyPageApi.DiyPageVO) => page.name === templateItems[selectedTemplateItem.value].name
// (page: DiyPageApi.DiyPageVO) => page.name === templateItems[1].name
// )
currentFormData.value = formData.value!.pages[selectedTemplateItem.value]
console.log(selectedTemplateItem.value, 'selectedTemplateItem.value11111111111111')
}
//
const templateLibs = [] as DiyComponentLibrary[]
//
const libs = ref<DiyComponentLibrary[]>(templateLibs)
//
const handleTemplateItemChange = () => {
//
if (selectedTemplateItem.value === 0) {
libs.value = templateLibs
currentFormData.value = formData.value
return
}
//
const submitForm = async () => {
//
if (!formRef) return
//
formLoading.value = true
try {
if (selectedTemplateItem.value === '0') {
//
await DiyTemplateApi.updateDiyTemplateProperty(unref(formData)!)
} else {
//
await DiyPageApi.updateDiyPageProperty(unref(currentFormData)!)
}
message.success('保存成功')
} finally {
formLoading.value = false
}
}
//
libs.value = PAGE_LIBS
currentFormData.value = formData.value!.pages.find(
(page: DiyPageApi.DiyPageVO) => page.name === templateItems[selectedTemplateItem.value].name
)
}
//
const resetForm = () => {
formData.value = {
id: undefined,
name: '',
used: false,
usedTime: undefined,
remark: '',
previewPicUrls: [],
property: '',
pages: []
} as DiyTemplateApi.DiyTemplatePropertyVO
formRef.value?.resetFields()
}
//
const submitForm = async () => {
//
if (!formRef) return
//
formLoading.value = true
try {
if (selectedTemplateItem.value === 0) {
//
await DiyTemplateApi.updateDiyTemplateProperty(unref(formData)!)
} else {
//
await DiyPageApi.updateDiyPageProperty(unref(currentFormData)!)
}
message.success('保存成功')
} finally {
formLoading.value = false
}
}
//
const handleEditorReset = () => storePageIndex()
//
const resetForm = () => {
formData.value = {
id: undefined,
name: '',
used: false,
usedTime: undefined,
remark: '',
previewPicUrls: [],
property: '',
pages: []
} as DiyTemplateApi.DiyTemplatePropertyVO
formRef.value?.resetFields()
}
//#region
//
const DIY_PAGE_INDEX_KEY = 'diy_page_index'
// 1.
const storePageIndex = () =>
sessionStorage.setItem(DIY_PAGE_INDEX_KEY, `${selectedTemplateItem.value}`)
// 2.
const recoverPageIndex = () => {
//
const pageIndex = toNumber(sessionStorage.getItem(DIY_PAGE_INDEX_KEY)) || 0
//
sessionStorage.removeItem(DIY_PAGE_INDEX_KEY)
//
if (pageIndex !== selectedTemplateItem.value) {
selectedTemplateItem.value = pageIndex
handleTemplateItemChange()
}
}
//#endregion
//
const handleEditorReset = () => storePageIndex()
onMounted(async () => {
resetForm()
// if (!currentRoute.value.params.id) {
// message.warning('')
// delView(unref(currentRoute))
// return
// }
//
// await getPageDetail(currentRoute.value.params.id)
await getPageDetail(4)
//
recoverPageIndex()
currentFormData.value = formData.value!.pages[0]
//#region
//
const DIY_PAGE_INDEX_KEY = 'diy_page_index'
// 1.
const storePageIndex = () =>
sessionStorage.setItem(DIY_PAGE_INDEX_KEY, `${selectedTemplateItem.value}`)
// 2.
const recoverPageIndex = () => {
//
const pageIndex = toNumber(sessionStorage.getItem(DIY_PAGE_INDEX_KEY)) || 0
//
sessionStorage.removeItem(DIY_PAGE_INDEX_KEY)
//
if (pageIndex !== selectedTemplateItem.value) {
selectedTemplateItem.value = pageIndex
handleTemplateItemChange()
}
}
//#endregion
/** 初始化 **/
const { currentRoute } = useRouter() //
const { delView } = useTagsViewStore() //
onMounted(async () => {
resetForm()
if (!currentRoute.value.params.id) {
message.warning('参数错误,页面编号不能为空!')
delView(unref(currentRoute))
return
}
//
await getPageDetail(currentRoute.value.params.id)
//
recoverPageIndex()
})
</script>
})
// watch(() => route.path, (newPath, oldPath) => {
// console.log(newPath,'newPathnewPath');
// // handleTemplateItemChange()
// }, { immediate: true });
</script>

View File

@ -0,0 +1,175 @@
<template>
<DiyEditor v-if="formData && !formLoading" 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"
:preview-url="previewUrl" @save="submitForm" @reset="handleEditorReset">
<template #toolBarLeft>
<!-- <el-radio-group
v-model="selectedTemplateItem"
class="h-full!"
@change="handleTemplateItemChange"
>
<el-tooltip v-for="(item, index) in templateItems" :key="index" :content="item.name">
<el-radio-button :label="index">
<Icon :icon="item.icon" :size="24" />
</el-radio-button>
</el-tooltip>
</el-radio-group> -->
</template>
</DiyEditor>
</template>
<script setup lang="ts">
// TODO @ decorate index.vue
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, PAGE_LIBS } from '@/components/DiyEditor/util' // DIY DiyEditor
import { toNumber } from 'lodash-es'
// import { watch } from 'vue';
/** 装修模板表单 */
defineOptions({ name: 'DiyTemplateDecorate' })
/** 初始化 **/
const { currentRoute } = useRouter() //
const { delView } = useTagsViewStore() //
const route = useRoute();
//
const selectedTemplateItem = ref('1')
// console.log(selectedTemplateItem.value,'selectedTemplateItemselectedTemplateItem')
const templateItems = reactive([
{ name: '基础设置', icon: 'ep:iphone' },
{ name: '首页', icon: 'ep:home-filled' },
{ name: '我的', icon: 'ep:user-filled' }
])
const message = useMessage() //
const formLoading = ref(false) // 12
const formData = ref<DiyTemplateApi.DiyTemplatePropertyVO>()
const formRef = ref() // Ref
//
const currentFormData = ref<DiyTemplateApi.DiyTemplatePropertyVO | DiyPageApi.DiyPageVO>()
// H5
const previewUrl = ref('')
//
const getPageDetail = async (id : any) => {
formLoading.value = true
try {
formData.value = await DiyTemplateApi.getDiyTemplateProperty(id)
currentFormData.value = formData.value
//
const domain = import.meta.env.VITE_MALL_H5_DOMAIN
previewUrl.value = `${domain}/#/pages/index/index?templateId=${formData.value.id}`
} finally {
formLoading.value = false
}
}
//
const templateLibs = [] as DiyComponentLibrary[]
//
const libs = ref<DiyComponentLibrary[]>(templateLibs)
//
const handleTemplateItemChange = () => {
//
// if (selectedTemplateItem.value === 0) {
// libs.value = templateLibs
// currentFormData.value = formData.value
// return
// }
//
libs.value = PAGE_LIBS
console.log(formData.value!.pages, 'PAGE_LIBS')
// currentFormData.value = formData.value!.pages.find(
// // (page: DiyPageApi.DiyPageVO) => page.name === templateItems[selectedTemplateItem.value].name
// (page: DiyPageApi.DiyPageVO) => page.name === templateItems[1].name
// )
currentFormData.value = formData.value!.pages[selectedTemplateItem.value]
console.log(selectedTemplateItem.value, 'selectedTemplateItem.value11111111111111')
}
//
const submitForm = async () => {
//
if (!formRef) return
//
formLoading.value = true
try {
if (selectedTemplateItem.value === '0') {
//
await DiyTemplateApi.updateDiyTemplateProperty(unref(formData)!)
} else {
//
await DiyPageApi.updateDiyPageProperty(unref(currentFormData)!)
}
message.success('保存成功')
} finally {
formLoading.value = false
}
}
//
const resetForm = () => {
formData.value = {
id: undefined,
name: '',
used: false,
usedTime: undefined,
remark: '',
previewPicUrls: [],
property: '',
pages: []
} as DiyTemplateApi.DiyTemplatePropertyVO
formRef.value?.resetFields()
}
//
const handleEditorReset = () => storePageIndex()
//#region
//
const DIY_PAGE_INDEX_KEY = 'diy_page_index'
// 1.
const storePageIndex = () =>
sessionStorage.setItem(DIY_PAGE_INDEX_KEY, `${selectedTemplateItem.value}`)
// 2.
const recoverPageIndex = () => {
//
const pageIndex = toNumber(sessionStorage.getItem(DIY_PAGE_INDEX_KEY)) || 0
//
sessionStorage.removeItem(DIY_PAGE_INDEX_KEY)
//
if (pageIndex !== selectedTemplateItem.value) {
selectedTemplateItem.value = pageIndex
handleTemplateItemChange()
}
}
//#endregion
onMounted(async () => {
resetForm()
// if (!currentRoute.value.params.id) {
// message.warning('')
// delView(unref(currentRoute))
// return
// }
//
// await getPageDetail(currentRoute.value.params.id)
await getPageDetail(4)
//
recoverPageIndex()
selectedTemplateItem.value = 1
currentFormData.value = formData.value!.pages[selectedTemplateItem.value]
// handleTemplateItemChange()
console.log(currentRoute.value.params.id, "currentRoute.value.params.id");
})
// watch(() => route.path, (newPath, oldPath) => {
// console.log(newPath,'newPathnewPath');
// // handleTemplateItemChange()
// }, { immediate: true });
</script>

View File

@ -0,0 +1,175 @@
<template>
<DiyEditor v-if="formData && !formLoading" 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"
:preview-url="previewUrl" @save="submitForm" @reset="handleEditorReset">
<template #toolBarLeft>
<!-- <el-radio-group
v-model="selectedTemplateItem"
class="h-full!"
@change="handleTemplateItemChange"
>
<el-tooltip v-for="(item, index) in templateItems" :key="index" :content="item.name">
<el-radio-button :label="index">
<Icon :icon="item.icon" :size="24" />
</el-radio-button>
</el-tooltip>
</el-radio-group> -->
</template>
</DiyEditor>
</template>
<script setup lang="ts">
// TODO @ decorate index.vue
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, PAGE_LIBS } from '@/components/DiyEditor/util' // DIY DiyEditor
import { toNumber } from 'lodash-es'
// import { watch } from 'vue';
/** 装修模板表单 */
defineOptions({ name: 'DiyTemplateDecorate' })
/** 初始化 **/
const { currentRoute } = useRouter() //
const { delView } = useTagsViewStore() //
const route = useRoute();
//
const selectedTemplateItem = ref('1')
// console.log(selectedTemplateItem.value,'selectedTemplateItemselectedTemplateItem')
const templateItems = reactive([
{ name: '基础设置', icon: 'ep:iphone' },
{ name: '首页', icon: 'ep:home-filled' },
{ name: '我的', icon: 'ep:user-filled' }
])
const message = useMessage() //
const formLoading = ref(false) // 12
const formData = ref<DiyTemplateApi.DiyTemplatePropertyVO>()
const formRef = ref() // Ref
//
const currentFormData = ref<DiyTemplateApi.DiyTemplatePropertyVO | DiyPageApi.DiyPageVO>()
// H5
const previewUrl = ref('')
//
const getPageDetail = async (id : any) => {
formLoading.value = true
try {
formData.value = await DiyTemplateApi.getDiyTemplateProperty(id)
currentFormData.value = formData.value
//
const domain = import.meta.env.VITE_MALL_H5_DOMAIN
previewUrl.value = `${domain}/#/pages/index/index?templateId=${formData.value.id}`
} finally {
formLoading.value = false
}
}
//
const templateLibs = [] as DiyComponentLibrary[]
//
const libs = ref<DiyComponentLibrary[]>(templateLibs)
//
const handleTemplateItemChange = () => {
//
// if (selectedTemplateItem.value === 0) {
// libs.value = templateLibs
// currentFormData.value = formData.value
// return
// }
//
libs.value = PAGE_LIBS
console.log(formData.value!.pages, 'PAGE_LIBS')
// currentFormData.value = formData.value!.pages.find(
// // (page: DiyPageApi.DiyPageVO) => page.name === templateItems[selectedTemplateItem.value].name
// (page: DiyPageApi.DiyPageVO) => page.name === templateItems[1].name
// )
currentFormData.value = formData.value!.pages[selectedTemplateItem.value]
console.log(selectedTemplateItem.value, 'selectedTemplateItem.value11111111111111')
}
//
const submitForm = async () => {
//
if (!formRef) return
//
formLoading.value = true
try {
if (selectedTemplateItem.value === '0') {
//
await DiyTemplateApi.updateDiyTemplateProperty(unref(formData)!)
} else {
//
await DiyPageApi.updateDiyPageProperty(unref(currentFormData)!)
}
message.success('保存成功')
} finally {
formLoading.value = false
}
}
//
const resetForm = () => {
formData.value = {
id: undefined,
name: '',
used: false,
usedTime: undefined,
remark: '',
previewPicUrls: [],
property: '',
pages: []
} as DiyTemplateApi.DiyTemplatePropertyVO
formRef.value?.resetFields()
}
//
const handleEditorReset = () => storePageIndex()
//#region
//
const DIY_PAGE_INDEX_KEY = 'diy_page_index'
// 1.
const storePageIndex = () =>
sessionStorage.setItem(DIY_PAGE_INDEX_KEY, `${selectedTemplateItem.value}`)
// 2.
const recoverPageIndex = () => {
//
const pageIndex = toNumber(sessionStorage.getItem(DIY_PAGE_INDEX_KEY)) || 0
//
sessionStorage.removeItem(DIY_PAGE_INDEX_KEY)
//
if (pageIndex !== selectedTemplateItem.value) {
selectedTemplateItem.value = pageIndex
handleTemplateItemChange()
}
}
//#endregion
onMounted(async () => {
resetForm()
// if (!currentRoute.value.params.id) {
// message.warning('')
// delView(unref(currentRoute))
// return
// }
//
// await getPageDetail(currentRoute.value.params.id)
await getPageDetail(4)
//
recoverPageIndex()
libs.value = templateLibs
currentFormData.value = formData.value
// handleTemplateItemChange()
console.log(currentRoute.value.params.id, "currentRoute.value.params.id");
})
// watch(() => route.path, (newPath, oldPath) => {
// console.log(newPath,'newPathnewPath');
// // handleTemplateItemChange()
// }, { immediate: true });
</script>