| | |
| | | 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 { |
| | |
| | | doorInfos.map(item=>{ |
| | | let doorInfo = data[item.ip]; |
| | | item.status = doorInfo.data2.lockStatus; |
| | | //item.status = 2; |
| | | 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; |