设备绑定
This commit is contained in:
parent
b5de0abf81
commit
2a59c27137
@ -10,6 +10,7 @@ export interface DeviceuserVO {
|
|||||||
createby: string // 创建人
|
createby: string // 创建人
|
||||||
updateby: string // 更新人
|
updateby: string // 更新人
|
||||||
username: string // 用户姓名
|
username: string // 用户姓名
|
||||||
|
devicetype: string // 设备类型
|
||||||
}
|
}
|
||||||
|
|
||||||
// 设备人员关联 API
|
// 设备人员关联 API
|
||||||
|
234
src/views/person/devicebind.vue
Normal file
234
src/views/person/devicebind.vue
Normal file
@ -0,0 +1,234 @@
|
|||||||
|
<template>
|
||||||
|
<el-dialog
|
||||||
|
v-model="dialogVisible"
|
||||||
|
title="设备绑定"
|
||||||
|
width="80%"
|
||||||
|
height="80vh"
|
||||||
|
append-to-body
|
||||||
|
destroy-on-close
|
||||||
|
>
|
||||||
|
<ContentWrap>
|
||||||
|
<el-form
|
||||||
|
class="-mb-15px"
|
||||||
|
:model="queryParams"
|
||||||
|
ref="queryFormRef"
|
||||||
|
:inline="true"
|
||||||
|
label-width="68px"
|
||||||
|
>
|
||||||
|
<el-form-item label="设备编号" prop="devicecode">
|
||||||
|
<el-input
|
||||||
|
v-model="queryParams.devicecode"
|
||||||
|
placeholder="请输入设备编号"
|
||||||
|
clearable
|
||||||
|
@keyup.enter="handleQuery"
|
||||||
|
class="!w-200px"
|
||||||
|
/>
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item label="设备类型" prop="devicetype">
|
||||||
|
<el-select
|
||||||
|
v-model="queryParams.devicetype"
|
||||||
|
placeholder="请选择设备类型"
|
||||||
|
clearable
|
||||||
|
class="!w-200px"
|
||||||
|
>
|
||||||
|
<el-option
|
||||||
|
v-for="dict in getStrDictOptions(DICT_TYPE.IOT_DEVICE_TYPE)"
|
||||||
|
:key="dict.value"
|
||||||
|
:label="dict.label"
|
||||||
|
:value="dict.value"
|
||||||
|
/>
|
||||||
|
</el-select>
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item>
|
||||||
|
<el-button @click="handleQuery"><Icon icon="ep:search" />搜索</el-button>
|
||||||
|
<el-button @click="resetQuery"><Icon icon="ep:refresh" />重置</el-button>
|
||||||
|
</el-form-item>
|
||||||
|
</el-form>
|
||||||
|
|
||||||
|
<div class="flex-1 overflow-hidden">
|
||||||
|
<el-table
|
||||||
|
v-loading="loading"
|
||||||
|
:data="list"
|
||||||
|
style="height: 100%"
|
||||||
|
>
|
||||||
|
<el-table-column
|
||||||
|
label="设备名称"
|
||||||
|
align="center"
|
||||||
|
prop="devicename"
|
||||||
|
width="120"
|
||||||
|
/>
|
||||||
|
<el-table-column
|
||||||
|
label="设备编号"
|
||||||
|
align="center"
|
||||||
|
prop="devicecode"
|
||||||
|
width="180"
|
||||||
|
/>
|
||||||
|
<el-table-column
|
||||||
|
label="设备类型"
|
||||||
|
align="center"
|
||||||
|
prop="devicetype"
|
||||||
|
width="120"
|
||||||
|
/>
|
||||||
|
<el-table-column
|
||||||
|
label="设备位置"
|
||||||
|
align="center"
|
||||||
|
prop="location"
|
||||||
|
min-width="180"
|
||||||
|
/>
|
||||||
|
<el-table-column label="设备状态" align="center" prop="devicestatus" width="150">
|
||||||
|
<template #default="scope">
|
||||||
|
<el-tag :type="getDeviceStatusType(scope.row.devicestatus)">
|
||||||
|
{{ getDeviceStatusLabel(scope.row.devicestatus) }}
|
||||||
|
</el-tag>
|
||||||
|
</template>
|
||||||
|
</el-table-column>
|
||||||
|
<el-table-column label="操作" align="center" width="100" fixed="right">
|
||||||
|
<template #default="scope">
|
||||||
|
<el-button
|
||||||
|
type="primary"
|
||||||
|
link
|
||||||
|
@click="handleBind(scope.row)"
|
||||||
|
>
|
||||||
|
<Icon icon="ep:link" />绑定
|
||||||
|
</el-button>
|
||||||
|
</template>
|
||||||
|
</el-table-column>
|
||||||
|
</el-table>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="mt-4">
|
||||||
|
<Pagination
|
||||||
|
:total="total"
|
||||||
|
v-model:page="queryParams.pageNo"
|
||||||
|
v-model:limit="queryParams.pageSize"
|
||||||
|
@pagination="getList"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</ContentWrap>
|
||||||
|
</el-dialog>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script lang="ts" setup>
|
||||||
|
import { DeviceApi, DeviceVO } from '@/api/device'
|
||||||
|
import { getUserProfile } from '@/api/system/user/profile'
|
||||||
|
import { getStrDictOptions } from '@/utils/dict'
|
||||||
|
import { DICT_TYPE } from '@/utils/dict'
|
||||||
|
import { ContentWrap } from '@/components/ContentWrap'
|
||||||
|
import { DeviceuserApi, DeviceuserVO } from '@/api/deviceuser'
|
||||||
|
|
||||||
|
defineOptions({ name: 'DeviceBind' })
|
||||||
|
const userProfile = ref()
|
||||||
|
const message = useMessage()
|
||||||
|
const dialogVisible = ref(false)
|
||||||
|
const loading = ref(false)
|
||||||
|
const total = ref(0)
|
||||||
|
const list = ref<DeviceVO[]>([])
|
||||||
|
const personId = ref<number>()
|
||||||
|
const personName = ref<string>()
|
||||||
|
|
||||||
|
const queryParams = reactive({
|
||||||
|
pageNo: 1,
|
||||||
|
pageSize: 10,
|
||||||
|
devicename: undefined,
|
||||||
|
devicecode: undefined,
|
||||||
|
devicetype: undefined,
|
||||||
|
devicestatus: 0,
|
||||||
|
orgid: undefined
|
||||||
|
})
|
||||||
|
|
||||||
|
const queryFormRef = ref()
|
||||||
|
|
||||||
|
/** 查询列表 */
|
||||||
|
const getList = async () => {
|
||||||
|
loading.value = true
|
||||||
|
try {
|
||||||
|
userProfile.value = await getUserProfile()
|
||||||
|
queryParams.orgid = userProfile.value.dept.id
|
||||||
|
const data = await DeviceApi.getDevicePage(queryParams)
|
||||||
|
list.value = data.list
|
||||||
|
total.value = data.total
|
||||||
|
} finally {
|
||||||
|
loading.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 搜索按钮操作 */
|
||||||
|
const handleQuery = () => {
|
||||||
|
queryParams.pageNo = 1
|
||||||
|
getList()
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 重置按钮操作 */
|
||||||
|
const resetQuery = () => {
|
||||||
|
queryFormRef.value?.resetFields()
|
||||||
|
queryParams.devicestatus = 0
|
||||||
|
handleQuery()
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 获取设备状态标签 */
|
||||||
|
const getDeviceStatusLabel = (status: number) => {
|
||||||
|
const statusMap = {
|
||||||
|
0: '待激活',
|
||||||
|
1: '在线',
|
||||||
|
2: '离线',
|
||||||
|
3: '禁用'
|
||||||
|
}
|
||||||
|
return statusMap[status] || '未知'
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 获取设备状态标签类型 */
|
||||||
|
const getDeviceStatusType = (status: number) => {
|
||||||
|
const typeMap = {
|
||||||
|
0: 'info',
|
||||||
|
1: 'success',
|
||||||
|
2: 'warning',
|
||||||
|
3: 'danger'
|
||||||
|
}
|
||||||
|
return typeMap[status] || ''
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 绑定设备 */
|
||||||
|
const handleBind = async (row: DeviceVO) => {
|
||||||
|
try {
|
||||||
|
if (!personId.value) {
|
||||||
|
message.error('人员ID不能为空')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
// 检查是否已经绑定
|
||||||
|
const bindData = await DeviceuserApi.getDeviceuserByDeviceId(row.id)
|
||||||
|
if (bindData && bindData.some((item: DeviceuserVO) => item.userid === personId.value)) {
|
||||||
|
message.error('该设备已经绑定过此用户')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
const data: DeviceuserVO = {
|
||||||
|
id: 0, // 新增时后端会自动生成
|
||||||
|
deviceid: row.id,
|
||||||
|
devicetype: row.devicetype,
|
||||||
|
userid: personId.value,
|
||||||
|
username: personName.value || '',
|
||||||
|
createtime: new Date(),
|
||||||
|
updatetime: new Date(),
|
||||||
|
createby: userProfile.value.nickname,
|
||||||
|
updateby: userProfile.value.nickname
|
||||||
|
}
|
||||||
|
await DeviceuserApi.createDeviceuser(data)
|
||||||
|
message.success('绑定成功')
|
||||||
|
dialogVisible.value = false
|
||||||
|
} catch (error) {
|
||||||
|
message.error('绑定失败')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 打开弹窗 */
|
||||||
|
const open = (id: number, name: string) => {
|
||||||
|
personId.value = id
|
||||||
|
personName.value = name
|
||||||
|
dialogVisible.value = true
|
||||||
|
getList()
|
||||||
|
}
|
||||||
|
|
||||||
|
defineExpose({
|
||||||
|
open
|
||||||
|
})
|
||||||
|
</script>
|
@ -115,6 +115,9 @@
|
|||||||
</el-button>
|
</el-button>
|
||||||
<template #dropdown>
|
<template #dropdown>
|
||||||
<el-dropdown-menu>
|
<el-dropdown-menu>
|
||||||
|
<el-dropdown-item @click="openForm('bind', scope.row.id, scope.row.name)">
|
||||||
|
<Icon icon="ep:link" />绑定设备
|
||||||
|
</el-dropdown-item>
|
||||||
<el-dropdown-item @click="openForm('update', scope.row.id)">
|
<el-dropdown-item @click="openForm('update', scope.row.id)">
|
||||||
<Icon icon="ep:edit" />修改
|
<Icon icon="ep:edit" />修改
|
||||||
</el-dropdown-item>
|
</el-dropdown-item>
|
||||||
@ -141,12 +144,15 @@
|
|||||||
<PersonForm ref="formRef" @success="handleSuccess" />
|
<PersonForm ref="formRef" @success="handleSuccess" />
|
||||||
<!-- 成员列表弹窗 -->
|
<!-- 成员列表弹窗 -->
|
||||||
<PersonMember ref="memberRef" />
|
<PersonMember ref="memberRef" />
|
||||||
|
<!-- 设备绑定弹窗 -->
|
||||||
|
<DeviceBind ref="deviceBindRef" />
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import { dateFormatter } from '@/utils/formatTime'
|
import { dateFormatter } from '@/utils/formatTime'
|
||||||
import PersonForm from './PersonFrom.vue'
|
import PersonForm from './PersonFrom.vue'
|
||||||
import PersonMember from './Personmember.vue'
|
import PersonMember from './Personmember.vue'
|
||||||
|
import DeviceBind from './devicebind.vue'
|
||||||
import { PersonApi, PersonVO } from '@/api/person'
|
import { PersonApi, PersonVO } from '@/api/person'
|
||||||
import { getUserProfile } from '@/api/system/user/profile'
|
import { getUserProfile } from '@/api/system/user/profile'
|
||||||
|
|
||||||
@ -207,27 +213,20 @@ const resetQuery = () => {
|
|||||||
|
|
||||||
/** 添加/修改操作 */
|
/** 添加/修改操作 */
|
||||||
const formRef = ref()
|
const formRef = ref()
|
||||||
const openForm = (type: string, id?: number) => {
|
const memberRef = ref()
|
||||||
formRef.value?.open(type, id, userProfile.value)
|
const deviceBindRef = ref()
|
||||||
|
const openForm = (type: string, id?: number, name?: string) => {
|
||||||
|
if (type === 'bind') {
|
||||||
|
deviceBindRef.value?.open(id, name)
|
||||||
|
} else {
|
||||||
|
formRef.value?.open(type, id)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const handleSuccess = () => {
|
const handleSuccess = () => {
|
||||||
getList()
|
getList()
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 获取家庭关系标签 */
|
|
||||||
const getFamilyRelationLabel = (relation: number) => {
|
|
||||||
const relationMap = {
|
|
||||||
1: '主号',
|
|
||||||
2: '兄弟',
|
|
||||||
3: '父亲',
|
|
||||||
4: '母亲',
|
|
||||||
5: '子女',
|
|
||||||
6: '其他'
|
|
||||||
}
|
|
||||||
return relationMap[relation] || '未知'
|
|
||||||
}
|
|
||||||
|
|
||||||
/** 获取家庭关系标签类型 */
|
/** 获取家庭关系标签类型 */
|
||||||
const getFamilyRelationType = (relation: number) => {
|
const getFamilyRelationType = (relation: number) => {
|
||||||
const typeMap = {
|
const typeMap = {
|
||||||
@ -246,7 +245,7 @@ const handleDelete = async (id: number) => {
|
|||||||
try {
|
try {
|
||||||
await message.delConfirm()
|
await message.delConfirm()
|
||||||
await PersonApi.deletePerson(id)
|
await PersonApi.deletePerson(id)
|
||||||
message.success('删除成功')
|
message.success(t('common.delSuccess'))
|
||||||
await getList()
|
await getList()
|
||||||
} catch {}
|
} catch {}
|
||||||
}
|
}
|
||||||
@ -266,7 +265,6 @@ const handleExport = async () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** 查看详情 */
|
/** 查看详情 */
|
||||||
const memberRef = ref()
|
|
||||||
const handleDetail = (row: PersonVO) => {
|
const handleDetail = (row: PersonVO) => {
|
||||||
memberRef.value?.open(row)
|
memberRef.value?.open(row)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user