重构列表功能,使其支持多列表,新增我喜欢列表

This commit is contained in:
lyswhut
2019-10-03 02:00:31 +08:00
parent 70b718d372
commit 4204b62f8f
10 changed files with 137 additions and 88 deletions
+4 -4
View File
@@ -56,7 +56,7 @@ export default {
...mapMutations(['setLeaderboard']),
...mapActions('leaderboard', ['getList']),
...mapActions('download', ['createDownload', 'createDownloadMultiple']),
...mapMutations('list', ['defaultListAdd', 'defaultListAddMultiple']),
...mapMutations('list', ['listAdd', 'listAddMultiple']),
...mapMutations('player', ['setList']),
handleListBtnClick(info) {
switch (info.action) {
@@ -80,11 +80,11 @@ export default {
let targetSong
if (index == null) {
targetSong = this.selectdData[0]
this.defaultListAddMultiple(this.selectdData)
this.listAddMultiple({ id: 'default', list: this.selectdData })
this.resetSelect()
} else {
targetSong = this.list[index]
this.defaultListAdd(targetSong)
this.listAdd({ id: 'default', musicInfo: targetSong })
}
let targetIndex = this.defaultList.list.findIndex(
s => s.songmid === targetSong.songmid
@@ -134,7 +134,7 @@ export default {
this.testPlay()
break
case 'add':
this.defaultListAddMultiple(this.selectdData)
this.listAddMultiple({ id: 'default', list: this.selectdData })
this.resetSelect()
break
}
+46 -29
View File
@@ -50,6 +50,7 @@ export default {
name: 'List',
data() {
return {
listId: null,
clickTime: window.performance.now(),
clickIndex: -1,
isShowDownload: false,
@@ -65,12 +66,15 @@ export default {
},
computed: {
...mapGetters(['userInfo', 'setting']),
...mapGetters('list', ['defaultList', 'userList']),
...mapGetters('player', ['listId', 'playIndex']),
...mapGetters('list', ['defaultList', 'loveList', 'userList']),
...mapGetters('player', {
playerListId: 'listId',
playIndex: 'playIndex',
}),
isPlayList() {
return this.listId != 'download' && (
((!this.$route.query.id || this.$route.query.id == 'test') && this.listId == 'test') ||
this.$route.query.id == this.listId
return this.playerListId != 'download' && (
((!this.$route.query.id || this.$route.query.id == 'test') && this.playerListId == 'test') ||
this.$route.query.id == this.playerListId
)
},
list() {
@@ -81,6 +85,22 @@ export default {
isAPITemp() {
return this.setting.apiSource == 'temp'
},
listData() {
if (this.listId == null) return this.defaultList
let targetList
switch (this.listId) {
case 'default':
targetList = this.defaultList
break
case 'love':
targetList = this.loveList
break
default:
targetList = this.userList.find(l => l.id === this.listId)
break
}
return targetList
},
},
watch: {
selectdData(n) {
@@ -98,17 +118,11 @@ export default {
this.resetSelect()
},
},
// beforeRouteUpdate(to, from, next) {
// // if (to.query.id === undefined) return
// // if (to.query.text === '') {
// // this.clearList()
// // } else {
// // this.text = to.query.text
// // this.page = 1
// // this.handleSearch(this.text, this.page)
// // }
// next()
// },
beforeRouteUpdate(to, from, next) {
if (to.query.id === undefined) return
this.listId = to.query.id
next()
},
// mounted() {
// console.log('mounted')
// if (this.$route.query.text === undefined) {
@@ -137,22 +151,25 @@ export default {
}, 1000)
},
mounted() {
if (this.list.length > 150) {
setTimeout(() => {
this.delayShow = true
if (this.setting.list.scroll.enable && this.setting.list.scroll.location) {
this.$nextTick(() => this.$refs.dom_scrollContent.scrollTo(0, this.setting.list.scroll.location))
}
}, 200)
} else {
this.delayShow = true
}
this.handleDelayShow()
},
methods: {
...mapMutations(['setListScroll']),
...mapMutations('list', ['defaultListRemove', 'defaultListRemoveMultiple']),
...mapMutations('list', ['listRemove', 'listRemoveMultiple']),
...mapActions('download', ['createDownload', 'createDownloadMultiple']),
...mapMutations('player', ['setList']),
handleDelayShow() {
if (this.list.length > 150) {
setTimeout(() => {
this.delayShow = true
if (this.setting.list.scroll.enable && this.setting.list.scroll.location) {
this.$nextTick(() => this.$refs.dom_scrollContent.scrollTo(0, this.setting.list.scroll.location))
}
}, 200)
} else {
this.delayShow = true
}
},
handleDoubleClick(index) {
if (
window.performance.now() - this.clickTime > 400 ||
@@ -171,7 +188,7 @@ export default {
this.setList({ list: this.list, listId: 'test', index })
},
handleRemove(index) {
this.defaultListRemove(index)
this.listRemove({ id: 'default', index })
},
handleListBtnClick(info) {
switch (info.action) {
@@ -215,7 +232,7 @@ export default {
this.isShowDownloadMultiple = true
break
case 'remove':
this.defaultListRemoveMultiple(this.selectdData)
this.listRemoveMultiple({ id: 'default', list: this.selectdData })
this.resetSelect()
break
}
+4 -4
View File
@@ -128,7 +128,7 @@ export default {
...mapActions('search', ['search']),
...mapActions('download', ['createDownload', 'createDownloadMultiple']),
...mapMutations('search', ['clearList', 'setPage']),
...mapMutations('list', ['defaultListAdd', 'defaultListAddMultiple']),
...mapMutations('list', ['listAdd', 'listAddMultiple']),
...mapMutations('player', ['setList']),
handleSearch(text, page) {
if (text === '') return this.clearList()
@@ -172,11 +172,11 @@ export default {
let targetSong
if (index == null) {
targetSong = this.selectdData[0]
this.defaultListAddMultiple(this.filterList(this.selectdData))
this.listAddMultiple({ id: 'default', list: this.filterList(this.selectdData) })
} else {
if ((this.isAPITemp && this.listInfo.list[index].source != 'kw') || this.listInfo.list[index].source == 'tx' || this.listInfo.list[index].source == 'wy') return
targetSong = this.listInfo.list[index]
this.defaultListAdd(targetSong)
this.listAdd({ id: 'default', musicInfo: targetSong })
}
let targetIndex = this.defaultList.list.findIndex(
s => s.songmid === targetSong.songmid
@@ -218,7 +218,7 @@ export default {
this.resetSelect()
break
case 'add':
this.defaultListAddMultiple(this.filterList(this.selectdData))
this.listAddMultiple({ id: 'default', list: this.filterList(this.selectdData) })
this.resetSelect()
break
}
+3 -3
View File
@@ -286,7 +286,7 @@ export default {
},
methods: {
...mapMutations(['setSetting', 'setVersionModalVisible']),
...mapMutations('list', ['setDefaultList']),
...mapMutations('list', ['setList']),
init() {
this.current_setting = JSON.parse(JSON.stringify(this.setting))
},
@@ -332,7 +332,7 @@ export default {
return
}
if (defautlList.type !== 'defautlList') return
this.setDefaultList(defautlList.data.list)
this.setList({ id: 'default', list: defautlList.data.list })
},
exportPlayList(path) {
const data = {
@@ -353,7 +353,7 @@ export default {
if (allData.type !== 'allData') return
this.setSetting(updateSetting(allData.setting))
this.init()
this.setDefaultList(allData.defaultList.list)
this.setList({ id: 'default', list: allData.defaultList.list })
},
exportAllData(path) {
let allData = {
+4 -4
View File
@@ -121,7 +121,7 @@ export default {
...mapActions('songList', ['getTags', 'getList', 'getListDetail']),
...mapMutations('songList', ['setVisibleListDetail', 'setSelectListInfo', 'clearListDetail']),
...mapActions('download', ['createDownload', 'createDownloadMultiple']),
...mapMutations('list', ['defaultListAdd', 'defaultListAddMultiple']),
...mapMutations('list', ['listAdd', 'listAddMultiple']),
...mapMutations('player', ['setList']),
handleListBtnClick(info) {
switch (info.action) {
@@ -145,11 +145,11 @@ export default {
let targetSong
if (index == null) {
targetSong = this.selectdData[0]
this.defaultListAddMultiple(this.selectdData)
this.listAddMultiple({ id: 'default', list: this.selectdData })
this.resetSelect()
} else {
targetSong = this.listDetail.list[index]
this.defaultListAdd(targetSong)
this.listAdd({ id: 'default', musicInfo: targetSong })
}
let targetIndex = this.defaultList.list.findIndex(
s => s.songmid === targetSong.songmid
@@ -216,7 +216,7 @@ export default {
this.testPlay()
break
case 'add':
this.defaultListAddMultiple(this.selectdData)
this.listAddMultiple({ id: 'default', list: this.selectdData })
this.resetSelect()
break
}