mirror of
https://github.com/pipipi-pikachu/PPTist.git
synced 2025-04-15 02:20:00 +08:00
fix: 允许键盘移动可独立操作的组合元素成员(#50)
This commit is contained in:
parent
8628ba1476
commit
9ac7757647
@ -1,24 +1,27 @@
|
|||||||
import { computed } from 'vue'
|
import { computed } from 'vue'
|
||||||
import { MutationTypes, useStore } from '@/store'
|
import { MutationTypes, useStore } from '@/store'
|
||||||
import { Slide } from '@/types/slides'
|
import { PPTElement, Slide } from '@/types/slides'
|
||||||
import { KEYS } from '@/configs/hotkey'
|
import { KEYS } from '@/configs/hotkey'
|
||||||
import useHistorySnapshot from '@/hooks/useHistorySnapshot'
|
import useHistorySnapshot from '@/hooks/useHistorySnapshot'
|
||||||
|
|
||||||
export default () => {
|
export default () => {
|
||||||
const store = useStore()
|
const store = useStore()
|
||||||
const activeElementIdList = computed(() => store.state.activeElementIdList)
|
const activeElementIdList = computed(() => store.state.activeElementIdList)
|
||||||
|
const activeGroupElementId = computed(() => store.state.activeGroupElementId)
|
||||||
const currentSlide = computed<Slide>(() => store.getters.currentSlide)
|
const currentSlide = computed<Slide>(() => store.getters.currentSlide)
|
||||||
|
|
||||||
const { addHistorySnapshot } = useHistorySnapshot()
|
const { addHistorySnapshot } = useHistorySnapshot()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 将元素向指定方向移动指定的距离
|
* 将元素向指定方向移动指定的距离
|
||||||
|
* 组合元素成员中,存在被选中可独立操作的元素时,优先移动该元素。否则默认移动所有被选中的元素
|
||||||
* @param command 移动方向
|
* @param command 移动方向
|
||||||
* @param step 移动距离
|
* @param step 移动距离
|
||||||
*/
|
*/
|
||||||
const moveElement = (command: string, step = 1) => {
|
const moveElement = (command: string, step = 1) => {
|
||||||
const newElementList = currentSlide.value.elements.map(el => {
|
let newElementList: PPTElement[] = []
|
||||||
if (activeElementIdList.value.includes(el.id)) {
|
|
||||||
|
const move = (el: PPTElement) => {
|
||||||
let { left, top } = el
|
let { left, top } = el
|
||||||
switch (command) {
|
switch (command) {
|
||||||
case KEYS.LEFT:
|
case KEYS.LEFT:
|
||||||
@ -37,8 +40,18 @@ export default () => {
|
|||||||
}
|
}
|
||||||
return { ...el, left, top }
|
return { ...el, left, top }
|
||||||
}
|
}
|
||||||
return el
|
|
||||||
|
if (activeGroupElementId.value) {
|
||||||
|
newElementList = currentSlide.value.elements.map(el => {
|
||||||
|
return activeGroupElementId.value === el.id ? move(el) : el
|
||||||
})
|
})
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
newElementList = currentSlide.value.elements.map(el => {
|
||||||
|
return activeElementIdList.value.includes(el.id) ? move(el) : el
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
store.commit(MutationTypes.UPDATE_SLIDE, { elements: newElementList })
|
store.commit(MutationTypes.UPDATE_SLIDE, { elements: newElementList })
|
||||||
addHistorySnapshot()
|
addHistorySnapshot()
|
||||||
}
|
}
|
||||||
|
@ -171,7 +171,7 @@ export default defineComponent({
|
|||||||
|
|
||||||
const throttleMassage = throttle(function(msg) {
|
const throttleMassage = throttle(function(msg) {
|
||||||
message.success(msg)
|
message.success(msg)
|
||||||
}, 3000, { leading: true, trailing: false })
|
}, 1000, { leading: true, trailing: false })
|
||||||
|
|
||||||
// 向上/向下播放
|
// 向上/向下播放
|
||||||
// 遇到元素动画时,优先执行动画播放,无动画则执行翻页
|
// 遇到元素动画时,优先执行动画播放,无动画则执行翻页
|
||||||
|
Loading…
x
Reference in New Issue
Block a user