Skip to content

Commit

Permalink
更新元素设置坐标
Browse files Browse the repository at this point in the history
  • Loading branch information
more-strive committed Oct 23, 2024
1 parent d49e1a0 commit 32a7884
Showing 1 changed file with 45 additions and 11 deletions.
56 changes: 45 additions & 11 deletions src/hooks/useHandleActive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ export default () => {
break

default:
// @ts-ignore
value = activeObject[key]
break
}
Expand All @@ -125,7 +126,10 @@ export default () => {
const activeObject = canvas.activeObject.value as FabricObject & Textbox
if (lockChange || !isDefined(activeObject)) return
if (['width', 'height', 'left', 'top', 'angle'].includes(key)) {
const currentObject = activeObject
activeObject.canvas?.discardActiveObject()
activeObject.set(key, Number(newValue))
activeObject.canvas?.setActiveObject(currentObject)
if (type === 'change' && activeObject.group?.updateLayout) {
activeObject.group.updateLayout()
}
Expand Down Expand Up @@ -153,18 +157,48 @@ export default () => {
canvas.requestRenderAll()
}

return computed(() => ({
disabled: !isDefined(canvas.activeObject.value),
modelValue: modelValue.value as T,
onSwipe: (value: T) => {
changeValue(value, 'swipe')
},
onChange: (value: T) => {
changeValue(value, 'change')
if (!isDefined(canvas.activeObject)) return
canvas.fire('object:modified', { target: canvas.activeObject.value })
// return computed(() => ({
// disabled: !isDefined(canvas.activeObject.value),
// modelValue: modelValue.value as T,
// onSwipe: (value: T) => {
// changeValue(value, 'swipe')
// },
// onChange: (value: T) => {
// changeValue(value, 'change')
// if (!isDefined(canvas.activeObject)) return
// canvas.fire('object:modified', { target: canvas.activeObject.value })
// },
// }))
return computed({
get() {
return {
disabled: !isDefined(canvas.activeObject.value),
modelValue: modelValue.value as T,
onSwipe: (value: T) => {
changeValue(value, 'swipe')
},
onChange: (value: T) => {
changeValue(value, 'change')
if (!isDefined(canvas.activeObject)) return
canvas.fire('object:modified', { target: canvas.activeObject.value })
}
}
},
}))
set() {
return {
disabled: !isDefined(canvas.activeObject.value),
modelValue: modelValue.value as T,
onSwipe: (value: T) => {
changeValue(value, 'swipe')
},
onChange: (value: T) => {
changeValue(value, 'change')
if (!isDefined(canvas.activeObject)) return
canvas.fire('object:modified', { target: canvas.activeObject.value })
}
}
}
})
}

return {
Expand Down

0 comments on commit 32a7884

Please sign in to comment.