From 0242a9f336888fe6173e96651de00d6106f766ba Mon Sep 17 00:00:00 2001 From: pipipi-pikachu <1171051090@qq.com> Date: Tue, 26 Jan 2021 11:12:30 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E6=95=B4=E8=A1=A8=E6=A0=BC=E6=96=87?= =?UTF-8?q?=E5=AD=97=E6=A0=B7=E5=BC=8F=E8=B0=83=E6=95=B4=E6=96=B9=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/utils/emitter.ts | 2 +- .../ElementStylePanel/TableStylePanel.vue | 45 ++++++++++++------- .../components/element/TableElement/index.vue | 35 +-------------- 3 files changed, 32 insertions(+), 50 deletions(-) diff --git a/src/utils/emitter.ts b/src/utils/emitter.ts index e70b8a18..d12dbb21 100644 --- a/src/utils/emitter.ts +++ b/src/utils/emitter.ts @@ -4,7 +4,7 @@ export enum EmitterEvents { UPDATE_TEXT_STATE = 'UPDATE_TEXT_STATE', EXEC_TEXT_COMMAND = 'EXEC_TEXT_COMMAND', UPDATE_TABLE_SELECTED_CELL = 'UPDATE_TABLE_SELECTED_CELL', - EXEC_TABLE_TEXT_COMMAND = 'EXEC_TABLE_TEXT_COMMAND', + EXEC_TABLE_COMMAND = 'EXEC_TABLE_COMMAND', SCALE_ELEMENT_STATE = 'SCALE_ELEMENT_STATE', } diff --git a/src/views/Editor/Toolbar/ElementStylePanel/TableStylePanel.vue b/src/views/Editor/Toolbar/ElementStylePanel/TableStylePanel.vue index 99bcd457..1e6f0f8c 100644 --- a/src/views/Editor/Toolbar/ElementStylePanel/TableStylePanel.vue +++ b/src/views/Editor/Toolbar/ElementStylePanel/TableStylePanel.vue @@ -4,7 +4,7 @@ @@ -28,7 +28,7 @@ @@ -42,7 +42,7 @@ @@ -59,28 +59,28 @@ @@ -89,7 +89,7 @@ class="row" button-style="solid" :value="textAttrs.align" - @change="e => emitUpdateTextAttrCommand({ align: e.target.value })" + @change="e => updateTextAttrs({ align: e.target.value })" > @@ -186,7 +186,7 @@ import { computed, defineComponent, onUnmounted, ref, watch } from 'vue' import { useStore } from 'vuex' import { MutationTypes, State } from '@/store' -import { PPTTableElement, TableCellStyle, TableTheme } from '@/types/slides' +import { PPTTableElement, TableCell, TableCellStyle, TableTheme } from '@/types/slides' import emitter, { EmitterEvents } from '@/utils/emitter' import useHistorySnapshot from '@/hooks/useHistorySnapshot' @@ -227,7 +227,7 @@ export default defineComponent({ const selectedCells = ref([]) - const updateTextAttrs = () => { + const updateTextAttrState = () => { if(!handleElement.value) return let rowIndex = 0 @@ -269,7 +269,7 @@ export default defineComponent({ const updateSelectedCells = (cells: string[]) => { selectedCells.value = cells - updateTextAttrs() + updateTextAttrState() } emitter.on(EmitterEvents.UPDATE_TABLE_SELECTED_CELL, cells => updateSelectedCells(cells)) @@ -284,9 +284,22 @@ export default defineComponent({ const { addHistorySnapshot } = useHistorySnapshot() - const emitUpdateTextAttrCommand = (textAttrProp: Partial) => { - emitter.emit(EmitterEvents.EXEC_TABLE_TEXT_COMMAND, textAttrProp) - updateTextAttrs() + const updateTextAttrs = (textAttrProp: Partial) => { + const data: TableCell[][] = JSON.parse(JSON.stringify(handleElement.value.data)) + + for(let i = 0; i < data.length; i++) { + for(let j = 0; j < data[i].length; j++) { + if(!selectedCells.value.length || selectedCells.value.includes(`${i}_${j}`)) { + const style = data[i][j].style || {} + data[i][j].style = { ...style, ...textAttrProp } + } + } + } + const props = { data } + store.commit(MutationTypes.UPDATE_ELEMENT, { id: handleElement.value.id, props }) + + addHistorySnapshot() + updateTextAttrState() } const updateTheme = (themeProp: Partial) => { @@ -319,7 +332,7 @@ export default defineComponent({ availableFonts, fontSizeOptions, textAttrs, - emitUpdateTextAttrCommand, + updateTextAttrs, theme, hasTheme, toggleTheme, diff --git a/src/views/components/element/TableElement/index.vue b/src/views/components/element/TableElement/index.vue index 3e789023..4b569083 100644 --- a/src/views/components/element/TableElement/index.vue +++ b/src/views/components/element/TableElement/index.vue @@ -43,7 +43,7 @@ import { computed, defineComponent, nextTick, onMounted, onUnmounted, PropType, ref, watch } from 'vue' import { useStore } from 'vuex' import { MutationTypes, State } from '@/store' -import { PPTTableElement, TableCell, TableCellStyle } from '@/types/slides' +import { PPTTableElement, TableCell } from '@/types/slides' import emitter, { EmitterEvents } from '@/utils/emitter' import { ContextmenuItem } from '@/components/Contextmenu/types' import useHistorySnapshot from '@/hooks/useHistorySnapshot' @@ -159,40 +159,10 @@ export default defineComponent({ addHistorySnapshot() } - const selectedCells = ref([]) - - const updateTextAttrs = (textAttrProp: Partial) => { - const data: TableCell[][] = JSON.parse(JSON.stringify(props.elementInfo.data)) - - for(let i = 0; i < data.length; i++) { - for(let j = 0; j < data[i].length; j++) { - if(!selectedCells.value.length || selectedCells.value.includes(`${i}_${j}`)) { - const style = data[i][j].style || {} - data[i][j].style = { ...style, ...textAttrProp } - } - } - } - - store.commit(MutationTypes.UPDATE_ELEMENT, { - id: props.elementInfo.id, - props: { data }, - }) - - addHistorySnapshot() - } - const updateSelectedCells = (cells: string[]) => { - selectedCells.value = cells - nextTick(() => { - emitter.emit(EmitterEvents.UPDATE_TABLE_SELECTED_CELL, selectedCells.value) - }) + nextTick(() => emitter.emit(EmitterEvents.UPDATE_TABLE_SELECTED_CELL, cells)) } - emitter.on(EmitterEvents.EXEC_TABLE_TEXT_COMMAND, state => updateTextAttrs(state)) - onUnmounted(() => { - emitter.off(EmitterEvents.EXEC_TABLE_TEXT_COMMAND, state => updateTextAttrs(state)) - }) - const startEdit = () => { if(!props.elementInfo.lock) editable.value = true } @@ -205,7 +175,6 @@ export default defineComponent({ updateColWidths, editable, startEdit, - selectedCells, updateSelectedCells, } },