createAttrsForm.tsx 3.8 KB

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