A full-featured download manager.
refactor: select torrent file list
Dr_rOot28bbf26334fd
diff --git a/src/renderer/components/Task/FileList.vue b/src/renderer/components/Task/FileList.vuenew file mode 100644index 00000000..1b9cc2e1--- /dev/null+++ b/src/renderer/components/Task/FileList.vue@@ -0,0 +1,206 @@+<template>+ <div class="file-list">+ <div class="file-table-wrapper">+ <el-table+ stripe+ ref="torrentTable"+ :height="height"+ :data="files"+ tooltip-effect="dark"+ style="width: 100%"+ @row-dblclick="handleRowDbClick"+ @selection-change="handleSelectionChange">+ <el-table-column+ type="selection"+ width="42">+ </el-table-column>+ <el-table-column+ :label="$t('task.file-name')"+ show-overflow-tooltip>+ <template slot-scope="scope">{{ scope.row.name }}</template>+ </el-table-column>+ <el-table-column+ :label="$t('task.file-extension')"+ width="80">+ <template slot-scope="scope">{{ scope.row.extension | removeExtensionDot }}</template>+ </el-table-column>+ <el-table-column+ :label="$t('task.file-size')"+ width="90">+ <template slot-scope="scope">{{ scope.row.length | bytesToSize }}</template>+ </el-table-column>+ <el-table-column+ v-if="mode === 'detail'"+ :label="$t('task.file-completed-size')"+ width="90">+ <template slot-scope="scope">{{ scope.row.completedLength | bytesToSize }}</template>+ </el-table-column>+ </el-table>+ </div>+ <el-row :gutter="12" v-if="mode === 'add'">+ <el-col class="file-filters" :span="8">+ <el-button-group>+ <el-button @click="toggleVideoSelection()">+ <mo-icon name="video" width="12" height="12" />+ </el-button>+ <el-button @click="toggleAudioSelection()">+ <mo-icon name="audio" width="12" height="12" />+ </el-button>+ <el-button @click="toggleImageSelection()">+ <mo-icon name="image" width="12" height="12" />+ </el-button>+ </el-button-group>+ </el-col>+ <el-col :span="16" style="text-align: right">+ {{ $t('task.selected-files-sum', { selectedFilesCount, selectedFilesTotalSize }) }}+ </el-col>+ </el-row>+ </div>+</template>++<script>+ import { isEmpty } from 'lodash'+ import '@/components/Icons/video'+ import '@/components/Icons/audio'+ import '@/components/Icons/image'+ import {+ NONE_SELECTED_FILES,+ SELECTED_ALL_FILES+ } from '@shared/constants'+ import {+ bytesToSize,+ filterVideoFiles,+ filterAudioFiles,+ filterImageFiles,+ removeExtensionDot+ } from '@shared/utils'++ export default {+ name: 'mo-file-list',+ components: {+ },+ filters: {+ bytesToSize,+ removeExtensionDot+ },+ props: {+ mode: {+ type: String,+ default: 'add',+ validator: function (value) {+ return ['add', 'detail'].indexOf(value) !== -1+ }+ },+ height: {+ type: [Number, String],+ default: function () {+ return 200+ }+ },+ files: {+ type: Array,+ default: function () {+ return []+ }+ }+ },+ data () {+ return {+ selectedFiles: []+ }+ },+ computed: {+ selectedFilesCount () {+ return this.selectedFiles.length+ },+ selectedFilesTotalSize () {+ const result = this.selectedFiles.reduce((acc, cur) => {+ return acc + cur.length+ }, 0)+ return bytesToSize(result)+ },+ selectedFileIndex () {+ const { files, selectedFiles } = this+ if (files.length === 0 || selectedFiles.length === 0) {+ return NONE_SELECTED_FILES+ }+ if (files.length === selectedFiles.length) {+ return SELECTED_ALL_FILES+ }+ const indexArr = this.selectedFiles.map((item) => item.idx)+ const result = indexArr.join(',')+ return result+ }+ },+ watch: {+ selectedFiles (val) {+ console.log('this.files', this.files)+ console.log('selectedFiles===>', val)+ },+ selectedFileIndex () {+ const { selectedFileIndex } = this+ this.$emit('selection-change', selectedFileIndex)+ }+ },+ methods: {+ toggleAllSelection () {+ if (!this.$refs.torrentTable) {+ return+ }+ this.$refs.torrentTable.toggleAllSelection()+ },+ clearSelection () {+ if (!this.$refs.torrentTable) {+ return+ }+ this.$refs.torrentTable.clearSelection()+ },+ toggleSelection (rows) {+ if (isEmpty(rows)) {+ this.$refs.torrentTable.clearSelection()+ } else {+ this.$refs.torrentTable.clearSelection()+ rows.forEach(row => {+ this.$refs.torrentTable.toggleRowSelection(row, true)+ })+ }+ },+ toggleVideoSelection () {+ const filtered = filterVideoFiles(this.files)+ this.toggleSelection(filtered)+ },+ toggleAudioSelection () {+ const filtered = filterAudioFiles(this.files)+ this.toggleSelection(filtered)+ },+ toggleImageSelection () {+ const filtered = filterImageFiles(this.files)+ this.toggleSelection(filtered)+ },+ handleRowDbClick (row, column, event) {+ this.$refs.torrentTable.toggleRowSelection(row)+ },+ handleSelectionChange (val) {+ this.selectedFiles = val+ }+ }+ }+</script>++<style lang="scss">+.file-filters {+ button {+ font-size: 0;+ }+}+.file-table-wrapper {+ border: 1px solid #ebeef5;+ border-bottom: none;+ overflow-x: hidden;+ overflow-y: auto;+ margin-bottom: 8px;+ .el-table th {+ padding: 2px 0;+ }+}+</style>diff --git a/src/renderer/components/Task/SelectTorrent.vue b/src/renderer/components/Task/SelectTorrent.vueindex c10e2d8e..1bf56c14 100644--- a/src/renderer/components/Task/SelectTorrent.vue+++ b/src/renderer/components/Task/SelectTorrent.vue@@ -28,74 +28,27 @@</el-tooltip></el-col><el-col class="torrent-actions" :span="4">- <span- @click="handleTrashClick"- >+ <span @click="handleTrashClick"><mo-icon name="trash" width="14" height="14" /></span></el-col></el-row>- <div class="torrent-file-list">- <el-table- stripe- ref="torrentTable"- height="200"- :data="files"- tooltip-effect="dark"- style="width: 100%"- @row-dblclick="handleRowDbClick"- @selection-change="handleSelectionChange">- <el-table-column- type="selection"- width="42">- </el-table-column>- <el-table-column- :label="$t('task.file-name')"- show-overflow-tooltip>- <template slot-scope="scope">{{ scope.row.name }}</template>- </el-table-column>- <el-table-column- :label="$t('task.file-extension')"- width="80">- <template slot-scope="scope">{{ scope.row.extension | removeExtensionDot }}</template>- </el-table-column>- <el-table-column- :label="$t('task.file-size')"- width="90">- <template slot-scope="scope">{{ scope.row.length | bytesToSize }}</template>- </el-table-column>- </el-table>- </div>- <el-row :gutter="12">- <el-col class="file-filters" :span="8">- <el-button-group>- <el-button @click="toggleVideoSelection()">- <mo-icon name="video" width="12" height="12" />- </el-button>- <el-button @click="toggleAudioSelection()">- <mo-icon name="audio" width="12" height="12" />- </el-button>- <el-button @click="toggleImageSelection()">- <mo-icon name="image" width="12" height="12" />- </el-button>- </el-button-group>- </el-col>- <el-col :span="16" style="text-align: right">- {{ $t('task.selected-files-sum', { selectedFilesCount, selectedFilesTotalSize }) }}- </el-col>- </el-row>+ <mo-file-list+ ref="torrentFileList"+ mode="add"+ :files="files"+ @selection-change="handleSelectionChange"+ /></div></template><script>import { mapState } from 'vuex'- import { isEmpty } from 'lodash'import parseTorrent from 'parse-torrent'+ import FileList from '@/components/Task/FileList'import '@/components/Icons/inbox'- import '@/components/Icons/video'- import '@/components/Icons/audio'- import '@/components/Icons/image'import {+ EMPTY_STRING,NONE_SELECTED_FILES,SELECTED_ALL_FILES} from '@shared/constants'@@ -103,9 +56,6 @@buildFileList,listTorrentFiles,bytesToSize,- filterVideoFiles,- filterAudioFiles,- filterImageFiles,getAsBase64,removeExtensionDot} from '@shared/utils'@@ -113,6 +63,7 @@export default {name: 'mo-select-torrent',components: {+ [FileList.name]: FileList},filters: {bytesToSize,@@ -122,8 +73,8 @@},data () {return {- name: '',- currentTorrent: '',+ name: EMPTY_STRING,+ currentTorrent: EMPTY_STRING,files: [],selectedFiles: []}@@ -137,27 +88,6 @@}),isTorrentsEmpty () {return this.torrents.length === 0- },- selectedFilesCount () {- return this.selectedFiles.length- },- selectedFilesTotalSize () {- const result = this.selectedFiles.reduce((acc, cur) => {- return acc + cur.length- }, 0)- return bytesToSize(result)- },- selectedFileIndex () {- const { files, selectedFiles } = this- if (files.length === 0 || selectedFiles.length === 0) {- return NONE_SELECTED_FILES- }- if (files.length === selectedFiles.length) {- return SELECTED_ALL_FILES- }- const indexArr = this.selectedFiles.map((item) => item.idx)- const result = indexArr.join(',')- return result}},watch: {@@ -176,7 +106,7 @@if (err) throw errconsole.log('[Motrix] parsed torrent: ', parsedTorrent)this.files = listTorrentFiles(parsedTorrent.files)- this.$refs.torrentTable.toggleAllSelection()+ this.$refs.torrentFileList.toggleAllSelection()getAsBase64(file.raw, (torrent) => {this.name = file.name@@ -184,21 +114,17 @@this.$emit('change', torrent, SELECTED_ALL_FILES)})})- },- selectedFileIndex () {- const { currentTorrent, selectedFileIndex } = this- this.$emit('change', currentTorrent, selectedFileIndex)}},methods: {reset () {- this.name = ''- this.currentTorrent = ''+ this.name = EMPTY_STRING+ this.currentTorrent = EMPTY_STRINGthis.files = []- if (this.$refs.torrentTable) {- this.$refs.torrentTable.clearSelection()+ if (this.$refs.torrentFileList) {+ this.$refs.torrentFileList.clearSelection()}- this.$emit('change', '', NONE_SELECTED_FILES)+ this.$emit('change', EMPTY_STRING, NONE_SELECTED_FILES)},handleChange (file, fileList) {this.$store.dispatch('app/addTaskAddTorrents', { fileList })@@ -210,96 +136,58 @@handleTrashClick () {this.$store.dispatch('app/addTaskAddTorrents', { fileList: [] })},- toggleSelection (rows) {- if (isEmpty(rows)) {- this.$refs.torrentTable.clearSelection()- } else {- this.$refs.torrentTable.clearSelection()- rows.forEach(row => {- this.$refs.torrentTable.toggleRowSelection(row)- })- }- },- toggleVideoSelection () {- const filtered = filterVideoFiles(this.files)- this.toggleSelection(filtered)- },- toggleAudioSelection () {- const filtered = filterAudioFiles(this.files)- this.toggleSelection(filtered)- },- toggleImageSelection () {- const filtered = filterImageFiles(this.files)- this.toggleSelection(filtered)- },- handleRowDbClick (row, column, event) {- this.$refs.torrentTable.toggleRowSelection(row)- },handleSelectionChange (val) {- this.selectedFiles = val+ console.log('handleSelectionChange===>', val)+ const { currentTorrent } = this+ this.$emit('change', currentTorrent, val)}}}</script><style lang="scss">- .upload-torrent {+.upload-torrent {+ width: 100%;+ .el-upload, .el-upload-dragger {width: 100%;- .el-upload, .el-upload-dragger {- width: 100%;- }- .el-upload-dragger {- border-radius: 4px;- padding: 24px;- height: auto;- }- .upload-inbox-icon {- display: inline-block;- margin-bottom: 12px;- }- .torrent-name {- margin-top: 4px;- font-size: $--font-size-small;- color: $--color-text-secondary;- line-height: 16px;- }}- .selective-torrent {- .torrent-name {- overflow: hidden;- white-space: nowrap;- text-overflow: ellipsis;- }- .torrent-info {- margin-bottom: 15px;- font-size: 12px;- line-height: 16px;- }- .torrent-actions {- text-align: right;- line-height: 16px;- &> span {- cursor: pointer;- display: inline-block;- vertical-align: middle;- height: 14px;- padding: 1px;- }- }+ .el-upload-dragger {+ border-radius: 4px;+ padding: 24px;+ height: auto;}- .file-filters {- button {- font-size: 0;- }+ .upload-inbox-icon {+ display: inline-block;+ margin-bottom: 12px;+ }+ .torrent-name {+ margin-top: 4px;+ font-size: $--font-size-small;+ color: $--color-text-secondary;+ line-height: 16px;}- .torrent-file-list {- border: 1px solid #ebeef5;- border-bottom: none;- overflow-x: hidden;- overflow-y: scroll;- margin-bottom: 8px;- .el-table th {- padding: 2px 0;+}+.selective-torrent {+ .torrent-name {+ overflow: hidden;+ white-space: nowrap;+ text-overflow: ellipsis;+ }+ .torrent-info {+ margin-bottom: 15px;+ font-size: 12px;+ line-height: 16px;+ }+ .torrent-actions {+ text-align: right;+ line-height: 16px;+ &> span {+ cursor: pointer;+ display: inline-block;+ vertical-align: middle;+ height: 14px;+ padding: 1px;}}+}</style>