balancePressHomeBD.vue 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298
  1. <template>
  2. <a-spin tip="Loading..." :spinning="loading">
  3. <div class="monitor-container">
  4. <div class="lr left-box">
  5. <ventBox1>
  6. <template #title>
  7. <div>均压与低氧参数监测与设置</div>
  8. </template>
  9. <template #container>
  10. <div class="vent-flex-row-between auto-control mt-10px mb-10px">
  11. <div class="title">自动调节:</div>
  12. <a-radio-group :value="avePressSetting.isAutoControl" name="radioGroup" @change="changeIsAutoControl">
  13. <a-radio value="1">关闭</a-radio>
  14. <a-radio value="2">开启</a-radio>
  15. </a-radio-group>
  16. </div>
  17. <div class="input-box">
  18. <!-- <div class="divider-line">开始条件</div>
  19. <div v-for="(item, index) in settingParam1" class="input-item" :key="index">
  20. <div class="title">{{ item.title }}:</div>
  21. <a-input-number class="input-value" v-model:value="formData[item.code]" placeholder="" />
  22. <div class="unit">{{ item.unit }}</div>
  23. </div> -->
  24. <div class="divider-line">调节参数</div>
  25. <div v-for="(item, index) in settingParam4" class="input-item" :key="index">
  26. <div class="title">{{ item.title }}:</div>
  27. <a-input-number class="input-value" v-model:value="avePressSetting[item.code]" placeholder="" :disabled="settingFormDisabled" />
  28. <div class="unit">{{ item.unit }}</div>
  29. </div>
  30. <!-- <div class="divider-line">结束时间</div>
  31. <div v-for="(item, index) in settingParam3" class="input-item" :key="index">
  32. <div class="title">{{ item.title }}:</div>
  33. <a-input-number class="input-value" v-model:value="formData[item.code]" placeholder="" />
  34. <div class="unit">{{ item.unit }}</div>
  35. </div> -->
  36. </div>
  37. <div class="btn-box flex" style="text-align: center">
  38. <div class="btn btn1 flex-1" @click="editSettingForm">{{ settingFormDisabled ? '编辑' : '取消' }}</div>
  39. <div class="btn btn1 flex-1" @click="submitSettingForm">提交</div>
  40. </div>
  41. </template>
  42. </ventBox1>
  43. </div>
  44. <div class="lr">
  45. <ventBox1>
  46. <template #title>
  47. <div>均压工作面风机与风门联动</div>
  48. </template>
  49. <template #container>
  50. <div class="vent-flex-row-between auto-control mt-10px mb-10px">
  51. <div class="title">自动调节:</div>
  52. <a-radio-group :value="avePressLinkage.isAuto" name="radioGroup" @change="changeIsAuto">
  53. <a-radio :value="false">关闭</a-radio>
  54. <a-radio :value="true">开启</a-radio>
  55. </a-radio-group>
  56. </div>
  57. <div class="btn-box" style="text-align: center">
  58. <div class="btn btn1" @click="() => openModal()">控制密码修改</div>
  59. </div>
  60. </template>
  61. </ventBox1>
  62. </div>
  63. <ModuleCommon
  64. v-for="cfg in configs"
  65. :key="cfg.deviceType"
  66. :show-style="cfg.showStyle"
  67. :module-data="cfg.moduleData"
  68. :module-name="cfg.moduleName"
  69. :device-type="cfg.deviceType"
  70. :data="selectData"
  71. :visible="true"
  72. />
  73. </div>
  74. <PasswordModal :modal-is-show="modalVisible" modal-title="提交" @handle-ok="handleResolve" />
  75. <UpdatePassword @register="updatePwdRegister" @submit="handleChangePassword" />
  76. </a-spin>
  77. </template>
  78. <script setup lang="ts">
  79. import { ref, onMounted, onUnmounted, defineProps } from 'vue';
  80. import { mountedThree, destroy, setModelType, updateText, play } from '../balancePress.threejs';
  81. import { list } from '../balancePress.api';
  82. import ModuleCommon from '../../../home/configurable/components/ModuleCommon.vue';
  83. import { useInitConfigs } from '../../../home/configurable/hooks/useInit';
  84. import { useGlobSetting } from '/@/hooks/setting';
  85. import { settingParam4 } from '../balancePress.data';
  86. import { notification } from 'ant-design-vue';
  87. import ventBox1 from '/@/components/vent/ventBox1.vue';
  88. import PasswordModal from '../../comment/components/PasswordModal.vue';
  89. import UpdatePassword from '../../comment/components/UpdatePassword.vue';
  90. import { useModal } from '/@/components/Modal';
  91. import { connectWebSocket, onWebSocket } from '/@/hooks/web/useWebSocket';
  92. import { getToken } from '/@/utils/auth';
  93. import { useUserStore } from '/@/store/modules/user';
  94. import { usePressControl } from '../hooks/useControl';
  95. // import { Config } from '../../../deviceManager/configurationTable/types';
  96. const props = defineProps({
  97. deviceId: {
  98. type: String,
  99. require: true,
  100. },
  101. });
  102. const { sysOrgCode } = useGlobSetting();
  103. const loading = ref(false);
  104. // 监测数据
  105. const selectData = ref();
  106. // https获取监测数据
  107. let timer: any = null;
  108. function getMonitor(flag?) {
  109. if (Object.prototype.toString.call(timer) === '[object Null]') {
  110. timer = setTimeout(
  111. async () => {
  112. if (props.deviceId) {
  113. const data = await getDataSource(props.deviceId);
  114. // Object.assign(selectData, data);
  115. updateText(selectData);
  116. selectData.value = data;
  117. }
  118. if (timer) {
  119. timer = null;
  120. }
  121. await getMonitor();
  122. },
  123. flag ? 0 : 1000
  124. );
  125. }
  126. }
  127. async function getDataSource(systemID) {
  128. const res = await list({ devicetype: 'sys', systemID });
  129. const result = Array.from(res.msgTxt).reduce(
  130. (obj: any, e: any) => {
  131. obj[e.type] = e;
  132. // if (true) {
  133. if (sysOrgCode === 'sdmtjtswmk') {
  134. if (e.type.startsWith('fanlocal')) {
  135. obj.fanlocal.datalist.push(...e.datalist);
  136. }
  137. if (e.type.startsWith('safetymonitor')) {
  138. e.datalist.forEach((ele) => {
  139. if (ele.strinstallpos.includes('风门')) {
  140. obj.gate.datalist.push(ele);
  141. } else if (ele.strinstallpos.includes('风窗')) {
  142. obj.window.datalist.push(ele);
  143. } else if (ele.strinstallpos.includes('工作面')) {
  144. obj.work_surface.datalist.push(ele);
  145. } else {
  146. obj.others.datalist.push(ele);
  147. }
  148. });
  149. }
  150. }
  151. return obj;
  152. },
  153. {
  154. /** 用于归类fanlocal */
  155. fanlocal: { datalist: [] },
  156. /** 用于归类gate */
  157. gate: { datalist: [] },
  158. /** 用于归类window */
  159. window: { datalist: [] },
  160. /** 用于归类work_surface */
  161. work_surface: { datalist: [] },
  162. others: { datalist: [] },
  163. }
  164. );
  165. return result;
  166. }
  167. const { avePressSetting, avePressLinkage, formData, getAvePress, changePassword, linkageControl, settingControl } = usePressControl();
  168. const modalVisible = ref(false);
  169. const { configs, fetchConfigs } = useInitConfigs();
  170. const [updatePwdRegister, { openModal, closeModal, setModalProps }] = useModal();
  171. function handleChangePassword(values) {
  172. setModalProps({ confirmLoading: true });
  173. changePassword(values).finally(() => {
  174. setModalProps({ confirmLoading: false });
  175. closeModal();
  176. });
  177. }
  178. function changeIsAuto({ target }) {
  179. formData.value.isAuto = target.value;
  180. modalVisible.value = true;
  181. resolver = (password) => {
  182. linkageControl(
  183. { password },
  184. {
  185. isAuto: formData.value.isAuto,
  186. }
  187. ).finally(() => {
  188. modalVisible.value = false;
  189. });
  190. };
  191. }
  192. function changeIsAutoControl({ target }) {
  193. formData.value.isAutoControl = target.value;
  194. modalVisible.value = true;
  195. resolver = (password) => {
  196. settingControl(
  197. { password },
  198. {
  199. isAutoControl: formData.value.isAutoControl,
  200. }
  201. ).finally(() => {
  202. modalVisible.value = false;
  203. });
  204. };
  205. }
  206. // function submitLinkageForm(password) {}
  207. function submitSettingForm() {
  208. modalVisible.value = true;
  209. resolver = (password) => {
  210. settingControl({ password }, avePressSetting.value).finally(() => {
  211. modalVisible.value = false;
  212. });
  213. };
  214. }
  215. let resolver: any = null;
  216. function handleResolve(password) {
  217. if (resolver) resolver(password);
  218. resolver = null;
  219. }
  220. // 初始化 WebSocket
  221. function initWebSocket() {
  222. const token = getToken();
  223. const userStore = useUserStore();
  224. const glob = useGlobSetting();
  225. // WebSocket与普通的请求所用协议有所不同,ws等同于http,wss等同于https
  226. const url = `${glob.wsUrl?.replace('https://', 'wss://').replace('http://', 'ws://')}/websocket/${userStore.getUserInfo.id}?token=${token}`;
  227. connectWebSocket(url);
  228. onWebSocket((data: any) => {
  229. console.error('NO ERROR HERE! ', data);
  230. notification.open({
  231. message: data.title,
  232. description: JSON.parse(data.content).info,
  233. placement: 'topRight',
  234. });
  235. });
  236. }
  237. const settingFormDisabled = ref(true);
  238. function editSettingForm() {
  239. settingFormDisabled.value = !settingFormDisabled.value;
  240. /** 如果取消了编辑模式,那么需要重置表单 */
  241. if (settingFormDisabled.value) {
  242. getAvePress();
  243. }
  244. }
  245. onMounted(() => {
  246. initWebSocket();
  247. // getMonitor()
  248. fetchConfigs('balancePressHome');
  249. getAvePress();
  250. loading.value = true;
  251. mountedThree().then(async () => {
  252. await setModelType('balancePressBase'); //balancePressBase
  253. loading.value = false;
  254. timer = null;
  255. await getMonitor(true);
  256. play('startSmoke', 'top', 30, 'open', 0);
  257. });
  258. // loading.value = false;
  259. // timer = null;
  260. // getMonitor(true);
  261. });
  262. onUnmounted(() => {
  263. destroy();
  264. if (timer) {
  265. clearTimeout(timer);
  266. }
  267. });
  268. </script>
  269. <style lang="less" scoped>
  270. @import '/@/design/vent/modal.less';
  271. @import '../../comment/less/workFace.less';
  272. @ventSpace: zxm;
  273. .monitor-container {
  274. margin-top: 60px;
  275. }
  276. </style>