2023-10-29 22:03:24 +08:00
|
|
|
|
import { ref, Ref } from 'vue'
|
|
|
|
|
import { PageConfigProperty } from '@/components/DiyEditor/components/mobile/PageConfig/config'
|
|
|
|
|
import { NavigationBarProperty } from '@/components/DiyEditor/components/mobile/NavigationBar/config'
|
|
|
|
|
import { TabBarProperty } from '@/components/DiyEditor/components/mobile/TabBar/config'
|
|
|
|
|
|
2023-11-05 20:42:50 +08:00
|
|
|
|
// 页面装修组件
|
2023-10-29 22:03:24 +08:00
|
|
|
|
export interface DiyComponent<T> {
|
2023-12-07 21:18:51 +08:00
|
|
|
|
// 用于区分同一种组件的不同实例
|
|
|
|
|
uid: number
|
2023-11-05 20:42:50 +08:00
|
|
|
|
// 组件唯一标识
|
2023-10-29 22:03:24 +08:00
|
|
|
|
id: string
|
2023-11-05 20:42:50 +08:00
|
|
|
|
// 组件名称
|
2023-10-29 22:03:24 +08:00
|
|
|
|
name: string
|
2023-11-05 20:42:50 +08:00
|
|
|
|
// 组件图标
|
2023-10-29 22:03:24 +08:00
|
|
|
|
icon: string
|
2023-12-09 16:45:54 +08:00
|
|
|
|
/*
|
|
|
|
|
组件位置:
|
|
|
|
|
top: 固定于手机顶部,例如 顶部的导航栏
|
|
|
|
|
bottom: 固定于手机底部,例如 底部的菜单导航栏
|
|
|
|
|
center: 位于手机中心,每个组件占一行,顺序向下排列
|
|
|
|
|
空:同center
|
|
|
|
|
fixed: 由组件自己决定位置,如弹窗位于手机中心、浮动按钮一般位于手机右下角
|
|
|
|
|
*/
|
|
|
|
|
position: 'top' | 'bottom' | 'center' | '' | 'fixed'
|
2023-11-05 20:42:50 +08:00
|
|
|
|
// 组件属性
|
2023-10-29 22:03:24 +08:00
|
|
|
|
property: T
|
|
|
|
|
}
|
|
|
|
|
|
2023-11-05 20:42:50 +08:00
|
|
|
|
// 页面装修组件库
|
2023-10-29 22:03:24 +08:00
|
|
|
|
export interface DiyComponentLibrary {
|
2023-11-05 20:42:50 +08:00
|
|
|
|
// 组件库名称
|
2023-10-29 22:03:24 +08:00
|
|
|
|
name: string
|
2023-11-05 20:42:50 +08:00
|
|
|
|
// 是否展开
|
2023-10-29 22:03:24 +08:00
|
|
|
|
extended: boolean
|
2023-11-05 20:42:50 +08:00
|
|
|
|
// 组件列表
|
2023-10-29 22:03:24 +08:00
|
|
|
|
components: string[]
|
|
|
|
|
}
|
|
|
|
|
|
2023-11-04 22:06:40 +08:00
|
|
|
|
// 组件样式
|
|
|
|
|
export interface ComponentStyle {
|
|
|
|
|
// 背景类型
|
|
|
|
|
bgType: 'color' | 'img'
|
|
|
|
|
// 背景颜色
|
|
|
|
|
bgColor: string
|
|
|
|
|
// 背景图片
|
|
|
|
|
bgImg: string
|
|
|
|
|
// 外边距
|
|
|
|
|
margin: number
|
|
|
|
|
marginTop: number
|
|
|
|
|
marginRight: number
|
|
|
|
|
marginBottom: number
|
|
|
|
|
marginLeft: number
|
|
|
|
|
// 内边距
|
|
|
|
|
padding: number
|
|
|
|
|
paddingTop: number
|
|
|
|
|
paddingRight: number
|
|
|
|
|
paddingBottom: number
|
|
|
|
|
paddingLeft: number
|
|
|
|
|
// 边框圆角
|
|
|
|
|
borderRadius: number
|
|
|
|
|
borderTopLeftRadius: number
|
|
|
|
|
borderTopRightRadius: number
|
|
|
|
|
borderBottomRightRadius: number
|
|
|
|
|
borderBottomLeftRadius: number
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-29 22:03:24 +08:00
|
|
|
|
// 页面配置
|
|
|
|
|
export interface PageConfig {
|
|
|
|
|
// 页面属性
|
|
|
|
|
page: PageConfigProperty
|
|
|
|
|
// 顶部导航栏属性
|
|
|
|
|
navigationBar: NavigationBarProperty
|
|
|
|
|
// 底部导航菜单属性
|
2023-11-05 12:40:32 +08:00
|
|
|
|
tabBar?: TabBarProperty
|
2023-10-29 22:03:24 +08:00
|
|
|
|
// 页面组件列表
|
|
|
|
|
components: PageComponent[]
|
|
|
|
|
}
|
|
|
|
|
// 页面组件,只保留组件ID,组件属性
|
|
|
|
|
export interface PageComponent extends Pick<DiyComponent<any>, 'id' | 'property'> {}
|
|
|
|
|
|
|
|
|
|
// 属性表单监听
|
|
|
|
|
export function usePropertyForm<T>(modelValue: T, emit: Function): { formData: Ref<T> } {
|
|
|
|
|
const formData = ref<T>()
|
|
|
|
|
// 监听属性数据变动
|
|
|
|
|
watch(
|
|
|
|
|
() => modelValue,
|
|
|
|
|
() => {
|
|
|
|
|
formData.value = modelValue
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
deep: true,
|
|
|
|
|
immediate: true
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
// 监听表单数据变动
|
|
|
|
|
watch(
|
|
|
|
|
() => formData.value,
|
|
|
|
|
() => {
|
|
|
|
|
emit('update:modelValue', formData.value)
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
deep: true
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
return { formData }
|
|
|
|
|
}
|
2023-11-05 20:42:50 +08:00
|
|
|
|
|
|
|
|
|
// 页面组件库
|
|
|
|
|
export const PAGE_LIBS = [
|
|
|
|
|
{
|
|
|
|
|
name: '基础组件',
|
|
|
|
|
extended: true,
|
2023-12-09 21:33:47 +08:00
|
|
|
|
components: [
|
|
|
|
|
'SearchBar',
|
|
|
|
|
'NoticeBar',
|
|
|
|
|
'MenuSwiper',
|
|
|
|
|
'MenuGrid',
|
|
|
|
|
'MenuList',
|
|
|
|
|
'Popover',
|
|
|
|
|
'FloatingActionButton'
|
|
|
|
|
]
|
2023-11-09 09:18:46 +08:00
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: '图文组件',
|
|
|
|
|
extended: true,
|
2023-11-12 19:29:24 +08:00
|
|
|
|
components: ['ImageBar', 'Carousel', 'TitleBar', 'VideoPlayer', 'Divider', 'MagicCube']
|
2023-11-05 20:42:50 +08:00
|
|
|
|
},
|
2023-11-19 18:27:25 +08:00
|
|
|
|
{ name: '商品组件', extended: true, components: ['ProductCard', 'ProductList'] },
|
2023-11-05 20:42:50 +08:00
|
|
|
|
{
|
2023-12-01 23:34:19 +08:00
|
|
|
|
name: '用户组件',
|
2023-11-05 20:42:50 +08:00
|
|
|
|
extended: true,
|
2023-11-22 16:58:00 +08:00
|
|
|
|
components: ['UserCard', 'UserOrder', 'UserWallet', 'UserCoupon']
|
2023-11-05 20:42:50 +08:00
|
|
|
|
},
|
2023-11-22 16:58:00 +08:00
|
|
|
|
{
|
|
|
|
|
name: '营销组件',
|
|
|
|
|
extended: true,
|
2023-12-01 20:24:55 +08:00
|
|
|
|
components: [
|
|
|
|
|
'PromotionCombination',
|
|
|
|
|
'PromotionSeckill',
|
|
|
|
|
'PromotionPoint',
|
|
|
|
|
'CouponCard',
|
|
|
|
|
'PromotionArticle'
|
|
|
|
|
]
|
2023-11-22 16:58:00 +08:00
|
|
|
|
}
|
2023-11-05 20:42:50 +08:00
|
|
|
|
] as DiyComponentLibrary[]
|