1
0
forked from um/web

Add instant download to avoid memory occupation

This commit is contained in:
MengYX 2020-02-05 01:53:58 +08:00
parent 50fbb69394
commit a7c7b6cbfa
No known key found for this signature in database
GPG Key ID: E63F9C7303E8F604

View File

@ -21,6 +21,7 @@
<el-radio name="format" v-model="format" label="1">歌曲名</el-radio> <el-radio name="format" v-model="format" label="1">歌曲名</el-radio>
<el-radio name="format" v-model="format" label="2">歌手-歌曲名</el-radio> <el-radio name="format" v-model="format" label="2">歌手-歌曲名</el-radio>
<el-radio name="format" v-model="format" label="3">歌曲名-歌手</el-radio> <el-radio name="format" v-model="format" label="3">歌曲名-歌手</el-radio>
<el-checkbox v-model="instantDownload" border>立即保存</el-checkbox>
</el-row> </el-row>
<el-button @click="handleDownloadAll" icon="el-icon-download" plain>下载全部</el-button> <el-button @click="handleDownloadAll" icon="el-icon-download" plain>下载全部</el-button>
@ -107,6 +108,7 @@
playing_url: "", playing_url: "",
playing_auto: false, playing_auto: false,
format: '2', format: '2',
instantDownload: false,
workCount: 0, workCount: 0,
cacheQueue: [], cacheQueue: [],
cacheQueueOption: { cacheQueueOption: {
@ -174,12 +176,17 @@
handleDoFile(file, worker_id) { handleDoFile(file, worker_id) {
this.workers[worker_id](file).then(data => { this.workers[worker_id](file).then(data => {
if (data.status) { if (data.status) {
if (this.instantDownload) {
this.handleDownload(data);
this.handleDelete(null, data);
} else {
this.tableData.push(data); this.tableData.push(data);
this.$notify.success({ this.$notify.success({
title: '解锁成功', title: '解锁成功',
message: '成功解锁 ' + data.title, message: '成功解锁 ' + data.title,
duration: 3000 duration: 3000
}); });
}
let _rp_data = [data.title, data.artist, data.album]; let _rp_data = [data.title, data.artist, data.album];
window._paq.push(["trackEvent", "Unlock", data.rawExt + "," + data.mime, JSON.stringify(_rp_data)]); window._paq.push(["trackEvent", "Unlock", data.rawExt + "," + data.mime, JSON.stringify(_rp_data)]);
} else { } else {
@ -207,12 +214,14 @@
handleDelete(index, row) { handleDelete(index, row) {
URL.revokeObjectURL(row.file); URL.revokeObjectURL(row.file);
URL.revokeObjectURL(row.picture); URL.revokeObjectURL(row.picture);
if (index != null) {
this.tableData.splice(index, 1); this.tableData.splice(index, 1);
}
}, },
handleDownload(row) { handleDownload(row) {
let a = document.createElement('a'); let a = document.createElement('a');
a.href = row.file; a.href = row.file;
switch(this.format) { switch (this.format) {
case "1": case "1":
a.download = row.title + "." + row.ext; a.download = row.title + "." + row.ext;
break; break;