截图更改及长短径工具更改

main
caiyiling 2026-05-08 15:04:26 +08:00
parent c9057e12cd
commit 7266d0a4f5
2 changed files with 104 additions and 21 deletions

View File

@ -915,7 +915,13 @@ export default {
fullScreenWidth: window.innerWidth - 570 + 'px',
fullScreenHeight: window.innerHeight - 130 + 'px',
ManualsClose: false
ManualsClose: false,
screenshotCache: {
key: '',
at: 0,
base64: ''
},
screenshotInFlight: null
}
},
@ -1051,30 +1057,27 @@ export default {
console.log('getMeasureData')
})
DicomEvent.$on('getScreenshots', async (measuredData, callback) => {
if (this.currentDicomCanvasIndex > -1) {
if (this.currentDicomCanvasIndex <= -1 || typeof callback !== 'function') return
const shouldRelocate = this.shouldRelocateBeforeScreenshot(measuredData)
if (shouldRelocate) {
await this.imageLocation(measuredData)
if (!measuredData.isMarked) {
callback()
return
}
setTimeout(async () => {
// var base64Str = this.$refs[`dicomCanvas${this.currentDicomCanvasIndex}`][0].getScreenshots()
const divForDownloadViewport = document.querySelector(
`div[data-canvas-uid="dicomCanvas${this.currentDicomCanvasIndex}"]`
)
var canvas = await html2canvas(divForDownloadViewport)
var base64Str = canvas.toDataURL('image/png', 1)
console.log('getScreenshots')
callback(base64Str)
}, 50)
}
if (!measuredData || !measuredData.isMarked) {
callback()
return
}
const cacheKey = this.getScreenshotCacheKey(measuredData)
const base64Str = await this.getOrCaptureScreenshot(cacheKey)
callback(base64Str)
})
DicomEvent.$on('imageLocation', async (measuredData) => {
return new Promise(async resolve => {
if (!measuredData) return
await this.imageLocation(measuredData)
console.log('imageLocation')
// await this.imageLocation(measuredData)
const shouldRelocate = this.shouldRelocateBeforeScreenshot(measuredData)
if (shouldRelocate) {
await this.imageLocation(measuredData)
}
resolve()
})
})
@ -1710,6 +1713,85 @@ export default {
}
})
},
shouldRelocateBeforeScreenshot(measuredData) {
if (!measuredData) return false
const currentCanvas = this.$refs[`dicomCanvas${this.currentDicomCanvasIndex}`] && this.$refs[`dicomCanvas${this.currentDicomCanvasIndex}`][0]
if (!currentCanvas || !currentCanvas.stack) return true
const currentStack = currentCanvas.stack
if (currentStack.visitTaskId !== measuredData.visitTaskId) return true
// imageLocation
const targetSeries = this.getSeriesInfoByMark(measuredData.visitTaskId, measuredData)
if (!targetSeries) return false
if (currentStack.seriesId !== targetSeries.seriesId) return true
if (typeof targetSeries.imageIdIndex === 'number' &&
targetSeries.imageIdIndex !== currentStack.currentImageIdIndex) {
return true
}
return false
},
getScreenshotCacheKey(measuredData) {
const currentCanvas = this.$refs[`dicomCanvas${this.currentDicomCanvasIndex}`] && this.$refs[`dicomCanvas${this.currentDicomCanvasIndex}`][0]
const currentStack = currentCanvas && currentCanvas.stack ? currentCanvas.stack : {}
return [
this.currentDicomCanvasIndex,
currentStack.visitTaskId || '',
currentStack.seriesId || '',
typeof currentStack.currentImageIdIndex === 'number' ? currentStack.currentImageIdIndex : '',
measuredData.visitTaskId || '',
measuredData.questionId || '',
measuredData.rowIndex || '',
measuredData.lesionName || '',
measuredData.isMarked ? 1 : 0
].join('|')
},
async getOrCaptureScreenshot(cacheKey) {
const now = Date.now()
if (this.screenshotCache.key === cacheKey &&
this.screenshotCache.base64 &&
now - this.screenshotCache.at < 1500) {
return this.screenshotCache.base64
}
if (this.screenshotInFlight && this.screenshotInFlight.key === cacheKey) {
return this.screenshotInFlight.promise
}
const promise = this.captureActiveViewportScreenshot()
.then((base64) => {
this.screenshotCache = {
key: cacheKey,
at: Date.now(),
base64: base64 || ''
}
return base64
})
.finally(() => {
if (this.screenshotInFlight && this.screenshotInFlight.key === cacheKey) {
this.screenshotInFlight = null
}
})
this.screenshotInFlight = { key: cacheKey, promise }
return promise
},
async captureActiveViewportScreenshot() {
// const currentCanvas = this.$refs[`dicomCanvas${this.currentDicomCanvasIndex}`] && this.$refs[`dicomCanvas${this.currentDicomCanvasIndex}`][0]
await this.$nextTick()
const divForDownloadViewport = document.querySelector(
`div[data-canvas-uid="dicomCanvas${this.currentDicomCanvasIndex}"]`
)
if (divForDownloadViewport) {
try {
const canvas = await html2canvas(divForDownloadViewport, {
logging: false,
useCORS: true,
scale: 1
})
return canvas.toDataURL('image/png')
} catch (e) {
console.log(e)
}
}
return ''
},
setToolToTarget(obj) {
if (obj.readingTaskState < 2 && obj.markTool && !obj.isMarked) {
if (this.activeTool) {

View File

@ -15,7 +15,7 @@ import createNewMeasurement from './createNewMeasurement'
*/
export default class BidirectionalTool extends cornerstoneTools.BidirectionalTool {
constructor(props) {
constructor(props = {}) {
const defaultProps = {
name: 'Bidirectional',
configuration: {
@ -25,7 +25,8 @@ export default class BidirectionalTool extends cornerstoneTools.BidirectionalToo
super(props, defaultProps)
this.throttledUpdateCachedStats = throttle(this.updateCachedStats, 50)
this.digits = isNaN(parseInt(props.configuration.digits)) ? 2 : props.configuration.digits
const digits = props?.configuration?.digits
this.digits = isNaN(parseInt(digits)) ? 2 : digits
this.createNewMeasurement = createNewMeasurement.bind(this)
this.renderToolData = renderToolData.bind(this)
}