import { message } from 'ant-design-vue'; import { get } from 'lodash-es'; import { ref } from 'vue'; import { submitEdit, updatePassword, validPassword, subList2, controlWindow, cancelcontrolWindow } from '../balancePress.api'; export function usePressControl() { /** 参数与设置、风机风门联动表单数据 */ const formData = ref({ /** 风机风门联动的自动调控 */ isAuto: false, /** 参数与设置的状态暂存字段 */ temp: false, }); /** 参数与设置、风机风门联动的数据 */ const avePressLinkage = ref({ isAuto: false }); const avePressSetting = ref({ isAuto: false }); /** 风门与风门联动控制 */ const gateLinkage = ref({ isAuto: false }); /** 获取 参数与设置、风机风门联动 的数据 */ function getAvePress() { return Promise.all([ subList2({ strType: 'sdg_fan_sys_gate', }), subList2({ strType: 'sdg_gate_to_gate', }), // subList({ // strType: 'sdg_gas_monitor', // }), subList2({ strType: 'sdg_pressure_to_window', }), ]).then(([linkageData, gateData, settingData]) => { avePressLinkage.value = get(linkageData, '[0]', {}); gateLinkage.value = get(gateData, '[0]', {}); avePressSetting.value = get(settingData, '[0]', {}); }); } function changePassword({ password, oldpassword, id }) { return updatePassword({ id, newPassword: password, oldPassword: oldpassword, }) .then(() => { message.success('操作成功'); }) .catch((e) => { message.error(e); }) .finally(() => { getAvePress(); }); } function linkageControl({ password, id }, formData) { return validPassword({ id, password, }) .then(() => { return submitEdit({ id, ...formData, }) .then(() => { message.success('操作成功'); }) .catch(() => { message.error('操作失败'); }); }) .catch((e) => { message.error(e); }) .finally(() => { getAvePress(); }); } function settingControl({ password, id }, formData) { return validPassword({ id, password, }) .then(() => { return submitEdit({ id, ...formData, }) .then(() => { message.success('操作成功'); }) .catch(() => { message.error('操作失败'); }); }) .catch((e) => { message.error(e); }) .finally(() => { getAvePress(); }); } function autoControl({ password, id }, { avgPressLogId }) { return validPassword({ id, password, }) .then(() => { return controlWindow({ avgPressId: avePressSetting.value.id, avgPressLogId }) .then(() => { message.success('预警已处理'); }) .catch((e) => { message.error('下发失败'); throw e; }); }) .catch((e) => { message.error(e); throw e; }) .finally(() => { getAvePress(); }); } function cancelControl(___, { avgPressLogId }) { return cancelcontrolWindow({ avgPressId: avePressSetting.value.id, avgPressLogId }) .then(() => { message.success('已取消'); }) .catch((e) => { message.error('下发失败'); throw e; }); } return { settingControl, linkageControl, changePassword, getAvePress, autoControl, cancelControl, avePressLinkage, avePressSetting, gateLinkage, formData, }; } export function usePressControlSP() { /** 参数与设置、风机风门联动表单数据 */ const formData = ref({ /** 风机风门联动的自动调控 */ isAuto: false, /** 参数与设置的状态暂存字段 */ temp: false, }); /** 参数与设置、风机风门联动的数据 */ const avePressSetting = ref({ isAuto: false }); /** 获取 参数与设置、风机风门联动 的数据 */ function getAvePress() { return Promise.all([ subList2({ strType: 'sp_pressure_to_window', }), ]).then(([settingData]) => { avePressSetting.value = get(settingData, '[0]', {}); }); } function changePassword({ password, oldpassword, id }) { return updatePassword({ id, newPassword: password, oldPassword: oldpassword, }) .then(() => { message.success('操作成功'); }) .catch((e) => { message.error(e); }) .finally(() => { getAvePress(); }); } function linkageControl({ password, id }, formData) { return validPassword({ id, password, }) .then(() => { return submitEdit({ id, ...formData, }) .then(() => { message.success('操作成功'); }) .catch(() => { message.error('操作失败'); }); }) .catch((e) => { message.error(e); }) .finally(() => { getAvePress(); }); } function settingControl({ password, id }, formData) { return validPassword({ id, password, }) .then(() => { return submitEdit({ id, ...formData, }) .then(() => { message.success('操作成功'); }) .catch(() => { message.error('操作失败'); }); }) .catch((e) => { message.error(e); }) .finally(() => { getAvePress(); }); } function autoControl({ password, id }, { avgPressLogId }) { return validPassword({ id, password, }) .then(() => { return controlWindow({ avgPressId: avePressSetting.value.id, avgPressLogId }) .then(() => { message.success('预警已处理'); }) .catch((e) => { message.error('下发失败'); throw e; }); }) .catch((e) => { message.error(e); throw e; }) .finally(() => { getAvePress(); }); } function cancelControl(___, { avgPressLogId }) { return cancelcontrolWindow({ avgPressId: avePressSetting.value.id, avgPressLogId }) .then(() => { message.success('已取消'); }) .catch((e) => { message.error('下发失败'); throw e; }); } return { settingControl, linkageControl, changePassword, getAvePress, autoControl, cancelControl, avePressSetting, formData, }; }