util.ts 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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. uid?: number
  9. // 组件唯一标识
  10. id: string
  11. // 组件名称
  12. name: string
  13. // 组件图标
  14. icon: string
  15. /*
  16. 组件位置:
  17. top: 固定于手机顶部,例如 顶部的导航栏
  18. bottom: 固定于手机底部,例如 底部的菜单导航栏
  19. center: 位于手机中心,每个组件占一行,顺序向下排列
  20. 空:同center
  21. fixed: 由组件自己决定位置,如弹窗位于手机中心、浮动按钮一般位于手机右下角
  22. */
  23. position?: 'top' | 'bottom' | 'center' | '' | 'fixed'
  24. // 组件属性
  25. property: T
  26. }
  27. // 页面装修组件库
  28. export interface DiyComponentLibrary {
  29. // 组件库名称
  30. name: string
  31. // 是否展开
  32. extended: boolean
  33. // 组件列表
  34. components: string[]
  35. }
  36. // 组件样式
  37. export interface ComponentStyle {
  38. // 背景类型
  39. bgType: 'color' | 'img'
  40. // 背景颜色
  41. bgColor: string
  42. // 背景图片
  43. bgImg: string
  44. // 外边距
  45. margin: number
  46. marginTop: number
  47. marginRight: number
  48. marginBottom: number
  49. marginLeft: number
  50. // 内边距
  51. padding: number
  52. paddingTop: number
  53. paddingRight: number
  54. paddingBottom: number
  55. paddingLeft: number
  56. // 边框圆角
  57. borderRadius: number
  58. borderTopLeftRadius: number
  59. borderTopRightRadius: number
  60. borderBottomRightRadius: number
  61. borderBottomLeftRadius: number
  62. }
  63. // 页面配置
  64. export interface PageConfig {
  65. // 页面属性
  66. page: PageConfigProperty
  67. // 顶部导航栏属性
  68. navigationBar: NavigationBarProperty
  69. // 底部导航菜单属性
  70. tabBar?: TabBarProperty
  71. // 页面组件列表
  72. components: PageComponent[]
  73. }
  74. // 页面组件,只保留组件ID,组件属性
  75. export interface PageComponent extends Pick<DiyComponent<any>, 'id' | 'property'> {}
  76. // 属性表单监听
  77. export function usePropertyForm<T>(modelValue: T, emit: Function): { formData: Ref<T> } {
  78. const formData = ref<T>()
  79. // 监听属性数据变动
  80. watch(
  81. () => modelValue,
  82. () => {
  83. formData.value = modelValue
  84. },
  85. {
  86. deep: true,
  87. immediate: true
  88. }
  89. )
  90. // 监听表单数据变动
  91. watch(
  92. () => formData.value,
  93. () => {
  94. emit('update:modelValue', formData.value)
  95. },
  96. {
  97. deep: true
  98. }
  99. )
  100. return { formData } as { formData: Ref<T> }
  101. }
  102. // 页面组件库
  103. export const PAGE_LIBS = [
  104. {
  105. name: '基础组件',
  106. extended: true,
  107. components: [
  108. 'SearchBar',
  109. 'NoticeBar',
  110. 'MenuSwiper',
  111. 'MenuGrid',
  112. 'MenuList',
  113. 'Popover',
  114. // 'FloatingActionButton'
  115. ]
  116. },
  117. {
  118. name: '图文组件',
  119. extended: true,
  120. components: [
  121. 'ImageBar',
  122. 'Carousel',
  123. 'TitleBar',
  124. 'VideoPlayer',
  125. 'Divider',
  126. 'MagicCube',
  127. // 'HotZone'
  128. ]
  129. },
  130. { name: '商品组件', extended: true, components: ['ProductCard', 'ProductList'] },
  131. // {
  132. // name: '用户组件',
  133. // extended: true,
  134. // components: ['UserCard', 'UserOrder', 'UserWallet', 'UserCoupon']
  135. // },
  136. // {
  137. // name: '营销组件',
  138. // extended: true,
  139. // components: [
  140. // 'PromotionCombination',
  141. // 'PromotionSeckill',
  142. // 'PromotionPoint',
  143. // 'CouponCard',
  144. // 'PromotionArticle'
  145. // ]
  146. // }
  147. ] as DiyComponentLibrary[]