createAttrsForm.tsx 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339
  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 animateColumns: ColumnItem[] = [
  93. {
  94. label: "入场效果",
  95. dataIndex: "layout.border.style",
  96. component: "Select",
  97. props: {
  98. bordered: false,
  99. style: { backgroundColor: "#303030" },
  100. defaultValue: "none",
  101. options: [
  102. { label: "无", value: "none" },
  103. { label: "直线", value: "solid" },
  104. { label: "点状线", value: "dotted" },
  105. { label: "破折线", value: "dashed" },
  106. ],
  107. },
  108. },
  109. ];
  110. export const bdColumns: ColumnItem[] = [
  111. {
  112. label: "边框样式",
  113. dataIndex: "layout.border.style",
  114. component: "Select",
  115. props: {
  116. bordered: false,
  117. style: { backgroundColor: "#303030" },
  118. defaultValue: "none",
  119. options: [
  120. { label: "无", value: "none" },
  121. { label: "直线", value: "solid" },
  122. { label: "点状线", value: "dotted" },
  123. { label: "破折线", value: "dashed" },
  124. ],
  125. },
  126. },
  127. {
  128. label: "边框颜色",
  129. dataIndex: "layout.border.color",
  130. ...createColorOpts(),
  131. },
  132. {
  133. label: "边框尺寸",
  134. dataIndex: "layout.border.width",
  135. component: Slider,
  136. getValue(v) {
  137. if (v == undefined) return 0;
  138. return v;
  139. },
  140. props: {
  141. defaultValue: 0,
  142. step: 1,
  143. min: 0,
  144. max: 2,
  145. },
  146. },
  147. {
  148. label: "边框弧度",
  149. dataIndex: "layout.border.radius",
  150. component: Slider,
  151. getValue(v) {
  152. if (v == undefined) return 0;
  153. return v;
  154. },
  155. // isVisible: (value, data) =>
  156. // ["Web3D", "Container", "Video"].includes(data.compKey) ? false : true,
  157. props: {
  158. defaultValue: 0,
  159. min: 0,
  160. max: 100,
  161. step: 1,
  162. },
  163. },
  164. ];
  165. export const bgColumns: ColumnItem[] = [
  166. {
  167. label: "背景颜色",
  168. dataIndex: "layout.background.color",
  169. ...createColorOpts(true),
  170. },
  171. {
  172. label: "透明度",
  173. dataIndex: "layout.opacity",
  174. component: Slider,
  175. getValue(v) {
  176. if (v == undefined) return 1;
  177. return v;
  178. },
  179. isVisible: (value, data) =>
  180. ["Web3D", "Video"].includes(data.compKey) ? false : true,
  181. props: {
  182. defaultValue: 1,
  183. min: 0,
  184. max: 1,
  185. step: 0.01,
  186. },
  187. },
  188. // {
  189. // label: "背景图片",
  190. // dataIndex: "background.image",
  191. // component: ImagePicker,
  192. // },
  193. // {
  194. // label: "repeat",
  195. // dataIndex: "background.repeat",
  196. // component: "Select",
  197. // props: {
  198. // options: [
  199. // "repeat",
  200. // "no-repeat",
  201. // "repeat-x",
  202. // "repeat-y",
  203. // "repeat-round",
  204. // "repeat-space",
  205. // ].map((v) => ({ label: v, value: v })),
  206. // },
  207. // },
  208. // {
  209. // label: "position",
  210. // dataIndex: "background.position",
  211. // component: "Select",
  212. // props: {
  213. // options: [
  214. // "center",
  215. // "top",
  216. // "bottom",
  217. // "left",
  218. // "left-top",
  219. // "left-bottom",
  220. // "right",
  221. // "right-top",
  222. // "right-bottom",
  223. // ].map((v) => ({ label: v, value: v })),
  224. // },
  225. // },
  226. // {
  227. // label: "size",
  228. // dataIndex: "background.size",
  229. // component: "Select",
  230. // props: {
  231. // options: ["auto", "cover", "contain"].map((v) => ({
  232. // label: v,
  233. // value: v,
  234. // })),
  235. // },
  236. // },
  237. // {
  238. // label: "clipPath",
  239. // dataIndex: "background.clipPath",
  240. // component: "Input",
  241. // },
  242. ];
  243. export function createAttrsForm(valueColumns: ColumnItem[], columnsUI?: any) {
  244. return defineComponent({
  245. props: {
  246. component: any<DesignComp>().isRequired,
  247. },
  248. setup(props) {
  249. const { store, actions } = useEditor();
  250. function changeVal(e: { dataIndex: string; value: any }) {
  251. actions.updateCompData(store.currComp, e.dataIndex, e.value);
  252. actions.submitUpdate();
  253. }
  254. return () => {
  255. const { component } = props;
  256. return (
  257. <div class={formStyle}>
  258. {valueColumns.length ? (
  259. <>
  260. <div>
  261. <span class="text-white">属性</span>
  262. </div>
  263. <FormUI
  264. data={component}
  265. columns={valueColumns}
  266. onChange={changeVal}
  267. />
  268. <Divider></Divider>
  269. </>
  270. ) : null}
  271. {columnsUI && <columnsUI component={component} />}
  272. <div>
  273. <span class="text-white">布局</span>
  274. </div>
  275. <FormUI
  276. data={component}
  277. columns={layoutColumns}
  278. style={{ color: "red" }}
  279. onChange={changeVal}
  280. />
  281. {["Web3D", "Video", "Map"].includes(component.compKey) ? null : (
  282. <>
  283. <Divider></Divider>
  284. <div>
  285. <span class="text-white">背景</span>{" "}
  286. </div>
  287. <FormUI
  288. data={component}
  289. columns={bgColumns}
  290. onChange={changeVal}
  291. />
  292. </>
  293. )}
  294. {["Text", "Image", "Map"].includes(component.compKey) ? (
  295. <>
  296. <Divider></Divider>
  297. <div>
  298. <span class="text-white">边框</span>
  299. </div>
  300. <FormUI
  301. data={component}
  302. columns={bdColumns}
  303. onChange={changeVal}
  304. />
  305. </>
  306. ) : null}
  307. {/* 动效 */}
  308. <>
  309. <Divider />
  310. {/* <div>
  311. <span class="text-white">动效</span>
  312. </div>
  313. <FormUI
  314. data={component}
  315. columns={animateColumns}
  316. onChange={changeVal}
  317. /> */}
  318. </>
  319. </div>
  320. );
  321. };
  322. },
  323. });
  324. }
  325. const formStyle = css`
  326. .item_label {
  327. color: #a9abaf !important;
  328. }
  329. & > div {
  330. padding: 0 !important;
  331. }
  332. `;