深度画布保存接口

This commit is contained in:
lzp
2026-03-20 09:46:15 +08:00
parent 262e3e6c71
commit ecf928691e
5 changed files with 90 additions and 23 deletions

View File

@@ -293,12 +293,12 @@ export class CanvasManager {
/** 导出画布为处理图片的JSON */
getCanvasDisUrlJSON() {
const canvas = this.canvas.toJSON()
const images = [];
const images = {};
var i = 0;
const create = (url) => {
const logo = `xxxxxxxx_${i++}_xxxxxxxx`;
images.push({ index: logo, url })
return logo
const key = `xxxxxxxx_${i++}_xxxxxxxx`;
images[key] = url
return key
}
canvas.objects.forEach((object: any) => {
if (object.thumbnail) {
@@ -317,11 +317,13 @@ export class CanvasManager {
return { canvas: JSON.stringify(canvas), images }
}
/** 处理JSON为正常画布 */
processCanvasDisUrlJSON(obj: { canvas: string, images: Object[] }) {
processCanvasDisUrlJSON(obj: { canvas: string, images: Object }) {
var json = obj.canvas;
const images = obj.images || []
images.forEach((v: any) => json = json.replace(new RegExp(v.index), v.url))
return JSON.parse(json)
const images = obj.images || {}
for (const key in images) {
json = json.replace(new RegExp(key), images[key])
}
return json
}
dispose() {
this.animationManager?.dispose()