Compare commits

...

3 Commits

5 changed files with 193 additions and 170 deletions

View File

@ -4,7 +4,8 @@ NODE_ENV=development
VITE_DEV=true
# 请求路径
VITE_BASE_URL='https://zysc.fjptzykj.com'
# VITE_BASE_URL='https://zysc.fjptzykj.com'
VITE_BASE_URL='http://192.168.10.13:6127'
# VITE_BASE_URL='http://192.168.1.12:6127'
# 文件上传类型server - 后端上传, client - 前端直连上传,仅支持 S3 服务

View File

@ -39,6 +39,11 @@ export const getDiyPageProperty = async (id: number) => {
return await request.get({ url: `/promotion/diy-page/get-property?id=` + id })
}
// 查询组件列表动态
export const getDiyComponentList = async (params: any) => {
return await request.get({ url: `promotion/market-function/page`, params })
}
// 更新装修页面属性
export const updateDiyPageProperty = async (data: DiyPageVO) => {
return await request.put({ url: `/promotion/diy-page/update-property`, data })

View File

@ -2,31 +2,18 @@
<el-aside class="editor-left" width="261px">
<el-scrollbar>
<el-collapse v-model="extendGroups">
<el-collapse-item
v-for="group in groups"
:key="group.name"
:name="group.name"
:title="group.name"
>
<draggable
class="component-container"
ghost-class="draggable-ghost"
item-key="index"
:list="group.components"
:sort="false"
:group="{ name: 'component', pull: 'clone', put: false }"
:clone="handleCloneComponent"
:animation="200"
:force-fallback="true"
>
<el-collapse-item v-for="group in groups" :key="group.name" :name="group.name" :title="group.name">
<draggable class="component-container" ghost-class="draggable-ghost" item-key="index" :list="group.components"
:sort="false" :group="{ name: 'component', pull: 'clone', put: false }" :clone="handleCloneComponent"
:animation="200" :force-fallback="true">
<template #item="{ element }">
<div>
<div class="drag-placement">组件放置区域</div>
<div class="component">
<!-- <Icon :icon="element.icon" :size="32" /> -->
<div>
<img :src="element.icon" />
</div>
<div>
<img :src="element.icon" />
</div>
<span class="text-12px">{{ element.name }}</span>
</div>
</div>
@ -166,6 +153,7 @@ const handleCloneComponent = (component: DiyComponent<any>) => {
}
.drag-area {
/* 拖拽到手机区域时的样式 */
.draggable-ghost {
display: flex;
@ -173,17 +161,15 @@ const handleCloneComponent = (component: DiyComponent<any>) => {
height: 40px;
/* 条纹背景 */
background: linear-gradient(
45deg,
#91a8d5 0,
#91a8d5 10%,
#94b4eb 10%,
#94b4eb 50%,
#91a8d5 50%,
#91a8d5 60%,
#94b4eb 60%,
#94b4eb
);
background: linear-gradient(45deg,
#91a8d5 0,
#91a8d5 10%,
#94b4eb 10%,
#94b4eb 50%,
#91a8d5 50%,
#91a8d5 60%,
#94b4eb 60%,
#94b4eb);
background-size: 1rem 1rem;
transition: all 0.5s;
justify-content: center;

View File

@ -2,7 +2,7 @@
<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" :showTabBar = "false">
:preview-url="previewUrl" @save="submitForm" @reset="handleEditorReset" :showTabBar="false">
<template #toolBarLeft>
<!-- <el-radio-group
v-model="selectedTemplateItem"
@ -19,154 +19,185 @@
</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';
// 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('0')
// console.log(selectedTemplateItem.value,'selectedTemplateItemselectedTemplateItem')
const templateItems = reactive([
{ name: '基础设置', icon: 'ep:iphone' },
{ name: '首页', icon: 'ep:home-filled' },
{ name: '我的', icon: 'ep:user-filled' }
])
/** 装修模板表单 */
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 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 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 queryParams = reactive({
pageNo: 1,
pageSize: 10,
name: null,
createTime: []
})
//
const getPagelibsActive = async () => {
const data = await DiyPageApi.getDiyComponentList(queryParams)
console.log("diy列表数据", data)
console.log('组件列表数据', libs.value)
// const newData = libs.value?.map(item => {
// if (item.name === '') {
// return { ...item, type: 'new-promotion' }; // type
// }
// // const components = data.map(item => functionToComponentMap[item.functionName]);
// return item;
// });
}
//
const handleTemplateItemChange = async () => {
//
// 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 templateLibs = [] as DiyComponentLibrary[]
//
const libs = ref<DiyComponentLibrary[]>(templateLibs)
//
const handleTemplateItemChange = () => {
//
// if (selectedTemplateItem.value === 0) {
// libs.value = templateLibs
// currentFormData.value = formData.value
// return
// }
//
const resetForm = () => {
formData.value = {
id: undefined,
name: '',
used: false,
usedTime: undefined,
remark: '',
previewPicUrls: [],
property: '',
pages: []
} as DiyTemplateApi.DiyTemplatePropertyVO
formRef.value?.resetFields()
}
//
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 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
//
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()
}
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]
//
const handleEditorReset = () => storePageIndex()
getPagelibsActive();
//#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()
currentFormData.value = formData.value!.pages[0]
})
// watch(() => route.path, (newPath, oldPath) => {
// console.log(newPath,'newPathnewPath');
// // handleTemplateItemChange()
// }, { immediate: true });
// watch(() => route.path, (newPath, oldPath) => {
// console.log(newPath,'newPathnewPath');
// // handleTemplateItemChange()
// }, { immediate: true });
</script>

View File

@ -28,7 +28,7 @@ import * as DiyTemplateApi from '@/api/mall/promotion/diy/template'
import { useTagsdivStore } from '@/store/modules/tagsdiv'
import { DiyComponentLibrary, PAGE_LIBS } from '@/components/DiyEditor/util' // DIY DiyEditor
import { toNumber } from 'lodash-es'
const message = useMessage() //
const message = useMessage(); //
const currItem = ref();
function clickItem(val) {