index.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481
  1. <template>
  2. <div class="bg" style="width: 100%; height: 100%; display: flex; justify-content: center; align-items: center; overflow: hidden"> </div>
  3. <div class="scene-box">
  4. <div class="top-box">
  5. <div class="top-center row">
  6. <div v-if="hasPermission('btn:control')" class="button-box" @click="playAnimation(1)">打开防火门</div>
  7. <div v-if="hasPermission('btn:control')" class="button-box" @click="playAnimation(2)">关闭防火门</div>
  8. </div>
  9. <!-- 控制模式 -->
  10. <div class="top-right row">
  11. <div class="vent-flex-m row" v-if="selectData.contrlMod == 'loopCtrl'">
  12. <div class="control-title">控制模式:</div>
  13. <a-radio-group v-model:value="selectData.autoRoManual">
  14. <template v-for="(item, index) in modelList" :key="index">
  15. <a-radio :value="item.value" :disabled="true">{{ item.text }}</a-radio>
  16. </template>
  17. </a-radio-group>
  18. <div class="button-box" @click="playAnimation(7)">切换模式</div>
  19. </div>
  20. <div class="vent-flex-m row" v-else>
  21. <div class="control-title">控制模式:</div>
  22. <a-radio-group v-model:value="selectData.autoRoManual">
  23. <template v-for="(item, index) in modelList" :key="index">
  24. <a-radio :value="item.value" :disabled="true">{{ item.text }}</a-radio>
  25. </template>
  26. </a-radio-group>
  27. <div class="button-box" v-for="(item, index) in modelList" @click="playAnimation(7, item.value)" :key="index">{{ item.text }}</div>
  28. </div>
  29. <!-- <div class="run-type row">
  30. <div class="control-title">运行状态:</div>
  31. <a-radio-group v-model:value="selectData.runRoRecondition">
  32. <a-radio :value="`0`">检修</a-radio>
  33. <a-radio :value="`1`">运行</a-radio>
  34. </a-radio-group>
  35. </div> -->
  36. </div>
  37. </div>
  38. <div class="title-text"> 设备监测 </div>
  39. <div class="bottom-tabs-box" @mousedown="setDivHeight($event, 300, scroll)">
  40. <dv-border-box8 :dur="5" :style="`padding: 5px; height: ${scroll.y + 120}px`">
  41. <a-tabs class="tabs-box" v-model:activeKey="activeKey" @change="tabChange">
  42. <a-tab-pane key="1" tab="实时监测">
  43. <MonitorTable
  44. v-if="activeKey === '1'"
  45. ref="MonitorDataTable"
  46. class="monitor-table"
  47. :columnsType="deviceType"
  48. :isShowActionColumn="true"
  49. :dataSource="dataSource"
  50. design-scope="gate-monitor"
  51. @selectRow="getSelectRow"
  52. :scroll="{ y: scroll.y - 40 }"
  53. title="风门监测"
  54. :isShowPagination="true"
  55. >
  56. <template #filterCell="{ column, record }">
  57. <a-tag v-if="column.dataIndex === 'frontGateOpen' && record.frontGateOpen == '0' && record.frontGateClose == '0'" color="red"
  58. >正在运行</a-tag
  59. >
  60. <a-tag v-else-if="column.dataIndex === 'frontGateOpen' && record.frontGateOpen == '0' && record.frontGateClose == 1" color="default"
  61. >关闭</a-tag
  62. >
  63. <a-tag v-else-if="column.dataIndex === 'frontGateOpen' && record.frontGateOpen == '1' && record.frontGateClose == '0'" color="#46C66F"
  64. >打开</a-tag
  65. >
  66. <a-tag v-else-if="column.dataIndex === 'frontGateOpen' && record.frontGateOpen == '1' && record.frontGateClose == '1'" color="#FF0000"
  67. >点位异常</a-tag
  68. >
  69. <template v-else-if="column.dataIndex === 'warnLevel'">
  70. <a-tag v-if="record.warnLevel == '101'" color="green">低风险</a-tag>
  71. <a-tag v-else-if="record.warnLevel == '102'" color="#FF5812">一般风险</a-tag>
  72. <a-tag v-else-if="record.warnLevel == '103'" color="#FF5812">较大风险</a-tag>
  73. <a-tag v-else-if="record.warnLevel == '104'" color="#FF5812">重大风险</a-tag>
  74. <a-tag v-else-if="record.warnLevel == '201'" color="#FF0000">报警</a-tag>
  75. <a-tag v-else-if="record.warnLevel == '10000'" color="#FF5812">数据超限</a-tag>
  76. <a-tag v-else-if="record.warnLevel == '1001'" color="default">网络中断</a-tag>
  77. <a-tag v-else color="green">正常</a-tag>
  78. </template>
  79. <a-tag v-else-if="column.dataIndex === 'warnFlag'" :color="record.warnFlag == '0' ? 'green' : 'red'">{{
  80. record.warnFlag == '0' ? '正常' : '报警'
  81. }}</a-tag>
  82. <a-tag v-if="column.dataIndex === 'netStatus'" :color="record.netStatus == '0' ? '#f00' : 'green'">{{
  83. record.netStatus == '0' ? '断开' : '连接'
  84. }}</a-tag>
  85. </template>
  86. <template #action="{ record }">
  87. <a v-if="globalConfig?.showReport" class="table-action-link" @click="deviceEdit($event, 'reportInfo', record)">报表录入</a>
  88. <a class="table-action-link" @click="deviceEdit($event, 'deviceInfo', record)">设备编辑</a>
  89. </template>
  90. </MonitorTable>
  91. </a-tab-pane>
  92. <a-tab-pane key="3" tab="历史数据">
  93. <div class="tab-item" v-if="activeKey === '3'">
  94. <HistoryTable :columnsType="deviceType" :device-type="deviceType" designScope="gate-history" :scroll="scroll">
  95. <template #filterCell="{ column, record }">
  96. <a-tag v-if="column.dataIndex === 'frontGateOpen' && record.frontGateOpen == '0' && record.frontGateClose == '0'" color="red"
  97. >正在运行</a-tag
  98. >
  99. <a-tag v-else-if="column.dataIndex === 'frontGateOpen' && record.frontGateOpen == '0' && record.frontGateClose == 1" color="default"
  100. >关闭</a-tag
  101. >
  102. <a-tag
  103. v-else-if="column.dataIndex === 'frontGateOpen' && record.frontGateOpen == '1' && record.frontGateClose == '0'"
  104. color="#46C66F"
  105. >打开</a-tag
  106. >
  107. <a-tag
  108. v-else-if="column.dataIndex === 'frontGateOpen' && record.frontGateOpen == '1' && record.frontGateClose == '1'"
  109. color="#FF0000"
  110. >点位异常</a-tag
  111. >
  112. <template v-else-if="column.dataIndex === 'warnLevel'">
  113. <a-tag v-if="record.warnLevel == '101'" color="green">低风险</a-tag>
  114. <a-tag v-else-if="record.warnLevel == '102'" color="#FF5812">一般风险</a-tag>
  115. <a-tag v-else-if="record.warnLevel == '103'" color="#FF5812">较大风险</a-tag>
  116. <a-tag v-else-if="record.warnLevel == '104'" color="#FF5812">重大风险</a-tag>
  117. <a-tag v-else-if="record.warnLevel == '201'" color="#FF0000">报警</a-tag>
  118. <a-tag v-else-if="record.warnLevel == '10000'" color="#FF5812">数据超限</a-tag>
  119. <a-tag v-else-if="record.warnLevel == '1001'" color="default">网络中断</a-tag>
  120. <a-tag v-else color="green">正常</a-tag>
  121. </template>
  122. </template>
  123. </HistoryTable>
  124. </div>
  125. </a-tab-pane>
  126. <a-tab-pane key="4" tab="报警历史">
  127. <div class="tab-item" v-if="activeKey === '4'">
  128. <AlarmHistoryTable
  129. columns-type="alarm"
  130. :device-type="deviceType"
  131. :device-list-api="getTableList"
  132. designScope="alarm-history"
  133. :scroll="scroll"
  134. >
  135. <template #filterCell="{ column, record }">
  136. <a-tag v-if="column.dataIndex === 'warnFlag'" :color="record.warnFlag == '0' ? 'green' : record.warnFlag == 1 ? '#FF5812' : 'gray'">
  137. {{ record.warnFlag == '0' ? '正常' : record.warnFlag == 1 ? '报警' : record.warnFlag == 2 ? '断开' : '未监测' }}</a-tag
  138. >
  139. <a-tag v-if="column.dataIndex === 'netStatus'" :color="record.netStatus == '0' ? '#f00' : 'green'">{{
  140. record.netStatus == '0' ? '断开' : '连接'
  141. }}</a-tag>
  142. </template>
  143. </AlarmHistoryTable>
  144. </div>
  145. </a-tab-pane>
  146. <a-tab-pane key="5" tab="操作历史">
  147. <div class="tab-item" v-if="activeKey === '5'">
  148. <HandlerHistoryTable
  149. columns-type="operator_history"
  150. :device-type="deviceType"
  151. :device-list-api="getTableList"
  152. designScope="operator_history"
  153. :scroll="scroll"
  154. />
  155. </div>
  156. </a-tab-pane>
  157. </a-tabs>
  158. </dv-border-box8>
  159. </div>
  160. </div>
  161. <div ref="playerRef" style="z-index: 999; position: absolute; top: 100px; right: 15px; width: 300px; height: 280px; margin: auto"> </div>
  162. <HandleModal
  163. v-if="!globalConfig?.simulatedPassword"
  164. :modal-is-show="modalIsShow"
  165. :modal-title="modalTitle"
  166. :modal-type="modalType"
  167. @handle-ok="handleOK"
  168. @handle-cancel="handleCancel"
  169. />
  170. <DeviceBaseInfo @register="registerModal" :device-type="selectData['deviceType']" />
  171. </template>
  172. <script setup lang="ts">
  173. import { onBeforeUnmount, onUnmounted, onMounted, ref, reactive, nextTick, inject, unref } from 'vue';
  174. import MonitorTable from '../comment/MonitorTable.vue';
  175. import HistoryTable from '../comment/HistoryTable.vue';
  176. import AlarmHistoryTable from '../comment/AlarmHistoryTable.vue';
  177. import HandlerHistoryTable from '../comment/HandlerHistoryTable.vue';
  178. import HandleModal from './modal.vue';
  179. import DeviceBaseInfo from '../comment/components/DeviceBaseInfo.vue';
  180. import { deviceControlApi } from '/@/api/vent/index';
  181. import { message } from 'ant-design-vue';
  182. import { list, getTableList } from './deviceMonitor.api';
  183. import lodash from 'lodash';
  184. import { setDivHeight } from '/@/utils/event';
  185. import { BorderBox8 as DvBorderBox8 } from '@kjgl77/datav-vue3';
  186. import { useRouter } from 'vue-router';
  187. import { useModal } from '/@/components/Modal';
  188. import { useCamera } from '/@/hooks/system/useCamera';
  189. import { usePermission } from '/@/hooks/web/usePermission';
  190. import { getDictItems } from '/@/api/common/api';
  191. const { hasPermission } = usePermission();
  192. const globalConfig = inject('globalConfig');
  193. const { currentRoute } = useRouter();
  194. const MonitorDataTable = ref();
  195. let contrlValue = '';
  196. const playerRef = ref();
  197. const deviceType = ref('door');
  198. // const deviceType = ref('firedoor');
  199. const activeKey = ref('1'); // tab
  200. const scroll = reactive({
  201. y: 230,
  202. });
  203. const modelList = ref<{ text: string; value: string }[]>([]);
  204. const doorIsOpen = ref(false); //前门是否开启
  205. const modalIsShow = ref<boolean>(false); // 是否显示模态框
  206. const modalTitle = ref(''); // 模态框标题显示内容,根据设备操作类型决定
  207. const modalType = ref(''); // 模态框内容显示类型,设备操作类型
  208. const selectRowIndex = ref(-1); // 选中行
  209. const dataSource = ref([]);
  210. const deviceBaseList = ref([]); // 设备基本信息
  211. const [registerModal, { openModal, closeModal }] = useModal();
  212. const { getCamera, removeCamera } = useCamera();
  213. const tabChange = (activeKeyVal) => {
  214. activeKey.value = activeKeyVal;
  215. if (activeKeyVal == 1) {
  216. nextTick(() => {
  217. if (MonitorDataTable.value) MonitorDataTable.value.setSelectedRowKeys([selectData.deviceID]);
  218. });
  219. }
  220. };
  221. const initData = {
  222. deviceID: '',
  223. deviceType: '',
  224. strname: '',
  225. frontRearDP: '-', //压差
  226. // sourcePressure: '-', //气源压力
  227. runRoRecondition: null,
  228. autoRoManual: null,
  229. netStatus: '0', //通信状态
  230. frontGateOpen: '0',
  231. frontGateClose: '1',
  232. rearGateOpen: '0',
  233. rearGateClose: '1',
  234. midGateOpen: '0',
  235. midGateClose: '1',
  236. fault: '气源压力超限',
  237. masterComputer: 0,
  238. frontGateOpenCtrl: false,
  239. rearGateOpenCtrl: false,
  240. cameras: [],
  241. };
  242. // 监测数据
  243. const selectData = reactive(lodash.cloneDeep(initData));
  244. function deviceEdit(e: Event, type: string, record) {
  245. e.stopPropagation();
  246. openModal(true, {
  247. type,
  248. deviceId: record['deviceID'],
  249. });
  250. }
  251. // 获取设备基本信息列表
  252. function getDeviceBaseList() {
  253. getTableList({ pageSize: 1000 }).then((res) => {
  254. deviceBaseList.value = res.records;
  255. });
  256. }
  257. // https获取监测数据
  258. let timer: null | NodeJS.Timeout = null;
  259. async function getMonitor(flag?) {
  260. if (Object.prototype.toString.call(timer) === '[object Null]') {
  261. timer = await setTimeout(
  262. async () => {
  263. const res = await list({ devicetype: deviceType.value, pagetype: 'normal' });
  264. if (res.msgTxt && res.msgTxt[0]) {
  265. dataSource.value = res.msgTxt[0].datalist || [];
  266. dataSource.value.forEach((data: any) => {
  267. const readData = data.readData;
  268. data = Object.assign(data, readData);
  269. });
  270. if (dataSource.value.length > 0 && selectRowIndex.value == -1 && MonitorDataTable.value) {
  271. // 初始打开页面
  272. if (currentRoute.value && currentRoute.value['query'] && currentRoute.value['query']['id']) {
  273. MonitorDataTable.value.setSelectedRowKeys([currentRoute.value['query']['id']]);
  274. } else {
  275. MonitorDataTable.value.setSelectedRowKeys([dataSource.value[0]['deviceID']]);
  276. }
  277. }
  278. Object.assign(selectData, dataSource.value[selectRowIndex.value]);
  279. monitorAnimation(selectData);
  280. if (timer) {
  281. timer = null;
  282. }
  283. getMonitor();
  284. }
  285. },
  286. flag ? 0 : 1000
  287. );
  288. }
  289. }
  290. // 切换检测数据
  291. async function getSelectRow(selectRow, index) {
  292. if (!selectRow) return;
  293. selectRowIndex.value = index;
  294. const baseData: any = deviceBaseList.value.find((baseData: any) => baseData.id === selectRow.deviceID);
  295. Object.assign(selectData, initData, selectRow, baseData);
  296. doorDeviceState = 1; //记录设备状态,为了与下一次监测数据做比较
  297. isdoorOpenRunning = true; //开关门动作是否在进行
  298. await getCamera(selectRow.deviceID, playerRef.value);
  299. }
  300. function playAnimation(handlerState, data: any = null) {
  301. const value = data;
  302. switch (handlerState) {
  303. case 1: // 打开前门
  304. modalTitle.value = '打开';
  305. modalType.value = '1';
  306. modalIsShow.value = true;
  307. break;
  308. case 2: // 关闭前门
  309. modalTitle.value = '关闭';
  310. modalType.value = '2';
  311. modalIsShow.value = true;
  312. break;
  313. case 7: // 控制模式切换
  314. modalTitle.value = '控制模式切换';
  315. modalType.value = '7';
  316. modalIsShow.value = true;
  317. break;
  318. }
  319. if (globalConfig?.simulatedPassword) {
  320. handleOK('', handlerState + '');
  321. }
  322. contrlValue = value;
  323. }
  324. function handleOK(passWord, handlerState) {
  325. if (!passWord && !globalConfig?.simulatedPassword) {
  326. message.warning('请输入密码');
  327. return;
  328. }
  329. if (isOpenRunning) {
  330. return;
  331. }
  332. const data = {
  333. deviceid: selectData.deviceID,
  334. devicetype: selectData.deviceType,
  335. paramcode: '',
  336. value: contrlValue,
  337. password: passWord || globalConfig?.simulatedPassword,
  338. masterComputer: selectData.masterComputer,
  339. };
  340. switch (handlerState) {
  341. case '1': // 打开前门
  342. if (selectData.doorOpen == '0' && selectData.doorClose == '1') {
  343. data.paramcode = 'frontGateOpen_S';
  344. }
  345. break;
  346. case '2': // 关闭前门
  347. if (selectData.doorOpen == '1' && selectData.doorClose == '0') {
  348. data.paramcode = 'frontGateClose_S';
  349. }
  350. break;
  351. case '7': // 远程与就地
  352. data.paramcode = 'autoRoManualControl';
  353. data.value = selectData.contrlMod != 'loopCtrl' ? contrlValue : '';
  354. selectData.autoRoManual = null;
  355. }
  356. if (data.paramcode) {
  357. deviceControlApi(data).then((res) => {
  358. // 模拟时开启
  359. if (res.success) {
  360. modalIsShow.value = false;
  361. if (globalConfig.History_Type == 'remote') {
  362. message.success('指令已下发至生产管控平台成功!');
  363. } else {
  364. message.success('指令已下发成功!');
  365. }
  366. } else {
  367. message.error(res.message);
  368. }
  369. });
  370. }
  371. }
  372. let isOpenRunning = false; //开关门动作是否在进行
  373. /** 开关门动画调用 */
  374. let isdoorOpenRunning = false; //开关门动作是否在进行
  375. // let isMidCloseRunning = false; //中间门动作是否在进行
  376. // 0 关闭 1 正在打开 2 打开 3正在关闭
  377. let doorDeviceState = 1; //记录设备状态,为了与下一次监测数据做比较
  378. function monitorAnimation(selectData) {
  379. const timeScale = 0.005;
  380. // 打开
  381. if (selectData.frontGateOpen == '1' && !isdoorOpenRunning) {
  382. isdoorOpenRunning = true;
  383. if (doorDeviceState != 1) {
  384. doorDeviceState = 1;
  385. doorIsOpen.value = true;
  386. }
  387. }
  388. // 关闭
  389. if (selectData.frontGateOpen == '0' && isdoorOpenRunning) {
  390. isdoorOpenRunning = false;
  391. if (doorDeviceState != 0) {
  392. doorDeviceState = 0;
  393. doorIsOpen.value = false;
  394. }
  395. }
  396. }
  397. function handleCancel() {
  398. modalIsShow.value = false;
  399. modalTitle.value = '';
  400. modalType.value = '';
  401. selectData.autoRoManual = null;
  402. }
  403. onMounted(async () => {
  404. const { query } = unref(currentRoute);
  405. if (query['deviceType']) deviceType.value = query['deviceType'] as string;
  406. modelList.value = await getDictItems('fireDoorModel');
  407. });
  408. onBeforeUnmount(() => {
  409. getDeviceBaseList();
  410. });
  411. onUnmounted(() => {
  412. removeCamera();
  413. if (timer) {
  414. clearTimeout(timer);
  415. timer = undefined;
  416. }
  417. });
  418. </script>
  419. ,
  420. <style lang="less" scoped>
  421. @import '/@/design/vent/modal.less';
  422. .scene-box {
  423. .bottom-tabs-box {
  424. height: 300px;
  425. }
  426. }
  427. .button-box {
  428. border: none !important;
  429. height: 34px !important;
  430. &:hover {
  431. background: linear-gradient(#2cd1ff55, #1eb0ff55) !important;
  432. }
  433. &::before {
  434. height: 27px !important;
  435. background: linear-gradient(#1fa6cb, #127cb5) !important;
  436. }
  437. &::after {
  438. top: 35px !important;
  439. }
  440. }
  441. :deep(.@{ventSpace}-tabs-tabpane-active) {
  442. height: 100%;
  443. }
  444. ::-webkit-scrollbar-thumb {
  445. -webkit-box-shadow: inset 0 0 5px rgba(0, 0, 0, 0.2);
  446. background: #4288a444;
  447. }
  448. :deep(.zxm-radio-disabled + span) {
  449. color: #fff !important;
  450. }
  451. :deep(.zxm-radio-disabled .zxm-radio-inner::after) {
  452. background-color: #127cb5 !important;
  453. }
  454. </style>