From fcfba8b12c70795e56012e6a6574b9a5cfa0fa04 Mon Sep 17 00:00:00 2001 From: lyswhut Date: Sat, 4 Jun 2022 12:48:26 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E6=B7=BB=E5=8A=A0=E6=AD=8C?= =?UTF-8?q?=E6=9B=B2=E5=88=B0=E2=80=9C=E6=88=91=E7=9A=84=E5=88=97=E8=A1=A8?= =?UTF-8?q?=E2=80=9D=E6=97=B6=EF=BC=8C=E8=8B=A5=E6=8C=89=E4=BD=8F`ctrl`?= =?UTF-8?q?=E9=94=AE=EF=BC=8C=E5=88=99=E4=B8=8D=E4=BC=9A=E8=87=AA=E5=8A=A8?= =?UTF-8?q?=E5=85=B3=E9=97=AD=E6=B7=BB=E5=8A=A0=E7=AA=97=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- publish/changeLog.md | 4 ++ .../components/common/ListAddModal.vue | 6 +++ .../common/ListAddMultipleModal.vue | 6 +++ src/renderer/utils/compositions/useKeyDown.js | 38 +++++++++++++++++++ .../views/list/components/MusicList/index.vue | 2 +- 5 files changed, 55 insertions(+), 1 deletion(-) create mode 100644 src/renderer/utils/compositions/useKeyDown.js diff --git a/publish/changeLog.md b/publish/changeLog.md index 6d1c85f0..a1369f92 100644 --- a/publish/changeLog.md +++ b/publish/changeLog.md @@ -2,6 +2,10 @@ - 新增设置-以全屏模式启动设置 +### 优化 + +- 添加歌曲到“我的列表”时,若按住`ctrl`键(Mac对应`Command`),则不会自动关闭添加窗口,这对想要将同一首(一批)歌曲添加到多个列表时会很有用 + ### 修复 - 修复若配置了`http_proxy`环境变量时,会意外使用此代理配置的问题 diff --git a/src/renderer/components/common/ListAddModal.vue b/src/renderer/components/common/ListAddModal.vue index 42f2007b..a9537a71 100644 --- a/src/renderer/components/common/ListAddModal.vue +++ b/src/renderer/components/common/ListAddModal.vue @@ -21,6 +21,7 @@ import { mapMutations } from 'vuex' import { computed } from '@renderer/utils/vueTools' import { defaultList, loveList, userLists } from '@renderer/core/share/list' import { getList } from '@renderer/core/share/utils' +import useKeyDown from '@renderer/utils/compositions/useKeyDown' export default { props: { @@ -57,6 +58,8 @@ export default { }, emits: ['update:show'], setup(props) { + const keyModDown = useKeyDown('mod') + const lists = computed(() => { if (!props.musicInfo) return [] const targetMid = props.musicInfo.songmid @@ -67,6 +70,7 @@ export default { ].filter(l => !props.excludeListId.includes(l.id)).map(l => ({ ...l, isExist: getList(l.id).some(s => s.songmid == targetMid) })) }) return { + keyModDown, lists, } }, @@ -103,6 +107,8 @@ export default { this.isMove ? this.listMove({ fromId: this.fromListId, toId: this.lists[index].id, musicInfo: this.musicInfo }) : this.listAdd({ id: this.lists[index].id, musicInfo: this.musicInfo }) + + if (this.keyModDown && !this.isMove) return this.$nextTick(() => { this.handleClose() }) diff --git a/src/renderer/components/common/ListAddMultipleModal.vue b/src/renderer/components/common/ListAddMultipleModal.vue index 8cc11cfe..9232ba7b 100644 --- a/src/renderer/components/common/ListAddMultipleModal.vue +++ b/src/renderer/components/common/ListAddMultipleModal.vue @@ -20,6 +20,7 @@ import { mapMutations } from 'vuex' import { computed } from '@renderer/utils/vueTools' import { defaultList, loveList, userLists } from '@renderer/core/share/list' +import useKeyDown from '@renderer/utils/compositions/useKeyDown' export default { props: { @@ -59,6 +60,8 @@ export default { }, emits: ['update:show', 'confirm'], setup(props) { + const keyModDown = useKeyDown('mod') + const lists = computed(() => { return [ defaultList, @@ -67,6 +70,7 @@ export default { ].filter(l => !props.excludeListId.includes(l.id)) }) return { + keyModDown, lists, } }, @@ -104,6 +108,8 @@ export default { this.isMove ? this.listMoveMultiple({ fromId: this.fromListId, toId: this.lists[index].id, list: this.musicList }) : this.listAddMultiple({ id: this.lists[index].id, list: this.musicList }) + + if (this.keyModDown && !this.isMove) return this.$nextTick(() => { this.handleClose() this.$emit('confirm') diff --git a/src/renderer/utils/compositions/useKeyDown.js b/src/renderer/utils/compositions/useKeyDown.js new file mode 100644 index 00000000..c536799d --- /dev/null +++ b/src/renderer/utils/compositions/useKeyDown.js @@ -0,0 +1,38 @@ +import { onMounted, onBeforeUnmount, ref } from '@renderer/utils/vueTools' + +export default name => { + const keyDown = ref(false) + const down = `key_${name}_down` + const up = `key_${name}_up` + + const handle_key_down = event => { + if (!keyDown.value) { + // console.log(event) + switch (event.event.target.tagName) { + case 'INPUT': + case 'SELECT': + case 'TEXTAREA': + return + default: if (event.event.target.isContentEditable) return + } + + keyDown.value = true + } + } + + const handle_key_up = () => { + if (keyDown.value) keyDown.value = false + } + + onMounted(() => { + window.eventHub.on(down, handle_key_down) + window.eventHub.on(up, handle_key_up) + }) + + onBeforeUnmount(() => { + window.eventHub.off(down, handle_key_down) + window.eventHub.off(up, handle_key_up) + }) + + return keyDown +} diff --git a/src/renderer/views/list/components/MusicList/index.vue b/src/renderer/views/list/components/MusicList/index.vue index 175c14fc..38a58ecd 100644 --- a/src/renderer/views/list/components/MusicList/index.vue +++ b/src/renderer/views/list/components/MusicList/index.vue @@ -90,7 +90,7 @@ export default { listItemHeight, handleSelectData, removeAllSelect, - } = useList({ list, setting, emit }) + } = useList({ list, setting }) const { handlePlayMusic,