diff --git a/src/configs/element.ts b/src/configs/element.ts index f64ca2a..f4e40dd 100644 --- a/src/configs/element.ts +++ b/src/configs/element.ts @@ -1,3 +1,5 @@ +import { PPTElementOutline } from '@/types/slides' + const DEFAULT_COLOR = '#d14424' export const ELEMENT_TYPE = { @@ -43,21 +45,24 @@ export const DEFAULT_CHART = { }, } +const tableOutline: PPTElementOutline = { + width: 2, + style: 'solid', + color: '#eeece1', +} export const DEFAULT_TABLE = { left: 0, top: 0, - outline: { - width: 2, - style: 'solid', + outline: tableOutline, + theme: { color: DEFAULT_COLOR, + rowHeader: true, + rowFooter: false, + colHeader: false, + colFooter: false, }, } -export const DEFAULT_FORMULA = { - left: 0, - top: 0, -} - export const MIN_SIZE = { text: 20, image: 20, diff --git a/src/hooks/useCreateElement.ts b/src/hooks/useCreateElement.ts index e1ff005..718ec77 100644 --- a/src/hooks/useCreateElement.ts +++ b/src/hooks/useCreateElement.ts @@ -3,7 +3,7 @@ import { MutationTypes } from '@/store' import { createRandomCode } from '@/utils/common' import { getImageSize } from '@/utils/image' import { VIEWPORT_SIZE, VIEWPORT_ASPECT_RATIO } from '@/configs/canvas' -import { ChartType, PPTElement } from '@/types/slides' +import { ChartType, PPTElement, TableCell } from '@/types/slides' import { ShapePoolItem } from '@/configs/shapes' import { LinePoolItem } from '@/configs/lines' import { @@ -12,6 +12,7 @@ import { DEFAULT_SHAPE, DEFAULT_LINE, DEFAULT_CHART, + DEFAULT_TABLE, } from '@/configs/element' import useHistorySnapshot from '@/hooks/useHistorySnapshot' @@ -75,8 +76,24 @@ export default () => { }) } - const createTableElement = (rowCount: number, colCount: number) => { - console.log(rowCount, colCount) + const createTableElement = (row: number, col: number) => { + const rowCells: TableCell[] = new Array(col).fill({ id: createRandomCode(), colspan: 1, rowspan: 1, text: '' }) + const data: TableCell[][] = new Array(row).fill(rowCells) + + const DEFAULT_CELL_WIDTH = 100 + const DEFAULT_CELL_HEIGHT = 40 + + const colWidths: number[] = new Array(col).fill(1 / col) + + createElement({ + ...DEFAULT_TABLE, + type: 'table', + id: createRandomCode(), + width: col * DEFAULT_CELL_WIDTH, + height: row * DEFAULT_CELL_HEIGHT, + colWidths, + data, + }) } const createTextElement = (position: CommonElementPosition) => { diff --git a/src/views/Editor/CanvasTool/TableGenerator.vue b/src/views/Editor/CanvasTool/TableGenerator.vue new file mode 100644 index 0000000..f941e64 --- /dev/null +++ b/src/views/Editor/CanvasTool/TableGenerator.vue @@ -0,0 +1,163 @@ + + + + + \ No newline at end of file diff --git a/src/views/Editor/CanvasTool/index.vue b/src/views/Editor/CanvasTool/index.vue index ae65925..af158b4 100644 --- a/src/views/Editor/CanvasTool/index.vue +++ b/src/views/Editor/CanvasTool/index.vue @@ -42,9 +42,17 @@ - - - + + + + + +
@@ -72,6 +80,7 @@ import useCreateElement from '@/hooks/useCreateElement' import ShapePool from './ShapePool.vue' import LinePool from './LinePool.vue' import ChartPool from './ChartPool.vue' +import TableGenerator from './TableGenerator.vue' export default defineComponent({ name: 'canvas-tool', @@ -79,6 +88,7 @@ export default defineComponent({ ShapePool, LinePool, ChartPool, + TableGenerator, }, setup() { const store = useStore() @@ -91,7 +101,7 @@ export default defineComponent({ const { scaleCanvas, setCanvasPercentage } = useScaleCanvas() const { redo, undo } = useHistorySnapshot() - const { createImageElement, createChartElement } = useCreateElement() + const { createImageElement, createChartElement, createTableElement } = useCreateElement() const insertImageElement = (files: File[]) => { const imageFile = files[0] @@ -102,6 +112,7 @@ export default defineComponent({ const shapePoolVisible = ref(false) const linePoolVisible = ref(false) const chartPoolVisible = ref(false) + const tableGeneratorVisible = ref(false) const drawText = () => { store.commit(MutationTypes.SET_CREATING_ELEMENT, { @@ -136,10 +147,12 @@ export default defineComponent({ shapePoolVisible, linePoolVisible, chartPoolVisible, + tableGeneratorVisible, drawText, drawShape, drawLine, createChartElement, + createTableElement, } }, })