深度画布保存接口
This commit is contained in:
@@ -178,8 +178,8 @@
|
||||
}
|
||||
const onWorkbench = async () => {
|
||||
exportCanvasToImage(canvasManager.canvas).then((url) => {
|
||||
const json = canvasManager.getCanvasJSON()
|
||||
emit('workbench', { url, json })
|
||||
const { canvas, images } = canvasManager.getCanvasDisUrlJSON()
|
||||
emit('workbench', { url, canvas, images })
|
||||
})
|
||||
}
|
||||
</script>
|
||||
|
||||
@@ -89,16 +89,19 @@
|
||||
globalStore.setLoading(true)
|
||||
keyEventManager.registerEvents()
|
||||
const url = props.config.url || ''
|
||||
const json = props.config.json || ''
|
||||
const canvasData = props.config.canvasData || ''
|
||||
await canvasManager.initCanvas({
|
||||
canvasRef,
|
||||
canvasViewWidth: canvasContainerRef.value.clientWidth,
|
||||
canvasViewHeight: canvasContainerRef.value.clientHeight,
|
||||
canvasWidth: props.config.width || 750,
|
||||
canvasHeight: props.config.height || 600,
|
||||
url: json ? '' : url
|
||||
url: canvasData ? '' : url
|
||||
})
|
||||
if (json) await canvasManager.loadJSON(json)
|
||||
if (canvasData) {
|
||||
const json = canvasManager.processCanvasDisUrlJSON(canvasData)
|
||||
await canvasManager.loadJSON(json)
|
||||
}
|
||||
globalStore.setLoading(false)
|
||||
|
||||
stateManager.onMounted()
|
||||
|
||||
@@ -9,33 +9,54 @@
|
||||
<script setup lang="ts">
|
||||
import { base64Tofile } from '../tools/tools'
|
||||
import { uploadImage } from '@/api/upload'
|
||||
import { getDepthCanvas, saveDepthCanvas } from '@/api/depth-canvas'
|
||||
import FullscreenDialog from '../components/fullscreen-dialog.vue'
|
||||
import depthCanvas from './depth-canvas.vue'
|
||||
import { ref } from 'vue'
|
||||
const dialogVisible = ref(false)
|
||||
const config = ref({
|
||||
id: '',
|
||||
canvasId: '',
|
||||
sketchId: '',
|
||||
url: '',
|
||||
json: ''
|
||||
canvasData: '' as any,
|
||||
onWorkbench(options) {},
|
||||
onClose() {}
|
||||
})
|
||||
|
||||
const open = (options) => {
|
||||
const open = async (options) => {
|
||||
config.value = options
|
||||
console.log(config.value)
|
||||
config.value.json = sessionStorage.getItem('canvasJson_' + config.value.id)
|
||||
if (config.value.canvasId) {
|
||||
const res = await getDepthCanvas(config.value.canvasId)
|
||||
const canvas = res.deepCanvasDetail
|
||||
const images = res.images
|
||||
if (canvas && images) {
|
||||
config.value.canvasData = { canvas: JSON.stringify(canvas), images }
|
||||
} else {
|
||||
config.value.canvasData = null
|
||||
}
|
||||
}
|
||||
|
||||
dialogVisible.value = true
|
||||
}
|
||||
// 工作区
|
||||
const onWorkbench = async (options) => {
|
||||
const json = options.json
|
||||
|
||||
sessionStorage.setItem('canvasJson_' + config.value.id, json)
|
||||
|
||||
// 保存画布数据
|
||||
const data = {
|
||||
deepCanvasDetail: JSON.parse(options.canvas),
|
||||
images: options.images,
|
||||
sketchId: config.value.sketchId,
|
||||
id: config.value.canvasId || null
|
||||
}
|
||||
const sData = await saveDepthCanvas(data)
|
||||
console.log(sData)
|
||||
const canvasId = sData.id
|
||||
// base64 转 file 上传转换为 url
|
||||
const file = base64Tofile(options.url, 'canvas.png')
|
||||
const formData = new FormData()
|
||||
formData.append('file', file)
|
||||
const url = await uploadImage(formData)
|
||||
config.value.onWorkbench?.({ url })
|
||||
config.value.onWorkbench?.({ url, canvasId })
|
||||
|
||||
dialogVisible.value = false
|
||||
}
|
||||
// 关闭
|
||||
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user