Open lory8545 opened 4 years ago
当传入错误的密码时, 除非刷新 ,要不然再也打不开其它的PDF文件了, 即使该pdf文件不需要密码
I've just run into the same issue on v4.2.0
@lory8545 did you manage to find a workaround for this?
Steps to reproduce:
vue-pdf
pointing to a password protected PDFvue-pdf
pointing to an unprotected PDFThe issue is probably reproducible with multiple instances of vue-pdf
on a single page, but I haven't tested this.
@FranckFreiburger I think the problem may stem from here https://github.com/FranckFreiburger/vue-pdf/blob/master/src/pdfjsWrapper.js#L67
pdfDoc === null
when a password has not yet been successfully provided. pendingOperation
is thus NOT cleared, and this prevents the next PDF from loadingthis.destroy = function() {
if ( pdfDoc === null )
return;
// Aborts all network requests and destroys worker.
pendingOperation = pdfDoc.destroy();
pdfDoc = null;
}
Would it be safe for us to just re-initialise the pendingOperation
if the document hasn't been loaded?
if ( pdfDoc === null ) {
pendingOperation = Promise.resolve();
return;
}
I've given this a quick test run locally, and it seems to resolve the issue.
You should watch "reason" params, eg:
handleNeedPsw: function (updatePassword, reason) {
if (reason === 'NEED_PASSWORD') {
updatePassword(prompt('该文件已加密,请输入密码'))
}
if (reason === 'INCORRECT_PASSWORD') {
this.$message({
message: '密码错误',
type: 'error',
})
this.src = ''
this.loadingProgress = '0%'
}
}
other, you should edit the file: https://github.com/FranckFreiburger/vue-pdf/blob/master/src/pdfjsWrapper.js#L67
this.destroy = function () {
if (pdfDoc === null) {
pendingOperation = Promise.resolve();
return;
}
// Aborts all network requests and destroys worker.
pendingOperation = pdfDoc.destroy();
pdfDoc = null;
};