createAttrsForm.tsx 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. import { DesignComp } from "@/modules/editor/objects/DesignTemp/DesignComp";
  2. import FormUI, { ColumnItem } from "@queenjs/components/FormUI";
  3. import { isEmpty, set } from "lodash";
  4. import { defineComponent } from "vue";
  5. import { any } from "vue-types";
  6. import { GroupNumber } from "../formItems/GroupNumber";
  7. import { InputNumber, Select } from "ant-design-vue";
  8. import { createColorOpts } from "./formOpts/createColorOpts";
  9. import { ImagePicker } from "../formItems/ImagePicker";
  10. import { compMasks } from "@/modules/editor/objects/DesignTemp/creates/CompMasks";
  11. const layoutColumns: ColumnItem[] = [
  12. {
  13. label: "尺寸",
  14. dataIndex: "layout.size",
  15. component: GroupNumber,
  16. props: {
  17. labels: ["宽度", "高度"],
  18. },
  19. },
  20. // {
  21. // label: "对齐",
  22. // dataIndex: "layout.alignSelf",
  23. // component: Select,
  24. // props: {
  25. // class: "w-full",
  26. // options: [
  27. // { label: "左对齐", value: "start" },
  28. // { label: "居中", value: "center" },
  29. // { label: "右对齐", value: "end" },
  30. // ],
  31. // },
  32. // },
  33. {
  34. label: "外边距",
  35. dataIndex: "layout.margin",
  36. component: "Input",
  37. },
  38. {
  39. label: "内边距",
  40. dataIndex: "layout.padding",
  41. component: "Input",
  42. },
  43. // {
  44. // label: "左右偏移",
  45. // dataIndex: "layout.offsetX",
  46. // component: "Slider",
  47. // props: {
  48. // min: -375,
  49. // max: 375,
  50. // },
  51. // getValue: (v) => v || 0,
  52. // },
  53. // {
  54. // label: "上下偏移",
  55. // dataIndex: "layout.offsetY",
  56. // component: "Slider",
  57. // props: {
  58. // min: -375,
  59. // max: 375,
  60. // },
  61. // getValue: (v) => v || 0,
  62. // },
  63. {
  64. label: "层级",
  65. dataIndex: "layout.zIndex",
  66. component: InputNumber,
  67. props: {
  68. min: 0,
  69. max: 99,
  70. },
  71. },
  72. {
  73. label: "遮罩",
  74. dataIndex: "layout.mask",
  75. component: Select,
  76. props: {
  77. class: "w-full",
  78. options: [{ label: "无", value: "" }].concat(
  79. Object.entries(compMasks).map(([key, value]) => {
  80. return {
  81. label: value.name,
  82. value: key,
  83. };
  84. })
  85. ),
  86. },
  87. },
  88. ];
  89. const bgColumns: ColumnItem[] = [
  90. {
  91. label: "背景颜色",
  92. dataIndex: "background.color",
  93. ...createColorOpts(),
  94. },
  95. {
  96. label: "背景图片",
  97. dataIndex: "background.image",
  98. component: ImagePicker,
  99. },
  100. {
  101. label: "repeat",
  102. dataIndex: "background.repeat",
  103. component: "Select",
  104. props: {
  105. options: [
  106. "repeat",
  107. "no-repeat",
  108. "repeat-x",
  109. "repeat-y",
  110. "repeat-round",
  111. "repeat-space",
  112. ].map((v) => ({ label: v, value: v })),
  113. },
  114. },
  115. {
  116. label: "position",
  117. dataIndex: "background.position",
  118. component: "Select",
  119. props: {
  120. options: [
  121. "center",
  122. "top",
  123. "bottom",
  124. "left",
  125. "left-top",
  126. "left-bottom",
  127. "right",
  128. "right-top",
  129. "right-bottom",
  130. ].map((v) => ({ label: v, value: v })),
  131. },
  132. },
  133. {
  134. label: "size",
  135. dataIndex: "background.size",
  136. component: "Select",
  137. props: {
  138. options: ["auto", "cover", "contain"].map((v) => ({
  139. label: v,
  140. value: v,
  141. })),
  142. },
  143. },
  144. {
  145. label: "clipPath",
  146. dataIndex: "background.clipPath",
  147. component: "Input",
  148. },
  149. ];
  150. export function createAttrsForm(valueColumns: ColumnItem[]) {
  151. return defineComponent({
  152. props: {
  153. component: any<DesignComp>().isRequired,
  154. },
  155. setup(props) {
  156. function changeVal(e: { dataIndex: string; value: any }) {
  157. set(props.component, e.dataIndex, e.value);
  158. }
  159. return () => {
  160. const { component } = props;
  161. return (
  162. <div>
  163. {valueColumns.length ? (
  164. <>
  165. <div>组件属性</div>
  166. <FormUI
  167. data={component}
  168. columns={valueColumns}
  169. onChange={changeVal}
  170. />
  171. </>
  172. ) : null}
  173. <div>组件布局</div>
  174. <FormUI
  175. data={component}
  176. columns={layoutColumns}
  177. onChange={changeVal}
  178. />
  179. {!isEmpty(component?.background) ? (
  180. <>
  181. <div>组件背景</div>
  182. <FormUI
  183. data={component}
  184. columns={bgColumns}
  185. onChange={changeVal}
  186. />
  187. </>
  188. ) : null}
  189. </div>
  190. );
  191. };
  192. },
  193. });
  194. }