Skip to content

Commit

Permalink
更新右键清空画布
Browse files Browse the repository at this point in the history
  • Loading branch information
more-strive committed Aug 10, 2024
1 parent 04def2b commit da95e76
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 8 deletions.
9 changes: 4 additions & 5 deletions src/configs/contextMenu.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { ContextMenu } from '@/components/ContextMenu/types'
import { ContextMenu } from '@/components/Contextmenu/types'
import { ElementNames, AlignCommand, LayerCommand } from '@/types/elements'
import { Object as FabricObject } from 'fabric'
import { storeToRefs } from 'pinia'
import { useMainStore } from '@/store'
import useHandleElement from '@/hooks/useHandleElement'
Expand Down Expand Up @@ -35,10 +34,10 @@ export const contextMenuThumbnails = (): ContextMenu[] => {
}

export const contextMenus = (): ContextMenu[] => {
const { lockElement, deleteElement, cutElement, copyElement, pasteElement, uncombineElements, combineElements } = useHandleElement()
const { lockElement, deleteElement, cutElement, copyElement, pasteElement, uncombineElements, combineElements, resetElements } = useHandleElement()
const { alignElement, layerElement } = useHandleTool()
const { canvasObject } = storeToRefs(useMainStore())
const element = canvasObject.value as FabricObject
const element = canvasObject.value
if (!element) {
return [
{
Expand All @@ -62,7 +61,7 @@ export const contextMenus = (): ContextMenu[] => {
},
{
text: '重置',
// handler: enterScreeningFromStart,
handler: resetElements,
},
]
}
Expand Down
17 changes: 14 additions & 3 deletions src/hooks/useHandleElement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { useFabricStore, useMainStore, useTemplatesStore } from "@/store"
import { TextboxElement, CanvasElement, GroupElement } from "@/types/canvas"
import { clipperPath } from '@/utils/clipper'
import { useActiveElement } from '@vueuse/core'
import { computed } from 'vue'
import { ElMessageBox } from "element-plus"
import useCanvas from "@/views/Canvas/useCanvas"
import useCanvasZindex from "./useCanvasZindex"
import { copyText } from '@/utils/clipboard'
Expand All @@ -28,7 +28,7 @@ export default () => {
const element = queryElement(option.id)
if (!element) return
if (element.group) {
const elementGroup = queryOption((element.group as GroupElement).id) as Group
const elementGroup = queryOption((element.group as GroupElement).id) as GroupElement | undefined
if (!elementGroup) return
const _element = elementGroup.objects[oldIndex]
elementGroup.objects.splice(oldIndex, 1)
Expand Down Expand Up @@ -379,6 +379,16 @@ export default () => {

}

const resetElements = () => {
const [ canvas ] = useCanvas()
ElMessageBox.confirm('确认是否清空画布?', 'Warning', {
confirmButtonText: 'OK',
type: 'warning',
}).then(() => {
templatesStore.clearTemplate()
});
}

return {
// createElement,
layerElement,
Expand All @@ -402,6 +412,7 @@ export default () => {
backwardElement,
checkElement,
intersectElements,
maskElement
maskElement,
resetElements
}
}
6 changes: 6 additions & 0 deletions src/store/modules/template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,12 @@ export const useTemplatesStore = defineStore('Templates', {
addHistorySnapshot()
},

clearTemplate() {
const objects = this.templates[this.templateIndex].objects.filter(item => item.id === WorkSpaceDrawType)
this.templates[this.templateIndex].objects = objects
this.renderTemplate()
},

updateWorkSpace(props: Partial<Template>) {
const templateIndex = this.templateIndex
this.templates[templateIndex] = { ...this.templates[templateIndex], ...props }
Expand Down

0 comments on commit da95e76

Please sign in to comment.