createAttrsForm.tsx 4.6 KB

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