useComponentConfig.ts 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  1. import type { IFormItem } from "shalu-dashboard-ui";
  2. import { computed } from "vue";
  3. import { cloneDeep } from "lodash";
  4. import { useProjectStore } from "@/store/modules/project";
  5. export const useComponentConfig = () => {
  6. const projectStore = useProjectStore();
  7. const formItems = computed((): IFormItem[] => {
  8. const element = projectStore.currentSelectedElements[0];
  9. const containerStyle = element?.container?.style || {};
  10. const containerProps = element?.container?.props || {};
  11. return [
  12. {
  13. label: "组件样式",
  14. prop: "style",
  15. type: "group",
  16. children: [
  17. {
  18. label: "边框背景",
  19. prop: "style.background",
  20. type: "backgroundSelect",
  21. defaultValue: cloneDeep(containerStyle?.background) ?? {
  22. type: "none",
  23. color: "",
  24. image: "",
  25. fillType: "cover",
  26. },
  27. },
  28. {
  29. label: "不透明度",
  30. prop: "style.opacity",
  31. type: "slider",
  32. defaultValue: containerStyle?.opacity ?? 1,
  33. },
  34. {
  35. label: "边框线",
  36. prop: "style.borderStyle",
  37. type: "select",
  38. fieldProps: {
  39. options: [
  40. { label: "无", value: "none" },
  41. { label: "实线", value: "solid" },
  42. { label: "虚线", value: "dashed" },
  43. { label: "点线", value: "dotted" },
  44. ],
  45. },
  46. defaultValue: containerStyle?.borderStyle || "none",
  47. },
  48. {
  49. label: '',
  50. prop: "",
  51. type: 'dependency',
  52. name: ['style.borderStyle'],
  53. children: (model: any) => {
  54. return model['style.borderStyle'] !== 'none' ? [
  55. {
  56. label: "边框颜色",
  57. prop: "style.borderColor",
  58. type: "colorSelect",
  59. defaultValue: containerStyle?.borderColor ?? "#EEEEEEFF",
  60. fieldProps: {
  61. gradient: false
  62. }
  63. },
  64. {
  65. label: "边框宽度",
  66. prop: "style.borderWidth",
  67. type: "inputNumber",
  68. fieldProps: {
  69. min: 0,
  70. addonAfter: "px",
  71. },
  72. defaultValue: containerStyle?.borderWidth ?? 1,
  73. },
  74. ] : [];
  75. }
  76. },
  77. {
  78. label: "圆角",
  79. prop: "style.borderRadius",
  80. type: "boderRadiusSelect",
  81. fieldProps: {
  82. min: 0,
  83. addonAfter: "px",
  84. },
  85. defaultValue: containerStyle?.borderRadius ?? 0,
  86. },
  87. {
  88. label: "毛玻璃",
  89. prop: "style.backdropFilter",
  90. type: "radioGroup",
  91. fieldProps: {
  92. options: [
  93. { label: "开启", value: "blur(10px)" },
  94. { label: "关闭", value: "" },
  95. ],
  96. },
  97. defaultValue: containerStyle?.backdropFilter || "",
  98. },
  99. {
  100. label: "阴影",
  101. prop: "style.boxShadow",
  102. type: "radioGroup",
  103. fieldProps: {
  104. options: [
  105. {
  106. label: "开启",
  107. value: "rgba(0,0,0,0.3) 15px 20px 20px",
  108. },
  109. { label: "关闭", value: "" },
  110. ],
  111. },
  112. defaultValue: containerStyle?.boxShadowEnabled || "",
  113. },
  114. {
  115. label: "倒影",
  116. prop: "style.webkitBoxReflect",
  117. type: "radioGroup",
  118. fieldProps: {
  119. options: [
  120. {
  121. label: "开启",
  122. value:
  123. "below 2px linear-gradient(transparent, rgba(0,0,0,0.5))",
  124. },
  125. { label: "关闭", value: "" },
  126. ],
  127. },
  128. defaultValue: containerStyle?.webkitBoxReflect || "",
  129. },
  130. ],
  131. },
  132. {
  133. label: "组件属性",
  134. prop: "props",
  135. type: "group",
  136. children: [
  137. {
  138. label: "名称",
  139. prop: "name",
  140. type: "input",
  141. defaultValue: element?.name ?? "",
  142. },
  143. {
  144. label: "宽高",
  145. type: 'divider',
  146. prop: "",
  147. },
  148. {
  149. label: "宽度",
  150. prop: "props.width",
  151. type: "inputNumber",
  152. fieldProps: {
  153. min: 0,
  154. addonAfter: "px",
  155. },
  156. defaultValue: containerProps?.width ?? 400,
  157. },
  158. {
  159. label: "高度",
  160. prop: "props.height",
  161. type: "inputNumber",
  162. fieldProps: {
  163. min: 0,
  164. addonAfter: "px",
  165. },
  166. defaultValue: containerProps?.height ?? 260,
  167. },
  168. {
  169. label: "位置",
  170. type: 'divider',
  171. prop: "",
  172. },
  173. {
  174. label: "X",
  175. prop: "props.x",
  176. type: "inputNumber",
  177. fieldProps: {
  178. min: 0,
  179. addonAfter: "px",
  180. },
  181. defaultValue: containerProps?.x ?? 0,
  182. },
  183. {
  184. label: "Y",
  185. prop: "props.y",
  186. type: "inputNumber",
  187. fieldProps: {
  188. min: 0,
  189. addonAfter: "px",
  190. },
  191. defaultValue: containerProps?.y ?? 0,
  192. },
  193. {
  194. label: "边距",
  195. type: 'divider',
  196. prop: "",
  197. },
  198. {
  199. label: "顶边距",
  200. prop: "props.paddingTop",
  201. type: "inputNumber",
  202. fieldProps: {
  203. min: 0,
  204. addonAfter: "px",
  205. },
  206. defaultValue: containerProps?.paddingTop ?? 0,
  207. },
  208. {
  209. label: "右边距",
  210. prop: "props.paddingRight",
  211. type: "inputNumber",
  212. fieldProps: {
  213. min: 0,
  214. addonAfter: "px",
  215. },
  216. defaultValue: containerProps?.paddingRight ?? 0,
  217. },
  218. {
  219. label: "底边距",
  220. prop: "props.paddingBottom",
  221. type: "inputNumber",
  222. fieldProps: {
  223. min: 0,
  224. addonAfter: "px",
  225. },
  226. defaultValue: containerProps?.paddingBottom ?? 0,
  227. },
  228. {
  229. label: "左边距",
  230. prop: "props.paddingLeft",
  231. type: "inputNumber",
  232. fieldProps: {
  233. min: 0,
  234. addonAfter: "px",
  235. },
  236. defaultValue: containerProps?.paddingLeft ?? 0,
  237. },
  238. {
  239. label: "旋转",
  240. type: 'divider',
  241. prop: "",
  242. },
  243. {
  244. label: "X轴旋转",
  245. prop: "props.rotateX",
  246. type: "inputNumber",
  247. fieldProps: {
  248. min: 0,
  249. addonAfter: "deg",
  250. },
  251. defaultValue: containerProps?.rotateX ?? 0,
  252. },
  253. {
  254. label: "Y轴旋转",
  255. prop: "props.rotateY",
  256. type: "inputNumber",
  257. fieldProps: {
  258. min: 0,
  259. addonAfter: "deg",
  260. },
  261. defaultValue: containerProps?.rotateY ?? 0,
  262. },
  263. {
  264. label: "Z轴旋转",
  265. prop: "props.rotateZ",
  266. type: "inputNumber",
  267. fieldProps: {
  268. min: 0,
  269. addonAfter: "deg",
  270. },
  271. defaultValue: containerProps?.rotateZ ?? 0,
  272. },
  273. {
  274. label: "整体",
  275. type: 'divider',
  276. prop: "",
  277. },
  278. {
  279. label: "不透明度",
  280. prop: "props.opacity",
  281. type: "slider",
  282. defaultValue: containerProps?.opacity ?? 100,
  283. },
  284. ],
  285. },
  286. ];
  287. });
  288. return {
  289. formItems
  290. }
  291. };