Skip to content

Commit

Permalink
fix: 按数据名称下载文件名
Browse files Browse the repository at this point in the history
  • Loading branch information
leviathan233 committed Oct 31, 2023
1 parent c55fcba commit b36bef3
Showing 1 changed file with 44 additions and 4 deletions.
48 changes: 44 additions & 4 deletions src/views/face/Single.vue
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@
<span class="u-label">版本 : <em>{{ item.created_at }}</em></span>
<span class="u-label" v-if="item.describe">备注 : <em>{{ item.describe }}</em></span>
</div>
<a class="u-action" href="" @click.prevent="getDownUrl(item.uuid)">下载</a>
<a class="u-action" href="" @click.prevent="getDownUrl(item.uuid, item.name)">下载</a>
</li>
</ul>
</div>
Expand Down Expand Up @@ -448,11 +448,51 @@ export default {
this.loading = false;
});
},
getDownUrl(uuid) {
getDownUrl(uuid, filename) {
getDownUrl(this.id, uuid).then((res) => {
window.location.href = resolveImagePath(res.data.data?.url);
// window.location.href = resolveImagePath(res.data.data?.url);
this.downloadfile(res.data.data?.url, filename)
});
},
downloadfile(url, filename) {
this.getBlob(url).then((blob) => {
this.saveAs(blob, filename);
});
},
getBlob(url) {
return new Promise((resolve) => {
const xhr = new XMLHttpRequest();
xhr.open('GET', url, true);
xhr.responseType = 'blob';
xhr.onload = () => {
if (xhr.status === 200) {
resolve(xhr.response);
}
};
xhr.send();
});
},
saveAs(blob, filename) {
if (window.navigator.msSaveOrOpenBlob) {
navigator.msSaveBlob(blob, filename);
} else {
const link = document.createElement('a');
const body = document.querySelector('body');
link.href = window.URL.createObjectURL(blob);
link.download = filename;
// fix Firefox
link.style.display = 'none';
body.appendChild(link);
link.click();
body.removeChild(link);
window.URL.revokeObjectURL(link.href);
}
},
downloadAll() {
const urlArr = []
this.downFileList.forEach(item => {
Expand All @@ -463,7 +503,7 @@ export default {
p.then(arr => {
downloadFiles = arr.map((item, index) => {
return {
name: this.downFileList[index].name + '.jx3dat',
name: this.downFileList[index].name,
url: item.data.data?.url
}
})
Expand Down

0 comments on commit b36bef3

Please sign in to comment.