非dicom影像阅片大小不对、无法移动问题解决
continuous-integration/drone/push Build is passing Details

uat_us^2
wangxiaoshuang 2026-08-14 15:47:44 +08:00
parent e497a31608
commit ee58ae4a22
1 changed files with 68 additions and 21 deletions

View File

@ -137,6 +137,7 @@ export default {
currentDrawData: {},
canvasData: [],
imgZoom: 1,
isDragging: false,
isToolDisabled: false,
lesionName: '',
visitTaskId: '',
@ -209,6 +210,10 @@ export default {
}
this.deviceSupportInstall()
},
beforeDestroy() {
window.removeEventListener('message', this.receiveMsg)
this.stopDragging()
},
methods: {
getCanvasData() {
return new Promise(async resolve => {
@ -337,25 +342,55 @@ export default {
//
initCanvas(img) {
this.loading = true
this.canvasSize.height = img.height
this.canvasSize.width = img.width
this.imgSize.height = img.height
this.imgSize.width = img.width
const canvasDiv = document.getElementsByClassName('image-viewer__canvas')[0]
const widthRatio = canvasDiv && canvasDiv.offsetWidth ? canvasDiv.offsetWidth / img.width : 1
const heightRatio = canvasDiv && canvasDiv.offsetHeight ? canvasDiv.offsetHeight / img.height : 1
this.imgZoom = Math.min(widthRatio, heightRatio, 1)
this.canvasSize.height = Math.round(img.height * this.imgZoom)
this.canvasSize.width = Math.round(img.width * this.imgZoom)
this.canvasPosition = {
x: canvasDiv.offsetWidth / 2 - img.width / 2,
y: canvasDiv.offsetHeight / 2 - img.height / 2 - 25
x: canvasDiv.offsetWidth / 2 - this.canvasSize.width / 2,
y: canvasDiv.offsetHeight / 2 - this.canvasSize.height / 2 - 25
} //
this.$nextTick(async () => {
ctx = document.getElementById('canvas').getContext('2d') //
await ctx.drawImage(img, 0, 0, img.width, img.height) // canvas()
await ctx.drawImage(img, 0, 0, this.canvasSize.width, this.canvasSize.height) // canvas()
this.drawToArr()
this.loading = false
})
},
scalePoint(point) {
return {
x: point.x * this.imgZoom,
y: point.y * this.imgZoom
}
},
startDragging(e) {
const { offsetX, offsetY } = this.transform
const startX = e.pageX
const startY = e.pageY
this.isDragging = true
this._dragHandler = rafThrottle((ev) => {
this.transform.offsetX = offsetX + ev.pageX - startX
this.transform.offsetY = offsetY + ev.pageY - startY
})
this._dragEndHandler = () => {
this.stopDragging()
}
on(document, 'mousemove', this._dragHandler)
on(document, 'mouseup', this._dragEndHandler)
},
stopDragging() {
off(document, 'mousemove', this._dragHandler)
off(document, 'mouseup', this._dragEndHandler)
this._dragHandler = null
this._dragEndHandler = null
this.isDragging = false
},
//
clearCanvas() {
@ -381,6 +416,11 @@ export default {
if (e.button !== 0) {
return
}
if (!this.model) {
this.startDragging(e)
e.preventDefault()
return
}
this.isMouseDown = true //
//
this.canvasMouseStart = {
@ -391,6 +431,9 @@ export default {
//
async handleMouseMove(e) {
if (!this.model || this.isDragging) {
return
}
// ()
this.mousePosition = {
x: e.pageX,
@ -437,10 +480,12 @@ export default {
var headlen = 10// 线
var theta = 45// 线线
var arrowX, arrowY// 线
var fromX = e.data.handles.start.x
var fromY = e.data.handles.start.y
var toX = e.data.handles.end.x
var toY = e.data.handles.end.y
var start = this.scalePoint(e.data.handles.start)
var end = this.scalePoint(e.data.handles.end)
var fromX = start.x
var fromY = start.y
var toX = end.x
var toY = end.y
//
var angle = Math.atan2(fromY - toY, fromX - toX) * 180 / Math.PI
var angle1 = (angle + theta) * Math.PI / 180
@ -453,8 +498,8 @@ export default {
// 线
ctx.lineWidth = this.lineWidth
ctx.beginPath()
ctx.moveTo(fromX * this.imgZoom, fromY * this.imgZoom)
ctx.lineTo(toX * this.imgZoom, toY * this.imgZoom)
ctx.moveTo(fromX, fromY)
ctx.lineTo(toX, toY)
arrowX = toX + topX
arrowY = toY + topY
@ -473,18 +518,16 @@ export default {
ctx.lineWidth = this.lineWidth
ctx.beginPath()
ctx.strokeStyle = this.color
const start = this.scalePoint(e.data.handles.start)
const end = this.scalePoint(e.data.handles.end)
//
ctx.strokeRect(
// this.canvasMouseStart.x,
// this.canvasMouseStart.y,
// e.offsetX - this.canvasMouseStart.x,
// e.offsetY - this.canvasMouseStart.y
e.data.handles.start.x,
e.data.handles.start.y,
e.data.handles.end.x - e.data.handles.start.x,
e.data.handles.end.y - e.data.handles.start.y
start.x,
start.y,
end.x - start.x,
end.y - start.y
)
this.drawText(ctx, { x: e.data.handles.start.x, y: e.data.handles.start.y }, { x: e.data.handles.end.x, y: e.data.handles.end.y }, e.data.remark, this.color)
this.drawText(ctx, start, end, e.data.remark, this.color)
}
}
})
@ -495,6 +538,10 @@ export default {
if (e.button !== 0) {
return //
}
if (this.isDragging) {
this.stopDragging()
return
}
//
if (this.model === 'ArrowAnnotate' || this.model === 'RectangleRoi') {