移除列表选择框,新增键盘选择机制

This commit is contained in:
lyswhut
2020-04-26 22:06:13 +08:00
parent 3d52fa059e
commit cdbedf3d64
13 changed files with 608 additions and 129 deletions
+123 -19
View File
@@ -8,9 +8,7 @@ div(:class="$style.download")
table
thead
tr
th.nobreak.center(style="width: 37px;")
material-checkbox(id="search_select_all" v-model="isSelectAll" @change="handleSelectAllData"
:indeterminate="isIndeterminate" :title="isSelectAll && !isIndeterminate ? $t('view.download.unselect_all') : $t('view.download.select_all')")
th.nobreak.center(style="width: 10px;") #
th.nobreak(style="width: 28%;") {{$t('view.download.name')}}
th.nobreak(style="width: 22%;") {{$t('view.download.progress')}}
th.nobreak(style="width: 15%;") {{$t('view.download.status')}}
@@ -18,10 +16,9 @@ div(:class="$style.download")
th.nobreak(style="width: 20%;") {{$t('view.download.action')}}
div.scroll(v-if="list.length" :class="$style.tbody")
table
tbody
tbody(ref="dom_tbody")
tr(v-for='(item, index) in showList' :key='item.key' @click="handleDoubleClick($event, index)" :class="playListIndex === index ? $style.active : ''")
td.nobreak.center(style="width: 37px;" @click.stop)
material-checkbox(:id="index.toString()" v-model="selectdData" :value="item")
td.nobreak.center(style="width: 37px;" @click.stop) {{index + 1}}
td.break(style="width: 28%;")
span.select {{item.musicInfo.name}} - {{item.musicInfo.singer}}
td.break(style="width: 22%;") {{item.progress.progress}}%
@@ -48,8 +45,6 @@ export default {
clickTime: window.performance.now(),
clickIndex: -1,
selectdData: [],
isSelectAll: false,
isIndeterminate: false,
isShowEditBtn: false,
isShowDownloadMultiple: false,
tabs: [
@@ -75,6 +70,11 @@ export default {
},
],
tabId: 'all',
keyEvent: {
isShiftDown: false,
isAltDown: false,
isADown: false,
},
}
},
computed: {
@@ -110,22 +110,62 @@ export default {
selectdData(n) {
const len = n.length
if (len) {
this.isSelectAll = true
this.isIndeterminate = len !== this.showList.length
this.isShowEditBtn = true
} else {
this.isSelectAll = false
this.isShowEditBtn = false
}
},
list() {
this.resetSelect()
this.removeAllSelect()
},
},
created() {
this.listenEvent()
},
beforeDestroy() {
this.unlistenEvent()
},
methods: {
...mapActions('download', ['removeTask', 'removeTaskMultiple', 'startTask']),
...mapMutations('player', ['setList']),
...mapMutations('download', ['pauseTask', 'updateFilePath']),
listenEvent() {
window.eventHub.$on('shift_down', this.handle_shift_down)
window.eventHub.$on('shift_up', this.handle_shift_up)
window.eventHub.$on('alt_down', this.handle_alt_down)
window.eventHub.$on('alt_up', this.handle_alt_up)
window.eventHub.$on('mod+a_down', this.handle_mod_a_down)
window.eventHub.$on('mod+a_up', this.handle_mod_a_up)
},
unlistenEvent() {
window.eventHub.$off('shift_down', this.handle_shift_down)
window.eventHub.$off('shift_up', this.handle_shift_up)
window.eventHub.$off('alt_down', this.handle_alt_down)
window.eventHub.$off('alt_up', this.handle_alt_up)
window.eventHub.$off('mod+a_down', this.handle_mod_a_down)
window.eventHub.$off('mod+a_up', this.handle_mod_a_up)
},
handle_shift_down() {
if (!this.keyEvent.isShiftDown) this.keyEvent.isShiftDown = true
},
handle_shift_up() {
if (this.keyEvent.isShiftDown) this.keyEvent.isShiftDown = false
},
handle_alt_down() {
if (!this.keyEvent.isAltDown) this.keyEvent.isAltDown = true
},
handle_alt_up() {
if (this.keyEvent.isAltDown) this.keyEvent.isAltDown = false
},
handle_mod_a_down() {
if (!this.keyEvent.isADown) {
this.keyEvent.isADown = true
this.handleSelectAllData()
}
},
handle_mod_a_up() {
if (this.keyEvent.isADown) this.keyEvent.isADown = false
},
handlePauseTask(index) {
let info = this.list[index]
let dl = this.dls[info.key]
@@ -150,6 +190,8 @@ export default {
handleDoubleClick(event, index) {
if (event.target.classList.contains('select')) return
this.handleSelectData(event, index)
if (
window.performance.now() - this.clickTime > 400 ||
this.clickIndex !== index
@@ -162,6 +204,52 @@ export default {
this.clickTime = 0
this.clickIndex = -1
},
handleSelectData(event, clickIndex) {
if (this.keyEvent.isShiftDown) {
if (this.selectdData.length) {
let lastSelectIndex = this.showList.indexOf(this.selectdData[this.selectdData.length - 1])
this.removeAllSelect()
if (lastSelectIndex != clickIndex) {
let isNeedReverse = false
if (clickIndex < lastSelectIndex) {
let temp = lastSelectIndex
lastSelectIndex = clickIndex
clickIndex = temp
isNeedReverse = true
}
this.selectdData = this.showList.slice(lastSelectIndex, clickIndex + 1)
if (isNeedReverse) this.selectdData.reverse()
let nodes = this.$refs.dom_tbody.childNodes
do {
nodes[lastSelectIndex].classList.add('active')
lastSelectIndex++
} while (lastSelectIndex <= clickIndex)
}
} else {
event.currentTarget.classList.add('active')
this.selectdData.push(this.showList[clickIndex])
}
} else if (this.keyEvent.isAltDown) {
let item = this.showList[clickIndex]
let index = this.selectdData.indexOf(item)
if (index < 0) {
this.selectdData.push(item)
event.currentTarget.classList.add('active')
} else {
this.selectdData.splice(index, 1)
event.currentTarget.classList.remove('active')
}
} else if (this.selectdData.length) this.removeAllSelect()
},
removeAllSelect() {
this.selectdData = []
let dom_tbody = this.$refs.dom_tbody
if (!dom_tbody) return
let nodes = dom_tbody.querySelectorAll('.active')
for (const node of nodes) {
if (node.parentNode == dom_tbody) node.classList.remove('active')
}
},
handleClick(index) {
const key = this.showList[index].key
index = this.list.findIndex(i => i.key === key)
@@ -203,12 +291,14 @@ export default {
break
}
},
handleSelectAllData(isSelect) {
this.selectdData = isSelect ? [...this.showList] : []
},
resetSelect() {
this.isSelectAll = false
this.selectdData = []
handleSelectAllData() {
this.removeAllSelect()
this.selectdData = [...this.showList]
let nodes = this.$refs.dom_tbody.childNodes
for (const node of nodes) {
node.classList.add('active')
}
},
handleFlowBtnClick(action) {
switch (action) {
@@ -241,7 +331,7 @@ export default {
this.removeTaskMultiple(this.selectdData)
break
}
this.resetSelect()
this.removeAllSelect()
},
handleOpenFolder(index) {
let path = this.list[index].filePath
@@ -300,12 +390,21 @@ export default {
}
.thead {
flex: none;
tr > th:first-child {
color: @color-theme_2-font-label;
// padding-left: 10px;
}
}
.tbody {
flex: auto;
overflow-y: auto;
td {
font-size: 12px;
&:first-child {
// padding-left: 10px;
font-size: 11px;
color: @color-theme_2-font-label;
}
}
tr {
&.active {
@@ -322,6 +421,11 @@ each(@themes, {
color: ~'@{color-@{value}-theme}';
}
}
td {
&:first-child {
color: ~'@{color-@{value}-theme_2-font-label}';
}
}
}
}
})