新增下载失败时显示搜索按钮

pull/166/head
lyswhut 2020-02-01 14:44:15 +08:00
parent 81985b0e31
commit 5edf51810d
3 changed files with 36 additions and 6 deletions

View File

@ -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')
</template>

View File

@ -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]
;(info.status != state.downloadStatus.COMPLETED ? deleteFile(info.filePath) : Promise.resolve()).finally(() => {
this.dispatch('download/startTask')
})
},
removeTaskMultiple({ commit, rootState, state }, list) {
list.forEach(item => {

View File

@ -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)
</template>
@ -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}`,
},
})
},
},
}
</script>