feat(userManagement): 成员编辑删除与运维模式接口区分
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.7
parent
2afe598881
commit
48b75f37c9
@@ -1,6 +1,6 @@
|
||||
import { get, put } from '../../utils/request/index'
|
||||
import { getUserInfoByIdCard, type UserInfo } from '../../api/index'
|
||||
import { parseIdCard, isIdCardValid } from '../../utils/idCard/index'
|
||||
import { parseIdCard, isIdCardValid, calcAge } from '../../utils/idCard/index'
|
||||
|
||||
/** 表单数据模型 */
|
||||
interface MemberForm {
|
||||
@@ -22,8 +22,14 @@ const getEmployeeByWorkNo = (sn: string, workNo: string) =>
|
||||
const addUser = (data: Record<string, any>) =>
|
||||
put('weighingScale/v6/edit/user', data)
|
||||
|
||||
/** 用户详情接口(编辑模式回填) */
|
||||
const getUserInfoById = (id: string) =>
|
||||
get<Record<string, any>>('weighingScale/v3/select/userinfo/byId', { id })
|
||||
|
||||
/** 目标设备 SN(由 userManagement 跳转传入) */
|
||||
let targetSn = ''
|
||||
/** 编辑的用户 id(空表示新增) */
|
||||
let editUserId = ''
|
||||
|
||||
Page({
|
||||
data: {
|
||||
@@ -46,14 +52,62 @@ Page({
|
||||
employeeNotFound: false,
|
||||
unitDisplay: '',
|
||||
employeeQueryResult: null as Record<string, any> | null,
|
||||
rawUser: null as Record<string, any> | null,
|
||||
isEdit: false,
|
||||
},
|
||||
|
||||
onLoad(options: Record<string, string>) {
|
||||
targetSn = decodeURIComponent(options.sn || '')
|
||||
editUserId = decodeURIComponent(options.userId || '')
|
||||
this.setData({ isEdit: !!editUserId })
|
||||
if (editUserId) {
|
||||
this._loadEditUser(editUserId)
|
||||
}
|
||||
},
|
||||
|
||||
/** 编辑模式:加载用户详情回填表单 */
|
||||
_loadEditUser(userId: string) {
|
||||
getUserInfoById(userId)
|
||||
.then((res) => {
|
||||
const u = res.result
|
||||
if (!u) {
|
||||
wx.showToast({ title: '加载用户信息失败', icon: 'none' })
|
||||
return
|
||||
}
|
||||
const isFamily = u.dataType === 1
|
||||
const sex = u.sex ?? 0
|
||||
const gender = sex === 1 ? '男' : sex === 2 ? '女' : ''
|
||||
const age = calcAge(u.birthday ?? '')
|
||||
|
||||
this.setData({
|
||||
rawUser: u,
|
||||
userType: isFamily ? 'family' : 'employee',
|
||||
birthday: u.birthday ?? '',
|
||||
'form.workNo': u.workNo ?? '',
|
||||
'form.name': u.realname ?? '',
|
||||
'form.idCard': u.idCard ?? '',
|
||||
'form.gender': gender,
|
||||
'form.age': String(age),
|
||||
'form.sex': sex,
|
||||
'form.height': u.height ? String(u.height) : '',
|
||||
'form.weight': u.weight ? String(u.weight) : '',
|
||||
})
|
||||
if (!isFamily) {
|
||||
this.setData({
|
||||
employeeQueried: true,
|
||||
employeeQueryResult: u,
|
||||
unitDisplay: [u.secondDepart, u.thirdDepart].filter(Boolean).join(' / '),
|
||||
})
|
||||
}
|
||||
})
|
||||
.catch(() => {
|
||||
wx.showToast({ title: '加载用户信息失败', icon: 'none' })
|
||||
})
|
||||
},
|
||||
|
||||
/** tabs 切换:清空查询结果、重置表单 */
|
||||
onTabTap(e: WechatMiniprogram.TouchEvent) {
|
||||
if (this.data.isEdit) return
|
||||
const tab = e.currentTarget.dataset.value as string
|
||||
this.setData({
|
||||
userType: tab as 'employee' | 'family',
|
||||
@@ -289,10 +343,12 @@ Page({
|
||||
}
|
||||
|
||||
const userInfo = wx.getStorageSync('userInfo') as Record<string, any> | null
|
||||
// 员工:以查询接口返回为 base;家庭:以身份证查询结果为 base
|
||||
const baseSpread = userType === 'employee'
|
||||
// 编辑:以详情接口返回为 base;新增:员工用查询结果、家庭用身份证查询结果
|
||||
const baseSpread = editUserId
|
||||
? (this.data.rawUser ?? {})
|
||||
: (userType === 'employee'
|
||||
? (this.data.employeeQueryResult ?? {})
|
||||
: (this.data.serverResult ?? {})
|
||||
: (this.data.serverResult ?? {}))
|
||||
|
||||
const payload: Record<string, any> = {
|
||||
...baseSpread,
|
||||
@@ -308,10 +364,13 @@ Page({
|
||||
weight: isNaN(weightNum) ? 0 : weightNum,
|
||||
mode: getApp<IAppOption>().globalData.operationsEngineer ? 'ops' : 'normal',
|
||||
}
|
||||
if (editUserId) {
|
||||
payload.id = editUserId
|
||||
}
|
||||
|
||||
addUser(payload)
|
||||
.then(() => {
|
||||
wx.showToast({ title: '添加成功', icon: 'success' })
|
||||
wx.showToast({ title: editUserId ? '保存成功' : '添加成功', icon: 'success' })
|
||||
// 调用上一个页面(userManagement)刷新成员列表
|
||||
const pages = getCurrentPages()
|
||||
const prevPage = pages[pages.length - 2] as any
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { get, post } from '../../utils/request/index'
|
||||
import { get, post, del } from '../../utils/request/index'
|
||||
import { leFuService } from '../../lefu/index'
|
||||
import type { SyncUserData } from '../../lefu/index'
|
||||
import { calcAge } from '../../utils/idCard/index'
|
||||
@@ -50,14 +50,23 @@ interface GroupItem {
|
||||
members: MemberItem[]
|
||||
}
|
||||
|
||||
/** 获取设备成员列表 */
|
||||
/** 获取设备成员列表(运维模式走 ops/getDeviceUsers,普通模式走 v3/selectUserBySn/user) */
|
||||
const getDeviceMembers = (sn: string, userId: string) =>
|
||||
get<SysUserDevice[]>('weighingScale/v3/selectUserBySn/user', { sn, userId })
|
||||
get<SysUserDevice[]>(
|
||||
getApp<IAppOption>().globalData.operationsEngineer
|
||||
? 'weighingScale/ops/getDeviceUsers'
|
||||
: 'weighingScale/v3/selectUserBySn/user',
|
||||
{ sn, userId },
|
||||
)
|
||||
|
||||
/** 标记用户已同步到设备 */
|
||||
const markSynced = (data: { sn: string; list: string[] }) =>
|
||||
post('weighingScale/v6/markSynced', data, { loading: false })
|
||||
|
||||
/** 删除设备成员 */
|
||||
const deleteMember = (id: string) =>
|
||||
del('weighingScale/v2/del/user', { id }, { loading: false })
|
||||
|
||||
/** equipment 页传入的目标设备 */
|
||||
let targetDevice: { sn: string; deviceId: string; name: string; connected: boolean; connectDeviceInfo: string } | null = null
|
||||
|
||||
@@ -370,6 +379,36 @@ Page({
|
||||
wx.navigateTo({ url: `/pages/addUser/addUser?sn=${encodeURIComponent(sn)}` })
|
||||
},
|
||||
|
||||
/** 编辑成员:跳转 addUser 编辑模式 */
|
||||
onTapEdit(e: WechatMiniprogram.TouchEvent) {
|
||||
const item = e.currentTarget.dataset.item as MemberItem
|
||||
const sn = targetDevice?.sn || ''
|
||||
wx.navigateTo({ url: `/pages/addUser/addUser?sn=${encodeURIComponent(sn)}&userId=${encodeURIComponent(item.userId)}` })
|
||||
},
|
||||
|
||||
/** 删除成员 */
|
||||
onTapDelete(e: WechatMiniprogram.TouchEvent) {
|
||||
const item = e.currentTarget.dataset.item as MemberItem
|
||||
wx.showModal({
|
||||
title: '删除用户',
|
||||
content: `是否确认删除「${item.name}」?`,
|
||||
cancelText: '取消',
|
||||
confirmText: '删除',
|
||||
confirmColor: '#F24439',
|
||||
success: (res) => {
|
||||
if (!res.confirm) return
|
||||
deleteMember(item.id)
|
||||
.then(() => {
|
||||
wx.showToast({ title: '删除成功', icon: 'success' })
|
||||
this._loadMembers()
|
||||
})
|
||||
.catch(() => {
|
||||
wx.showToast({ title: '删除失败,请重试', icon: 'none' })
|
||||
})
|
||||
},
|
||||
})
|
||||
},
|
||||
|
||||
/** 一键添加本人 */
|
||||
onTapAddSelf() {
|
||||
// 一键添加本人(待接入)
|
||||
|
||||
@@ -36,7 +36,8 @@
|
||||
<scroll-view scroll-y class="scrollView" wx:if="{{ hasData }}">
|
||||
<view class="scrollViewContent">
|
||||
<!-- 本人 -->
|
||||
<view class="member-card" wx:if="{{ self }}">
|
||||
<block wx:if="{{ self }}">
|
||||
<view class="member-card">
|
||||
<view class="member-top">
|
||||
<view class="member-avatar">
|
||||
<image src="{{ self.gender === '女' ? '/images/woman.png' : '/images/man.png' }}" mode="aspectFit" />
|
||||
@@ -55,9 +56,10 @@
|
||||
</view>
|
||||
<view class="member-divider"></view>
|
||||
<view class="member-ops">
|
||||
<view class="op-delete">删除</view>
|
||||
<view class="op-delete" bind:tap="onTapDelete" data-item="{{ self }}">删除</view>
|
||||
</view>
|
||||
</view>
|
||||
</block>
|
||||
|
||||
<!-- 分组 -->
|
||||
<block wx:for="{{ groups }}" wx:key="title" wx:for-item="group">
|
||||
@@ -79,8 +81,8 @@
|
||||
</view>
|
||||
<view class="member-divider"></view>
|
||||
<view class="member-ops">
|
||||
<view class="op-edit">编辑</view>
|
||||
<view class="op-delete">删除</view>
|
||||
<view class="op-edit" bind:tap="onTapEdit" data-item="{{ member }}">编辑</view>
|
||||
<view class="op-delete" bind:tap="onTapDelete" data-item="{{ member }}">删除</view>
|
||||
</view>
|
||||
</view>
|
||||
</block>
|
||||
@@ -96,9 +98,13 @@
|
||||
|
||||
<!-- 底部常驻添加用户按钮 -->
|
||||
<view class="footer">
|
||||
<block wx:if="{{ self }}">
|
||||
<view class="btn-primary" bind:tap="onTapAddUser">添加用户(最多10位)</view>
|
||||
<!-- <view class="btn-primary" bind:tap="onTapAddSelf">一键添加本人</view>-->
|
||||
<!-- <view class="btn-cancel" bind:tap="onTapAddNew">添加新用户</view>-->
|
||||
</block>
|
||||
<block wx:else>
|
||||
<view class="btn-primary" bind:tap="onTapAddSelf">一键添加本人</view>
|
||||
<view class="btn-cancel" bind:tap="onTapAddNew">添加新用户</view>
|
||||
</block>
|
||||
</view>
|
||||
|
||||
<!-- 同步进度弹框 -->
|
||||
|
||||
Reference in New Issue
Block a user