修改绑定逻辑

This commit is contained in:
Flow 2025-06-16 17:09:25 +08:00
parent 094bbc2477
commit 00f61c4db7
2 changed files with 35 additions and 9 deletions

View File

@ -11,7 +11,7 @@ export interface DeviceuserVO {
updateby: string // 更新人
username: string // 用户姓名
devicetype: string // 设备类型
familyid: string // 家庭组号
familyid: number // 家庭组号
}
// 设备人员关联 API

View File

@ -231,12 +231,14 @@ const list = ref<DeviceVO[]>([])
const boundList = ref<DeviceVO[]>([])
const personId = ref<number>()
const personName = ref<string>()
const familyId = ref<string>()
const familyId = ref<number>()
const queryParams = reactive({
pageNo: 1,
pageSize: 10,
orgid: undefined,
devicecode: undefined as string | undefined,
devicetype: undefined as string | undefined
})
const queryFormRef = ref()
@ -342,19 +344,43 @@ const getDeviceStatusType = (status: number) => {
}
/** 绑定设备 */
const handleBind = async (row: DeviceVO) => {
const handleBind = async (row: DeviceVO & { familyid?: number }) => {
try {
if (!personId.value) {
message.error('人员ID不能为空')
return
}
//
const bindData = await DeviceuserApi.getDeviceuserByDeviceId(row.devicecode)
if (bindData && bindData.some((item: DeviceuserVO) => item.userid === personId.value)) {
message.error('该设备已经绑定过此用户')
//
if (familyId.value && row.familyid && familyId.value !== row.familyid) {
message.error('该设备属于其他家庭组,无法绑定')
return
}
//
if (!familyId.value && row.familyid) {
message.error('当前人员未分配家庭组,无法绑定已有家庭组的设备')
return
}
//
const bindData = await DeviceuserApi.getDeviceuserByDeviceId(row.devicecode)
if (bindData && bindData.length > 0) {
//
const isBoundByCurrentUser = bindData.some(item => item.userid === personId.value)
if (isBoundByCurrentUser) {
message.error('该设备已经绑定过此用户')
return
}
//
const isBoundBySameFamily = bindData.some(item => item.familyid === familyId.value)
if (!isBoundBySameFamily) {
message.error('该设备已被其他家庭组的用户绑定')
return
}
}
const datetime = dayjs().format('YYYY-MM-DD HH:mm:ss')
const data: DeviceuserVO = {
id: 0, //
@ -362,7 +388,7 @@ const handleBind = async (row: DeviceVO) => {
devicetype: row.devicetype,
userid: personId.value,
username: personName.value || '',
familyid: familyId.value || '',
familyid: familyId.value || 0,
createtime: datetime,
updatetime: datetime,
createby: userProfile.value.nickname,
@ -406,7 +432,7 @@ const handleUnbind = async (row: DeviceVO) => {
const open = (id: number, name: string, familyid: string) => {
personId.value = id
personName.value = name
familyId.value = familyid
familyId.value = parseInt(familyid)
dialogVisible.value = true
getList()
getBoundList()