feat(userManagement): 同步支持删除标记,完成后统一刷新列表
- 列表含 delFlag=1 时清空设备后下发未删除用户并全量上报 - 长按标题清空重下发、不上报 - 同步完成统一重新拉取用户列表,前端不本地维护同步状态 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.7
parent
548c26cad5
commit
f771bb97d6
@@ -19,6 +19,7 @@ interface SysUserDevice {
|
|||||||
dataType: number
|
dataType: number
|
||||||
relationType: number | null
|
relationType: number | null
|
||||||
syncStatus?: number
|
syncStatus?: number
|
||||||
|
delFlag?: number
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 同步用的用户项 */
|
/** 同步用的用户项 */
|
||||||
@@ -30,6 +31,7 @@ interface SyncUser {
|
|||||||
age: number
|
age: number
|
||||||
height: number
|
height: number
|
||||||
sync: string
|
sync: string
|
||||||
|
delFlag?: number
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 展示用成员项 */
|
/** 展示用成员项 */
|
||||||
@@ -44,6 +46,7 @@ interface MemberItem {
|
|||||||
syncClass: string
|
syncClass: string
|
||||||
/** 1=本人 2=自己添加 3=他人添加 */
|
/** 1=本人 2=自己添加 3=他人添加 */
|
||||||
relationType: number | null
|
relationType: number | null
|
||||||
|
delFlag?: number
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 展示用分组 */
|
/** 展示用分组 */
|
||||||
@@ -147,6 +150,7 @@ Page({
|
|||||||
sync: item.syncStatus === 1 ? '已同步' : '待同步',
|
sync: item.syncStatus === 1 ? '已同步' : '待同步',
|
||||||
syncClass: item.syncStatus === 1 ? 'done' : 'pending',
|
syncClass: item.syncStatus === 1 ? 'done' : 'pending',
|
||||||
relationType: item.relationType,
|
relationType: item.relationType,
|
||||||
|
delFlag: item.delFlag,
|
||||||
})
|
})
|
||||||
const self = list.find(m => m.relationType === 1)
|
const self = list.find(m => m.relationType === 1)
|
||||||
this.setData({
|
this.setData({
|
||||||
@@ -234,36 +238,27 @@ Page({
|
|||||||
...(self ? [{
|
...(self ? [{
|
||||||
id: self.id, userId: self.userId, name: self.name,
|
id: self.id, userId: self.userId, name: self.name,
|
||||||
gender: self.gender === '男' ? 1 : 0,
|
gender: self.gender === '男' ? 1 : 0,
|
||||||
age: self.age, height: self.height, sync: self.sync,
|
age: self.age, height: self.height, sync: self.sync, delFlag: self.delFlag,
|
||||||
}] : []),
|
}] : []),
|
||||||
...this.data.groups.flatMap(g => g.members.map(m => ({
|
...this.data.groups.flatMap(g => g.members.map(m => ({
|
||||||
id: String(m.id), userId: m.userId, name: m.name,
|
id: String(m.id), userId: m.userId, name: m.name,
|
||||||
gender: m.gender === '男' ? 1 : 0, age: m.age, height: m.height, sync: m.sync,
|
gender: m.gender === '男' ? 1 : 0, age: m.age, height: m.height, sync: m.sync, delFlag: m.delFlag,
|
||||||
}))),
|
}))),
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
|
||||||
/** 同步完成后的统一处理:标记同步 + 更新列表状态 + 关闭弹框 */
|
/** 同步完成后的统一处理:上报后刷新列表 + 关闭弹框 */
|
||||||
_handleSyncSuccess(users: SyncUser[], successText: string) {
|
_finishSync(reportUsers: SyncUser[] | null, successText: string) {
|
||||||
this.setData({ syncPercent: 100, syncStatus: '同步完成' })
|
this.setData({ syncPercent: 100, syncStatus: '同步完成' })
|
||||||
wx.showToast({ title: successText, icon: 'success' })
|
wx.showToast({ title: successText, icon: 'success' })
|
||||||
const syncedIds = users.map(u => u.userId).filter(Boolean)
|
if (reportUsers && reportUsers.length && targetDevice?.sn) {
|
||||||
if (targetDevice?.sn && syncedIds.length) {
|
const syncedIds = reportUsers.map(u => u.userId).filter(Boolean)
|
||||||
|
if (syncedIds.length) {
|
||||||
markSynced({ sn: targetDevice.sn, list: syncedIds })
|
markSynced({ sn: targetDevice.sn, list: syncedIds })
|
||||||
.then(() => {
|
.then(() => this._loadMembers())
|
||||||
const syncedSet = new Set(syncedIds)
|
|
||||||
this.setData({
|
|
||||||
self: this.data.self && syncedSet.has(this.data.self.userId)
|
|
||||||
? { ...this.data.self, sync: '已同步', syncClass: 'done' }
|
|
||||||
: this.data.self,
|
|
||||||
groups: this.data.groups.map(g => ({
|
|
||||||
...g,
|
|
||||||
members: g.members.map(m => syncedSet.has(m.userId) ? { ...m, sync: '已同步', syncClass: 'done' } : m),
|
|
||||||
})),
|
|
||||||
})
|
|
||||||
})
|
|
||||||
.catch(() => {})
|
.catch(() => {})
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if (syncCloseTimer !== null) { clearTimeout(syncCloseTimer); syncCloseTimer = null }
|
if (syncCloseTimer !== null) { clearTimeout(syncCloseTimer); syncCloseTimer = null }
|
||||||
syncCloseTimer = setTimeout(() => {
|
syncCloseTimer = setTimeout(() => {
|
||||||
syncCloseTimer = null
|
syncCloseTimer = null
|
||||||
@@ -271,7 +266,7 @@ Page({
|
|||||||
}, 1000)
|
}, 1000)
|
||||||
},
|
},
|
||||||
|
|
||||||
/** 同步用户至设备:只下发「待同步」的用户 */
|
/** 同步用户至设备:有删除标记则清空重下发,否则只下发「待同步」 */
|
||||||
onTapSync() {
|
onTapSync() {
|
||||||
if (!this._ensureConnected()) return
|
if (!this._ensureConnected()) return
|
||||||
|
|
||||||
@@ -280,13 +275,19 @@ Page({
|
|||||||
wx.showToast({ title: '暂无用户可同步', icon: 'none' })
|
wx.showToast({ title: '暂无用户可同步', icon: 'none' })
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
// 只下发「待同步」的用户
|
// 有删除标记(delFlag=1):清空设备后下发未删除的用户,上报所有用户
|
||||||
|
const hasDeleted = allUsers.some(u => u.delFlag === 1)
|
||||||
|
if (hasDeleted) {
|
||||||
|
const normalUsers = allUsers.filter(u => u.delFlag !== 1)
|
||||||
|
this._clearAndSync(normalUsers, allUsers)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
// 无删除标记:只下发「待同步」的用户
|
||||||
const pendingUsers = allUsers.filter(u => u.sync !== '已同步')
|
const pendingUsers = allUsers.filter(u => u.sync !== '已同步')
|
||||||
if (!pendingUsers.length) {
|
if (!pendingUsers.length) {
|
||||||
wx.showToast({ title: '没有需要同步的用户', icon: 'none' })
|
wx.showToast({ title: '没有需要同步的用户', icon: 'none' })
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// 先读设备端主用户列表,判断设备是否已有主用户
|
// 先读设备端主用户列表,判断设备是否已有主用户
|
||||||
leFuService.fetchDeviceUserIds()
|
leFuService.fetchDeviceUserIds()
|
||||||
.then((deviceUserIds) => this._syncUsers(pendingUsers, deviceUserIds))
|
.then((deviceUserIds) => this._syncUsers(pendingUsers, deviceUserIds))
|
||||||
@@ -325,14 +326,14 @@ Page({
|
|||||||
syncStatus: `正在同步 ${current}/${total}...`,
|
syncStatus: `正在同步 ${current}/${total}...`,
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
.then(() => this._handleSyncSuccess(pendingUsers, '用户同步成功'))
|
.then(() => this._finishSync(pendingUsers, '用户同步成功'))
|
||||||
.catch((err: Error) => {
|
.catch((err: Error) => {
|
||||||
this.setData({ syncShow: false })
|
this.setData({ syncShow: false })
|
||||||
wx.showToast({ title: err.message || '同步失败,请重试', icon: 'none' })
|
wx.showToast({ title: err.message || '同步失败,请重试', icon: 'none' })
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
|
||||||
/** 长按标题:清除设备用户信息并全部重新下发 */
|
/** 长按标题:清除设备用户信息并全部重新下发(不上报) */
|
||||||
onLongPressSectionTitle() {
|
onLongPressSectionTitle() {
|
||||||
if (!this._ensureConnected()) return
|
if (!this._ensureConnected()) return
|
||||||
const allUsers = this._buildAllUsers()
|
const allUsers = this._buildAllUsers()
|
||||||
@@ -340,13 +341,13 @@ Page({
|
|||||||
wx.showToast({ title: '暂无用户可下发', icon: 'none' })
|
wx.showToast({ title: '暂无用户可下发', icon: 'none' })
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
this._resendAllUsers(allUsers)
|
this._clearAndSync(allUsers, null)
|
||||||
},
|
},
|
||||||
|
|
||||||
/** 清除设备用户后全部重新下发 */
|
/** 清除设备用户后重新下发;reportUsers 为 null 时不上报后台 */
|
||||||
_resendAllUsers(allUsers: SyncUser[]) {
|
_clearAndSync(syncUsers: SyncUser[], reportUsers: SyncUser[] | null) {
|
||||||
const mainUser = allUsers[0]
|
const mainUser = syncUsers[0]
|
||||||
const syncDataList: SyncUserData[] = allUsers.map((user, index) => ({
|
const syncDataList: SyncUserData[] = syncUsers.map((user, index) => ({
|
||||||
userID: mainUser.id,
|
userID: mainUser.id,
|
||||||
userName: user.name,
|
userName: user.name,
|
||||||
memberID: user.id === mainUser.id ? '' : user.id,
|
memberID: user.id === mainUser.id ? '' : user.id,
|
||||||
@@ -369,7 +370,7 @@ Page({
|
|||||||
syncStatus: `正在同步 ${current}/${total}...`,
|
syncStatus: `正在同步 ${current}/${total}...`,
|
||||||
})
|
})
|
||||||
}))
|
}))
|
||||||
.then(() => this._handleSyncSuccess(allUsers, '重新下发成功'))
|
.then(() => this._finishSync(reportUsers, '重新下发成功'))
|
||||||
.catch((err: Error) => {
|
.catch((err: Error) => {
|
||||||
this.setData({ syncShow: false })
|
this.setData({ syncShow: false })
|
||||||
wx.showToast({ title: err.message || '重新下发失败', icon: 'none' })
|
wx.showToast({ title: err.message || '重新下发失败', icon: 'none' })
|
||||||
|
|||||||
Reference in New Issue
Block a user