Skip to content

Commit

Permalink
更新添加新页面缩放功能bug
Browse files Browse the repository at this point in the history
  • Loading branch information
more-strive committed Jan 22, 2024
1 parent 23359ee commit feeae71
Show file tree
Hide file tree
Showing 6 changed files with 6 additions and 40 deletions.
1 change: 0 additions & 1 deletion src/hooks/useAddTemplateElement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ export default () => {
if (element.type === ElementNames.GROUP) element.id = groupIdMap[element.id]
}
templatesStore.addElement(elements)
mainStore.setActiveElementIdList(Object.values(elIdMap))
}

/**
Expand Down
14 changes: 0 additions & 14 deletions src/hooks/useCanvasHotkey.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,17 @@
import { storeToRefs } from 'pinia'
import { useMainStore, useTemplatesStore, useKeyboardStore } from '@/store'
// import { ElementOrderCommands } from '@/types/edit'
import { KEYS } from '@/configs/hotkey'
import useHandleTemplate from './useHandleTemplate'
import useHandleElement from './useHandleElement'
import useHistorySnapshot from './useHistorySnapshot'
import { CanvasElement, GroupElement } from '@/types/canvas'
import { ElementNames } from '@/types/elements'

// import useSlideHandler from './useSlideHandler'
// import useCombineElement from './useCombineElement'
// import useCopyAndPasteElement from './useCopyAndPasteElement'
// import useSelectAllElement from './useSelectAllElement'
// import useMoveElement from './useMoveElement'
// import useOrderElement from './useOrderElement'
// import useHistorySnapshot from './useHistorySnapshot'
// import useScreening from './useScreening'
// import useScaleCanvas from './useScaleCanvas'

export default () => {
const mainStore = useMainStore()
const keyboardStore = useKeyboardStore()
const templatesStore = useTemplatesStore()
const {
activeElementIdList,
disableHotkeys,
handleElement,
canvasObject,
Expand Down Expand Up @@ -138,14 +126,12 @@ export default () => {
// if (!currentSlide.value.elements.length) return
// if (!handleElementId.value) {
// const firstElement = currentSlide.value.elements[0]
// mainStore.setActiveElementIdList([firstElement.id])
// return
// }
// const currentIndex = currentSlide.value.elements.findIndex(el => el.id === handleElementId.value)
// const nextIndex = currentIndex >= currentSlide.value.elements.length - 1 ? 0 : currentIndex + 1
// const nextElementId = currentSlide.value.elements[nextIndex].id

// mainStore.setActiveElementIdList([nextElementId])
// }

const keydownListener = (e: KeyboardEvent) => {
Expand Down
18 changes: 6 additions & 12 deletions src/hooks/useHandleTemplate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export default () => {
const { templates, templateIndex, currentTemplate } = storeToRefs(templatesStore)
// const mainStore = useMainStore()
// const slidesStore = useSlidesStore()
const { selectedTemplatesIndex: _selectedTemplatesIndex, activeElementIdList } = storeToRefs(mainStore)
const { selectedTemplatesIndex: _selectedTemplatesIndex } = storeToRefs(mainStore)
// const { currentSlide, templates, theme, slideIndex } = storeToRefs(templatesStore)

const selectedTemplatesIndex = computed(() => [..._selectedTemplatesIndex.value, templateIndex.value])
Expand Down Expand Up @@ -51,11 +51,10 @@ export default () => {
}

// // 重置页面
const resetTemplate = () => {
const resetTemplate = async () => {
templatesStore.setTemplateIndex(0)
mainStore.setActiveElementIdList([])
templatesStore.setTemplates([getEmptyTemplate()])
templatesStore.renderTemplate()
await templatesStore.renderTemplate()
}

/**
Expand All @@ -64,11 +63,9 @@ export default () => {
*/
const updateTemplateIndex = (command: string) => {
if (command === KEYS.UP && templateIndex.value > 0) {
if (activeElementIdList.value.length) mainStore.setActiveElementIdList([])
templatesStore.setTemplateIndex(templateIndex.value - 1)
}
else if (command === KEYS.DOWN && templateIndex.value < templates.value.length - 1) {
if (activeElementIdList.value.length) mainStore.setActiveElementIdList([])
templatesStore.setTemplateIndex(templateIndex.value + 1)
}
templatesStore.renderTemplate()
Expand Down Expand Up @@ -96,11 +93,10 @@ export default () => {
}

// 创建一页空白页并添加到下一页
const createTemplate = () => {
mainStore.setActiveElementIdList([])
templatesStore.addTemplate(getEmptyTemplate())
const createTemplate = async () => {
await templatesStore.addTemplate(getEmptyTemplate())
templatesStore.setTemplateIndex(templateIndex.value)
templatesStore.renderTemplate()
await templatesStore.renderTemplate()
}

const addTemplate = (template: Template) => {
Expand All @@ -123,7 +119,6 @@ export default () => {
// ...slide,
// id: nanoid(10),
// }
// mainStore.setActiveElementIdList([])
// slidesStore.addSlide(newSlide)
//
// }
Expand Down Expand Up @@ -153,7 +148,6 @@ export default () => {
// 选中全部页面
const selectAllSlide = () => {
const newSelectedSlidesIndex = Array.from(Array(templates.value.length), (item, index) => index)
mainStore.setActiveElementIdList([])
mainStore.updateSelectedTemplatesIndex(newSelectedSlidesIndex)
}

Expand Down
9 changes: 0 additions & 9 deletions src/store/modules/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ export interface MainState {
imageCategoryData: ImageCategoryData[]
illustrationCategoryType: string[]
illustrationCategoryData: ImageCategoryData[]
activeElementIdList: string[]
handleElementId: string
sizeMode: number
unitMode: number
Expand Down Expand Up @@ -54,7 +53,6 @@ export const useMainStore = defineStore('main', {
imageCategoryData: ImageCategoryInfo,
illustrationCategoryType: [],
illustrationCategoryData: ImageCategoryInfo,
activeElementIdList: [], // 被选中的元素ID集合,包含 handleElementId
handleElementId: '', // 正在操作的元素ID
sizeMode: 0, // 模板样式
unitMode: 0, // 单位
Expand All @@ -78,7 +76,6 @@ export const useMainStore = defineStore('main', {
// const slidesStore = useSlidesStore()
// const currentSlide = slidesStore.currentSlide
// if (!currentSlide || !currentSlide.elements) return []
// return currentSlide.elements.filter(element => state.activeElementIdList.includes(element.id))
},

handleElement() {
Expand All @@ -90,12 +87,6 @@ export const useMainStore = defineStore('main', {
},

actions: {
setActiveElementIdList(activeElementIdList: string[]) {
if (activeElementIdList.length === 1) this.handleElementId = activeElementIdList[0]
else this.handleElementId = ''

this.activeElementIdList = activeElementIdList
},

setCanvasObject(canvasObject: FabricObject | undefined) {
this.canvasObject = canvasObject
Expand Down
2 changes: 0 additions & 2 deletions src/views/Editor/CanvasThumb/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -174,11 +174,9 @@ const handleClickTemplateThumbnail = (e: MouseEvent, index: number) => {
// 切换页面
const changeSlideIndex = (index: number) => {
mainStore.setActiveElementIdList([])
if (templateIndex.value === index) return
templatesStore.setTemplateIndex(index)
templatesStore.renderTemplate()
canvasObject.value = undefined
}
</script>
Expand Down
2 changes: 0 additions & 2 deletions src/views/Editor/CanvasThumb/mobile.vue
Original file line number Diff line number Diff line change
Expand Up @@ -135,11 +135,9 @@ const handleClickTemplateThumbnail = (e: MouseEvent, index: number) => {
// 切换页面
const changeSlideIndex = (index: number) => {
mainStore.setActiveElementIdList([])
if (templateIndex.value === index) return
templatesStore.setTemplateIndex(index)
templatesStore.renderTemplate()
canvasObject.value = null
}
const thumbToggle = () => {
Expand Down

0 comments on commit feeae71

Please sign in to comment.