From 443607170a505495e5cbb3261654fc6ddb5c717a Mon Sep 17 00:00:00 2001 From: pipipi-pikachu Date: Wed, 9 Jun 2021 17:21:42 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E5=B0=86=E5=AF=8C=E6=96=87?= =?UTF-8?q?=E6=9C=AC=E7=8A=B6=E6=80=81=E5=92=8C=E8=A1=A8=E6=A0=BC=E6=A0=B7?= =?UTF-8?q?=E5=BC=8F=E7=8A=B6=E6=80=81=E7=9A=84=E7=9B=91=E5=90=AC/?= =?UTF-8?q?=E6=9B=B4=E6=96=B0=E6=9C=BA=E5=88=B6=E7=94=B1mitt=E6=94=B9?= =?UTF-8?q?=E4=B8=BAvuex?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/store/constants.ts | 2 ++ src/store/mutations.ts | 16 ++++++++-- src/store/state.ts | 5 +++ src/utils/emitter.ts | 2 -- src/utils/prosemirror/utils.ts | 20 +++++++++++- .../ElementStylePanel/TableStylePanel.vue | 17 ++-------- .../ElementStylePanel/TextStylePanel.vue | 32 ++----------------- .../components/element/TableElement/index.vue | 2 +- .../components/element/TextElement/index.vue | 4 +-- 9 files changed, 48 insertions(+), 52 deletions(-) diff --git a/src/store/constants.ts b/src/store/constants.ts index 2982f6ad..066d28da 100644 --- a/src/store/constants.ts +++ b/src/store/constants.ts @@ -14,6 +14,8 @@ export const enum MutationTypes { SET_AVAILABLE_FONTS = 'setAvailableFonts', SET_TOOLBAR_STATE = 'setToolbarState', SET_CLIPING_IMAGE_ELEMENT_ID = 'setClipingImageElementId', + SET_RICHTEXT_ATTRS = 'setRichTextAttrs', + SET_SELECTED_TABLE_CELLS = 'setSelectedTableCells', // slides SET_THEME = 'setTheme', diff --git a/src/store/mutations.ts b/src/store/mutations.ts index d4d8119d..4eebd920 100644 --- a/src/store/mutations.ts +++ b/src/store/mutations.ts @@ -6,6 +6,8 @@ import { Slide, PPTElement, SlideTheme } from '@/types/slides' import { CreatingElement } from '@/types/edit' import { SYS_FONTS } from '@/configs/font' import { isSupportFont } from '@/utils/font' +import { ToolbarState } from '@/types/toolbar' +import { TextAttrs } from '@/utils/prosemirror/utils' interface RemoveElementPropData { id: string; @@ -68,14 +70,22 @@ export const mutations: MutationTree = { state.availableFonts = SYS_FONTS.filter(font => isSupportFont(font.value)) }, - [MutationTypes.SET_TOOLBAR_STATE](state, type) { - state.toolbarState = type + [MutationTypes.SET_TOOLBAR_STATE](state, toolbarState: ToolbarState) { + state.toolbarState = toolbarState }, - [MutationTypes.SET_CLIPING_IMAGE_ELEMENT_ID](state, elId) { + [MutationTypes.SET_CLIPING_IMAGE_ELEMENT_ID](state, elId: string) { state.clipingImageElementId = elId }, + [MutationTypes.SET_RICHTEXT_ATTRS](state, attrs: TextAttrs) { + state.richTextAttrs = attrs + }, + + [MutationTypes.SET_SELECTED_TABLE_CELLS](state, cells: string[]) { + state.selectedTableCells = cells + }, + // slides [MutationTypes.SET_THEME](state, themeProps: Partial) { diff --git a/src/store/state.ts b/src/store/state.ts index bc0ae9eb..d617c2bb 100644 --- a/src/store/state.ts +++ b/src/store/state.ts @@ -4,6 +4,7 @@ import { ToolbarState } from '@/types/toolbar' import { slides } from '@/mocks/slides' import { theme } from '@/mocks/theme' import { SYS_FONTS } from '@/configs/font' +import { TextAttrs, defaultRichTextAttrs } from '@/utils/prosemirror/utils' export interface State { activeElementIdList: string[]; @@ -29,6 +30,8 @@ export interface State { shiftKeyState: boolean; screening: boolean; clipingImageElementId: string; + richTextAttrs: TextAttrs; + selectedTableCells: string[]; } export const state: State = { @@ -55,4 +58,6 @@ export const state: State = { shiftKeyState: false, // shift键按下状态 screening: false, // 是否进入放映状态 clipingImageElementId: '', // 当前正在裁剪的图片ID + richTextAttrs: defaultRichTextAttrs, // 富文本状态 + selectedTableCells: [], // 选中的表格单元格 } \ No newline at end of file diff --git a/src/utils/emitter.ts b/src/utils/emitter.ts index 618868c9..2ddd8e8f 100644 --- a/src/utils/emitter.ts +++ b/src/utils/emitter.ts @@ -1,9 +1,7 @@ import mitt, { Handler, Emitter } from 'mitt' export const enum EmitterEvents { - UPDATE_TEXT_STATE = 'UPDATE_TEXT_STATE', EXEC_TEXT_COMMAND = 'EXEC_TEXT_COMMAND', - UPDATE_TABLE_SELECTED_CELL = 'UPDATE_TABLE_SELECTED_CELL', SCALE_ELEMENT_STATE = 'SCALE_ELEMENT_STATE', } diff --git a/src/utils/prosemirror/utils.ts b/src/utils/prosemirror/utils.ts index 4a5ac2c6..41ec6939 100644 --- a/src/utils/prosemirror/utils.ts +++ b/src/utils/prosemirror/utils.ts @@ -112,4 +112,22 @@ export const getTextAttrs = (view: EditorView) => { } } -export type TextAttrs = ReturnType \ No newline at end of file +export type TextAttrs = ReturnType + +export const defaultRichTextAttrs: TextAttrs = { + bold: false, + em: false, + underline: false, + strikethrough: false, + superscript: false, + subscript: false, + code: false, + color: '#000', + backcolor: '#000', + fontsize: '20px', + fontname: '微软雅黑', + align: 'left', + bulletList: false, + orderedList: false, + blockquote: false, +} \ No newline at end of file diff --git a/src/views/Editor/Toolbar/ElementStylePanel/TableStylePanel.vue b/src/views/Editor/Toolbar/ElementStylePanel/TableStylePanel.vue index 8c693154..81f6ba59 100644 --- a/src/views/Editor/Toolbar/ElementStylePanel/TableStylePanel.vue +++ b/src/views/Editor/Toolbar/ElementStylePanel/TableStylePanel.vue @@ -192,10 +192,9 @@