util.ts 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. import { ref, Ref } from 'vue'
  2. import { PageConfigProperty } from '@/components/DiyEditor/components/mobile/PageConfig/config'
  3. import { NavigationBarProperty } from '@/components/DiyEditor/components/mobile/NavigationBar/config'
  4. import { TabBarProperty } from '@/components/DiyEditor/components/mobile/TabBar/config'
  5. // 页面装修组件
  6. export interface DiyComponent<T> {
  7. // 组件唯一标识
  8. id: string
  9. // 组件名称
  10. name: string
  11. // 组件图标
  12. icon: string
  13. // 组件属性
  14. property: T
  15. }
  16. // 页面装修组件库
  17. export interface DiyComponentLibrary {
  18. // 组件库名称
  19. name: string
  20. // 是否展开
  21. extended: boolean
  22. // 组件列表
  23. components: string[]
  24. }
  25. // 组件样式
  26. export interface ComponentStyle {
  27. // 背景类型
  28. bgType: 'color' | 'img'
  29. // 背景颜色
  30. bgColor: string
  31. // 背景图片
  32. bgImg: string
  33. // 外边距
  34. margin: number
  35. marginTop: number
  36. marginRight: number
  37. marginBottom: number
  38. marginLeft: number
  39. // 内边距
  40. padding: number
  41. paddingTop: number
  42. paddingRight: number
  43. paddingBottom: number
  44. paddingLeft: number
  45. // 边框圆角
  46. borderRadius: number
  47. borderTopLeftRadius: number
  48. borderTopRightRadius: number
  49. borderBottomRightRadius: number
  50. borderBottomLeftRadius: number
  51. }
  52. // 页面配置
  53. export interface PageConfig {
  54. // 页面属性
  55. page: PageConfigProperty
  56. // 顶部导航栏属性
  57. navigationBar: NavigationBarProperty
  58. // 底部导航菜单属性
  59. tabBar?: TabBarProperty
  60. // 页面组件列表
  61. components: PageComponent[]
  62. }
  63. // 页面组件,只保留组件ID,组件属性
  64. export interface PageComponent extends Pick<DiyComponent<any>, 'id' | 'property'> {}
  65. // 属性表单监听
  66. export function usePropertyForm<T>(modelValue: T, emit: Function): { formData: Ref<T> } {
  67. const formData = ref<T>()
  68. // 监听属性数据变动
  69. watch(
  70. () => modelValue,
  71. () => {
  72. formData.value = modelValue
  73. },
  74. {
  75. deep: true,
  76. immediate: true
  77. }
  78. )
  79. // 监听表单数据变动
  80. watch(
  81. () => formData.value,
  82. () => {
  83. emit('update:modelValue', formData.value)
  84. },
  85. {
  86. deep: true
  87. }
  88. )
  89. return { formData }
  90. }
  91. // 页面组件库
  92. export const PAGE_LIBS = [
  93. {
  94. name: '基础组件',
  95. extended: true,
  96. components: ['SearchBar', 'NoticeBar', 'MenuSwiper', 'MenuGrid', 'MenuList']
  97. },
  98. {
  99. name: '图文组件',
  100. extended: true,
  101. components: ['ImageBar', 'Carousel', 'TitleBar', 'VideoPlayer', 'Divider', 'MagicCube']
  102. },
  103. { name: '商品组件', extended: true, components: ['ProductCard', 'ProductList'] },
  104. {
  105. name: '会员组件',
  106. extended: true,
  107. components: ['UserCard', 'UserOrder', 'UserWallet', 'UserCoupon']
  108. },
  109. {
  110. name: '营销组件',
  111. extended: true,
  112. components: ['CombinationCard', 'SeckillCard', 'PointCard', 'CouponCard']
  113. }
  114. ] as DiyComponentLibrary[]