diff --git a/src/renderer/components/material/ListButtons.vue b/src/renderer/components/material/ListButtons.vue index 75b9b1d5..ce649a5c 100644 --- a/src/renderer/components/material/ListButtons.vue +++ b/src/renderer/components/material/ListButtons.vue @@ -21,12 +21,12 @@ div(:class="$style.btns") button(type="button" v-if="fileBtn" title="定位文件" @click.stop="handleClick('file')") svg(version='1.1' xmlns='http://www.w3.org/2000/svg' xlink='http://www.w3.org/1999/xlink' height='100%' viewBox='-61 0 512 512' space='preserve') use(xlink:href='#icon-musicFile') - button(type="button" v-if="removeBtn" title="移除" @click.stop="handleClick('remove')") - svg(version='1.1' xmlns='http://www.w3.org/2000/svg' xlink='http://www.w3.org/1999/xlink' height='100%' viewBox='0 0 212.982 212.982' space='preserve') - use(xlink:href='#icon-delete') button(type="button" v-if="searchBtn" title="搜索" @click.stop="handleClick('search')") svg(version='1.1' xmlns='http://www.w3.org/2000/svg' xlink='http://www.w3.org/1999/xlink' height='100%' viewBox='0 0 30.239 30.239' space='preserve') use(xlink:href='#icon-search') + button(type="button" v-if="removeBtn" title="移除" @click.stop="handleClick('remove')") + svg(version='1.1' xmlns='http://www.w3.org/2000/svg' xlink='http://www.w3.org/1999/xlink' height='100%' viewBox='0 0 212.982 212.982' space='preserve') + use(xlink:href='#icon-delete') diff --git a/src/renderer/store/modules/download.js b/src/renderer/store/modules/download.js index 865caee5..580604d8 100644 --- a/src/renderer/store/modules/download.js +++ b/src/renderer/store/modules/download.js @@ -134,6 +134,21 @@ const refreshUrl = function(commit, downloadInfo) { }) } +/** + * 删除文件 + * @param {*} path + */ +const deleteFile = path => new Promise((resolve, reject) => { + fs.access(path, fs.constants.F_OK, err => { + if (err) return reject(err) + fs.unlink(path, err => { + if (err) return reject(err) + resolve() + }) + }) +}) + + // actions const actions = { createDownload({ state, rootState, commit }, { musicInfo, type }) { @@ -280,7 +295,9 @@ const actions = { } commit('removeTask', index) if (dls[info.key]) delete dls[info.key] - this.dispatch('download/startTask') + ;(info.status != state.downloadStatus.COMPLETED ? deleteFile(info.filePath) : Promise.resolve()).finally(() => { + this.dispatch('download/startTask') + }) }, removeTaskMultiple({ commit, rootState, state }, list) { list.forEach(item => { diff --git a/src/renderer/views/Download.vue b/src/renderer/views/Download.vue index b7b98fd2..1fd3ad74 100644 --- a/src/renderer/views/Download.vue +++ b/src/renderer/views/Download.vue @@ -28,9 +28,10 @@ div(:class="$style.download") td.break(style="width: 15%;") {{item.statusText}} td.break(style="width: 10%;") {{item.type && item.type.toUpperCase()}} td(style="width: 20%; padding-left: 0; padding-right: 0;") - material-list-buttons(:index="index" :download-btn="false" :file-btn="true" :start-btn="!item.isComplate && item.status != downloadStatus.WAITING && (item.status != downloadStatus.RUN)" + material-list-buttons(:index="index" :download-btn="false" :file-btn="item.status != downloadStatus.ERROR" + :start-btn="!item.isComplate && item.status != downloadStatus.WAITING && (item.status != downloadStatus.RUN)" :pause-btn="!item.isComplate && (item.status == downloadStatus.RUN || item.status == downloadStatus.WAITING)" :list-add-btn="false" - :play-btn="item.status == downloadStatus.COMPLETED" @btn-click="handleListBtnClick") + :play-btn="item.status == downloadStatus.COMPLETED" :search-btn="item.status == downloadStatus.ERROR" @btn-click="handleListBtnClick") material-flow-btn(:show="isShowEditBtn" :play-btn="false" :download-btn="false" :add-btn="false" :start-btn="true" :pause-btn="true" @btn-click="handleFlowBtnClick") div(:class="$style.noItem" v-else) @@ -185,6 +186,9 @@ export default { case 'file': this.handleOpenFolder(index) break + case 'search': + this.handleSearch(index) + break } }, handleSelectAllData(isSelect) { @@ -232,6 +236,15 @@ export default { if (!checkPath(path)) return openDirInExplorer(path) }, + handleSearch(index) { + const info = this.list[index].musicInfo + this.$router.push({ + path: 'search', + query: { + text: `${info.name} ${info.singer}`, + }, + }) + }, }, }