mirror of
https://github.com/pipipi-pikachu/PPTist.git
synced 2025-04-15 02:20:00 +08:00
docs: 补充代码注释
This commit is contained in:
parent
ce3e0eb529
commit
4b25579b45
@ -35,6 +35,7 @@ export default defineComponent({
|
|||||||
},
|
},
|
||||||
setup(props, { emit }) {
|
setup(props, { emit }) {
|
||||||
const color = computed(() => props.value)
|
const color = computed(() => props.value)
|
||||||
|
|
||||||
const gradientColor = computed(() => {
|
const gradientColor = computed(() => {
|
||||||
const rgbaStr = [color.value.r, color.value.g, color.value.b].join(',')
|
const rgbaStr = [color.value.r, color.value.g, color.value.b].join(',')
|
||||||
return `linear-gradient(to right, rgba(${rgbaStr}, 0) 0%, rgba(${rgbaStr}, 1) 100%)`
|
return `linear-gradient(to right, rgba(${rgbaStr}, 0) 0%, rgba(${rgbaStr}, 1) 100%)`
|
||||||
|
@ -6,6 +6,7 @@
|
|||||||
import { computed, defineComponent } from 'vue'
|
import { computed, defineComponent } from 'vue'
|
||||||
|
|
||||||
const checkboardCache = {}
|
const checkboardCache = {}
|
||||||
|
|
||||||
const renderCheckboard = (white: string, grey: string, size: number) => {
|
const renderCheckboard = (white: string, grey: string, size: number) => {
|
||||||
const canvas = document.createElement('canvas')
|
const canvas = document.createElement('canvas')
|
||||||
canvas.width = canvas.height = size * 2
|
canvas.width = canvas.height = size * 2
|
||||||
|
@ -27,7 +27,7 @@
|
|||||||
height: rubberSize + 'px',
|
height: rubberSize + 'px',
|
||||||
}"
|
}"
|
||||||
v-if="mouseInCanvas && model === 'eraser'"
|
v-if="mouseInCanvas && model === 'eraser'"
|
||||||
><IconClearFormat class="icon" :size="rubberSize * 0.6" /></div>
|
></div>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
@ -53,6 +53,7 @@ export default defineComponent({
|
|||||||
let ctx: CanvasRenderingContext2D | null = null
|
let ctx: CanvasRenderingContext2D | null = null
|
||||||
const writingBoardRef = ref<HTMLElement>()
|
const writingBoardRef = ref<HTMLElement>()
|
||||||
const canvasRef = ref<HTMLCanvasElement>()
|
const canvasRef = ref<HTMLCanvasElement>()
|
||||||
|
|
||||||
let lastPos = {
|
let lastPos = {
|
||||||
x: 0,
|
x: 0,
|
||||||
y: 0,
|
y: 0,
|
||||||
@ -61,12 +62,22 @@ export default defineComponent({
|
|||||||
let lastTime = 0
|
let lastTime = 0
|
||||||
let lastLineWidth = -1
|
let lastLineWidth = -1
|
||||||
|
|
||||||
|
// 鼠标位置坐标:用于画笔或橡皮位置跟随
|
||||||
const mouse = reactive({
|
const mouse = reactive({
|
||||||
x: 0,
|
x: 0,
|
||||||
y: 0,
|
y: 0,
|
||||||
})
|
})
|
||||||
|
// 更新鼠标位置坐标
|
||||||
|
const updateMousePosition = (e: MouseEvent) => {
|
||||||
|
mouse.x = e.pageX
|
||||||
|
mouse.y = e.pageY
|
||||||
|
}
|
||||||
|
|
||||||
|
// 鼠标是否处在画布范围内:处在范围内才会显示画笔或橡皮
|
||||||
const mouseInCanvas = ref(false)
|
const mouseInCanvas = ref(false)
|
||||||
|
|
||||||
|
|
||||||
|
// 初始化画布
|
||||||
const initCanvas = () => {
|
const initCanvas = () => {
|
||||||
if (!canvasRef.value || !writingBoardRef.value) return
|
if (!canvasRef.value || !writingBoardRef.value) return
|
||||||
|
|
||||||
@ -82,30 +93,9 @@ export default defineComponent({
|
|||||||
ctx.lineCap = 'round'
|
ctx.lineCap = 'round'
|
||||||
ctx.lineJoin = 'round'
|
ctx.lineJoin = 'round'
|
||||||
}
|
}
|
||||||
|
onMounted(initCanvas)
|
||||||
|
|
||||||
const getDistance = (posX: number, posY: number) => {
|
// 绘制画笔墨迹方法
|
||||||
const lastPosX = lastPos.x
|
|
||||||
const lastPosY = lastPos.y
|
|
||||||
return Math.sqrt((posX - lastPosX) * (posX - lastPosX) + (posY - lastPosY) * (posY - lastPosY))
|
|
||||||
}
|
|
||||||
|
|
||||||
const getLineWidth = (s: number, t: number) => {
|
|
||||||
const maxV = 10
|
|
||||||
const minV = 0.1
|
|
||||||
const maxWidth = penSize
|
|
||||||
const minWidth = 3
|
|
||||||
const v = s / t
|
|
||||||
let lineWidth
|
|
||||||
|
|
||||||
if (v <= minV) lineWidth = maxWidth
|
|
||||||
else if (v >= maxV) lineWidth = minWidth
|
|
||||||
else lineWidth = maxWidth - v / maxV * maxWidth
|
|
||||||
|
|
||||||
if (lastLineWidth === -1) return lineWidth
|
|
||||||
return lineWidth * 1 / 3 + lastLineWidth * 2 / 3
|
|
||||||
}
|
|
||||||
|
|
||||||
// 画笔绘制方法
|
|
||||||
const draw = (posX: number, posY: number, lineWidth: number) => {
|
const draw = (posX: number, posY: number, lineWidth: number) => {
|
||||||
if (!ctx) return
|
if (!ctx) return
|
||||||
|
|
||||||
@ -121,7 +111,7 @@ export default defineComponent({
|
|||||||
ctx.closePath()
|
ctx.closePath()
|
||||||
}
|
}
|
||||||
|
|
||||||
// 橡皮擦除方法
|
// 擦除墨迹方法
|
||||||
const erase = (posX: number, posY: number) => {
|
const erase = (posX: number, posY: number) => {
|
||||||
if (!ctx || !canvasRef.value) return
|
if (!ctx || !canvasRef.value) return
|
||||||
const lastPosX = lastPos.x
|
const lastPosX = lastPos.x
|
||||||
@ -155,47 +145,60 @@ export default defineComponent({
|
|||||||
ctx.restore()
|
ctx.restore()
|
||||||
}
|
}
|
||||||
|
|
||||||
const startDraw = (posX: number, posY: number) => {
|
// 准备开始绘制/擦除墨迹(落笔)
|
||||||
lastPos = { x: posX, y: posY }
|
|
||||||
lastTime = new Date().getTime()
|
|
||||||
}
|
|
||||||
|
|
||||||
const startMove = (posX: number, posY: number) => {
|
|
||||||
const time = new Date().getTime()
|
|
||||||
|
|
||||||
// 画笔模式(这里通过绘制速度调节画笔的粗细)
|
|
||||||
if (props.model === 'pen') {
|
|
||||||
const s = getDistance(posX, posY)
|
|
||||||
const t = time - lastTime
|
|
||||||
const lineWidth = getLineWidth(s, t)
|
|
||||||
|
|
||||||
draw(posX, posY, lineWidth)
|
|
||||||
lastLineWidth = lineWidth
|
|
||||||
}
|
|
||||||
// 橡皮模式
|
|
||||||
else erase(posX, posY)
|
|
||||||
|
|
||||||
lastPos = { x: posX, y: posY }
|
|
||||||
lastTime = new Date().getTime()
|
|
||||||
}
|
|
||||||
|
|
||||||
const handleMousedown = (e: MouseEvent) => {
|
const handleMousedown = (e: MouseEvent) => {
|
||||||
isMouseDown = true
|
isMouseDown = true
|
||||||
startDraw(e.offsetX, e.offsetY)
|
lastPos = { x: e.offsetX, y: e.offsetY }
|
||||||
|
lastTime = new Date().getTime()
|
||||||
}
|
}
|
||||||
|
|
||||||
const updateMousePosition = (e: MouseEvent) => {
|
// 计算鼠标两次移动之间的距离
|
||||||
mouse.x = e.pageX
|
const getDistance = (posX: number, posY: number) => {
|
||||||
mouse.y = e.pageY
|
const lastPosX = lastPos.x
|
||||||
|
const lastPosY = lastPos.y
|
||||||
|
return Math.sqrt((posX - lastPosX) * (posX - lastPosX) + (posY - lastPosY) * (posY - lastPosY))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 根据鼠标两次移动之间的距离s和时间t计算绘制速度,速度越快,墨迹越细
|
||||||
|
const getLineWidth = (s: number, t: number) => {
|
||||||
|
const maxV = 10
|
||||||
|
const minV = 0.1
|
||||||
|
const maxWidth = penSize
|
||||||
|
const minWidth = 3
|
||||||
|
const v = s / t
|
||||||
|
let lineWidth
|
||||||
|
|
||||||
|
if (v <= minV) lineWidth = maxWidth
|
||||||
|
else if (v >= maxV) lineWidth = minWidth
|
||||||
|
else lineWidth = maxWidth - v / maxV * maxWidth
|
||||||
|
|
||||||
|
if (lastLineWidth === -1) return lineWidth
|
||||||
|
return lineWidth * 1 / 3 + lastLineWidth * 2 / 3
|
||||||
|
}
|
||||||
|
|
||||||
|
// 开始绘制/擦除墨迹(移动)
|
||||||
const handleMousemove = (e: MouseEvent) => {
|
const handleMousemove = (e: MouseEvent) => {
|
||||||
updateMousePosition(e)
|
updateMousePosition(e)
|
||||||
|
|
||||||
if (!isMouseDown) return
|
if (!isMouseDown) return
|
||||||
startMove(e.offsetX, e.offsetY)
|
|
||||||
|
const time = new Date().getTime()
|
||||||
|
|
||||||
|
if (props.model === 'pen') {
|
||||||
|
const s = getDistance(e.offsetX, e.offsetY)
|
||||||
|
const t = time - lastTime
|
||||||
|
const lineWidth = getLineWidth(s, t)
|
||||||
|
|
||||||
|
draw(e.offsetX, e.offsetY, lineWidth)
|
||||||
|
lastLineWidth = lineWidth
|
||||||
|
}
|
||||||
|
else erase(e.offsetX, e.offsetY)
|
||||||
|
|
||||||
|
lastPos = { x: e.offsetX, y: e.offsetY }
|
||||||
|
lastTime = new Date().getTime()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 结束绘制/擦除墨迹(停笔)
|
||||||
const handleMouseup = () => {
|
const handleMouseup = () => {
|
||||||
if (!isMouseDown) return
|
if (!isMouseDown) return
|
||||||
isMouseDown = false
|
isMouseDown = false
|
||||||
@ -207,8 +210,6 @@ export default defineComponent({
|
|||||||
ctx.clearRect(0, 0, canvasRef.value.width, canvasRef.value.height)
|
ctx.clearRect(0, 0, canvasRef.value.width, canvasRef.value.height)
|
||||||
}
|
}
|
||||||
|
|
||||||
onMounted(initCanvas)
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
mouse,
|
mouse,
|
||||||
mouseInCanvas,
|
mouseInCanvas,
|
||||||
|
@ -15,6 +15,10 @@ export default () => {
|
|||||||
|
|
||||||
const { addHistorySnapshot } = useHistorySnapshot()
|
const { addHistorySnapshot } = useHistorySnapshot()
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 将所有选中的元素对齐到画布
|
||||||
|
* @param command 对齐方向
|
||||||
|
*/
|
||||||
const alignElementToCanvas = (command: ElementAlignCommand) => {
|
const alignElementToCanvas = (command: ElementAlignCommand) => {
|
||||||
const viewportWidth = VIEWPORT_SIZE
|
const viewportWidth = VIEWPORT_SIZE
|
||||||
const viewportHeight = VIEWPORT_SIZE * VIEWPORT_ASPECT_RATIO
|
const viewportHeight = VIEWPORT_SIZE * VIEWPORT_ASPECT_RATIO
|
||||||
@ -24,33 +28,45 @@ export default () => {
|
|||||||
for (const element of newElementList) {
|
for (const element of newElementList) {
|
||||||
if (!activeElementIdList.value.includes(element.id)) continue
|
if (!activeElementIdList.value.includes(element.id)) continue
|
||||||
|
|
||||||
|
// 水平垂直居中
|
||||||
if (command === ElementAlignCommands.CENTER) {
|
if (command === ElementAlignCommands.CENTER) {
|
||||||
const offsetY = minY + (maxY - minY) / 2 - viewportHeight / 2
|
const offsetY = minY + (maxY - minY) / 2 - viewportHeight / 2
|
||||||
const offsetX = minX + (maxX - minX) / 2 - viewportWidth / 2
|
const offsetX = minX + (maxX - minX) / 2 - viewportWidth / 2
|
||||||
element.top = element.top - offsetY
|
element.top = element.top - offsetY
|
||||||
element.left = element.left - offsetX
|
element.left = element.left - offsetX
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 顶部对齐
|
||||||
if (command === ElementAlignCommands.TOP) {
|
if (command === ElementAlignCommands.TOP) {
|
||||||
const offsetY = minY - 0
|
const offsetY = minY - 0
|
||||||
element.top = element.top - offsetY
|
element.top = element.top - offsetY
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 垂直居中
|
||||||
else if (command === ElementAlignCommands.VERTICAL) {
|
else if (command === ElementAlignCommands.VERTICAL) {
|
||||||
const offsetY = minY + (maxY - minY) / 2 - viewportHeight / 2
|
const offsetY = minY + (maxY - minY) / 2 - viewportHeight / 2
|
||||||
element.top = element.top - offsetY
|
element.top = element.top - offsetY
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 底部对齐
|
||||||
else if (command === ElementAlignCommands.BOTTOM) {
|
else if (command === ElementAlignCommands.BOTTOM) {
|
||||||
const offsetY = maxY - viewportHeight
|
const offsetY = maxY - viewportHeight
|
||||||
element.top = element.top - offsetY
|
element.top = element.top - offsetY
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 左侧对齐
|
||||||
else if (command === ElementAlignCommands.LEFT) {
|
else if (command === ElementAlignCommands.LEFT) {
|
||||||
const offsetX = minX - 0
|
const offsetX = minX - 0
|
||||||
element.left = element.left - offsetX
|
element.left = element.left - offsetX
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 水平居中
|
||||||
else if (command === ElementAlignCommands.HORIZONTAL) {
|
else if (command === ElementAlignCommands.HORIZONTAL) {
|
||||||
const offsetX = minX + (maxX - minX) / 2 - viewportWidth / 2
|
const offsetX = minX + (maxX - minX) / 2 - viewportWidth / 2
|
||||||
element.left = element.left - offsetX
|
element.left = element.left - offsetX
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 右侧对齐
|
||||||
else if (command === ElementAlignCommands.RIGHT) {
|
else if (command === ElementAlignCommands.RIGHT) {
|
||||||
const offsetX = maxX - viewportWidth
|
const offsetX = maxX - viewportWidth
|
||||||
element.left = element.left - offsetX
|
element.left = element.left - offsetX
|
||||||
|
@ -9,16 +9,23 @@ export default () => {
|
|||||||
const activeElementIdList = computed(() => store.state.activeElementIdList)
|
const activeElementIdList = computed(() => store.state.activeElementIdList)
|
||||||
const activeElementList = computed<PPTElement[]>(() => store.getters.activeElementList)
|
const activeElementList = computed<PPTElement[]>(() => store.getters.activeElementList)
|
||||||
const currentSlide = computed<Slide>(() => store.getters.currentSlide)
|
const currentSlide = computed<Slide>(() => store.getters.currentSlide)
|
||||||
|
const handleElementId = computed(() => store.state.handleElementId)
|
||||||
|
|
||||||
const { addHistorySnapshot } = useHistorySnapshot()
|
const { addHistorySnapshot } = useHistorySnapshot()
|
||||||
|
|
||||||
// 组合元素(为当前所有激活元素添加一个相同的groupId)
|
/**
|
||||||
|
* 组合当前选中的元素:给当前选中的元素赋予一个相同的分组ID
|
||||||
|
*/
|
||||||
const combineElements = () => {
|
const combineElements = () => {
|
||||||
if (!activeElementList.value.length) return
|
if (!activeElementList.value.length) return
|
||||||
|
|
||||||
|
// 生成一个新元素列表进行后续操作
|
||||||
let newElementList: PPTElement[] = JSON.parse(JSON.stringify(currentSlide.value.elements))
|
let newElementList: PPTElement[] = JSON.parse(JSON.stringify(currentSlide.value.elements))
|
||||||
|
|
||||||
|
// 生成分组ID
|
||||||
const groupId = createRandomCode()
|
const groupId = createRandomCode()
|
||||||
|
|
||||||
|
// 收集需要组合的元素列表,并赋上唯一分组ID
|
||||||
const combineElementList: PPTElement[] = []
|
const combineElementList: PPTElement[] = []
|
||||||
for (const element of newElementList) {
|
for (const element of newElementList) {
|
||||||
if (activeElementIdList.value.includes(element.id)) {
|
if (activeElementIdList.value.includes(element.id)) {
|
||||||
@ -27,19 +34,23 @@ export default () => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 注意,组合元素的层级应该是连续的,所以需要获取该组元素中最顶层的元素,将组内其他成员从原位置移动到最顶层的元素的下面
|
// 确保该组合内所有元素成员的层级是连续的,具体操作方法为:
|
||||||
const combineElementMaxIndex = newElementList.findIndex(_element => _element.id === combineElementList[combineElementList.length - 1].id)
|
// 先获取到该组合内最上层元素的层级,将本次需要组合的元素从新元素列表中移除,
|
||||||
|
// 再根据最上层元素的层级位置,将上面收集到的需要组合的元素列表一起插入到新元素列表中合适的位置
|
||||||
|
const combineElementMaxLevel = newElementList.findIndex(_element => _element.id === combineElementList[combineElementList.length - 1].id)
|
||||||
const combineElementIdList = combineElementList.map(_element => _element.id)
|
const combineElementIdList = combineElementList.map(_element => _element.id)
|
||||||
newElementList = newElementList.filter(_element => !combineElementIdList.includes(_element.id))
|
newElementList = newElementList.filter(_element => !combineElementIdList.includes(_element.id))
|
||||||
|
|
||||||
const insertIndex = combineElementMaxIndex - combineElementList.length + 1
|
const insertLevel = combineElementMaxLevel - combineElementList.length + 1
|
||||||
newElementList.splice(insertIndex, 0, ...combineElementList)
|
newElementList.splice(insertLevel, 0, ...combineElementList)
|
||||||
|
|
||||||
store.commit(MutationTypes.UPDATE_SLIDE, { elements: newElementList })
|
store.commit(MutationTypes.UPDATE_SLIDE, { elements: newElementList })
|
||||||
addHistorySnapshot()
|
addHistorySnapshot()
|
||||||
}
|
}
|
||||||
|
|
||||||
// 取消组合元素(移除所有被激活元素的groupId)
|
/**
|
||||||
|
* 取消组合元素:移除选中元素的分组ID
|
||||||
|
*/
|
||||||
const uncombineElements = () => {
|
const uncombineElements = () => {
|
||||||
if (!activeElementList.value.length) return
|
if (!activeElementList.value.length) return
|
||||||
const hasElementInGroup = activeElementList.value.some(item => item.groupId)
|
const hasElementInGroup = activeElementList.value.some(item => item.groupId)
|
||||||
@ -50,6 +61,11 @@ export default () => {
|
|||||||
if (activeElementIdList.value.includes(element.id) && element.groupId) delete element.groupId
|
if (activeElementIdList.value.includes(element.id) && element.groupId) delete element.groupId
|
||||||
}
|
}
|
||||||
store.commit(MutationTypes.UPDATE_SLIDE, { elements: newElementList })
|
store.commit(MutationTypes.UPDATE_SLIDE, { elements: newElementList })
|
||||||
|
|
||||||
|
// 取消组合后,需要重置激活元素状态
|
||||||
|
// 默认重置为当前正在操作的元素,如果不存在则重置为空
|
||||||
|
const handleElementIdList = handleElementId.value ? [handleElementId.value] : []
|
||||||
|
store.commit(MutationTypes.SET_ACTIVE_ELEMENT_ID_LIST, handleElementIdList)
|
||||||
addHistorySnapshot()
|
addHistorySnapshot()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -15,6 +15,7 @@ export default () => {
|
|||||||
const { pasteTextClipboardData } = usePasteTextClipboardData()
|
const { pasteTextClipboardData } = usePasteTextClipboardData()
|
||||||
const { deleteElement } = useDeleteElement()
|
const { deleteElement } = useDeleteElement()
|
||||||
|
|
||||||
|
// 将选中元素数据加密后复制到剪贴板
|
||||||
const copyElement = () => {
|
const copyElement = () => {
|
||||||
if (!activeElementIdList.value.length) return
|
if (!activeElementIdList.value.length) return
|
||||||
|
|
||||||
@ -28,17 +29,20 @@ export default () => {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 将选中元素复制后删除(剪切)
|
||||||
const cutElement = () => {
|
const cutElement = () => {
|
||||||
copyElement()
|
copyElement()
|
||||||
deleteElement()
|
deleteElement()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 尝试将剪贴板元素数据解密后进行粘贴
|
||||||
const pasteElement = () => {
|
const pasteElement = () => {
|
||||||
readClipboard().then(text => {
|
readClipboard().then(text => {
|
||||||
pasteTextClipboardData(text)
|
pasteTextClipboardData(text)
|
||||||
}).catch(err => message.warning(err))
|
}).catch(err => message.warning(err))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 将选中元素复制后立刻粘贴
|
||||||
const quickCopyElement = () => {
|
const quickCopyElement = () => {
|
||||||
copyElement()
|
copyElement()
|
||||||
pasteElement()
|
pasteElement()
|
||||||
|
@ -29,12 +29,17 @@ export default () => {
|
|||||||
|
|
||||||
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])
|
||||||
addHistorySnapshot()
|
addHistorySnapshot()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建图片元素
|
||||||
|
* @param src 图片地址
|
||||||
|
*/
|
||||||
const createImageElement = (src: string) => {
|
const createImageElement = (src: string) => {
|
||||||
getImageSize(src).then(({ width, height }) => {
|
getImageSize(src).then(({ width, height }) => {
|
||||||
const scale = height / width
|
const scale = height / width
|
||||||
@ -61,6 +66,10 @@ export default () => {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建图表元素
|
||||||
|
* @param chartType 图表类型
|
||||||
|
*/
|
||||||
const createChartElement = (chartType: ChartType) => {
|
const createChartElement = (chartType: ChartType) => {
|
||||||
createElement({
|
createElement({
|
||||||
type: 'chart',
|
type: 'chart',
|
||||||
@ -81,6 +90,11 @@ export default () => {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建表格元素
|
||||||
|
* @param row 行数
|
||||||
|
* @param col 列数
|
||||||
|
*/
|
||||||
const createTableElement = (row: number, col: number) => {
|
const createTableElement = (row: number, col: number) => {
|
||||||
const rowCells: TableCell[] = new Array(col).fill({ id: createRandomCode(), colspan: 1, rowspan: 1, text: '' })
|
const rowCells: TableCell[] = new Array(col).fill({ id: createRandomCode(), colspan: 1, rowspan: 1, text: '' })
|
||||||
const data: TableCell[][] = new Array(row).fill(rowCells)
|
const data: TableCell[][] = new Array(row).fill(rowCells)
|
||||||
@ -117,6 +131,11 @@ export default () => {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建文本元素
|
||||||
|
* @param position 位置大小信息
|
||||||
|
* @param content 文本内容
|
||||||
|
*/
|
||||||
const createTextElement = (position: CommonElementPosition, content = '请输入内容') => {
|
const createTextElement = (position: CommonElementPosition, content = '请输入内容') => {
|
||||||
const { left, top, width, height } = position
|
const { left, top, width, height } = position
|
||||||
createElement({
|
createElement({
|
||||||
@ -130,6 +149,11 @@ export default () => {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建形状元素
|
||||||
|
* @param position 位置大小信息
|
||||||
|
* @param data 形状路径信息
|
||||||
|
*/
|
||||||
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({
|
||||||
@ -146,6 +170,11 @@ export default () => {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建线条元素
|
||||||
|
* @param position 位置大小信息
|
||||||
|
* @param data 线条的路径和样式
|
||||||
|
*/
|
||||||
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({
|
||||||
|
@ -10,6 +10,7 @@ export default () => {
|
|||||||
|
|
||||||
const { addHistorySnapshot } = useHistorySnapshot()
|
const { addHistorySnapshot } = useHistorySnapshot()
|
||||||
|
|
||||||
|
// 删除全部选中元素
|
||||||
const deleteElement = () => {
|
const deleteElement = () => {
|
||||||
if (!activeElementIdList.value.length) return
|
if (!activeElementIdList.value.length) return
|
||||||
const newElementList = currentSlide.value.elements.filter(el => !activeElementIdList.value.includes(el.id))
|
const newElementList = currentSlide.value.elements.filter(el => !activeElementIdList.value.includes(el.id))
|
||||||
@ -18,6 +19,7 @@ export default () => {
|
|||||||
addHistorySnapshot()
|
addHistorySnapshot()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 删除内面内全部元素(无论是否选中)
|
||||||
const deleteAllElements = () => {
|
const deleteAllElements = () => {
|
||||||
if (!currentSlide.value.elements.length) return
|
if (!currentSlide.value.elements.length) return
|
||||||
store.commit(MutationTypes.SET_ACTIVE_ELEMENT_ID_LIST, [])
|
store.commit(MutationTypes.SET_ACTIVE_ELEMENT_ID_LIST, [])
|
||||||
|
@ -5,14 +5,17 @@ import { ActionTypes, useStore } from '@/store'
|
|||||||
export default () => {
|
export default () => {
|
||||||
const store = useStore()
|
const store = useStore()
|
||||||
|
|
||||||
|
// 添加历史快照(历史记录)
|
||||||
const addHistorySnapshot = debounce(function() {
|
const addHistorySnapshot = debounce(function() {
|
||||||
store.dispatch(ActionTypes.ADD_SNAPSHOT)
|
store.dispatch(ActionTypes.ADD_SNAPSHOT)
|
||||||
}, 300, { trailing: true })
|
}, 300, { trailing: true })
|
||||||
|
|
||||||
|
// 重做
|
||||||
const redo = throttle(function() {
|
const redo = throttle(function() {
|
||||||
store.dispatch(ActionTypes.RE_DO)
|
store.dispatch(ActionTypes.RE_DO)
|
||||||
}, 100, { leading: true, trailing: false })
|
}, 100, { leading: true, trailing: false })
|
||||||
|
|
||||||
|
// 撤销
|
||||||
const undo = throttle(function() {
|
const undo = throttle(function() {
|
||||||
store.dispatch(ActionTypes.UN_DO)
|
store.dispatch(ActionTypes.UN_DO)
|
||||||
}, 100, { leading: true, trailing: false })
|
}, 100, { leading: true, trailing: false })
|
||||||
|
@ -10,6 +10,7 @@ export default () => {
|
|||||||
|
|
||||||
const { addHistorySnapshot } = useHistorySnapshot()
|
const { addHistorySnapshot } = useHistorySnapshot()
|
||||||
|
|
||||||
|
// 锁定选中的元素,并清空选中元素状态
|
||||||
const lockElement = () => {
|
const lockElement = () => {
|
||||||
const newElementList: PPTElement[] = JSON.parse(JSON.stringify(currentSlide.value.elements))
|
const newElementList: PPTElement[] = JSON.parse(JSON.stringify(currentSlide.value.elements))
|
||||||
|
|
||||||
@ -21,6 +22,10 @@ export default () => {
|
|||||||
addHistorySnapshot()
|
addHistorySnapshot()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 解除元素的锁定状态,并将其设置为当前选择元素
|
||||||
|
* @param handleElement 需要解锁的元素
|
||||||
|
*/
|
||||||
const unlockElement = (handleElement: PPTElement) => {
|
const unlockElement = (handleElement: PPTElement) => {
|
||||||
const newElementList: PPTElement[] = JSON.parse(JSON.stringify(currentSlide.value.elements))
|
const newElementList: PPTElement[] = JSON.parse(JSON.stringify(currentSlide.value.elements))
|
||||||
|
|
||||||
|
@ -11,22 +11,27 @@ export default () => {
|
|||||||
|
|
||||||
const { addHistorySnapshot } = useHistorySnapshot()
|
const { addHistorySnapshot } = useHistorySnapshot()
|
||||||
|
|
||||||
const moveElement = (command: string) => {
|
/**
|
||||||
|
* 将元素向指定方向移动指定的距离
|
||||||
|
* @param command 移动方向
|
||||||
|
* @param step 移动距离
|
||||||
|
*/
|
||||||
|
const moveElement = (command: string, step = 1) => {
|
||||||
const newElementList = currentSlide.value.elements.map(el => {
|
const newElementList = currentSlide.value.elements.map(el => {
|
||||||
if (activeElementIdList.value.includes(el.id)) {
|
if (activeElementIdList.value.includes(el.id)) {
|
||||||
let { left, top } = el
|
let { left, top } = el
|
||||||
switch (command) {
|
switch (command) {
|
||||||
case KEYS.LEFT:
|
case KEYS.LEFT:
|
||||||
left = left - 1
|
left = left - step
|
||||||
break
|
break
|
||||||
case KEYS.RIGHT:
|
case KEYS.RIGHT:
|
||||||
left = left + 1
|
left = left + step
|
||||||
break
|
break
|
||||||
case KEYS.UP:
|
case KEYS.UP:
|
||||||
top = top - 1
|
top = top - step
|
||||||
break
|
break
|
||||||
case KEYS.DOWN:
|
case KEYS.DOWN:
|
||||||
top = top + 1
|
top = top + step
|
||||||
break
|
break
|
||||||
default: break
|
default: break
|
||||||
}
|
}
|
||||||
|
@ -10,165 +10,190 @@ export default () => {
|
|||||||
|
|
||||||
const { addHistorySnapshot } = useHistorySnapshot()
|
const { addHistorySnapshot } = useHistorySnapshot()
|
||||||
|
|
||||||
// 获取组合元素层级范围(组合成员中的最大层级和最小层级)
|
/**
|
||||||
const getCombineElementIndexRange = (elementList: PPTElement[], combineElementList: PPTElement[]) => {
|
* 获取组合元素层级范围
|
||||||
const minIndex = elementList.findIndex(_element => _element.id === combineElementList[0].id)
|
* @param elementList 本页所有元素列表
|
||||||
const maxIndex = elementList.findIndex(_element => _element.id === combineElementList[combineElementList.length - 1].id)
|
* @param combineElementList 组合元素列表
|
||||||
return { minIndex, maxIndex }
|
*/
|
||||||
|
const getCombineElementLevelRange = (elementList: PPTElement[], combineElementList: PPTElement[]) => {
|
||||||
|
return {
|
||||||
|
minLevel: elementList.findIndex(_element => _element.id === combineElementList[0].id),
|
||||||
|
maxLevel: elementList.findIndex(_element => _element.id === combineElementList[combineElementList.length - 1].id),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 上移一层,返回移动后新的元素列表(下移一层逻辑类似)
|
/**
|
||||||
|
* 上移一层
|
||||||
|
* @param elementList 本页所有元素列表
|
||||||
|
* @param element 当前操作的元素
|
||||||
|
*/
|
||||||
const moveUpElement = (elementList: PPTElement[], element: PPTElement) => {
|
const moveUpElement = (elementList: PPTElement[], element: PPTElement) => {
|
||||||
const copyOfElementList: PPTElement[] = JSON.parse(JSON.stringify(elementList))
|
const copyOfElementList: PPTElement[] = JSON.parse(JSON.stringify(elementList))
|
||||||
|
|
||||||
// 被操作的元素是组合元素成员
|
// 如果被操作的元素是组合元素成员,需要将该组合全部成员一起进行移动
|
||||||
if (element.groupId) {
|
if (element.groupId) {
|
||||||
|
|
||||||
// 获取该组合元素全部成员,以及组合元素层级范围
|
// 获取到该组合全部成员,以及所有成员的层级范围
|
||||||
const combineElementList = copyOfElementList.filter(_element => _element.groupId === element.groupId)
|
const combineElementList = copyOfElementList.filter(_element => _element.groupId === element.groupId)
|
||||||
const { minIndex, maxIndex } = getCombineElementIndexRange(elementList, combineElementList)
|
const { minLevel, maxLevel } = getCombineElementLevelRange(elementList, combineElementList)
|
||||||
|
|
||||||
// 无法移动(已经处在顶层)
|
// 已经处在顶层,无法继续移动
|
||||||
if (maxIndex === elementList.length - 1) return null
|
if (maxLevel === elementList.length - 1) return
|
||||||
|
|
||||||
// 该组合元素上一层的元素,以下简称为【元素next】
|
// 通过组合成员范围的最大值,获取到该组合上一层的元素,然后将该组合元素从元素列表中移除(并缓存被移除的元素列表)
|
||||||
const nextElement = copyOfElementList[maxIndex + 1]
|
// 若上层元素处在另一个组合中,则将上述被移除的组合元素插入到该上层组合上方
|
||||||
|
// 若上层元素不处于任何分组中,则将上述被移除的组合元素插入到该上层元素上方
|
||||||
|
const nextElement = copyOfElementList[maxLevel + 1]
|
||||||
|
const movedElementList = copyOfElementList.splice(minLevel, combineElementList.length)
|
||||||
|
|
||||||
// 从元素列表中移除该组合元素全部成员
|
|
||||||
const movedElementList = copyOfElementList.splice(minIndex, combineElementList.length)
|
|
||||||
|
|
||||||
// 如果【元素next】也是组合元素成员(另一个组合,不是上面被移除的那一组,以下简称为【组合next】)
|
|
||||||
// 需要获取【组合next】全部成员的长度,将上面移除的组合元素全部成员添加到【组合next】全部成员的上方
|
|
||||||
if (nextElement.groupId) {
|
if (nextElement.groupId) {
|
||||||
const nextCombineElementList = copyOfElementList.filter(_element => _element.groupId === nextElement.groupId)
|
const nextCombineElementList = copyOfElementList.filter(_element => _element.groupId === nextElement.groupId)
|
||||||
copyOfElementList.splice(minIndex + nextCombineElementList.length, 0, ...movedElementList)
|
copyOfElementList.splice(minLevel + nextCombineElementList.length, 0, ...movedElementList)
|
||||||
|
}
|
||||||
|
else copyOfElementList.splice(minLevel + 1, 0, ...movedElementList)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 如果【元素next】是单独的元素(非组合成员),将上面移除的组合元素全部成员添加到【元素next】上方
|
// 如果被操作的元素不是组合元素成员
|
||||||
else copyOfElementList.splice(minIndex + 1, 0, ...movedElementList)
|
|
||||||
}
|
|
||||||
|
|
||||||
// 被操作的元素是单独的元素(非组合成员)
|
|
||||||
else {
|
else {
|
||||||
|
|
||||||
// 元素在元素列表中的层级
|
// 获取该元素在列表中的层级
|
||||||
const elementIndex = elementList.findIndex(item => item.id === element.id)
|
const level = elementList.findIndex(item => item.id === element.id)
|
||||||
|
|
||||||
// 无法移动(已经处在顶层)
|
// 已经处在顶层,无法继续移动
|
||||||
if (elementIndex === elementList.length - 1) return null
|
if (level === elementList.length - 1) return
|
||||||
|
|
||||||
// 上一层的元素,以下简称为【元素next】
|
// 获取到该组合上一层的元素,然后将该组合元素从元素列表中移除(并缓存被移除的元素列表)
|
||||||
const nextElement = copyOfElementList[elementIndex + 1]
|
const nextElement = copyOfElementList[level + 1]
|
||||||
|
const movedElement = copyOfElementList.splice(level, 1)[0]
|
||||||
|
|
||||||
// 从元素列表中移除被操作的元素
|
// 通过组合成员范围的最大值,获取到该组合上一层的元素,然后将该组合元素从元素列表中移除(并缓存被移除的元素列表)
|
||||||
const movedElement = copyOfElementList.splice(elementIndex, 1)[0]
|
// 若上层元素处在另一个组合中,则将上述被移除的组合元素插入到该上层组合上方
|
||||||
|
// 若上层元素不处于任何分组中,则将上述被移除的组合元素插入到该上层元素上方
|
||||||
// 如果【元素next】是组合元素成员
|
|
||||||
// 需要获取该组合全部成员的长度,将上面移除的元素添加到该组合全部成员的上方
|
|
||||||
if (nextElement.groupId) {
|
if (nextElement.groupId) {
|
||||||
const combineElementList = copyOfElementList.filter(_element => _element.groupId === nextElement.groupId)
|
const combineElementList = copyOfElementList.filter(_element => _element.groupId === nextElement.groupId)
|
||||||
copyOfElementList.splice(elementIndex + combineElementList.length, 0, movedElement)
|
copyOfElementList.splice(level + combineElementList.length, 0, movedElement)
|
||||||
}
|
}
|
||||||
|
else copyOfElementList.splice(level + 1, 0, movedElement)
|
||||||
// 如果【元素next】是单独的元素(非组合成员),将上面移除的元素添加到【元素next】上方
|
|
||||||
else copyOfElementList.splice(elementIndex + 1, 0, movedElement)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return copyOfElementList
|
return copyOfElementList
|
||||||
}
|
}
|
||||||
|
|
||||||
// 下移一层
|
/**
|
||||||
|
* 下移一层,操作方式同上移
|
||||||
|
* @param elementList 本页所有元素列表
|
||||||
|
* @param element 当前操作的元素
|
||||||
|
*/
|
||||||
const moveDownElement = (elementList: PPTElement[], element: PPTElement) => {
|
const moveDownElement = (elementList: PPTElement[], element: PPTElement) => {
|
||||||
const copyOfElementList: PPTElement[] = JSON.parse(JSON.stringify(elementList))
|
const copyOfElementList: PPTElement[] = JSON.parse(JSON.stringify(elementList))
|
||||||
|
|
||||||
if (element.groupId) {
|
if (element.groupId) {
|
||||||
const combineElementList = copyOfElementList.filter(_element => _element.groupId === element.groupId)
|
const combineElementList = copyOfElementList.filter(_element => _element.groupId === element.groupId)
|
||||||
const { minIndex } = getCombineElementIndexRange(elementList, combineElementList)
|
const { minLevel } = getCombineElementLevelRange(elementList, combineElementList)
|
||||||
if (minIndex === 0) return null
|
if (minLevel === 0) return
|
||||||
const prevElement = copyOfElementList[minIndex - 1]
|
|
||||||
const movedElementList = copyOfElementList.splice(minIndex, combineElementList.length)
|
const prevElement = copyOfElementList[minLevel - 1]
|
||||||
|
const movedElementList = copyOfElementList.splice(minLevel, combineElementList.length)
|
||||||
|
|
||||||
if (prevElement.groupId) {
|
if (prevElement.groupId) {
|
||||||
const prevCombineElementList = copyOfElementList.filter(_element => _element.groupId === prevElement.groupId)
|
const prevCombineElementList = copyOfElementList.filter(_element => _element.groupId === prevElement.groupId)
|
||||||
copyOfElementList.splice(minIndex - prevCombineElementList.length, 0, ...movedElementList)
|
copyOfElementList.splice(minLevel - prevCombineElementList.length, 0, ...movedElementList)
|
||||||
}
|
}
|
||||||
else copyOfElementList.splice(minIndex - 1, 0, ...movedElementList)
|
else copyOfElementList.splice(minLevel - 1, 0, ...movedElementList)
|
||||||
}
|
}
|
||||||
|
|
||||||
else {
|
else {
|
||||||
const elementIndex = elementList.findIndex(item => item.id === element.id)
|
const level = elementList.findIndex(item => item.id === element.id)
|
||||||
if (elementIndex === 0) return null
|
if (level === 0) return
|
||||||
const prevElement = copyOfElementList[elementIndex - 1]
|
|
||||||
const movedElement = copyOfElementList.splice(elementIndex, 1)[0]
|
const prevElement = copyOfElementList[level - 1]
|
||||||
|
const movedElement = copyOfElementList.splice(level, 1)[0]
|
||||||
|
|
||||||
if (prevElement.groupId) {
|
if (prevElement.groupId) {
|
||||||
const combineElementList = copyOfElementList.filter(_element => _element.groupId === prevElement.groupId)
|
const combineElementList = copyOfElementList.filter(_element => _element.groupId === prevElement.groupId)
|
||||||
copyOfElementList.splice(elementIndex - combineElementList.length, 0, movedElement)
|
copyOfElementList.splice(level - combineElementList.length, 0, movedElement)
|
||||||
}
|
}
|
||||||
else copyOfElementList.splice(elementIndex - 1, 0, movedElement)
|
else copyOfElementList.splice(level - 1, 0, movedElement)
|
||||||
}
|
}
|
||||||
|
|
||||||
return copyOfElementList
|
return copyOfElementList
|
||||||
}
|
}
|
||||||
|
|
||||||
// 置顶层,返回移动后新的元素列表(置底层逻辑类似)
|
/**
|
||||||
|
* 置顶层
|
||||||
|
* @param elementList 本页所有元素列表
|
||||||
|
* @param element 当前操作的元素
|
||||||
|
*/
|
||||||
const moveTopElement = (elementList: PPTElement[], element: PPTElement) => {
|
const moveTopElement = (elementList: PPTElement[], element: PPTElement) => {
|
||||||
const copyOfElementList: PPTElement[] = JSON.parse(JSON.stringify(elementList))
|
const copyOfElementList: PPTElement[] = JSON.parse(JSON.stringify(elementList))
|
||||||
|
|
||||||
// 被操作的元素是组合元素成员
|
// 如果被操作的元素是组合元素成员,需要将该组合全部成员一起进行移动
|
||||||
if (element.groupId) {
|
if (element.groupId) {
|
||||||
|
|
||||||
// 获取该组合元素全部成员,以及组合元素层级范围
|
// 获取到该组合全部成员,以及所有成员的层级范围
|
||||||
const combineElementList = copyOfElementList.filter(_element => _element.groupId === element.groupId)
|
const combineElementList = copyOfElementList.filter(_element => _element.groupId === element.groupId)
|
||||||
const { minIndex, maxIndex } = getCombineElementIndexRange(elementList, combineElementList)
|
const { minLevel, maxLevel } = getCombineElementLevelRange(elementList, combineElementList)
|
||||||
|
|
||||||
// 无法移动(已经处在顶层)
|
// 已经处在顶层,无法继续移动
|
||||||
if (maxIndex === elementList.length - 1) return null
|
if (maxLevel === elementList.length - 1) return null
|
||||||
|
|
||||||
// 从元素列表中移除该组合元素全部成员,然后添加到元素列表最上方
|
// 将该组合元素从元素列表中移除,然后将被移除的元素添加到元素列表顶部
|
||||||
const movedElementList = copyOfElementList.splice(minIndex, combineElementList.length)
|
const movedElementList = copyOfElementList.splice(minLevel, combineElementList.length)
|
||||||
copyOfElementList.push(...movedElementList)
|
copyOfElementList.push(...movedElementList)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 被操作的元素是单独的元素(非组合成员)
|
// 如果被操作的元素不是组合元素成员
|
||||||
else {
|
else {
|
||||||
|
|
||||||
// 元素在元素列表中的层级
|
// 获取该元素在列表中的层级
|
||||||
const elementIndex = elementList.findIndex(item => item.id === element.id)
|
const level = elementList.findIndex(item => item.id === element.id)
|
||||||
|
|
||||||
// 无法移动(已经处在顶层)
|
// 已经处在顶层,无法继续移动
|
||||||
if (elementIndex === elementList.length - 1) return null
|
if (level === elementList.length - 1) return null
|
||||||
|
|
||||||
// 从元素列表中移除该元素,然后添加到元素列表最上方
|
// 将该组合元素从元素列表中移除,然后将被移除的元素添加到元素列表底部
|
||||||
copyOfElementList.splice(elementIndex, 1)
|
copyOfElementList.splice(level, 1)
|
||||||
copyOfElementList.push(element)
|
copyOfElementList.push(element)
|
||||||
}
|
}
|
||||||
|
|
||||||
return copyOfElementList
|
return copyOfElementList
|
||||||
}
|
}
|
||||||
|
|
||||||
// 置底层
|
/**
|
||||||
|
* 置底层,操作方式同置顶
|
||||||
|
* @param elementList 本页所有元素列表
|
||||||
|
* @param element 当前操作的元素
|
||||||
|
*/
|
||||||
const moveBottomElement = (elementList: PPTElement[], element: PPTElement) => {
|
const moveBottomElement = (elementList: PPTElement[], element: PPTElement) => {
|
||||||
const copyOfElementList: PPTElement[] = JSON.parse(JSON.stringify(elementList))
|
const copyOfElementList: PPTElement[] = JSON.parse(JSON.stringify(elementList))
|
||||||
|
|
||||||
if (element.groupId) {
|
if (element.groupId) {
|
||||||
const combineElementList = copyOfElementList.filter(_element => _element.groupId === element.groupId)
|
const combineElementList = copyOfElementList.filter(_element => _element.groupId === element.groupId)
|
||||||
const { minIndex } = getCombineElementIndexRange(elementList, combineElementList)
|
const { minLevel } = getCombineElementLevelRange(elementList, combineElementList)
|
||||||
if (minIndex === 0) return null
|
if (minLevel === 0) return
|
||||||
const movedElementList = copyOfElementList.splice(minIndex, combineElementList.length)
|
|
||||||
|
const movedElementList = copyOfElementList.splice(minLevel, combineElementList.length)
|
||||||
copyOfElementList.unshift(...movedElementList)
|
copyOfElementList.unshift(...movedElementList)
|
||||||
}
|
}
|
||||||
|
|
||||||
else {
|
else {
|
||||||
const elementIndex = elementList.findIndex(item => item.id === element.id)
|
const level = elementList.findIndex(item => item.id === element.id)
|
||||||
if (elementIndex === 0) return null
|
if (level === 0) return
|
||||||
copyOfElementList.splice(elementIndex, 1)
|
|
||||||
|
copyOfElementList.splice(level, 1)
|
||||||
copyOfElementList.unshift(element)
|
copyOfElementList.unshift(element)
|
||||||
}
|
}
|
||||||
|
|
||||||
return copyOfElementList
|
return copyOfElementList
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 调整元素层级
|
||||||
|
* @param element 需要调整层级的元素
|
||||||
|
* @param command 调整命令:上移、下移、置顶、置底
|
||||||
|
*/
|
||||||
const orderElement = (element: PPTElement, command: ElementOrderCommand) => {
|
const orderElement = (element: PPTElement, command: ElementOrderCommand) => {
|
||||||
let newElementList = null
|
let newElementList
|
||||||
|
|
||||||
if (command === ElementOrderCommands.UP) newElementList = moveUpElement(currentSlide.value.elements, element)
|
if (command === ElementOrderCommands.UP) newElementList = moveUpElement(currentSlide.value.elements, element)
|
||||||
else if (command === ElementOrderCommands.DOWN) newElementList = moveDownElement(currentSlide.value.elements, element)
|
else if (command === ElementOrderCommands.DOWN) newElementList = moveDownElement(currentSlide.value.elements, element)
|
||||||
|
@ -18,6 +18,10 @@ export default () => {
|
|||||||
const { addHistorySnapshot } = useHistorySnapshot()
|
const { addHistorySnapshot } = useHistorySnapshot()
|
||||||
const { createTextElement } = useCreateElement()
|
const { createTextElement } = useCreateElement()
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 粘贴元素(一组)
|
||||||
|
* @param elements 元素列表数据
|
||||||
|
*/
|
||||||
const pasteElement = (elements: PPTElement[]) => {
|
const pasteElement = (elements: PPTElement[]) => {
|
||||||
const groupIdMap = {}
|
const groupIdMap = {}
|
||||||
const elIdMap = {}
|
const elIdMap = {}
|
||||||
@ -47,6 +51,10 @@ export default () => {
|
|||||||
addHistorySnapshot()
|
addHistorySnapshot()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 粘贴页面
|
||||||
|
* @param slide 页面数据
|
||||||
|
*/
|
||||||
const pasteSlide = (slide: Slide) => {
|
const pasteSlide = (slide: Slide) => {
|
||||||
store.commit(MutationTypes.ADD_SLIDE, {
|
store.commit(MutationTypes.ADD_SLIDE, {
|
||||||
...slide,
|
...slide,
|
||||||
@ -55,6 +63,10 @@ export default () => {
|
|||||||
addHistorySnapshot()
|
addHistorySnapshot()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 粘贴普通文本:创建为新的文本元素
|
||||||
|
* @param text 文本
|
||||||
|
*/
|
||||||
const pasteText = (text: string) => {
|
const pasteText = (text: string) => {
|
||||||
createTextElement({
|
createTextElement({
|
||||||
left: 0,
|
left: 0,
|
||||||
@ -64,6 +76,11 @@ export default () => {
|
|||||||
}, text)
|
}, text)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 解析剪贴板内容,根据解析结果选择合适的粘贴方式
|
||||||
|
* @param text 剪贴板内容
|
||||||
|
* @param options 配置项:onlySlide -- 仅处理页面粘贴;onlyElements -- 仅处理元素粘贴;
|
||||||
|
*/
|
||||||
const pasteTextClipboardData = (text: string, options?: PasteTextClipboardDataOptions) => {
|
const pasteTextClipboardData = (text: string, options?: PasteTextClipboardDataOptions) => {
|
||||||
const onlySlide = options?.onlySlide || false
|
const onlySlide = options?.onlySlide || false
|
||||||
const onlyElements = options?.onlyElements || false
|
const onlyElements = options?.onlyElements || false
|
||||||
@ -76,7 +93,7 @@ export default () => {
|
|||||||
clipboardData = text
|
clipboardData = text
|
||||||
}
|
}
|
||||||
|
|
||||||
// 粘贴自定义元素或页面
|
// 元素或页面
|
||||||
if (typeof clipboardData === 'object') {
|
if (typeof clipboardData === 'object') {
|
||||||
const { type, data } = clipboardData
|
const { type, data } = clipboardData
|
||||||
|
|
||||||
@ -84,7 +101,7 @@ export default () => {
|
|||||||
else if (type === 'slide' && !onlyElements) pasteSlide(data)
|
else if (type === 'slide' && !onlyElements) pasteSlide(data)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 粘贴普通文本
|
// 普通文本
|
||||||
else if (!onlyElements && !onlySlide) pasteText(clipboardData)
|
else if (!onlyElements && !onlySlide) pasteText(clipboardData)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5,6 +5,10 @@ export default () => {
|
|||||||
const store = useStore()
|
const store = useStore()
|
||||||
const canvasPercentage = computed(() => store.state.canvasPercentage)
|
const canvasPercentage = computed(() => store.state.canvasPercentage)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 缩放画布百分比
|
||||||
|
* @param command 缩放命令:放大、缩小
|
||||||
|
*/
|
||||||
const scaleCanvas = (command: '+' | '-') => {
|
const scaleCanvas = (command: '+' | '-') => {
|
||||||
let percentage = canvasPercentage.value
|
let percentage = canvasPercentage.value
|
||||||
const step = 5
|
const step = 5
|
||||||
@ -16,6 +20,10 @@ export default () => {
|
|||||||
store.commit(MutationTypes.SET_CANVAS_PERCENTAGE, percentage)
|
store.commit(MutationTypes.SET_CANVAS_PERCENTAGE, percentage)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置画笔百分比
|
||||||
|
* @param percentage 百分比(小数形式,如0.8)
|
||||||
|
*/
|
||||||
const setCanvasPercentage = (percentage: number) => {
|
const setCanvasPercentage = (percentage: number) => {
|
||||||
store.commit(MutationTypes.SET_CANVAS_PERCENTAGE, percentage)
|
store.commit(MutationTypes.SET_CANVAS_PERCENTAGE, percentage)
|
||||||
}
|
}
|
||||||
|
@ -4,16 +4,19 @@ import { enterFullscreen, exitFullscreen, isFullscreen } from '@/utils/fullscree
|
|||||||
export default () => {
|
export default () => {
|
||||||
const store = useStore()
|
const store = useStore()
|
||||||
|
|
||||||
|
// 进入放映状态(从当前页开始)
|
||||||
const enterScreening = () => {
|
const enterScreening = () => {
|
||||||
enterFullscreen()
|
enterFullscreen()
|
||||||
store.commit(MutationTypes.SET_SCREENING, true)
|
store.commit(MutationTypes.SET_SCREENING, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 进入放映状态(从第一页开始)
|
||||||
const enterScreeningFromStart = () => {
|
const enterScreeningFromStart = () => {
|
||||||
store.commit(MutationTypes.UPDATE_SLIDE_INDEX, 0)
|
store.commit(MutationTypes.UPDATE_SLIDE_INDEX, 0)
|
||||||
enterScreening()
|
enterScreening()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 退出放映状态
|
||||||
const exitScreening = () => {
|
const exitScreening = () => {
|
||||||
store.commit(MutationTypes.SET_SCREENING, false)
|
store.commit(MutationTypes.SET_SCREENING, false)
|
||||||
if (isFullscreen()) exitFullscreen()
|
if (isFullscreen()) exitFullscreen()
|
||||||
|
@ -6,6 +6,7 @@ export default () => {
|
|||||||
const store = useStore()
|
const store = useStore()
|
||||||
const currentSlide = computed<Slide>(() => store.getters.currentSlide)
|
const currentSlide = computed<Slide>(() => store.getters.currentSlide)
|
||||||
|
|
||||||
|
// 将当前页面全部元素设置为被选择状态
|
||||||
const selectAllElement = () => {
|
const selectAllElement = () => {
|
||||||
const unlockedElements = currentSlide.value.elements.filter(el => !el.lock)
|
const unlockedElements = currentSlide.value.elements.filter(el => !el.lock)
|
||||||
const newActiveElementIdList = unlockedElements.map(el => el.id)
|
const newActiveElementIdList = unlockedElements.map(el => el.id)
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import { Ref, computed } from 'vue'
|
import { Ref, computed } from 'vue'
|
||||||
import { SlideBackground } from '@/types/slides'
|
import { SlideBackground } from '@/types/slides'
|
||||||
|
|
||||||
|
// 将页面背景数据转换为css样式
|
||||||
export default (background: Ref<SlideBackground | undefined>) => {
|
export default (background: Ref<SlideBackground | undefined>) => {
|
||||||
const backgroundStyle = computed(() => {
|
const backgroundStyle = computed(() => {
|
||||||
if (!background.value) return { backgroundColor: '#fff' }
|
if (!background.value) return { backgroundColor: '#fff' }
|
||||||
@ -15,7 +16,11 @@ export default (background: Ref<SlideBackground | undefined>) => {
|
|||||||
gradientType,
|
gradientType,
|
||||||
} = background.value
|
} = background.value
|
||||||
|
|
||||||
|
// 纯色背景
|
||||||
if (type === 'solid') return { backgroundColor: color }
|
if (type === 'solid') return { backgroundColor: color }
|
||||||
|
|
||||||
|
// 背景图模式
|
||||||
|
// 包括:背景图、背景大小,是否重复
|
||||||
else if (type === 'image') {
|
else if (type === 'image') {
|
||||||
if (!image) return { backgroundColor: '#fff' }
|
if (!image) return { backgroundColor: '#fff' }
|
||||||
if (imageSize === 'repeat') {
|
if (imageSize === 'repeat') {
|
||||||
@ -31,6 +36,8 @@ export default (background: Ref<SlideBackground | undefined>) => {
|
|||||||
backgroundSize: imageSize || 'cover',
|
backgroundSize: imageSize || 'cover',
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 渐变色背景
|
||||||
else if (type === 'gradient') {
|
else if (type === 'gradient') {
|
||||||
const rotate = gradientRotate || 0
|
const rotate = gradientRotate || 0
|
||||||
const color1 = gradientColor ? gradientColor[0] : '#fff'
|
const color1 = gradientColor ? gradientColor[0] : '#fff'
|
||||||
|
@ -19,6 +19,10 @@ export default () => {
|
|||||||
const { pasteTextClipboardData } = usePasteTextClipboardData()
|
const { pasteTextClipboardData } = usePasteTextClipboardData()
|
||||||
const { addHistorySnapshot } = useHistorySnapshot()
|
const { addHistorySnapshot } = useHistorySnapshot()
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 移动页面焦点
|
||||||
|
* @param command 移动页面焦点命令:上移、下移
|
||||||
|
*/
|
||||||
const updateSlideIndex = (command: string) => {
|
const updateSlideIndex = (command: string) => {
|
||||||
let targetIndex = 0
|
let targetIndex = 0
|
||||||
if (command === KEYS.UP && slideIndex.value > 0) {
|
if (command === KEYS.UP && slideIndex.value > 0) {
|
||||||
@ -30,6 +34,7 @@ export default () => {
|
|||||||
store.commit(MutationTypes.UPDATE_SLIDE_INDEX, targetIndex)
|
store.commit(MutationTypes.UPDATE_SLIDE_INDEX, targetIndex)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 将当前页面数据加密后复制到剪贴板
|
||||||
const copySlide = () => {
|
const copySlide = () => {
|
||||||
const text = encrypt(JSON.stringify({
|
const text = encrypt(JSON.stringify({
|
||||||
type: 'slide',
|
type: 'slide',
|
||||||
@ -41,12 +46,14 @@ export default () => {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 尝试将剪贴板页面数据解密后添加到下一页(粘贴)
|
||||||
const pasteSlide = () => {
|
const pasteSlide = () => {
|
||||||
readClipboard().then(text => {
|
readClipboard().then(text => {
|
||||||
pasteTextClipboardData(text, { onlySlide: true })
|
pasteTextClipboardData(text, { onlySlide: true })
|
||||||
}).catch(err => message.warning(err))
|
}).catch(err => message.warning(err))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 创建一页空白页并添加到下一页
|
||||||
const createSlide = () => {
|
const createSlide = () => {
|
||||||
const emptySlide = {
|
const emptySlide = {
|
||||||
id: createRandomCode(8),
|
id: createRandomCode(8),
|
||||||
@ -60,6 +67,7 @@ export default () => {
|
|||||||
addHistorySnapshot()
|
addHistorySnapshot()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 将当前页复制一份到下一页
|
||||||
const copyAndPasteSlide = () => {
|
const copyAndPasteSlide = () => {
|
||||||
store.commit(MutationTypes.ADD_SLIDE, {
|
store.commit(MutationTypes.ADD_SLIDE, {
|
||||||
...currentSlide.value,
|
...currentSlide.value,
|
||||||
@ -68,6 +76,7 @@ export default () => {
|
|||||||
addHistorySnapshot()
|
addHistorySnapshot()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 删除当前页
|
||||||
const deleteSlide = () => {
|
const deleteSlide = () => {
|
||||||
if (slidesLength.value === 1) return message.warning('无法继续删除')
|
if (slidesLength.value === 1) return message.warning('无法继续删除')
|
||||||
|
|
||||||
@ -75,6 +84,7 @@ export default () => {
|
|||||||
addHistorySnapshot()
|
addHistorySnapshot()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 将当前页复制后删除(剪切)
|
||||||
const cutSlide = () => {
|
const cutSlide = () => {
|
||||||
copySlide()
|
copySlide()
|
||||||
deleteSlide()
|
deleteSlide()
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
// https://iconpark.bytedance.com/official
|
||||||
|
|
||||||
import { App } from 'vue'
|
import { App } from 'vue'
|
||||||
import {
|
import {
|
||||||
PlayOne,
|
PlayOne,
|
||||||
@ -24,7 +26,6 @@ import {
|
|||||||
BackgroundColor,
|
BackgroundColor,
|
||||||
Group,
|
Group,
|
||||||
Ungroup,
|
Ungroup,
|
||||||
ClearFormat,
|
|
||||||
Back,
|
Back,
|
||||||
Next,
|
Next,
|
||||||
Fullwidth,
|
Fullwidth,
|
||||||
@ -160,7 +161,6 @@ export default {
|
|||||||
app.component('IconSearch', Search)
|
app.component('IconSearch', Search)
|
||||||
app.component('IconPpt', Ppt)
|
app.component('IconPpt', Ppt)
|
||||||
app.component('IconHelpcenter', Helpcenter)
|
app.component('IconHelpcenter', Helpcenter)
|
||||||
app.component('IconClearFormat', ClearFormat)
|
|
||||||
app.component('IconGithub', Github)
|
app.component('IconGithub', Github)
|
||||||
app.component('IconWrite', Write)
|
app.component('IconWrite', Write)
|
||||||
app.component('IconEffects', Effects)
|
app.component('IconEffects', Effects)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user