优化右击菜单逻辑

pull/277/head
lyswhut 2020-06-27 13:43:27 +08:00
parent fbd2a57a35
commit c9d0aafbfa
6 changed files with 12 additions and 15 deletions

View File

@ -37,7 +37,7 @@ export default {
},
location: {
handler(n) {
this.listStyles.left = n.x + 'px'
this.listStyles.left = n.x + 2 + 'px'
this.listStyles.top = n.y + 'px'
if (this.show) {
if (this.listStyles.transitionProperty != this.transition2) this.listStyles.transitionProperty = this.transition2
@ -89,10 +89,10 @@ export default {
const offsetHeight = containerHeight - top - listHeight
let x = 0
let y = 0
if (containerWidth > listWidth && offsetWidth < 0) {
x = offsetWidth - 15
if (containerWidth > listWidth && offsetWidth < 17) {
x = offsetWidth - 17
}
if (containerHeight > listHeight && offsetHeight < 0) {
if (containerHeight > listHeight && offsetHeight < 5) {
y = offsetHeight - 5
}
return `${x}px, ${y}px`

View File

@ -48,7 +48,7 @@ div(:class="$style.songList")
<script>
import { mapGetters } from 'vuex'
import { scrollTo, clipboardWriteText, assertApiSupport, findParentNode } from '../../utils'
import { scrollTo, clipboardWriteText, assertApiSupport } from '../../utils'
import musicSdk from '../../utils/music'
export default {
name: 'MaterialSongList',
@ -340,7 +340,7 @@ export default {
let dom_selected = this.$refs.dom_tbody.querySelector('tr.selected')
if (dom_selected) dom_selected.classList.remove('selected')
this.$refs.dom_tbody.querySelectorAll('tr')[index].classList.add('selected')
let dom_td = findParentNode(event.target, 'TD')
let dom_td = event.target.closest('td')
this.listMenu.rightClickItemIndex = index
this.listMenu.menuLocation.x = dom_td.offsetLeft + event.offsetX
this.listMenu.menuLocation.y = dom_td.offsetParent.offsetTop + dom_td.offsetTop + event.offsetY - this.$refs.dom_scrollContent.scrollTop

View File

@ -321,9 +321,6 @@ export const asyncSetArray = (from, to, num = 100) => new Promise(resolve => {
})
})
export const findParentNode = (target, tagName) => target.tagName == tagName ? target : target === document ? null : findParentNode(target.parentNode, tagName)
/**
* 获取缓存大小
*/

View File

@ -36,7 +36,7 @@ div(:class="$style.download")
<script>
import { mapGetters, mapActions, mapMutations } from 'vuex'
import { checkPath, openDirInExplorer, findParentNode, openUrl } from '../utils'
import { checkPath, openDirInExplorer, openUrl } from '../utils'
import musicSdk from '../utils/music'
import path from 'path'
@ -370,7 +370,7 @@ export default {
let dom_selected = this.$refs.dom_tbody.querySelector('tr.selected')
if (dom_selected) dom_selected.classList.remove('selected')
this.$refs.dom_tbody.querySelectorAll('tr')[index].classList.add('selected')
let dom_td = findParentNode(event.target, 'TD')
let dom_td = event.target.closest('td')
this.listMenu.rightClickItemIndex = index
this.listMenu.menuLocation.x = dom_td.offsetLeft + event.offsetX
this.listMenu.menuLocation.y = dom_td.offsetTop + event.offsetY - this.$refs.dom_scrollContent.scrollTop

View File

@ -70,7 +70,7 @@
<script>
import { mapMutations, mapGetters, mapActions } from 'vuex'
import { throttle, scrollTo, clipboardWriteText, assertApiSupport, findParentNode, openUrl } from '../utils'
import { throttle, scrollTo, clipboardWriteText, assertApiSupport, openUrl } from '../utils'
import musicSdk from '../utils/music'
export default {
name: 'List',
@ -687,7 +687,7 @@ export default {
let dom_selected = this.$refs.dom_tbody.querySelector('tr.selected')
if (dom_selected) dom_selected.classList.remove('selected')
this.$refs.dom_tbody.querySelectorAll('tr')[index].classList.add('selected')
let dom_td = findParentNode(event.target, 'TD')
let dom_td = event.target.closest('td')
this.listMenu.rightClickItemIndex = index
this.listMenu.menuLocation.x = dom_td.offsetLeft + event.offsetX

View File

@ -61,7 +61,7 @@
<script>
import { mapGetters, mapActions, mapMutations } from 'vuex'
import { scrollTo, clipboardWriteText, assertApiSupport, findParentNode, openUrl } from '../utils'
import { scrollTo, clipboardWriteText, assertApiSupport, openUrl } from '../utils'
import musicSdk from '../utils/music'
export default {
name: 'Search',
@ -427,7 +427,7 @@ export default {
let dom_selected = this.$refs.dom_tbody.querySelector('tr.selected')
if (dom_selected) dom_selected.classList.remove('selected')
this.$refs.dom_tbody.querySelectorAll('tr')[index].classList.add('selected')
let dom_td = findParentNode(event.target, 'TD')
let dom_td = event.target.closest('td')
this.listMenu.rightClickItemIndex = index
this.listMenu.menuLocation.x = dom_td.offsetLeft + event.offsetX
this.listMenu.menuLocation.y = dom_td.offsetTop + event.offsetY - this.$refs.dom_scrollContent.scrollTop