A full-featured download manager.
feat: task list drag select & batch delete task
Dr_rOotb00536a0c78c
diff --git a/src/main/index.dev.js b/src/main/index.dev.jsindex 7b00245f..b4a30459 100644--- a/src/main/index.dev.js+++ b/src/main/index.dev.js@@ -14,7 +14,7 @@ require('electron-debug')({})// Install `vue-devtools`-require('electron').app.on('ready', () => {+require('electron').app.whenReady().then(() => {let installExtension = require('electron-devtools-installer')installExtension.default(installExtension.VUEJS_DEVTOOLS).then(() => {})diff --git a/src/renderer/components/Preference/Index.vue b/src/renderer/components/Preference/Index.vueindex 7f9a6614..2a7e29c7 100644--- a/src/renderer/components/Preference/Index.vue+++ b/src/renderer/components/Preference/Index.vue@@ -21,7 +21,7 @@<style lang="scss">.form-preference {- padding-right: 7%;+ padding: 16px 7% 64px 0;.el-switch__label {font-weight: normal;color: $--color-text-regular;diff --git a/src/renderer/components/Task/TaskActions.vue b/src/renderer/components/Task/TaskActions.vueindex 7799e054..49d12f00 100644--- a/src/renderer/components/Task/TaskActions.vue+++ b/src/renderer/components/Task/TaskActions.vue@@ -1,30 +1,43 @@<template><div class="task-actions">- <el-tooltip class="item hidden-md-and-up" effect="dark" :content="$t('task.new-task')" placement="bottom">- <i @click.stop="onAddClick">+ <el-tooltip+ class="item hidden-md-and-up"+ effect="dark"+ :content="$t('task.new-task')"+ placement="bottom"+ >+ <i class="task-action" @click.stop="onAddClick"><mo-icon name="menu-add" width="14" height="14" /></i></el-tooltip>+ <el-tooltip+ class="item"+ effect="dark"+ placement="bottom"+ :content="$t('task.delete-selected-tasks')"+ >+ <i+ class="task-action"+ :class="{ disabled: selectedGidListCount === 0 }"+ @click="onBatchDeleteClick">+ <mo-icon name="delete" width="14" height="14" />+ </i>+ </el-tooltip><el-tooltip class="item" effect="dark" :content="$t('task.refresh-list')" placement="bottom">- <i @click="onRefreshClick">+ <i class="task-action" @click="onRefreshClick"><mo-icon name="refresh" width="14" height="14" :spin="refreshing" /></i></el-tooltip><el-tooltip class="item" effect="dark" :content="$t('task.resume-all-task')" placement="bottom">- <i @click="onResumeAllClick">+ <i class="task-action" @click="onResumeAllClick"><mo-icon name="task-start-line" width="14" height="14" /></i></el-tooltip><el-tooltip class="item" effect="dark" :content="$t('task.pause-all-task')" placement="bottom">- <i @click="onPauseAllClick">+ <i class="task-action" @click="onPauseAllClick"><mo-icon name="task-pause-line" width="14" height="14" /></i></el-tooltip>- <!-- <el-tooltip class="item" effect="dark" :content="$t('task.delete-selected-tasks')" placement="bottom">- <i>- <mo-icon name="delete" width="14" height="14" />- </i>- </el-tooltip> --><el-tooltipclass="item"effect="dark"@@ -32,7 +45,7 @@placement="bottom"v-if="currentList === 'stopped'">- <i @click="onPurgeRecordClick">+ <i class="task-action" @click="onPurgeRecordClick"><mo-icon name="purge" width="14" height="14" /></i></el-tooltip>@@ -43,6 +56,9 @@import { mapState } from 'vuex'import { ADD_TASK_TYPE } from '@shared/constants'import { bytesToSize, timeFormat } from '@shared/utils'+ import {+ moveTaskFilesToTrash+ } from '@/components/Native/utils'import '@/components/Icons/menu-add'import '@/components/Icons/refresh'import '@/components/Icons/task-start-line'@@ -63,7 +79,10 @@},computed: {...mapState('task', {- currentList: state => state.currentList+ currentList: state => state.currentList,+ taskList: state => state.taskList,+ selectedGidList: state => state.selectedGidList,+ selectedGidListCount: state => state.selectedGidList.length})},filters: {@@ -79,6 +98,74 @@this.refreshing = false}, 500)},+ delayDeleteTaskFiles (task, delay) {+ return new Promise((resolve) => {+ setTimeout(() => {+ try {+ const result = moveTaskFilesToTrash(task)+ resolve(result)+ } catch (err) {+ console.log('[Motrix] batch delay delete task files fail', err)+ resolve(false)+ }+ }, delay)+ })+ },+ batchDeleteTaskFiles (taskList) {+ const promises = taskList.map((task, index) => this.delayDeleteTaskFiles(task, index * 200))+ Promise.all(promises).then(values => {+ console.log(values)+ })+ },+ removeTasks (taskList, isRemoveWithFiles) {+ const gids = taskList.map((task) => task.gid)+ this.$store.dispatch('task/batchForcePauseTask', gids)+ .finally(() => {+ if (isRemoveWithFiles) {+ this.batchDeleteTaskFiles(taskList)+ }++ this.removeTaskItems(gids)+ })+ },+ removeTaskItems (gids) {+ this.$store.dispatch('task/batchRemoveTask', gids)+ .then(() => {+ this.$msg.success(this.$t('task.batch-delete-task-success'))+ })+ .catch(({ code }) => {+ if (code === 1) {+ this.$msg.error(this.$t('task.batch-delete-task-fail'))+ }+ })+ },+ onBatchDeleteClick: function (event) {+ const self = this+ const { taskList, selectedGidList, selectedGidListCount } = this+ if (selectedGidListCount === 0) {+ event.preventDefault()+ return+ }++ const selectedTaskList = taskList.filter((task) => {+ return selectedGidList.includes(task.gid)+ })+ const count = `${selectedGidListCount}`+ const isChecked = !!event.shiftKey+ this.$electron.remote.dialog.showMessageBox({+ type: 'warning',+ title: this.$t('task.delete-selected-task'),+ message: this.$t('task.batch-delete-task-confirm', { count }),+ buttons: [this.$t('app.yes'), this.$t('app.no')],+ cancelId: 1,+ checkboxLabel: this.$t('task.delete-task-label'),+ checkboxChecked: isChecked+ }).then(({ response, checkboxChecked }) => {+ if (response === 0) {+ self.removeTasks(selectedTaskList, checkboxChecked)+ }+ })+ },onRefreshClick: function () {this.refreshSpin()this.$store.dispatch('task/fetchList')@@ -136,7 +223,7 @@text-align: right;color: $--task-action-color;transition: all 0.25s;- &> i {+ .task-action {display: inline-block;padding: 5px;margin: 0 4px;@@ -146,6 +233,9 @@&:hover {color: $--task-action-hover-color;}+ &.disabled {+ color: $--task-action-disabled-color;+ }}}</style>diff --git a/src/renderer/components/Task/TaskItem.vue b/src/renderer/components/Task/TaskItem.vueindex 8e8b924a..42fd1cfe 100644--- a/src/renderer/components/Task/TaskItem.vue+++ b/src/renderer/components/Task/TaskItem.vue@@ -1,5 +1,5 @@<template>- <li :key="task.gid" class="task-item" v-on:dblclick="onDbClick">+ <div :key="task.gid" class="task-item" v-on:dblclick="onDbClick"><div class="task-name" :title="taskFullName"><span>{{ taskFullName }}</span></div>@@ -12,7 +12,7 @@/><mo-task-progress-info :task="task" /></div>- </li>+ </div></template><script>@@ -95,6 +95,9 @@right: 12px;}}+ .selected .task-item {+ border-color: $--task-item-hover-border-color;+ }.task-name {color: #505753;margin-bottom: 32px;diff --git a/src/renderer/components/Task/TaskList.vue b/src/renderer/components/Task/TaskList.vueindex 3892993d..1bd45f0f 100644--- a/src/renderer/components/Task/TaskList.vue+++ b/src/renderer/components/Task/TaskList.vue@@ -1,7 +1,21 @@<template>- <ul class="task-list" v-if="taskList.length > 0">- <mo-task-item v-for="task in taskList" :key="task.gid" :task="task" />- </ul>+ <mo-drag-select+ class="task-list"+ v-if="taskList.length > 0"+ attribute="attr"+ @change="handleDragSelectChange"+ >+ <div+ v-for="item in taskList"+ :key="item.gid"+ :attr="item.gid"+ :class="getItemClass(item)"+ >+ <mo-task-item+ :task="item"+ />+ </div>+ </mo-drag-select><div class="no-task" v-else><div class="no-task-inner">{{ $t('task.no-task') }}@@ -11,27 +25,53 @@<script>import { mapState } from 'vuex'+ import { cloneDeep } from 'lodash'+ import DragSelect from '@/components/DragSelect'import TaskItem from './TaskItem'export default {name: 'mo-task-list',components: {+ [DragSelect.name]: DragSelect,[TaskItem.name]: TaskItem},+ data () {+ const selectedList = cloneDeep(this.$store.state.task.selectedList) || []+ return {+ selectedList+ }+ },computed: {...mapState('task', {- taskList: state => state.taskList+ taskList: state => state.taskList,+ selectedGidList: state => state.selectedGidList})},methods: {+ handleDragSelectChange (selectedList) {+ this.selectedList = selectedList+ this.$store.dispatch('task/selectTasks', cloneDeep(selectedList))+ },+ getItemClass (item) {+ const isSelected = this.selectedList.includes(item.gid)+ return {+ selected: isSelected+ }+ }+ },+ watch: {+ selectedGidList (newVal) {+ this.selectedList = newVal+ }}}</script><style lang="scss">.task-list {- list-style: none;- padding: 0;+ padding: 16px 0 64px 0;+ min-height: 100%;+ box-sizing: border-box;}.no-task {display: flex;diff --git a/src/renderer/components/Theme/Default.scss b/src/renderer/components/Theme/Default.scssindex c0fa3686..3edf10c5 100644--- a/src/renderer/components/Theme/Default.scss+++ b/src/renderer/components/Theme/Default.scss@@ -40,6 +40,10 @@ img {max-height: 100%;}+iframe {+ border: 0;+}+.clearfix {@include clearfix();}@@ -237,7 +241,7 @@ img {}.panel-content {position: relative;- padding: 16px 36px 64px;+ padding: 0 36px 0;height: 100%;}}diff --git a/src/renderer/components/Theme/Light/Variables.scss b/src/renderer/components/Theme/Light/Variables.scssindex 8ce201a7..3771eac8 100644--- a/src/renderer/components/Theme/Light/Variables.scss+++ b/src/renderer/components/Theme/Light/Variables.scss@@ -40,6 +40,7 @@ $--form-actions-background: $--color-white !default;-------------------------- */$--task-action-color: #4d515a !default;$--task-action-hover-color: $--color-primary !default;+$--task-action-disabled-color: rgba(77, 81, 90, 0.5) !default;$--task-item-background: #fff !default;$--task-item-border-color: #ccc !default;$--task-item-hover-border-color: $--color-primary !default;diff --git a/src/renderer/store/modules/task.js b/src/renderer/store/modules/task.jsindex 90a36438..1914a30b 100644--- a/src/renderer/store/modules/task.js+++ b/src/renderer/store/modules/task.js@@ -1,11 +1,13 @@import api from '@/api'import { TASK_STATUS } from '@shared/constants'+import { intersection } from '@shared/utils'const state = {currentList: 'active',taskItemInfoVisible: false,currentTaskItem: null,- taskList: []+ taskList: [],+ selectedGidList: []}const getters = {@@ -15,6 +17,9 @@ const mutations = {UPDATE_TASK_LIST (state, taskList) {state.taskList = taskList},+ UPDATE_SELECTED_GID_LIST (state, gidList) {+ state.selectedGidList = gidList+ },CHANGE_CURRENT_LIST (state, currentList) {state.currentList = currentList},@@ -29,12 +34,18 @@ const mutations = {const actions = {changeCurrentList ({ commit, dispatch }, currentList) {commit('CHANGE_CURRENT_LIST', currentList)+ commit('UPDATE_SELECTED_GID_LIST', [])dispatch('fetchList')},- fetchList ({ state, commit }) {+ fetchList ({ commit, state }) {return api.fetchTaskList({ type: state.currentList }).then((data) => {commit('UPDATE_TASK_LIST', data)++ const { selectedGidList } = state+ const gids = data.map((task) => task.gid)+ const list = intersection(selectedGidList, gids)+ commit('UPDATE_SELECTED_GID_LIST', list)})},fetchItem ({ dispatch }, gid) {diff --git a/src/shared/utils/index.js b/src/shared/utils/index.jsindex 9d3f8e80..a23192fd 100644--- a/src/shared/utils/index.js+++ b/src/shared/utils/index.js@@ -606,3 +606,11 @@ export const getRandomInt = (min = 0, max = 10000) => {result += Math.floor(Math.random() * Math.floor(range))return result}++export const intersection = (array1 = [], array2 = []) => {+ if (array1.length === 0 || array2.length === 0) {+ return []+ }++ return array1.filter(value => array2.includes(value))+}