| | |
| | | import {ref} from "vue"; |
| | | import {reactive, ref} from "vue"; |
| | | import air from "@/assets/js/const/air"; |
| | | import {getAirParam} from "@/views/airConditioning/js/api"; |
| | | import {getAirParam, setAirParam} from "@/views/airConditioning/js/api"; |
| | | import {ElLoading, ElMessage} from "element-plus"; |
| | | |
| | | const airControlModule = ()=>{ |
| | | const cmd = air.cmd; |
| | | const airParam = ref({ |
| | | num: 0, |
| | | devId: 0, |
| | | const isCanSet = ref(false); |
| | | const airParam = reactive({ |
| | | num: 1, |
| | | devId: 210000001, |
| | | opCmd: 0, |
| | | stHumid: 0, |
| | | stTemp: 0, |
| | | }); |
| | | |
| | | /** |
| | | * 读取放电参数 |
| | | */ |
| | | const getParam = ()=>{ |
| | | const loading = ElLoading.service({ |
| | | lock: false, |
| | | text: '数据加装中', |
| | | background: 'rgba(0, 0, 0, 0.3)', |
| | | }); |
| | | getAirParam(210000001).then(res=>{ |
| | | let rs = res.data; |
| | | let data = { |
| | | num: 0, |
| | | devId: 0, |
| | | opCmd: 0, |
| | | stHumid: 0, |
| | | stTemp: 0, |
| | | }; |
| | | if(rs.code === 1 && rs.data) { |
| | | ElMessage({ |
| | | showClose: true, |
| | | message: '读取成功', |
| | | type: 'success', |
| | | }); |
| | | data = rs.data2; |
| | | isCanSet.value = true; |
| | | }else { |
| | | ElMessage({ |
| | | showClose: true, |
| | | message: '读取失败', |
| | | type: 'error', |
| | | }); |
| | | isCanSet.value = false; |
| | | } |
| | | // 设置值 |
| | | airParam.stTemp = data.stTemp; |
| | | airParam.stHumid =data.stHumid; |
| | | airParam.devId = data.devId; |
| | | airParam.num = data.num; |
| | | |
| | | loading.close(); |
| | | console.log(res); |
| | | }).catch(error=>{ |
| | | isCanSet.value = false; |
| | | loading.close(); |
| | | console.log(error); |
| | | }); |
| | | } |
| | | |
| | | const setParam = async ()=>{ |
| | | const loading = ElLoading.service({ |
| | | lock: false, |
| | | text: '数据加装中', |
| | | background: 'rgba(0, 0, 0, 0.3)', |
| | | }); |
| | | airParam.opCmd = cmd.set; |
| | | try { |
| | | const res = await setAirParam(airParam); |
| | | loading.close(); |
| | | let rs = res.data; |
| | | if(rs.code === 1 && rs.data) { |
| | | ElMessage({ |
| | | showClose: true, |
| | | message: '设置成功', |
| | | type: 'success', |
| | | }); |
| | | return Promise.resolve(true); |
| | | }else { |
| | | ElMessage({ |
| | | showClose: true, |
| | | message: '设置失败', |
| | | type: 'error', |
| | | }); |
| | | return Promise.resolve(false); |
| | | } |
| | | }catch (error) { |
| | | loading.close(); |
| | | console.log(error); |
| | | return Promise.resolve(false); |
| | | } |
| | | } |
| | | |
| | | return { |
| | | isCanSet, |
| | | airParam, |
| | | getParam, |
| | | setParam, |
| | | }; |
| | | } |
| | | export default airControlModule; |