| | |
| | | import {onMounted, reactive} from "vue"; |
| | | import door from "@/assets/js/const/door"; |
| | | import getLabelByKey from "@/assets/js/tools/getLabelByKey"; |
| | | import {changeDoorState} from "@/views/accessControl/js/api"; |
| | | import {ElLoading, ElMessage} from "element-plus"; |
| | | const lockStatusList = door.lockStatus; |
| | | const doorInfoModule = ()=>{ |
| | | const { |
| | |
| | | |
| | | const doorInfos = reactive([ |
| | | { |
| | | ip: "192.168.0.19", |
| | | passWord: "a1234567.", |
| | | port: 8000, |
| | | userName: "admin", |
| | | status: "未知" |
| | | }, |
| | | { |
| | | ip: "192.168.0.18", |
| | | passWord: "a1234567.", |
| | | port: 8000, |
| | | userName: "admin", |
| | | status: "未知" |
| | | status: 0, |
| | | name: "智能实验室", |
| | | statusText: "未知" |
| | | }, |
| | | { |
| | | ip: "192.168.0.19", |
| | | passWord: "a1234567.", |
| | | port: 8000, |
| | | userName: "admin", |
| | | status: 0, |
| | | name: "PCR实验室", |
| | | statusText: "未知" |
| | | }, |
| | | { |
| | | ip: "192.168.0.44", |
| | | passWord: "a1234567.", |
| | | port: 8000, |
| | | userName: "admin", |
| | | status: "未知" |
| | | status: 0, |
| | | name: "西藏安琪", |
| | | statusText: "未知" |
| | | }, |
| | | ]); |
| | | |
| | |
| | | let data = rs.data; |
| | | doorInfos.map(item=>{ |
| | | let doorInfo = data[item.ip]; |
| | | console.log(doorInfo); |
| | | item.status = getLabelByKey(doorInfo.data2.lockStatus, lockStatusList, "未知"); |
| | | item.status = doorInfo.data2.lockStatus; |
| | | item.statusText = getLabelByKey(doorInfo.data2.lockStatus, lockStatusList, "未知"); |
| | | }); |
| | | } |
| | | /** |
| | | * 开启门禁 |
| | | */ |
| | | const openDoor = async (info)=>{ |
| | | const loading = ElLoading.service({ |
| | | lock: false, |
| | | text: '开启门禁中...', |
| | | background: 'rgba(0, 0, 0, 0.3)', |
| | | }); |
| | | try { |
| | | const res = await changeDoorState(info, 1); |
| | | loading.close(); |
| | | let rs = res.data; |
| | | if(rs.code === 1 && rs.data) { |
| | | ElMessage({ |
| | | showClose: true, |
| | | message: '开启门禁成功', |
| | | type: 'success', |
| | | }); |
| | | }else { |
| | | ElMessage({ |
| | | showClose: true, |
| | | message: '开启门禁失败', |
| | | type: 'error', |
| | | }); |
| | | } |
| | | }catch (error){ |
| | | console.log(error); |
| | | loading.close(); |
| | | } |
| | | |
| | | } |
| | | |
| | | /** |
| | | * 关闭门禁 |
| | | */ |
| | | const closeDoor = async (info)=>{ |
| | | const loading = ElLoading.service({ |
| | | lock: false, |
| | | text: '关闭门禁中...', |
| | | background: 'rgba(0, 0, 0, 0.3)', |
| | | }); |
| | | try { |
| | | const res = await changeDoorState(info, 0); |
| | | loading.close(); |
| | | let rs = res.data; |
| | | if(rs.code === 1 && rs.data) { |
| | | ElMessage({ |
| | | showClose: true, |
| | | message: '关闭成功', |
| | | type: 'success', |
| | | }); |
| | | }else { |
| | | ElMessage({ |
| | | showClose: true, |
| | | message: '关闭失败', |
| | | type: 'error', |
| | | }); |
| | | } |
| | | }catch (error){ |
| | | console.log(error); |
| | | loading.close(); |
| | | } |
| | | } |
| | | |
| | | onMounted(()=>{ |
| | |
| | | SOCKET.value.addEventListener("message", handleMessage, false); |
| | | }); |
| | | |
| | | return {doorInfos}; |
| | | return { |
| | | doorInfos, |
| | | openDoor, |
| | | closeDoor |
| | | }; |
| | | } |
| | | |
| | | export default doorInfoModule; |