TextToolbar.tsx 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. import {
  2. IconStrikethrough,
  3. IconTextBold,
  4. IconTextItalic,
  5. IconTextUnderline,
  6. } from "@/assets/icons";
  7. import { useEditor } from "@/modules/editor";
  8. import { DesignComp } from "@/modules/editor/objects/DesignTemp/DesignComp";
  9. import { LinkOutlined } from "@ant-design/icons-vue";
  10. import { css } from "@linaria/core";
  11. import { Button, Divider, InputNumber, Select } from "ant-design-vue";
  12. import { defineComponent, nextTick } from "vue";
  13. import { any } from "vue-types";
  14. import ToolbarsUI from "../../formItems/ToolbarsUI";
  15. import {
  16. AlignComp,
  17. LineHeightComp,
  18. TextColor,
  19. FontStyleComp,
  20. FontFamily,
  21. FontSize,
  22. } from "./ToolbarComp";
  23. export const TextToolbar = defineComponent({
  24. props: {
  25. component: any<DesignComp>().isRequired,
  26. },
  27. setup(props) {
  28. const { store, actions, controls } = useEditor();
  29. const toolbarColumns = [
  30. {
  31. dataIndex: "fontFamily",
  32. component: FontFamily,
  33. props: {
  34. class: "w-180px",
  35. },
  36. },
  37. {
  38. label: "字号",
  39. dataIndex: "fontSize",
  40. component: FontSize,
  41. },
  42. {
  43. label: "字体颜色",
  44. dataIndex: "fontColor",
  45. component: TextColor,
  46. },
  47. {
  48. label: "加粗",
  49. dataIndex: "bold",
  50. component: (props: any) => (
  51. <FontStyleComp icon={<IconTextBold />} {...props} />
  52. ),
  53. itemProps: {
  54. class: "!mx-2px",
  55. },
  56. },
  57. {
  58. label: "斜体",
  59. dataIndex: "italic",
  60. component: (props: any) => (
  61. <FontStyleComp icon={<IconTextItalic />} {...props} />
  62. ),
  63. itemProps: {
  64. class: "!mx-2px",
  65. },
  66. },
  67. {
  68. label: "下划线",
  69. dataIndex: "underline",
  70. component: (props: any) => (
  71. <FontStyleComp icon={<IconTextUnderline />} {...props} />
  72. ),
  73. itemProps: {
  74. class: "!mx-2px",
  75. },
  76. },
  77. {
  78. label: "删除线",
  79. dataIndex: "strikethrough",
  80. component: (props: any) => (
  81. <FontStyleComp icon={<IconStrikethrough />} {...props} />
  82. ),
  83. itemProps: {
  84. class: "!mx-2px",
  85. },
  86. },
  87. {
  88. component: () => (
  89. <Divider
  90. type="vertical"
  91. style={{ fontSize: "26px", borderColor: "#1f1f1f" }}
  92. />
  93. ),
  94. },
  95. {
  96. label: "对齐方式",
  97. dataIndex: "alignment",
  98. component: AlignComp,
  99. itemProps: {
  100. class: "!mx-2px",
  101. },
  102. },
  103. {
  104. label: "行高",
  105. dataIndex: "lineHeight",
  106. component: LineHeightComp,
  107. itemProps: {
  108. class: "!mx-2px",
  109. },
  110. },
  111. {
  112. component: () => (
  113. <Divider
  114. type="vertical"
  115. style={{ fontSize: "26px", borderColor: "#1f1f1f" }}
  116. />
  117. ),
  118. },
  119. {
  120. label: "链接",
  121. dataIndex: "link",
  122. component: (props: any) => (
  123. <Button
  124. icon={<LinkOutlined />}
  125. type="text"
  126. onClick={() => {
  127. console.log(props);
  128. }}
  129. ></Button>
  130. ),
  131. itemProps: {
  132. class: "!mx-2px",
  133. },
  134. },
  135. {
  136. component: () => (
  137. <Divider
  138. type="vertical"
  139. style={{ fontSize: "26px", borderColor: "#1f1f1f" }}
  140. />
  141. ),
  142. },
  143. ];
  144. const changeVal = (e: { dataIndex: string; value: any }) => {
  145. const editor = controls.textEditor;
  146. if (!editor) {
  147. return;
  148. }
  149. // const command = editor ? editor.commands.get(e.dataIndex) : null;
  150. // console.log(e, command);
  151. editor.execute(e.dataIndex, { value: e.value });
  152. editor.editing.view.focus();
  153. // const command = editor.commands.get(e.commandName)
  154. // actions.updateCompData(props.component, e.dataIndex, e.value);
  155. };
  156. return () => {
  157. const { component } = props;
  158. return (
  159. <div class={[TextToolbarStyle, "flex items-center"]} id="text_toolbar">
  160. <ToolbarsUI
  161. editor={controls.textEditor}
  162. data={component}
  163. columns={toolbarColumns}
  164. onChange={changeVal}
  165. />
  166. </div>
  167. );
  168. };
  169. },
  170. });
  171. const TextToolbarStyle = css``;