111
This commit is contained in:
@@ -63,8 +63,8 @@
|
|||||||
provide('stateManager', stateManager)
|
provide('stateManager', stateManager)
|
||||||
|
|
||||||
// 画布管理器
|
// 画布管理器
|
||||||
const canvasManager = new CanvasManager({ stateManager })
|
const canvasManager = new CanvasManager({ stateManager, props })
|
||||||
stateManager.setManager({ canvasManager, canvasRef })
|
stateManager.setManager({ canvasManager })
|
||||||
provide('canvasManager', canvasManager)
|
provide('canvasManager', canvasManager)
|
||||||
|
|
||||||
// 图层管理器
|
// 图层管理器
|
||||||
|
|||||||
@@ -48,13 +48,13 @@
|
|||||||
id: config.value.canvasId || null
|
id: config.value.canvasId || null
|
||||||
}
|
}
|
||||||
const sData = await saveDepthCanvas(data)
|
const sData = await saveDepthCanvas(data)
|
||||||
|
|
||||||
const canvasId = sData.id
|
const canvasId = sData.id
|
||||||
// base64 转 file 上传转换为 url
|
// base64 转 file 上传转换为 url
|
||||||
const file = base64Tofile(options.url, 'canvas.png')
|
const file = base64Tofile(options.url, 'canvas.png')
|
||||||
const formData = new FormData()
|
const formData = new FormData()
|
||||||
formData.append('file', file)
|
formData.append('file', file)
|
||||||
const url = await uploadImage(formData)
|
const url = await uploadImage(formData, true)
|
||||||
config.value.onWorkbench?.({ url, canvasId })
|
config.value.onWorkbench?.({ url, canvasId })
|
||||||
|
|
||||||
dialogVisible.value = false
|
dialogVisible.value = false
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import { detectDeviceType } from '../tools/index'
|
|||||||
import { CanvasEventManager } from "./events/CanvasEventManager";
|
import { CanvasEventManager } from "./events/CanvasEventManager";
|
||||||
import { OperationType } from '../tools/layerHelper'
|
import { OperationType } from '../tools/layerHelper'
|
||||||
import { createId } from '../../tools/tools'
|
import { createId } from '../../tools/tools'
|
||||||
|
import md5 from 'md5'
|
||||||
|
|
||||||
// 自定义画布转对象属性
|
// 自定义画布转对象属性
|
||||||
fabric.Object.prototype.customProperties = ["top", "left", "width", "height", "scaleX", "scaleY", "info", "thumbnail"];
|
fabric.Object.prototype.customProperties = ["top", "left", "width", "height", "scaleX", "scaleY", "info", "thumbnail"];
|
||||||
@@ -45,8 +46,10 @@ export class CanvasManager {
|
|||||||
deviceInfo: any
|
deviceInfo: any
|
||||||
canvas: any
|
canvas: any
|
||||||
currentZoom: any
|
currentZoom: any
|
||||||
|
uniqueId: string
|
||||||
constructor(options) {
|
constructor(options) {
|
||||||
this.stateManager = options.stateManager;
|
this.stateManager = options.stateManager;
|
||||||
|
this.uniqueId = md5(options.props.config.url || Date.now());
|
||||||
this.deviceInfo = detectDeviceType();
|
this.deviceInfo = detectDeviceType();
|
||||||
this.currentZoom = ref(100)
|
this.currentZoom = ref(100)
|
||||||
}
|
}
|
||||||
@@ -279,6 +282,7 @@ export class CanvasManager {
|
|||||||
console.error('JSON解析错误:', error)
|
console.error('JSON解析错误:', error)
|
||||||
}
|
}
|
||||||
if (!jsonObj) return resolve(false)
|
if (!jsonObj) return resolve(false)
|
||||||
|
if (jsonObj.uniqueId) this.uniqueId = jsonObj.uniqueId
|
||||||
this.canvas.loadFromJSON(jsonObj, () => {
|
this.canvas.loadFromJSON(jsonObj, () => {
|
||||||
if (rerecord) this.stateManager.clearState()
|
if (rerecord) this.stateManager.clearState()
|
||||||
this.resetZoom(false)
|
this.resetZoom(false)
|
||||||
@@ -294,25 +298,26 @@ export class CanvasManager {
|
|||||||
getCanvasDisUrlJSON() {
|
getCanvasDisUrlJSON() {
|
||||||
const canvas = this.canvas.toJSON()
|
const canvas = this.canvas.toJSON()
|
||||||
const images = {};
|
const images = {};
|
||||||
var i = 0;
|
const create = (url, key) => {
|
||||||
const create = (url) => {
|
const key_ = `xxxxx_${this.uniqueId}_${md5(key)}_xxxxx`;
|
||||||
const key = `xxxxxxxx_${i++}_xxxxxxxx`;
|
images[key_] = url
|
||||||
images[key] = url
|
return key_
|
||||||
return key
|
|
||||||
}
|
}
|
||||||
|
canvas.uniqueId = this.uniqueId
|
||||||
canvas.objects.forEach((object: any) => {
|
canvas.objects.forEach((object: any) => {
|
||||||
|
const id = object.info?.id
|
||||||
if (object.thumbnail) {
|
if (object.thumbnail) {
|
||||||
object.thumbnail = create(object.thumbnail)
|
object.thumbnail = create(object.thumbnail, `thumbnail_${id}`)
|
||||||
}
|
}
|
||||||
if (object.src) {
|
if (object.src) {
|
||||||
object.src = create(object.src)
|
object.src = create(object.src, `src_${id}`)
|
||||||
object.crossOrigin = 'anonymous'
|
object.crossOrigin = 'anonymous'
|
||||||
}
|
}
|
||||||
if (object.fill?.source) {
|
if (object.fill?.source) {
|
||||||
object.fill.source = create(object.fill.source)
|
object.fill.source = create(object.fill.source, `fillsource_${id}`)
|
||||||
}
|
}
|
||||||
if (object.info?.fill?.source) {
|
if (object.info?.fill?.source) {
|
||||||
object.info.fill.source = create(object.info.fill.source)
|
object.info.fill.source = create(object.info.fill.source, `infofillsource_${id}`)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
return { canvas: JSON.stringify(canvas), images }
|
return { canvas: JSON.stringify(canvas), images }
|
||||||
|
|||||||
Reference in New Issue
Block a user