createAttrsForm.tsx 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  1. import { useEditor } from "@/modules/editor";
  2. import { DesignComp } from "@/modules/editor/objects/DesignTemp/DesignComp";
  3. import FormUI, { ColumnItem } from "@queenjs/components/FormUI";
  4. import { defineComponent } from "vue";
  5. import { any } from "vue-types";
  6. import { Size } from "../formItems/Size";
  7. import Slider from "../formItems/Slider";
  8. import { createColorOpts } from "./formOpts/createColorOpts";
  9. import { Divider } from "ant-design-vue";
  10. import Align from "./align";
  11. import { css } from "@linaria/core";
  12. export const layoutColumns: ColumnItem[] = [
  13. {
  14. label: "尺寸",
  15. dataIndex: "layout.size",
  16. component: Size,
  17. },
  18. {
  19. label: "对齐",
  20. component: Align,
  21. dataIndex: "id",
  22. },
  23. // {
  24. // label: "对齐",
  25. // dataIndex: "layout.alignSelf",
  26. // component: Select,
  27. // props: {
  28. // class: "w-full",
  29. // options: [
  30. // { label: "左对齐", value: "start" },
  31. // { label: "居中", value: "center" },
  32. // { label: "右对齐", value: "end" },
  33. // ],
  34. // },
  35. // },
  36. // {
  37. // label: "外边距",
  38. // dataIndex: "layout.margin",
  39. // component: "Input",
  40. // },
  41. // {
  42. // label: "内边距",
  43. // dataIndex: "layout.padding",
  44. // component: "Input",
  45. // },
  46. // {
  47. // label: "偏移矩阵",
  48. // dataIndex: "layout.transformMatrix",
  49. // component: Input,
  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. // label: "遮罩",
  72. // dataIndex: "layout.mask",
  73. // component: Select,
  74. // props: {
  75. // class: "w-full",
  76. // options: [{ label: "无", value: "" }].concat(
  77. // Object.entries(compMasks).map(([key, value]) => {
  78. // return {
  79. // label: value.name,
  80. // value: key,
  81. // };
  82. // })
  83. // ),
  84. // },
  85. // },
  86. // {
  87. // label: "锁定",
  88. // dataIndex: "layout.locked",
  89. // component: "Switch",
  90. // },
  91. ];
  92. export const bdColumns: ColumnItem[] = [
  93. {
  94. label: "边框样式",
  95. dataIndex: "layout.border.style",
  96. component: "Select",
  97. props: {
  98. defaultValue: "none",
  99. options: [
  100. { label: "无", value: "none" },
  101. { label: "直线", value: "solid" },
  102. { label: "点状线", value: "dotted" },
  103. { label: "破折线", value: "dashed" },
  104. ],
  105. },
  106. },
  107. {
  108. label: "边框颜色",
  109. dataIndex: "layout.border.color",
  110. ...createColorOpts(),
  111. },
  112. {
  113. label: "边框尺寸",
  114. dataIndex: "layout.border.width",
  115. component: Slider,
  116. getValue(v) {
  117. if (v== undefined ) return 0;
  118. return v;
  119. },
  120. props: {
  121. defaultValue: 0,
  122. step: 1,
  123. min: 0,
  124. max: 2,
  125. },
  126. },
  127. {
  128. label: "边框弧度",
  129. dataIndex: "layout.border.radius",
  130. component: Slider,
  131. getValue(v) {
  132. if (v== undefined ) return 0;
  133. return v;
  134. },
  135. // isVisible: (value, data) =>
  136. // ["Web3D", "Container", "Video"].includes(data.compKey) ? false : true,
  137. props: {
  138. defaultValue: 0,
  139. min: 0,
  140. max: 100,
  141. step: 1,
  142. },
  143. },
  144. ];
  145. export const bgColumns: ColumnItem[] = [
  146. {
  147. label: "背景颜色",
  148. dataIndex: "layout.background.color",
  149. ...createColorOpts(true),
  150. },
  151. {
  152. label: "透明度",
  153. dataIndex: "layout.opacity",
  154. component: Slider,
  155. isVisible: (value, data) =>
  156. ["Web3D", "Video"].includes(data.compKey) ? false : true,
  157. props: {
  158. defaultValue: 1,
  159. min: 0,
  160. max: 1,
  161. step: 0.01,
  162. },
  163. },
  164. // {
  165. // label: "背景图片",
  166. // dataIndex: "background.image",
  167. // component: ImagePicker,
  168. // },
  169. // {
  170. // label: "repeat",
  171. // dataIndex: "background.repeat",
  172. // component: "Select",
  173. // props: {
  174. // options: [
  175. // "repeat",
  176. // "no-repeat",
  177. // "repeat-x",
  178. // "repeat-y",
  179. // "repeat-round",
  180. // "repeat-space",
  181. // ].map((v) => ({ label: v, value: v })),
  182. // },
  183. // },
  184. // {
  185. // label: "position",
  186. // dataIndex: "background.position",
  187. // component: "Select",
  188. // props: {
  189. // options: [
  190. // "center",
  191. // "top",
  192. // "bottom",
  193. // "left",
  194. // "left-top",
  195. // "left-bottom",
  196. // "right",
  197. // "right-top",
  198. // "right-bottom",
  199. // ].map((v) => ({ label: v, value: v })),
  200. // },
  201. // },
  202. // {
  203. // label: "size",
  204. // dataIndex: "background.size",
  205. // component: "Select",
  206. // props: {
  207. // options: ["auto", "cover", "contain"].map((v) => ({
  208. // label: v,
  209. // value: v,
  210. // })),
  211. // },
  212. // },
  213. // {
  214. // label: "clipPath",
  215. // dataIndex: "background.clipPath",
  216. // component: "Input",
  217. // },
  218. ];
  219. export function createAttrsForm(valueColumns: ColumnItem[], columnsUI?: any) {
  220. return defineComponent({
  221. props: {
  222. component: any<DesignComp>().isRequired,
  223. },
  224. setup(props) {
  225. const { store, actions } = useEditor();
  226. function changeVal(e: { dataIndex: string; value: any }) {
  227. actions.updateCompData(store.currComp, e.dataIndex, e.value);
  228. actions.submitUpdate();
  229. }
  230. return () => {
  231. const { component } = props;
  232. return (
  233. <div class={formStyle}>
  234. {valueColumns.length ? (
  235. <>
  236. <div> <span class="text-white">属性</span></div>
  237. <FormUI
  238. data={component}
  239. columns={valueColumns}
  240. onChange={changeVal}
  241. />
  242. <Divider></Divider>
  243. </>
  244. ) : null}
  245. {columnsUI && <columnsUI component={component} />}
  246. <div><span class="text-white">布局</span></div>
  247. <FormUI
  248. data={component}
  249. columns={layoutColumns}
  250. style={{color: "red"}}
  251. onChange={changeVal}
  252. />
  253. {["Web3D", "Video", "Map"].includes(component.compKey) ? null : (
  254. <>
  255. <Divider></Divider>
  256. <div> <span class="text-white">背景</span> </div>
  257. <FormUI
  258. data={component}
  259. columns={bgColumns}
  260. onChange={changeVal}
  261. />
  262. </>
  263. )}
  264. {["Text", "Image", "Map"].includes(component.compKey) ? (
  265. <>
  266. <Divider></Divider>
  267. <div><span class="text-white">边框</span></div>
  268. <FormUI
  269. data={component}
  270. columns={bdColumns}
  271. onChange={changeVal}
  272. />
  273. </>
  274. ) : null}
  275. </div>
  276. );
  277. };
  278. },
  279. });
  280. }
  281. const formStyle = css`
  282. .item_label {
  283. color: #A9ABAF !important;
  284. }
  285. `