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

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平台下的图标大小 - 调整Mac平台下的图标大小
- 同步功能添加对列表顺序调整的控制,确保手动调整位置后的列表与不同的电脑同步时,列表位置不会被还原
### 修复 ### 修复

View File

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

View File

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

View File

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