feat(equipmentMember): 删除确认改为自定义弹窗,他人添加用户红色加粗警示
- 删除确认弹窗替代原生 wx.showModal,仿原生风格 - 他人添加成员删除时显示红色加粗警示文案 - 成员列表操作区统一展示编辑/删除按钮 - 名字旁补充「本人」「他人添加」标签 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.7
parent
d44e0a9e76
commit
97c135786c
@@ -37,10 +37,10 @@ interface SysUserDevice {
|
||||
relationType: number | null
|
||||
}
|
||||
|
||||
/** 页面展示用成员模型 */
|
||||
/** 页面展示用用户模型 */
|
||||
interface MemberDisplay {
|
||||
id: string
|
||||
/** 成员 ID */
|
||||
/** 用户 ID */
|
||||
userId: string
|
||||
realname: string
|
||||
/** '男' | '女' */
|
||||
@@ -101,7 +101,7 @@ const syncToDevice = (members: MemberDisplay[]): void => {
|
||||
})
|
||||
.then(() => {
|
||||
wx.hideLoading()
|
||||
wx.showToast({ title: '成员同步成功', icon: 'success' })
|
||||
wx.showToast({ title: '用户同步成功', icon: 'success' })
|
||||
})
|
||||
.catch((err: Error) => {
|
||||
wx.hideLoading()
|
||||
@@ -110,7 +110,7 @@ const syncToDevice = (members: MemberDisplay[]): void => {
|
||||
}
|
||||
|
||||
/**
|
||||
* 设备成员管理页
|
||||
* 设备用户管理页
|
||||
* sn 与设备名直接读 lefuService.deviceInfo,连接状态实时同步
|
||||
*/
|
||||
Page({
|
||||
@@ -128,6 +128,9 @@ Page({
|
||||
capacityTotal: 10,
|
||||
} as DeviceCard,
|
||||
memberList: [] as MemberDisplay[],
|
||||
/** 自定义删除确认弹窗 */
|
||||
showDeleteModal: false,
|
||||
deleteTarget: null as MemberDisplay | null,
|
||||
},
|
||||
|
||||
// 当前子页 addMember 未注册任何 SDK 回调,不会覆盖本页回调槽位,故无需 onShow 兜底。
|
||||
@@ -171,7 +174,7 @@ Page({
|
||||
},
|
||||
|
||||
/**
|
||||
* 调 v3 接口拉取成员列表,成功后更新设备名与成员数据
|
||||
* 调 v3 接口拉取用户列表,成功后更新设备名与用户数据
|
||||
* @param sn 设备 SN
|
||||
*/
|
||||
_loadData(sn: string) {
|
||||
@@ -213,13 +216,13 @@ Page({
|
||||
})
|
||||
},
|
||||
|
||||
/** 编辑成员:仅携带 userId 跳转,详情由目标页自行查询 */
|
||||
/** 编辑用户:仅携带 userId 跳转,详情由目标页自行查询 */
|
||||
onTapEdit(e: WechatMiniprogram.TouchEvent) {
|
||||
const id = e.currentTarget.dataset.id as string
|
||||
wx.navigateTo({ url: `/pages/addMember/addMember?userId=${id}` })
|
||||
},
|
||||
|
||||
/** 删除成员 */
|
||||
/** 删除用户:弹出自定义确认弹窗 */
|
||||
onTapDelete(e: WechatMiniprogram.TouchEvent) {
|
||||
const id = e.currentTarget.dataset.id as string
|
||||
const target = this.data.memberList.find(m => m.id === id)
|
||||
@@ -240,56 +243,72 @@ Page({
|
||||
}
|
||||
}
|
||||
|
||||
wx.showModal({
|
||||
title: '确认删除',
|
||||
content: `确定要删除成员「${target.realname}」吗?删除后将同步更新设备数据。`,
|
||||
success: (res) => {
|
||||
if (!res.confirm) return
|
||||
|
||||
// 1. 从列表中移除该成员(立即更新 UI)
|
||||
const newList = this.data.memberList.filter(m => m.id !== id)
|
||||
this.setData({
|
||||
memberList: newList,
|
||||
'deviceCard.capacityUsed': newList.length,
|
||||
})
|
||||
|
||||
wx.showLoading({ title: '正在同步设备数据...', mask: true })
|
||||
|
||||
// 2. 同步设备
|
||||
let devicePromise: Promise<void>
|
||||
if (newList.length) {
|
||||
// 有剩余成员:清除设备数据并重新下发
|
||||
devicePromise = lefuService.syncMembersToDevice(
|
||||
newList.map(toDeviceMember),
|
||||
(current, total) => {
|
||||
wx.showLoading({ title: `正在同步设备数据 ${current}/${total}...`, mask: true })
|
||||
},
|
||||
)
|
||||
} else {
|
||||
// 删除最后一个成员:仅清除设备数据,不下发
|
||||
devicePromise = lefuService.clearDeviceMembers()
|
||||
}
|
||||
|
||||
devicePromise
|
||||
.then(() => {
|
||||
// 3. 调用删除接口
|
||||
return del('weighingScale/v2/del/user', { id }, { loading: false })
|
||||
})
|
||||
.then(() => {
|
||||
wx.hideLoading()
|
||||
wx.showToast({ title: '删除成功', icon: 'success' })
|
||||
})
|
||||
.catch((err: Error) => {
|
||||
wx.hideLoading()
|
||||
// 失败时重新拉取列表恢复数据
|
||||
this._loadData(this.data.sn)
|
||||
wx.showToast({ title: err.message || '删除失败,请重试', icon: 'none' })
|
||||
})
|
||||
},
|
||||
this.setData({
|
||||
showDeleteModal: true,
|
||||
deleteTarget: target,
|
||||
})
|
||||
},
|
||||
|
||||
/** 添加成员:未连接态禁用 */
|
||||
/** 关闭删除确认弹窗 */
|
||||
onHideDeleteModal() {
|
||||
this.setData({
|
||||
showDeleteModal: false,
|
||||
deleteTarget: null,
|
||||
})
|
||||
},
|
||||
|
||||
/** 确认删除 */
|
||||
onConfirmDelete() {
|
||||
const target = this.data.deleteTarget
|
||||
if (!target) return
|
||||
|
||||
const id = target.id
|
||||
|
||||
// 1. 从列表中移除该用户(立即更新 UI)
|
||||
const newList = this.data.memberList.filter(m => m.id !== id)
|
||||
this.setData({
|
||||
memberList: newList,
|
||||
'deviceCard.capacityUsed': newList.length,
|
||||
showDeleteModal: false,
|
||||
deleteTarget: null,
|
||||
})
|
||||
|
||||
wx.showLoading({ title: '正在同步设备数据...', mask: true })
|
||||
|
||||
// 2. 同步设备
|
||||
let devicePromise: Promise<void>
|
||||
if (newList.length) {
|
||||
devicePromise = lefuService.syncMembersToDevice(
|
||||
newList.map(toDeviceMember),
|
||||
(current, total) => {
|
||||
wx.showLoading({ title: `正在同步设备数据 ${current}/${total}...`, mask: true })
|
||||
},
|
||||
)
|
||||
} else {
|
||||
devicePromise = lefuService.clearDeviceMembers()
|
||||
}
|
||||
|
||||
devicePromise
|
||||
.then(() => {
|
||||
// 3. 调用删除接口
|
||||
return del('weighingScale/v2/del/user', { id }, { loading: false })
|
||||
})
|
||||
.then(() => {
|
||||
wx.hideLoading()
|
||||
wx.showToast({ title: '删除成功', icon: 'success' })
|
||||
})
|
||||
.catch((err: Error) => {
|
||||
wx.hideLoading()
|
||||
// 失败时重新拉取列表恢复数据
|
||||
this._loadData(this.data.sn)
|
||||
wx.showToast({ title: err.message || '删除失败,请重试', icon: 'none' })
|
||||
})
|
||||
},
|
||||
|
||||
/** 空方法,阻止弹窗事件冒泡 */
|
||||
noop() {},
|
||||
|
||||
/** 添加用户:未连接态禁用 */
|
||||
onTapAddMember() {
|
||||
if (!this.data.connected) return
|
||||
if (this.data.memberList.length >= 10) {
|
||||
|
||||
Reference in New Issue
Block a user