取消cornerstone.js正在加载的dicom

422 阅读1分钟

配置

// 我测试环境用的版本是 3.3.1   cornerstoneWADOImageLoader

var options = {
    // xhr发送前调用处理,传四个参数  xhr, imageId, headers, params
    // 这里也可以保存 xhr
    beforeSend: function(){},
    // 这个函数发生在 xhr.onreadystatechange 成功之后
    beforeProcessing: function(xhr) {
        return Promise.resolve(xhr.response);
    },
    // 没有调用,其他地方可能用到
    imageCreated: function(){},
    strict: false,
    useWebWorkers: true,
    decodeConfig: {
        usePDFJS: false
    },
    // 不是必传 发生在xhr.onloadstart事件   也可在这一步保存xhr => event.target
    onloadstart(event, params){},
    // 不是必传 发生在xhr.onloadend事件
    onloadend(event, params){},
    // 不是必传 发生在 xhr.onreadystatechange
    // 若是传入这个函数,就必须要自己处理后续内容
    onreadystatechange(event, params){},
    // 不是必传 发生在 xhr.onprogress
    onprogress(){}
};

取消

// 前面配置基本一致,主要是后面
const el = document.querySelector("#test")
cornerstone.enable(el)

const imageId = "wadouri:http://xxxx"

let xhr = null
// 上面的 options 对象
options.onloadstart = function(event, params){
    xhr = event.target
}
// 取消正在加载请求
function cancel(){
    xhr.abort()
}
// 把加载器的配置对象替换成自己的
cornerstoneWADOImageLoader.internal.setOptions(options)

cornerstone.loadAndCacheImage(imageId).then(img => {}).catch(err => console.error(err))

效果

image.png

image.png 基本内容就这些。