123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176 |
- import {
- IconStrikethrough,
- IconTextBold,
- IconTextItalic,
- IconTextUnderline,
- } from "@/assets/icons";
- import { useEditor } from "@/modules/editor";
- import { DesignComp } from "@/modules/editor/objects/DesignTemp/DesignComp";
- import { LinkOutlined } from "@ant-design/icons-vue";
- import { css } from "@linaria/core";
- import { Button, Divider, InputNumber, Select } from "ant-design-vue";
- import { defineComponent, nextTick } from "vue";
- import { any } from "vue-types";
- import ToolbarsUI from "../../formItems/ToolbarsUI";
- import {
- AlignComp,
- LineHeightComp,
- TextColor,
- FontStyleComp,
- FontFamily,
- FontSize,
- } from "./ToolbarComp";
- export const TextToolbar = defineComponent({
- props: {
- component: any<DesignComp>().isRequired,
- },
- setup(props) {
- const { store, actions, controls } = useEditor();
- const toolbarColumns = [
- {
- dataIndex: "fontFamily",
- component: FontFamily,
- props: {
- class: "w-180px",
- },
- },
- {
- label: "字号",
- dataIndex: "fontSize",
- component: FontSize,
- },
- {
- label: "字体颜色",
- dataIndex: "fontColor",
- component: TextColor,
- },
- {
- label: "加粗",
- dataIndex: "bold",
- component: (props: any) => (
- <FontStyleComp icon={<IconTextBold />} {...props} />
- ),
- itemProps: {
- class: "!mx-2px",
- },
- },
- {
- label: "斜体",
- dataIndex: "italic",
- component: (props: any) => (
- <FontStyleComp icon={<IconTextItalic />} {...props} />
- ),
- itemProps: {
- class: "!mx-2px",
- },
- },
- {
- label: "下划线",
- dataIndex: "underline",
- component: (props: any) => (
- <FontStyleComp icon={<IconTextUnderline />} {...props} />
- ),
- itemProps: {
- class: "!mx-2px",
- },
- },
- {
- label: "删除线",
- dataIndex: "strikethrough",
- component: (props: any) => (
- <FontStyleComp icon={<IconStrikethrough />} {...props} />
- ),
- itemProps: {
- class: "!mx-2px",
- },
- },
- {
- component: () => (
- <Divider
- type="vertical"
- style={{ fontSize: "26px", borderColor: "#1f1f1f" }}
- />
- ),
- },
- {
- label: "对齐方式",
- dataIndex: "alignment",
- component: AlignComp,
- itemProps: {
- class: "!mx-2px",
- },
- },
- {
- label: "行高",
- dataIndex: "lineHeight",
- component: LineHeightComp,
- itemProps: {
- class: "!mx-2px",
- },
- },
- {
- component: () => (
- <Divider
- type="vertical"
- style={{ fontSize: "26px", borderColor: "#1f1f1f" }}
- />
- ),
- },
- {
- label: "链接",
- dataIndex: "link",
- component: (props: any) => (
- <Button
- icon={<LinkOutlined />}
- type="text"
- onClick={() => {
- console.log(props);
- }}
- ></Button>
- ),
- itemProps: {
- class: "!mx-2px",
- },
- },
- {
- component: () => (
- <Divider
- type="vertical"
- style={{ fontSize: "26px", borderColor: "#1f1f1f" }}
- />
- ),
- },
- ];
- const changeVal = (e: { dataIndex: string; value: any }) => {
- const editor = controls.textEditor;
- if (!editor) {
- return;
- }
- // const command = editor ? editor.commands.get(e.dataIndex) : null;
- // console.log(e, command);
- editor.execute(e.dataIndex, { value: e.value });
- editor.editing.view.focus();
- // const command = editor.commands.get(e.commandName)
- // actions.updateCompData(props.component, e.dataIndex, e.value);
- };
- return () => {
- const { component } = props;
- return (
- <div class={[TextToolbarStyle, "flex items-center"]} id="text_toolbar">
- <ToolbarsUI
- editor={controls.textEditor}
- data={component}
- columns={toolbarColumns}
- onChange={changeVal}
- />
- </div>
- );
- };
- },
- });
- const TextToolbarStyle = css``;
|