同步功能添加对列表顺序调整的控制

pull/733/head
lyswhut 2021-12-17 17:18:56 +08:00
parent 5b7c965c48
commit e3acb7ce4e
4 changed files with 56 additions and 16 deletions

View File

@ -11,6 +11,7 @@
- 优化列表性能,软件整体性能
- 调整Mac平台下的图标大小
- 同步功能添加对列表顺序调整的控制,确保手动调整位置后的列表与不同的电脑同步时,列表位置不会被还原
### 修复

View File

@ -156,14 +156,26 @@ const mergeList = (sourceListData, targetListData) => {
const userListDataObj = createUserListDataObj(sourceListData)
newListData.userList = [...sourceListData.userList]
for (const list of targetListData.userList) {
const targetList = userListDataObj[list.id]
if (targetList) {
targetList.list = handleMergeList(targetList, list, addMusicLocationType).list
targetListData.userList.forEach((list, index) => {
const targetUpdateTime = list?.locationUpdateTime ?? 0
const sourceList = userListDataObj[list.id]
if (sourceList) {
sourceList.list = handleMergeList(sourceList, list, addMusicLocationType).list
const sourceUpdateTime = sourceList?.locationUpdateTime ?? 0
if (targetUpdateTime >= sourceUpdateTime) return
// 调整位置
const [newList] = newListData.userList.splice(newListData.userList.findIndex(l => l.id == list.id), 1)
newList.locationUpdateTime = targetUpdateTime
newListData.userList.splice(index, 0, newList)
} else {
newListData.userList.push(list)
if (targetUpdateTime) {
newListData.userList.splice(index, 0, list)
} else {
newListData.userList.push(list)
}
}
}
})
return newListData
}
@ -175,11 +187,14 @@ const overwriteList = (sourceListData, targetListData) => {
const userListDataObj = createUserListDataObj(sourceListData)
newListData.userList = [...sourceListData.userList]
for (const list of targetListData.userList) {
const targetList = userListDataObj[list.id]
if (targetList) continue
newListData.userList.push(list)
}
targetListData.userList.forEach((list, index) => {
if (userListDataObj[list.id]) return
if (list?.locationUpdateTime) {
newListData.userList.splice(index, 0, list)
} else {
newListData.userList.push(list)
}
})
return newListData
}
@ -340,10 +355,26 @@ const handleMergeListDataFromSnapshot = async(socket, snapshot) => {
}
newUserList.push(newList)
}
for (const list of remoteListData.userList) {
if (removedListIds.has(list.id) || localUserListData[list.id]) continue
newUserList.push({ ...list })
}
remoteListData.userList.forEach((list, index) => {
if (removedListIds.has(list.id)) return
const remoteUpdateTime = list?.locationUpdateTime ?? 0
if (localUserListData[list.id]) {
const localUpdateTime = localUserListData[list.id]?.locationUpdateTime ?? 0
if (localUpdateTime >= remoteUpdateTime) return
// 调整位置
const [newList] = newUserList.splice(newUserList.findIndex(l => l.id == list.id), 1)
newList.locationUpdateTime = localUpdateTime
newUserList.splice(index, 0, newList)
} else {
if (remoteUpdateTime) {
newUserList.splice(index, 0, { ...list })
} else {
newUserList.push({ ...list })
}
}
})
newListData.userList = newUserList
setLocalList(newListData)
setRemotelList(socket, newListData)

View File

@ -51,7 +51,7 @@ export const tempList = reactive({
name: '临时列表',
})
export const userLists = reactive([])
export const userLists = window.userLists = reactive([])
export const addUserList = ({
name,
@ -60,6 +60,7 @@ export const addUserList = ({
source,
sourceListId,
position,
locationUpdateTime,
}) => {
if (position == null) {
userLists.push({
@ -67,6 +68,7 @@ export const addUserList = ({
id,
source,
sourceListId,
locationUpdateTime,
})
} else {
userLists.splice(position + 1, 0, {
@ -74,6 +76,7 @@ export const addUserList = ({
id,
source,
sourceListId,
locationUpdateTime,
})
}
allListUpdate(id, list)
@ -85,6 +88,7 @@ export const updateList = ({
list,
source,
sourceListId,
locationUpdateTime,
}) => {
let targetList
switch (id) {
@ -97,6 +101,7 @@ export const updateList = ({
targetList.name = name
targetList.source = source
targetList.sourceListId = sourceListId
if (locationUpdateTime) targetList.locationUpdateTime = locationUpdateTime
break
}
allListUpdate(id, list)

View File

@ -320,6 +320,7 @@ const mutations = {
position,
sourceListId,
}
if (position) newList.locationUpdateTime = Date.now()
addUserList(newList)
}
this.commit('list/listAddMultiple', { id, list, isSync: true })
@ -364,6 +365,7 @@ const mutations = {
let targetList = userLists[index]
userLists.splice(index, 1)
userLists.splice(index - 1, 0, targetList)
targetList.locationUpdateTime = Date.now()
window.eventHub.emit(eventListNames.listChange, [id])
},
movedownUserList(state, { id, isSync }) {
@ -378,6 +380,7 @@ const mutations = {
let targetList = userLists[index]
userLists.splice(index, 1)
userLists.splice(index + 1, 0, targetList)
targetList.locationUpdateTime = Date.now()
window.eventHub.emit(eventListNames.listChange, [id])
},
setMusicPosition(state, { id, position, list, isSync }) {