From feeae71d52da8fcb49c22e1a3ee172f6818fdf16 Mon Sep 17 00:00:00 2001 From: Nevermore <15972699417@163.com> Date: Mon, 22 Jan 2024 13:46:42 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E6=B7=BB=E5=8A=A0=E6=96=B0?= =?UTF-8?q?=E9=A1=B5=E9=9D=A2=E7=BC=A9=E6=94=BE=E5=8A=9F=E8=83=BDbug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/hooks/useAddTemplateElement.ts | 1 - src/hooks/useCanvasHotkey.ts | 14 -------------- src/hooks/useHandleTemplate.ts | 18 ++++++------------ src/store/modules/main.ts | 9 --------- src/views/Editor/CanvasThumb/index.vue | 2 -- src/views/Editor/CanvasThumb/mobile.vue | 2 -- 6 files changed, 6 insertions(+), 40 deletions(-) diff --git a/src/hooks/useAddTemplateElement.ts b/src/hooks/useAddTemplateElement.ts index cce48181..82421ea1 100644 --- a/src/hooks/useAddTemplateElement.ts +++ b/src/hooks/useAddTemplateElement.ts @@ -31,7 +31,6 @@ export default () => { if (element.type === ElementNames.GROUP) element.id = groupIdMap[element.id] } templatesStore.addElement(elements) - mainStore.setActiveElementIdList(Object.values(elIdMap)) } /** diff --git a/src/hooks/useCanvasHotkey.ts b/src/hooks/useCanvasHotkey.ts index 3e86dffe..0a259d30 100644 --- a/src/hooks/useCanvasHotkey.ts +++ b/src/hooks/useCanvasHotkey.ts @@ -1,6 +1,5 @@ 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' @@ -8,22 +7,11 @@ 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, @@ -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) => { diff --git a/src/hooks/useHandleTemplate.ts b/src/hooks/useHandleTemplate.ts index 6552ff7c..b8e6bc32 100644 --- a/src/hooks/useHandleTemplate.ts +++ b/src/hooks/useHandleTemplate.ts @@ -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]) @@ -51,11 +51,10 @@ export default () => { } // // 重置页面 - const resetTemplate = () => { + const resetTemplate = async () => { templatesStore.setTemplateIndex(0) - mainStore.setActiveElementIdList([]) templatesStore.setTemplates([getEmptyTemplate()]) - templatesStore.renderTemplate() + await templatesStore.renderTemplate() } /** @@ -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() @@ -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) => { @@ -123,7 +119,6 @@ export default () => { // ...slide, // id: nanoid(10), // } - // mainStore.setActiveElementIdList([]) // slidesStore.addSlide(newSlide) // // } @@ -153,7 +148,6 @@ export default () => { // 选中全部页面 const selectAllSlide = () => { const newSelectedSlidesIndex = Array.from(Array(templates.value.length), (item, index) => index) - mainStore.setActiveElementIdList([]) mainStore.updateSelectedTemplatesIndex(newSelectedSlidesIndex) } diff --git a/src/store/modules/main.ts b/src/store/modules/main.ts index ecea5828..df8a2b02 100644 --- a/src/store/modules/main.ts +++ b/src/store/modules/main.ts @@ -20,7 +20,6 @@ export interface MainState { imageCategoryData: ImageCategoryData[] illustrationCategoryType: string[] illustrationCategoryData: ImageCategoryData[] - activeElementIdList: string[] handleElementId: string sizeMode: number unitMode: number @@ -54,7 +53,6 @@ export const useMainStore = defineStore('main', { imageCategoryData: ImageCategoryInfo, illustrationCategoryType: [], illustrationCategoryData: ImageCategoryInfo, - activeElementIdList: [], // 被选中的元素ID集合,包含 handleElementId handleElementId: '', // 正在操作的元素ID sizeMode: 0, // 模板样式 unitMode: 0, // 单位 @@ -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() { @@ -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 diff --git a/src/views/Editor/CanvasThumb/index.vue b/src/views/Editor/CanvasThumb/index.vue index 36282338..584abc43 100644 --- a/src/views/Editor/CanvasThumb/index.vue +++ b/src/views/Editor/CanvasThumb/index.vue @@ -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 } diff --git a/src/views/Editor/CanvasThumb/mobile.vue b/src/views/Editor/CanvasThumb/mobile.vue index 4357791d..f2a721f0 100644 --- a/src/views/Editor/CanvasThumb/mobile.vue +++ b/src/views/Editor/CanvasThumb/mobile.vue @@ -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 = () => {