function multiselectJS(canvas) {//获取整体宽高 canvas.discardActiveObject() // 丢弃当前活动的对象和触发事件。 如果fabric作为鼠标事件的结果调用该函数,则将该事件作为参数传递给自定义事件的fire函数。 当作为一个方法使用时,参数没有任何应用。 const sel = new fabric.ActiveSelection(canvas.getObjects(), { canvas }) // console.log(sel) canvas.setActiveObject(sel) canvas.requestRenderAll() const activeObject = canvas.getActiveObject(); // 获取当前选中的整体对象 if (activeObject && activeObject.type === 'activeSelection') { const totalWidth = activeObject.width * activeObject.scaleX; const totalHeight = activeObject.height * activeObject.scaleY; return {totalWidth,totalHeight} console.log('Total Width:', totalWidth); console.log('Total Height:', totalHeight); } } export default {multiselectJS,}