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