添加背景页面修复应用背景图后无法应用背景颜色的问题

This commit is contained in:
jingrow 2026-01-22 13:04:23 +08:00
parent 03e62f6029
commit f7075b27a1

View File

@ -1943,6 +1943,20 @@ const applyBackgroundSilent = async () => {
const objects = fabricCanvas.getObjects()
if (objects.length === 0) return
// If there are multiple objects (background image exists), keep only the last one (foreground)
// This ensures we remove any background images before applying color
if (objects.length > 1) {
// Disable auto-rendering to prevent multiple redraws
fabricCanvas.renderOnAddRemove = false
// Remove all objects except the last one (foreground image)
const objectsToRemove = objects.slice(0, -1)
objectsToRemove.forEach(obj => fabricCanvas.remove(obj))
// Re-enable auto-rendering
fabricCanvas.renderOnAddRemove = true
}
// Set background color using fabric v7 API
fabricCanvas.backgroundColor = backgroundColor.value
fabricCanvas.renderAll()