TextToolForm.tsx 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. import { useEditor } from "@/modules/editor";
  2. import { DesignComp } from "@/modules/editor/objects/DesignTemp/DesignComp";
  3. import { css } from "@linaria/core";
  4. import { defineComponent, toRaw, watch, nextTick} from "vue";
  5. import { any } from "vue-types";
  6. import { Divider } from "ant-design-vue";
  7. import {
  8. AlignComp,
  9. FontFamily,
  10. FontSize,
  11. FontStyleWapper,
  12. LetterSpacingComp,
  13. LineHeightComp,
  14. TextToolItem,
  15. TextColor,
  16. TextStroke,
  17. } from "./TextToolComp";
  18. import { history } from "@/modules/editor/objects/DesignTemp/factory";
  19. import { designSizeToPx } from "@/modules/editor/module/utils";
  20. export const TextToolForm = defineComponent({
  21. props: {
  22. component: any<DesignComp>().isRequired,
  23. },
  24. setup(props) {
  25. const { controls, store , helper} = useEditor();
  26. const changeVal = (e: { dataIndex: string; value: any }) => {
  27. let editor = controls.textEditorCtrl.state.currEditor;
  28. if (!editor) {
  29. controls.textEditorCtrl.setCompValueInReg(e.dataIndex, e.value);
  30. return;
  31. }
  32. editor = toRaw(editor);
  33. editor.execute(e.dataIndex, e.value);
  34. console.log("change", e);
  35. setTimeout(() => {
  36. const selection = window.getSelection();
  37. selection?.removeAllRanges();
  38. editor.editing.view.focus();
  39. }, 100);
  40. };
  41. watch(
  42. () => store.currComp.value.text,
  43. () => {
  44. const editor = toRaw(controls.textEditorCtrl.state.currEditor);
  45. if (!editor && store.currComp.compKey == "Text") {
  46. nextTick(() => {
  47. const element: HTMLElement | null = document.querySelector(
  48. `#editor_${store.currComp.id}`
  49. );
  50. if (!element) {
  51. return;
  52. }
  53. const h = helper.pxToDesignSize(element.clientHeight);
  54. const size :any = store.currComp.layout.size.slice(0);
  55. size[1] = h;
  56. console.log("xxxxxxxxxxxxxxxxx");
  57. controls.selectCtrl.gizmo.selected[0].setSize(designSizeToPx(size[0]), designSizeToPx(h))
  58. helper.extendStreamCard(controls.pageCtrl.currStreamCardId);
  59. });
  60. }
  61. }
  62. );
  63. return () => {
  64. return (
  65. <div id="text_toolform">
  66. <div class={"text-white"}>文本</div>
  67. <div class={"mt-18px"}>
  68. <div class={formRowItem}>
  69. <TextToolItem
  70. column={{
  71. dataIndex: "fontFamily",
  72. component: FontFamily,
  73. props: {
  74. class: "w-190px",
  75. },
  76. }}
  77. onChange={changeVal}
  78. />
  79. <TextToolItem
  80. column={{
  81. label: "字号",
  82. dataIndex: "fontSize",
  83. component: FontSize,
  84. props: {
  85. class: "!w-full",
  86. },
  87. }}
  88. onChange={changeVal}
  89. />
  90. </div>
  91. <div class={formRowItem}>
  92. <TextToolItem
  93. column={{
  94. label: "字间距",
  95. dataIndex: "letterSpacing",
  96. component: LetterSpacingComp,
  97. props: {
  98. class: "!w-full",
  99. },
  100. }}
  101. onChange={changeVal}
  102. />
  103. <TextToolItem
  104. column={{
  105. label: "行高",
  106. dataIndex: "lineHeight",
  107. component: LineHeightComp,
  108. props: {
  109. class: "!w-full",
  110. },
  111. }}
  112. onChange={changeVal}
  113. />
  114. </div>
  115. <div class={formRowItem}>
  116. <FontStyleWapper onChange={changeVal} />
  117. <TextToolItem
  118. column={{
  119. label: "",
  120. dataIndex: "alignment",
  121. component: AlignComp,
  122. }}
  123. onChange={changeVal}
  124. />
  125. </div>
  126. </div>
  127. <Divider class={"!my-18px"} />
  128. <div class={[FormLabelItem, "justify-between mb-20px"]}>
  129. <div class={"label"}>颜色</div>
  130. <div>
  131. <TextToolItem
  132. column={{
  133. label: "字体颜色",
  134. dataIndex: "fontColor",
  135. component: TextColor,
  136. }}
  137. onChange={changeVal}
  138. />
  139. </div>
  140. </div>
  141. <div class={FormLabelItem}>
  142. <div class={"label"}>描边</div>
  143. <TextToolItem
  144. column={{
  145. label: "",
  146. dataIndex: "textStroke",
  147. component: TextStroke,
  148. }}
  149. onChange={changeVal}
  150. />
  151. </div>
  152. <Divider class={"!my-18px"} />
  153. </div>
  154. );
  155. };
  156. },
  157. });
  158. const formRowItem = css`
  159. display: flex;
  160. align-items: center;
  161. margin-bottom: 14px;
  162. &:last-child {
  163. margin-bottom: 0;
  164. }
  165. `;
  166. const FormLabelItem = css`
  167. display: flex;
  168. align-items: center;
  169. .label {
  170. min-width: 60px;
  171. margin-right: 10px;
  172. user-select: none;
  173. font-size: 12px;
  174. color: rgba(255, 255, 255, 0.8);
  175. }
  176. `;