Merge branch 'main' of ssh://18.167.251.121:10002/aidlab/FiDA_Front
This commit is contained in:
@@ -89,14 +89,18 @@
|
|||||||
const observer = ref(null)
|
const observer = ref(null)
|
||||||
onMounted(async () => {
|
onMounted(async () => {
|
||||||
keyEventManager.registerEvents()
|
keyEventManager.registerEvents()
|
||||||
|
const url = props.config.url || ''
|
||||||
|
const json = props.config.json || ''
|
||||||
await canvasManager.initCanvas({
|
await canvasManager.initCanvas({
|
||||||
canvasRef,
|
canvasRef,
|
||||||
canvasViewWidth: canvasContainerRef.value.clientWidth,
|
canvasViewWidth: canvasContainerRef.value.clientWidth,
|
||||||
canvasViewHeight: canvasContainerRef.value.clientHeight,
|
canvasViewHeight: canvasContainerRef.value.clientHeight,
|
||||||
canvasWidth: props.config.width || 750,
|
canvasWidth: props.config.width || 750,
|
||||||
canvasHeight: props.config.height || 600,
|
canvasHeight: props.config.height || 600,
|
||||||
url: props.config.url || ''
|
url: json ? '' : url
|
||||||
})
|
})
|
||||||
|
if (!url && json) await canvasManager.loadJSON(json)
|
||||||
|
|
||||||
stateManager.onMounted()
|
stateManager.onMounted()
|
||||||
canvasManager.onMounted()
|
canvasManager.onMounted()
|
||||||
layerManager.onMounted()
|
layerManager.onMounted()
|
||||||
@@ -164,10 +168,13 @@
|
|||||||
// a.download = 'canvas.png'
|
// a.download = 'canvas.png'
|
||||||
// a.click()
|
// a.click()
|
||||||
// })
|
// })
|
||||||
const object = canvasManager.getCanvasDisUrlJSON()
|
|
||||||
console.log(object)
|
console.log(canvasManager.getCanvasJSON())
|
||||||
const canvas = canvasManager.processCanvasDisUrlJSON(object)
|
|
||||||
console.log(canvas)
|
// const object = canvasManager.getCanvasDisUrlJSON()
|
||||||
|
// console.log(object)
|
||||||
|
// const canvas = canvasManager.processCanvasDisUrlJSON(object)
|
||||||
|
// console.log(canvas)
|
||||||
}
|
}
|
||||||
// 导出到本地存储
|
// 导出到本地存储
|
||||||
const exportCanvasToLocalStorage = () => {
|
const exportCanvasToLocalStorage = () => {
|
||||||
|
|||||||
@@ -13,7 +13,8 @@
|
|||||||
const dialogVisible = ref(false)
|
const dialogVisible = ref(false)
|
||||||
const config = ref({
|
const config = ref({
|
||||||
id: '',
|
id: '',
|
||||||
url: ''
|
url: '',
|
||||||
|
json: ''
|
||||||
})
|
})
|
||||||
|
|
||||||
const open = (options) => {
|
const open = (options) => {
|
||||||
|
|||||||
@@ -289,10 +289,7 @@ export class AnimationManager {
|
|||||||
* @param {Boolean} adaptive 是否自适应缩放
|
* @param {Boolean} adaptive 是否自适应缩放
|
||||||
*/
|
*/
|
||||||
async resetZoom(animated = true, adaptive = false) {
|
async resetZoom(animated = true, adaptive = false) {
|
||||||
const canvasViewWidth = this.canvasManager.canvasViewWidth;
|
const { canvasViewWidth, canvasViewHeight, canvasWidth, canvasHeight } = this.canvasManager.getCanvasSize();
|
||||||
const canvasViewHeight = this.canvasManager.canvasViewHeight;
|
|
||||||
const canvasWidth = this.canvasManager.canvasWidth;
|
|
||||||
const canvasHeight = this.canvasManager.canvasHeight;
|
|
||||||
const scaleX = canvasViewWidth / canvasWidth * 0.8
|
const scaleX = canvasViewWidth / canvasWidth * 0.8
|
||||||
const scaleY = canvasViewHeight / canvasHeight * 0.8
|
const scaleY = canvasViewHeight / canvasHeight * 0.8
|
||||||
const scale = Math.min(scaleX, scaleY, 1)
|
const scale = Math.min(scaleX, scaleY, 1)
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { fabric } from 'fabric-with-all'
|
import { fabric } from 'fabric-with-all'
|
||||||
import { ref } from 'vue'
|
import { ref, computed } from 'vue'
|
||||||
import { createCanvas } from '../tools/canvasFactory'
|
import { createCanvas } from '../tools/canvasFactory'
|
||||||
import { AnimationManager } from './AnimationManager'
|
import { AnimationManager } from './AnimationManager'
|
||||||
import { detectDeviceType } from '../tools/index'
|
import { detectDeviceType } from '../tools/index'
|
||||||
@@ -44,10 +44,6 @@ export class CanvasManager {
|
|||||||
eventManager: any
|
eventManager: any
|
||||||
deviceInfo: any
|
deviceInfo: any
|
||||||
canvas: any
|
canvas: any
|
||||||
canvasViewWidth: number
|
|
||||||
canvasViewHeight: number
|
|
||||||
canvasWidth: number
|
|
||||||
canvasHeight: number
|
|
||||||
currentZoom: any
|
currentZoom: any
|
||||||
constructor(options) {
|
constructor(options) {
|
||||||
this.stateManager = options.stateManager;
|
this.stateManager = options.stateManager;
|
||||||
@@ -55,23 +51,31 @@ export class CanvasManager {
|
|||||||
this.currentZoom = ref(100)
|
this.currentZoom = ref(100)
|
||||||
}
|
}
|
||||||
onMounted() { }
|
onMounted() { }
|
||||||
|
getCanvasSize() {
|
||||||
|
return {
|
||||||
|
canvasViewWidth: this.canvas.width,
|
||||||
|
canvasViewHeight: this.canvas.height,
|
||||||
|
canvasWidth: this.canvas.clipPath.width,
|
||||||
|
canvasHeight: this.canvas.clipPath.height,
|
||||||
|
}
|
||||||
|
}
|
||||||
setCanvasViewSize(options) {
|
setCanvasViewSize(options) {
|
||||||
this.canvasViewWidth = options.canvasViewWidth || 1920
|
var canvasViewWidth = options.canvasViewWidth || 1920
|
||||||
this.canvasViewHeight = options.canvasViewHeight || 1080
|
var canvasViewHeight = options.canvasViewHeight || 1080
|
||||||
this.canvas.setWidth(this.canvasViewWidth)
|
this.canvas.setWidth(canvasViewWidth)
|
||||||
this.canvas.setHeight(this.canvasViewHeight)
|
this.canvas.setHeight(canvasViewHeight)
|
||||||
}
|
}
|
||||||
/** 初始化画布 */
|
/** 初始化画布 */
|
||||||
async initCanvas(options: CanvasInitOptions) {
|
async initCanvas(options: CanvasInitOptions) {
|
||||||
this.layerManager = this.stateManager.layerManager
|
this.layerManager = this.stateManager.layerManager
|
||||||
this.canvasWidth = options.canvasWidth || 750
|
var canvasWidth = options.canvasWidth || 750
|
||||||
this.canvasHeight = options.canvasHeight || 600
|
var canvasHeight = options.canvasHeight || 600
|
||||||
var image = null;
|
var image = null;
|
||||||
if (options.url) {
|
if (options.url) {
|
||||||
await new Promise((resolve) => {
|
await new Promise((resolve) => {
|
||||||
fabric.Image.fromURL(options.url, async (img) => {
|
fabric.Image.fromURL(options.url, async (img) => {
|
||||||
this.canvasWidth = img.width
|
canvasWidth = img.width
|
||||||
this.canvasHeight = img.height
|
canvasHeight = img.height
|
||||||
img.set({
|
img.set({
|
||||||
left: 0,
|
left: 0,
|
||||||
top: 0,
|
top: 0,
|
||||||
@@ -104,8 +108,8 @@ export class CanvasManager {
|
|||||||
this.canvas.clipPath = new fabric.Rect({
|
this.canvas.clipPath = new fabric.Rect({
|
||||||
left: 0,
|
left: 0,
|
||||||
top: 0,
|
top: 0,
|
||||||
width: this.canvasWidth,
|
width: canvasWidth,
|
||||||
height: this.canvasHeight
|
height: canvasHeight
|
||||||
})
|
})
|
||||||
|
|
||||||
// 动画管理器
|
// 动画管理器
|
||||||
@@ -121,12 +125,12 @@ export class CanvasManager {
|
|||||||
this.setupBrushEvents()
|
this.setupBrushEvents()
|
||||||
|
|
||||||
/** 测试-开始 */
|
/** 测试-开始 */
|
||||||
this.stateManager.setIsRecord(false)
|
// this.stateManager.setIsRecord(false)
|
||||||
const rect = await this.layerManager.createRectLayer({ left: 200 })
|
// const rect = await this.layerManager.createRectLayer({ left: 200 })
|
||||||
await this.layerManager.createStarLayer({ left: 400 })
|
// await this.layerManager.createStarLayer({ left: 400 })
|
||||||
await this.layerManager.createArrowLayer({ left: 600 })
|
// await this.layerManager.createArrowLayer({ left: 600 })
|
||||||
this.layerManager.setActiveID(rect.info.id)
|
// this.layerManager.setActiveID(rect.info.id)
|
||||||
this.stateManager.setIsRecord(true)
|
// this.stateManager.setIsRecord(true)
|
||||||
/** 测试-结束 */
|
/** 测试-结束 */
|
||||||
|
|
||||||
this.resetZoom(false, true)// 画布居中
|
this.resetZoom(false, true)// 画布居中
|
||||||
@@ -266,18 +270,22 @@ export class CanvasManager {
|
|||||||
return JSON.stringify(json)
|
return JSON.stringify(json)
|
||||||
}
|
}
|
||||||
/** 加载画布JSON */
|
/** 加载画布JSON */
|
||||||
loadJSON(json: string, callback?: (success: boolean) => void) {
|
loadJSON(json: string) {
|
||||||
let jsonObj = null;
|
return new Promise((resolve) => {
|
||||||
try {
|
let jsonObj = null;
|
||||||
jsonObj = JSON.parse(json)
|
try {
|
||||||
} catch (error) {
|
jsonObj = JSON.parse(json)
|
||||||
console.error('JSON解析错误:', error)
|
} catch (error) {
|
||||||
}
|
console.error('JSON解析错误:', error)
|
||||||
if (!jsonObj) return callback?.(false);
|
}
|
||||||
this.canvas.loadFromJSON(jsonObj, () => {
|
if (!jsonObj) return resolve(false)
|
||||||
this.layerManager.updateLayers()
|
this.canvas.loadFromJSON(jsonObj, () => {
|
||||||
this.renderAll()
|
this.resetZoom(false)
|
||||||
callback?.(true)
|
this.layerManager.updateLayers()
|
||||||
|
this.renderAll()
|
||||||
|
|
||||||
|
resolve(true)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
/** 导出画布为处理图片的JSON */
|
/** 导出画布为处理图片的JSON */
|
||||||
|
|||||||
@@ -121,8 +121,8 @@ export class LayerManager {
|
|||||||
|
|
||||||
/** 设置图层位置-不设置默认居中 */
|
/** 设置图层位置-不设置默认居中 */
|
||||||
setLayerPosition(object, options?: any) {
|
setLayerPosition(object, options?: any) {
|
||||||
const width = this.canvasManager.canvasWidth
|
const width = this.canvasManager.canvas.clipPath.width
|
||||||
const height = this.canvasManager.canvasHeight
|
const height = this.canvasManager.canvas.clipPath.height
|
||||||
|
|
||||||
if (options && options.top !== undefined) {
|
if (options && options.top !== undefined) {
|
||||||
object.set({ top: options.top })
|
object.set({ top: options.top })
|
||||||
@@ -294,8 +294,7 @@ export class LayerManager {
|
|||||||
|
|
||||||
/** 创建图片图层 */
|
/** 创建图片图层 */
|
||||||
async createImageLayer(imgOrUrl: string | HTMLImageElement, options?: any, isRecord = true) {
|
async createImageLayer(imgOrUrl: string | HTMLImageElement, options?: any, isRecord = true) {
|
||||||
const canvasWidth = this.canvasManager.canvasWidth
|
const { canvasWidth, canvasHeight } = this.canvasManager.getCanvasSize();
|
||||||
const canvasHeight = this.canvasManager.canvasHeight
|
|
||||||
|
|
||||||
const imageObject = await new Promise((resolve) => {
|
const imageObject = await new Promise((resolve) => {
|
||||||
const url = typeof imgOrUrl === 'string' ? imgOrUrl : imgOrUrl.src
|
const url = typeof imgOrUrl === 'string' ? imgOrUrl : imgOrUrl.src
|
||||||
|
|||||||
Reference in New Issue
Block a user