From bfaf126fd8ff3978e5a8b296d515bcca62d7ee54 Mon Sep 17 00:00:00 2001
From: pipipi-pikachu <1171051090@qq.com>
Date: Mon, 25 Jan 2021 23:04:16 +0800
Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=8F=92=E5=85=A5=E8=A1=A8?=
=?UTF-8?q?=E6=A0=BC?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/configs/element.ts | 21 ++-
src/hooks/useCreateElement.ts | 23 ++-
.../Editor/CanvasTool/TableGenerator.vue | 163 ++++++++++++++++++
src/views/Editor/CanvasTool/index.vue | 21 ++-
4 files changed, 213 insertions(+), 15 deletions(-)
create mode 100644 src/views/Editor/CanvasTool/TableGenerator.vue
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 @@
+
+
+
+
+
+
+
+
+
+
+
+