From 1bcf0c92ac34f987a22ec6e57046576f652e3f9f Mon Sep 17 00:00:00 2001 From: LasyIsLazy <1255352506@qq.com> Date: Mon, 17 Aug 2020 15:32:31 +0800 Subject: [PATCH] =?UTF-8?q?=E5=85=A8=E9=83=A8=E6=92=AD=E6=94=BE=E5=8A=9F?= =?UTF-8?q?=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/modules/shortcut.js | 13 ++++++++++++ src/renderer/components/core/Player.vue | 3 +++ src/renderer/lang/en-us/view/list.json | 1 + src/renderer/lang/en-us/view/song_list.json | 1 + src/renderer/lang/zh-cn/view/list.json | 1 + src/renderer/lang/zh-cn/view/song_list.json | 1 + src/renderer/lang/zh-tw/view/list.json | 1 + src/renderer/lang/zh-tw/view/song_list.json | 1 + src/renderer/views/List.vue | 22 ++++++++++++++++++--- src/renderer/views/SongList.vue | 13 +++++++++++- 10 files changed, 53 insertions(+), 4 deletions(-) create mode 100644 src/main/modules/shortcut.js diff --git a/src/main/modules/shortcut.js b/src/main/modules/shortcut.js new file mode 100644 index 00000000..2d357c8b --- /dev/null +++ b/src/main/modules/shortcut.js @@ -0,0 +1,13 @@ +const { globalShortcut, app } = require('electron') +app.on('ready', function() { + globalShortcut.register('CommandOrControl+Alt+P', function() { + global.mainWindow.webContents.send('player:togglePlay') + }) + globalShortcut.register('CommandOrControl+Alt+Right', function() { + global.mainWindow.webContents.send('player:next') + }) +}) + +app.on('will-quit', function() { + globalShortcut.unregisterAll() +}) diff --git a/src/renderer/components/core/Player.vue b/src/renderer/components/core/Player.vue index 203e5f93..8d142ba3 100644 --- a/src/renderer/components/core/Player.vue +++ b/src/renderer/components/core/Player.vue @@ -515,6 +515,9 @@ export default { window.getComputedStyle(this.$refs.dom_progress, null).width, ) }, + /** + * 播放/暂停 + */ togglePlay() { if (!audio.src) return if (this.isPlay) { diff --git a/src/renderer/lang/en-us/view/list.json b/src/renderer/lang/en-us/view/list.json index 8a23de01..20af8200 100644 --- a/src/renderer/lang/en-us/view/list.json +++ b/src/renderer/lang/en-us/view/list.json @@ -1,6 +1,7 @@ { "lists_new_list_btn": "Create list", "lists_new_list_input": "New list...", + "lists_play": "Play", "lists_rename": "Rename", "lists_moveup": "Move Up", "lists_movedown": "Move Down", diff --git a/src/renderer/lang/en-us/view/song_list.json b/src/renderer/lang/en-us/view/song_list.json index e7993d13..5d5f98d1 100644 --- a/src/renderer/lang/en-us/view/song_list.json +++ b/src/renderer/lang/en-us/view/song_list.json @@ -1,4 +1,5 @@ { + "play_all": "Play All", "back": "Back", "loding_list": "Loading the list...", "loding_list_fail": "List loading failed", diff --git a/src/renderer/lang/zh-cn/view/list.json b/src/renderer/lang/zh-cn/view/list.json index e53c3460..24e5b2d2 100644 --- a/src/renderer/lang/zh-cn/view/list.json +++ b/src/renderer/lang/zh-cn/view/list.json @@ -1,6 +1,7 @@ { "lists_new_list_btn": "新建列表", "lists_new_list_input": "新列表...", + "lists_play": "播放", "lists_rename": "重命名", "lists_moveup": "上移", "lists_movedown": "下移", diff --git a/src/renderer/lang/zh-cn/view/song_list.json b/src/renderer/lang/zh-cn/view/song_list.json index aca6a947..b8fd1945 100644 --- a/src/renderer/lang/zh-cn/view/song_list.json +++ b/src/renderer/lang/zh-cn/view/song_list.json @@ -1,4 +1,5 @@ { + "play_all": "播放全部", "back": "返回", "loding_list": "列表加载中...", "loding_list_fail": "列表加载失败", diff --git a/src/renderer/lang/zh-tw/view/list.json b/src/renderer/lang/zh-tw/view/list.json index 52612a8c..0fe7761f 100644 --- a/src/renderer/lang/zh-tw/view/list.json +++ b/src/renderer/lang/zh-tw/view/list.json @@ -1,6 +1,7 @@ { "lists_new_list_btn": "新建列表", "lists_new_list_input": "新列表...", + "lists_play": "播放", "lists_rename": "重命名", "lists_moveup": "上移", "lists_movedown": "下移", diff --git a/src/renderer/lang/zh-tw/view/song_list.json b/src/renderer/lang/zh-tw/view/song_list.json index d47eb2d0..5d8f101a 100644 --- a/src/renderer/lang/zh-tw/view/song_list.json +++ b/src/renderer/lang/zh-tw/view/song_list.json @@ -1,4 +1,5 @@ { + "play_all": "播放全部", "back": "返回", "loding_list": "列表加载中...", "loding_list_fail": "列表加載失敗", diff --git a/src/renderer/views/List.vue b/src/renderer/views/List.vue index 4a42968e..11ff62c9 100644 --- a/src/renderer/views/List.vue +++ b/src/renderer/views/List.vue @@ -7,9 +7,9 @@ svg(version='1.1' xmlns='http://www.w3.org/2000/svg' xlink='http://www.w3.org/1999/xlink' height='70%' viewBox='0 0 24 24' space='preserve') use(xlink:href='#icon-list-add') ul.scroll(:class="$style.listsContent" ref="dom_lists_list") - li(:class="[$style.listsItem, defaultList.id == listId ? $style.active : null]" :title="defaultList.name" @click="handleListToggle(defaultList.id)") + li(:class="[$style.listsItem, defaultList.id == listId ? $style.active : null]" :title="defaultList.name" @click="handleListToggle(defaultList.id)" @contextmenu="handleListsItemRigthClick($event, -2)") span(:class="$style.listsLabel") {{defaultList.name}} - li(:class="[$style.listsItem, loveList.id == listId ? $style.active : null]" :title="loveList.name" @click="handleListToggle(loveList.id)") + li(:class="[$style.listsItem, loveList.id == listId ? $style.active : null]" :title="loveList.name" @click="handleListToggle(loveList.id)" @contextmenu="handleListsItemRigthClick($event, -1)") span(:class="$style.listsLabel") {{loveList.name}} li.user-list(:class="[$style.listsItem, item.id == listId ? $style.active : null, listsData.rightClickItemIndex == index ? $style.clicked : null]" @contextmenu="handleListsItemRigthClick($event, index)" :title="item.name" v-for="(item, index) in userList" :key="item.id") span(:class="$style.listsLabel" @click="handleListToggle(item.id, index + 2)") {{item.name}} @@ -100,6 +100,7 @@ export default { listsData: { isShowItemMenu: false, itemMenuControl: { + play: true, rename: true, moveup: true, movedown: true, @@ -176,6 +177,11 @@ export default { }, listsItemMenu() { return [ + { + name: this.$t('view.list.lists_play'), + action: 'play', + disabled: !this.listsData.itemMenuControl.play, + }, { name: this.$t('view.list.lists_rename'), action: 'rename', @@ -661,6 +667,7 @@ export default { let location = offsetTop - 150 if (location > 0) this.$refs.dom_lists_list.scrollTop = location }, + /** 切换歌单为激活状态 */ handleListToggle(id) { if (id == this.listId) return this.$router.push({ @@ -669,8 +676,10 @@ export default { }).catch(_ => _) }, handleListsItemRigthClick(event, index) { + // console.log('handleListsItemRigthClick', index) this.listsData.itemMenuControl.moveup = index > 0 - this.listsData.itemMenuControl.movedown = index < this.userList.length - 1 + this.listsData.itemMenuControl.movedown = index >= 0 && index < this.userList.length - 1 + this.listsData.itemMenuControl.remove = this.listsData.itemMenuControl.rename = index > 0 this.listsData.rightClickItemIndex = index this.listsData.menuLocation.x = event.currentTarget.offsetLeft + event.offsetX this.listsData.menuLocation.y = event.currentTarget.offsetTop + event.offsetY - this.$refs.dom_lists_list.scrollTop @@ -708,6 +717,13 @@ export default { this.listsData.isShowItemMenu = false let dom switch (action && action.action) { + case 'play': + this.handleListToggle(this.lists[index + 2].id) + // console.log('play--', index, this.lists[index + 2]) + this.$nextTick(() => { + this.testPlay(0) + }) + break case 'rename': dom = this.$refs.dom_lists_list.querySelectorAll('.user-list')[index] this.$nextTick(() => { diff --git a/src/renderer/views/SongList.vue b/src/renderer/views/SongList.vue index 6d5ff906..fd2510ce 100644 --- a/src/renderer/views/SongList.vue +++ b/src/renderer/views/SongList.vue @@ -14,6 +14,7 @@ //- |   //- material-btn(:class="$style.closeDetailButton" :disabled="detailLoading" @click="playSongListDetail") 播放 //- |   + material-btn(:class="$style.closeDetailButton" @click="playAll") {{$t('view.song_list.play_all')}} material-btn(:class="$style.closeDetailButton" @click="hideListDetail") {{$t('view.song_list.back')}} material-song-list(v-model="selectedData" @action="handleSongListAction" :source="source" :page="listDetail.page" :limit="listDetail.limit" :total="listDetail.total" :noItem="isGetDetailFailed ? $t('view.song_list.loding_list_fail') : $t('view.song_list.loding_list')" :list="listDetail.list") @@ -359,6 +360,14 @@ export default { this.setTagListWidth() }, 50) }, + playAll() { + if (this.listDetail.list.length) { + const filterList = this.filterList(this.listDetail.list) + this.listAddMultiple({ id: 'default', list: filterList }) + this.resetSelect() + this.testPlay(0) + } + }, handleListAddModalClose(isSelect) { if (isSelect) this.resetSelect() this.isShowListAddMultiple = false @@ -515,7 +524,9 @@ export default { flex: none; display: flex; align-items: center; - padding-right: 15px; + > * { + margin-right: 15px; + } } .song-list-detail-content {