下载逻辑修改
This commit is contained in:
@@ -269,17 +269,31 @@ export default {
|
|||||||
return path.split('/').pop();
|
return path.split('/').pop();
|
||||||
},
|
},
|
||||||
downloadDiploma() {
|
downloadDiploma() {
|
||||||
if (!this.lookForm.hardFile) return;
|
const raw = this.lookForm.hardFile;
|
||||||
const isAbsoluteUrl = this.lookForm.hardFile.startsWith('http');
|
if (!raw) return;
|
||||||
const pdfUrl = isAbsoluteUrl
|
// 支持逗号分隔的多个文件
|
||||||
? this.lookForm.hardFile
|
const files = String(raw)
|
||||||
: `${this.baseurl}${this.lookForm.hardFile}`;
|
.split(',')
|
||||||
|
.map(s => s.trim())
|
||||||
|
.filter(Boolean);
|
||||||
|
|
||||||
|
const triggerDownload = (href, filename) => {
|
||||||
const link = document.createElement('a');
|
const link = document.createElement('a');
|
||||||
link.href = pdfUrl;
|
link.href = href;
|
||||||
link.download = this.getFileName(this.lookForm.hardFile);
|
// 设置下载文件名(跨域时可能被浏览器忽略,但不影响触发下载/打开)
|
||||||
|
link.download = filename || '';
|
||||||
document.body.appendChild(link);
|
document.body.appendChild(link);
|
||||||
link.click();
|
link.click();
|
||||||
document.body.removeChild(link);
|
document.body.removeChild(link);
|
||||||
|
};
|
||||||
|
|
||||||
|
files.forEach((file, idx) => {
|
||||||
|
const isAbsoluteUrl = /^https?:\/\//i.test(file);
|
||||||
|
const url = isAbsoluteUrl ? file : `${this.baseurl}${file}`;
|
||||||
|
const name = this.getFileName(file);
|
||||||
|
// 轻微延时,避免浏览器对一次事件同时触发多个下载的限制
|
||||||
|
setTimeout(() => triggerDownload(url, name), idx * 200);
|
||||||
|
});
|
||||||
},
|
},
|
||||||
lookBiye() {
|
lookBiye() {
|
||||||
const isAbsoluteUrl = this.lookForm.hardFile.startsWith('http');
|
const isAbsoluteUrl = this.lookForm.hardFile.startsWith('http');
|
||||||
|
|||||||
Reference in New Issue
Block a user