|
@@ -1,19 +1,12 @@
|
|
|
|
|
+import { computed } from 'vue'
|
|
|
import { useStore } from 'vuex'
|
|
import { useStore } from 'vuex'
|
|
|
-import { MutationTypes } from '@/store'
|
|
|
|
|
|
|
+import { MutationTypes, State } from '@/store'
|
|
|
import { createRandomCode } from '@/utils/common'
|
|
import { createRandomCode } from '@/utils/common'
|
|
|
import { getImageSize } from '@/utils/image'
|
|
import { getImageSize } from '@/utils/image'
|
|
|
import { VIEWPORT_SIZE, VIEWPORT_ASPECT_RATIO } from '@/configs/canvas'
|
|
import { VIEWPORT_SIZE, VIEWPORT_ASPECT_RATIO } from '@/configs/canvas'
|
|
|
import { ChartType, PPTElement, TableCell } from '@/types/slides'
|
|
import { ChartType, PPTElement, TableCell } from '@/types/slides'
|
|
|
import { ShapePoolItem } from '@/configs/shapes'
|
|
import { ShapePoolItem } from '@/configs/shapes'
|
|
|
import { LinePoolItem } from '@/configs/lines'
|
|
import { LinePoolItem } from '@/configs/lines'
|
|
|
-import {
|
|
|
|
|
- DEFAULT_IMAGE,
|
|
|
|
|
- DEFAULT_TEXT,
|
|
|
|
|
- DEFAULT_SHAPE,
|
|
|
|
|
- DEFAULT_LINE,
|
|
|
|
|
- DEFAULT_CHART,
|
|
|
|
|
- DEFAULT_TABLE,
|
|
|
|
|
-} from '@/configs/element'
|
|
|
|
|
import useHistorySnapshot from '@/hooks/useHistorySnapshot'
|
|
import useHistorySnapshot from '@/hooks/useHistorySnapshot'
|
|
|
|
|
|
|
|
interface CommonElementPosition {
|
|
interface CommonElementPosition {
|
|
@@ -31,12 +24,12 @@ interface LineElementPosition {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
export default () => {
|
|
export default () => {
|
|
|
- const store = useStore()
|
|
|
|
|
|
|
+ const store = useStore<State>()
|
|
|
|
|
+ const themeColor = computed(() => store.state.theme.themeColor)
|
|
|
|
|
+ const fontColor = computed(() => store.state.theme.fontColor)
|
|
|
|
|
|
|
|
const { addHistorySnapshot } = useHistorySnapshot()
|
|
const { addHistorySnapshot } = useHistorySnapshot()
|
|
|
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
const createElement = (element: PPTElement) => {
|
|
const createElement = (element: PPTElement) => {
|
|
|
store.commit(MutationTypes.ADD_ELEMENT, element)
|
|
store.commit(MutationTypes.ADD_ELEMENT, element)
|
|
|
store.commit(MutationTypes.SET_ACTIVE_ELEMENT_ID_LIST, [element.id])
|
|
store.commit(MutationTypes.SET_ACTIVE_ELEMENT_ID_LIST, [element.id])
|
|
@@ -57,22 +50,35 @@ export default () => {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
createElement({
|
|
createElement({
|
|
|
- ...DEFAULT_IMAGE,
|
|
|
|
|
type: 'image',
|
|
type: 'image',
|
|
|
id: createRandomCode(),
|
|
id: createRandomCode(),
|
|
|
src,
|
|
src,
|
|
|
width,
|
|
width,
|
|
|
height,
|
|
height,
|
|
|
|
|
+ left: 0,
|
|
|
|
|
+ top: 0,
|
|
|
|
|
+ fixedRatio: true,
|
|
|
})
|
|
})
|
|
|
})
|
|
})
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
const createChartElement = (chartType: ChartType) => {
|
|
const createChartElement = (chartType: ChartType) => {
|
|
|
createElement({
|
|
createElement({
|
|
|
- ...DEFAULT_CHART,
|
|
|
|
|
type: 'chart',
|
|
type: 'chart',
|
|
|
id: createRandomCode(),
|
|
id: createRandomCode(),
|
|
|
chartType,
|
|
chartType,
|
|
|
|
|
+ left: 300,
|
|
|
|
|
+ top: 81.25,
|
|
|
|
|
+ width: 400,
|
|
|
|
|
+ height: 400,
|
|
|
|
|
+ themeColor: themeColor.value,
|
|
|
|
|
+ gridColor: fontColor.value,
|
|
|
|
|
+ data: {
|
|
|
|
|
+ labels: ['类别1', '类别2', '类别3', '类别4', '类别5'],
|
|
|
|
|
+ series: [
|
|
|
|
|
+ [12, 19, 5, 2, 18],
|
|
|
|
|
+ ],
|
|
|
|
|
+ },
|
|
|
})
|
|
})
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -86,33 +92,45 @@ export default () => {
|
|
|
const colWidths: number[] = new Array(col).fill(1 / col)
|
|
const colWidths: number[] = new Array(col).fill(1 / col)
|
|
|
|
|
|
|
|
createElement({
|
|
createElement({
|
|
|
- ...DEFAULT_TABLE,
|
|
|
|
|
type: 'table',
|
|
type: 'table',
|
|
|
id: createRandomCode(),
|
|
id: createRandomCode(),
|
|
|
width: col * DEFAULT_CELL_WIDTH,
|
|
width: col * DEFAULT_CELL_WIDTH,
|
|
|
height: row * DEFAULT_CELL_HEIGHT,
|
|
height: row * DEFAULT_CELL_HEIGHT,
|
|
|
colWidths,
|
|
colWidths,
|
|
|
data,
|
|
data,
|
|
|
|
|
+ left: 0,
|
|
|
|
|
+ top: 0,
|
|
|
|
|
+ outline: {
|
|
|
|
|
+ width: 2,
|
|
|
|
|
+ style: 'solid',
|
|
|
|
|
+ color: '#eeece1',
|
|
|
|
|
+ },
|
|
|
|
|
+ theme: {
|
|
|
|
|
+ color: themeColor.value,
|
|
|
|
|
+ rowHeader: true,
|
|
|
|
|
+ rowFooter: false,
|
|
|
|
|
+ colHeader: false,
|
|
|
|
|
+ colFooter: false,
|
|
|
|
|
+ },
|
|
|
})
|
|
})
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
const createTextElement = (position: CommonElementPosition) => {
|
|
const createTextElement = (position: CommonElementPosition) => {
|
|
|
const { left, top, width, height } = position
|
|
const { left, top, width, height } = position
|
|
|
createElement({
|
|
createElement({
|
|
|
- ...DEFAULT_TEXT,
|
|
|
|
|
type: 'text',
|
|
type: 'text',
|
|
|
id: createRandomCode(),
|
|
id: createRandomCode(),
|
|
|
left,
|
|
left,
|
|
|
top,
|
|
top,
|
|
|
width,
|
|
width,
|
|
|
height,
|
|
height,
|
|
|
|
|
+ content: '请输入内容',
|
|
|
})
|
|
})
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
const createShapeElement = (position: CommonElementPosition, data: ShapePoolItem) => {
|
|
const createShapeElement = (position: CommonElementPosition, data: ShapePoolItem) => {
|
|
|
const { left, top, width, height } = position
|
|
const { left, top, width, height } = position
|
|
|
createElement({
|
|
createElement({
|
|
|
- ...DEFAULT_SHAPE,
|
|
|
|
|
type: 'shape',
|
|
type: 'shape',
|
|
|
id: createRandomCode(),
|
|
id: createRandomCode(),
|
|
|
left,
|
|
left,
|
|
@@ -121,13 +139,14 @@ export default () => {
|
|
|
height,
|
|
height,
|
|
|
viewBox: data.viewBox,
|
|
viewBox: data.viewBox,
|
|
|
path: data.path,
|
|
path: data.path,
|
|
|
|
|
+ fill: themeColor.value,
|
|
|
|
|
+ fixedRatio: false,
|
|
|
})
|
|
})
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
const createLineElement = (position: LineElementPosition, data: LinePoolItem) => {
|
|
const createLineElement = (position: LineElementPosition, data: LinePoolItem) => {
|
|
|
const { left, top, start, end } = position
|
|
const { left, top, start, end } = position
|
|
|
createElement({
|
|
createElement({
|
|
|
- ...DEFAULT_LINE,
|
|
|
|
|
type: 'line',
|
|
type: 'line',
|
|
|
id: createRandomCode(),
|
|
id: createRandomCode(),
|
|
|
left,
|
|
left,
|
|
@@ -135,6 +154,9 @@ export default () => {
|
|
|
start,
|
|
start,
|
|
|
end,
|
|
end,
|
|
|
points: data.points,
|
|
points: data.points,
|
|
|
|
|
+ color: themeColor.value,
|
|
|
|
|
+ style: 'solid',
|
|
|
|
|
+ width: 2,
|
|
|
})
|
|
})
|
|
|
}
|
|
}
|
|
|
|
|
|