index.vue 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498
  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. @select-row="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
  162. v-if="renderPlayer"
  163. ref="playerRef"
  164. style="
  165. z-index: 999;
  166. position: absolute;
  167. top: 100px;
  168. right: 15px;
  169. width: 100%;
  170. height: 800px;
  171. margin: auto;
  172. pointer-events: none;
  173. overflow-y: auto;
  174. flex-direction: column;
  175. "
  176. >
  177. </div>
  178. <HandleModal
  179. v-if="!globalConfig?.simulatedPassword"
  180. :modal-is-show="modalIsShow"
  181. :modal-title="modalTitle"
  182. :modal-type="modalType"
  183. @handle-ok="handleOK"
  184. @handle-cancel="handleCancel"
  185. />
  186. <DeviceBaseInfo @register="registerModal" :device-type="selectData['deviceType']" />
  187. </template>
  188. <script setup lang="ts">
  189. import { onBeforeUnmount, onUnmounted, onMounted, ref, reactive, nextTick, inject, unref } from 'vue';
  190. import MonitorTable from '../comment/MonitorTable.vue';
  191. import HistoryTable from '../comment/HistoryTable.vue';
  192. import AlarmHistoryTable from '../comment/AlarmHistoryTable.vue';
  193. import HandlerHistoryTable from '../comment/HandlerHistoryTable.vue';
  194. import HandleModal from './modal.vue';
  195. import DeviceBaseInfo from '../comment/components/DeviceBaseInfo.vue';
  196. import { deviceControlApi } from '/@/api/vent/index';
  197. import { message } from 'ant-design-vue';
  198. import { list, getTableList } from './deviceMonitor.api';
  199. import lodash from 'lodash';
  200. import { setDivHeight } from '/@/utils/event';
  201. import { BorderBox8 as DvBorderBox8 } from '@kjgl77/datav-vue3';
  202. import { useRouter } from 'vue-router';
  203. import { useModal } from '/@/components/Modal';
  204. import { useCamera } from '/@/hooks/system/useCamera';
  205. import { usePermission } from '/@/hooks/web/usePermission';
  206. import { getDictItems } from '/@/api/common/api';
  207. const { hasPermission } = usePermission();
  208. const globalConfig = inject('globalConfig');
  209. const { currentRoute } = useRouter();
  210. const MonitorDataTable = ref();
  211. let contrlValue = '';
  212. const playerRef = ref();
  213. const renderPlayer = ref(true);
  214. const deviceType = ref('door');
  215. // const deviceType = ref('firedoor');
  216. const activeKey = ref('1'); // tab
  217. const scroll = reactive({
  218. y: 230,
  219. });
  220. const modelList = ref<{ text: string; value: string }[]>([]);
  221. const doorIsOpen = ref(false); //前门是否开启
  222. const modalIsShow = ref<boolean>(false); // 是否显示模态框
  223. const modalTitle = ref(''); // 模态框标题显示内容,根据设备操作类型决定
  224. const modalType = ref(''); // 模态框内容显示类型,设备操作类型
  225. const selectRowIndex = ref(-1); // 选中行
  226. const dataSource = ref([]);
  227. const deviceBaseList = ref([]); // 设备基本信息
  228. const [registerModal, { openModal, closeModal }] = useModal();
  229. const { getCamera, removeCamera } = useCamera();
  230. const tabChange = (activeKeyVal) => {
  231. activeKey.value = activeKeyVal;
  232. if (activeKeyVal == 1) {
  233. nextTick(() => {
  234. if (MonitorDataTable.value) MonitorDataTable.value.setSelectedRowKeys([selectData.deviceID]);
  235. });
  236. }
  237. };
  238. const initData = {
  239. deviceID: '',
  240. deviceType: '',
  241. strname: '',
  242. frontRearDP: '-', //压差
  243. // sourcePressure: '-', //气源压力
  244. runRoRecondition: null,
  245. autoRoManual: null,
  246. netStatus: '0', //通信状态
  247. frontGateOpen: '0',
  248. frontGateClose: '1',
  249. rearGateOpen: '0',
  250. rearGateClose: '1',
  251. midGateOpen: '0',
  252. midGateClose: '1',
  253. fault: '气源压力超限',
  254. masterComputer: 0,
  255. frontGateOpenCtrl: false,
  256. rearGateOpenCtrl: false,
  257. cameras: [],
  258. };
  259. // 监测数据
  260. const selectData = reactive(lodash.cloneDeep(initData));
  261. function deviceEdit(e: Event, type: string, record) {
  262. e.stopPropagation();
  263. openModal(true, {
  264. type,
  265. deviceId: record['deviceID'],
  266. });
  267. }
  268. // 获取设备基本信息列表
  269. function getDeviceBaseList() {
  270. getTableList({ pageSize: 1000 }).then((res) => {
  271. deviceBaseList.value = res.records;
  272. });
  273. }
  274. // https获取监测数据
  275. let timer: null | NodeJS.Timeout = null;
  276. async function getMonitor(flag?) {
  277. if (Object.prototype.toString.call(timer) === '[object Null]') {
  278. timer = await setTimeout(
  279. async () => {
  280. const res = await list({ devicetype: deviceType.value, pagetype: 'normal' });
  281. if (res.msgTxt && res.msgTxt[0]) {
  282. dataSource.value = res.msgTxt[0].datalist || [];
  283. dataSource.value.forEach((data: any) => {
  284. const readData = data.readData;
  285. data = Object.assign(data, readData);
  286. });
  287. if (dataSource.value.length > 0 && selectRowIndex.value == -1 && MonitorDataTable.value) {
  288. // 初始打开页面
  289. if (currentRoute.value && currentRoute.value['query'] && currentRoute.value['query']['id']) {
  290. MonitorDataTable.value.setSelectedRowKeys([currentRoute.value['query']['id']]);
  291. } else {
  292. MonitorDataTable.value.setSelectedRowKeys([dataSource.value[0]['deviceID']]);
  293. }
  294. }
  295. Object.assign(selectData, dataSource.value[selectRowIndex.value]);
  296. monitorAnimation(selectData);
  297. if (timer) {
  298. timer = null;
  299. }
  300. getMonitor();
  301. }
  302. },
  303. flag ? 0 : 1000
  304. );
  305. }
  306. }
  307. // 切换检测数据
  308. async function getSelectRow(selectRow, index) {
  309. if (!selectRow) return;
  310. selectRowIndex.value = index;
  311. const baseData: any = deviceBaseList.value.find((baseData: any) => baseData.id === selectRow.deviceID);
  312. Object.assign(selectData, initData, selectRow, baseData);
  313. doorDeviceState = 1; //记录设备状态,为了与下一次监测数据做比较
  314. isdoorOpenRunning = true; //开关门动作是否在进行
  315. await getCamera(selectRow.deviceID, playerRef, renderPlayer);
  316. }
  317. function playAnimation(handlerState, data: any = null) {
  318. const value = data;
  319. switch (handlerState) {
  320. case 1: // 打开前门
  321. modalTitle.value = '打开';
  322. modalType.value = '1';
  323. modalIsShow.value = true;
  324. break;
  325. case 2: // 关闭前门
  326. modalTitle.value = '关闭';
  327. modalType.value = '2';
  328. modalIsShow.value = true;
  329. break;
  330. case 7: // 控制模式切换
  331. modalTitle.value = '控制模式切换';
  332. modalType.value = '7';
  333. modalIsShow.value = true;
  334. break;
  335. }
  336. if (globalConfig?.simulatedPassword) {
  337. handleOK('', handlerState + '');
  338. }
  339. contrlValue = value;
  340. }
  341. function handleOK(passWord, handlerState) {
  342. if (!passWord && !globalConfig?.simulatedPassword) {
  343. message.warning('请输入密码');
  344. return;
  345. }
  346. if (isOpenRunning) {
  347. return;
  348. }
  349. const data = {
  350. deviceid: selectData.deviceID,
  351. devicetype: selectData.deviceType,
  352. paramcode: '',
  353. value: contrlValue,
  354. password: passWord || globalConfig?.simulatedPassword,
  355. masterComputer: selectData.masterComputer,
  356. };
  357. switch (handlerState) {
  358. case '1': // 打开前门
  359. if (selectData.doorOpen == '0' && selectData.doorClose == '1') {
  360. data.paramcode = 'frontGateOpen_S';
  361. }
  362. break;
  363. case '2': // 关闭前门
  364. if (selectData.doorOpen == '1' && selectData.doorClose == '0') {
  365. data.paramcode = 'frontGateClose_S';
  366. }
  367. break;
  368. case '7': // 远程与就地
  369. data.paramcode = 'autoRoManualControl';
  370. data.value = selectData.contrlMod != 'loopCtrl' ? contrlValue : '';
  371. selectData.autoRoManual = null;
  372. }
  373. if (data.paramcode) {
  374. deviceControlApi(data).then((res) => {
  375. // 模拟时开启
  376. if (res.success) {
  377. modalIsShow.value = false;
  378. if (globalConfig.History_Type == 'remote') {
  379. message.success('指令已下发至生产管控平台成功!');
  380. } else {
  381. message.success('指令已下发成功!');
  382. }
  383. } else {
  384. message.error(res.message);
  385. }
  386. });
  387. }
  388. }
  389. let isOpenRunning = false; //开关门动作是否在进行
  390. /** 开关门动画调用 */
  391. let isdoorOpenRunning = false; //开关门动作是否在进行
  392. // let isMidCloseRunning = false; //中间门动作是否在进行
  393. // 0 关闭 1 正在打开 2 打开 3正在关闭
  394. let doorDeviceState = 1; //记录设备状态,为了与下一次监测数据做比较
  395. function monitorAnimation(selectData) {
  396. const timeScale = 0.005;
  397. // 打开
  398. if (selectData.frontGateOpen == '1' && !isdoorOpenRunning) {
  399. isdoorOpenRunning = true;
  400. if (doorDeviceState != 1) {
  401. doorDeviceState = 1;
  402. doorIsOpen.value = true;
  403. }
  404. }
  405. // 关闭
  406. if (selectData.frontGateOpen == '0' && isdoorOpenRunning) {
  407. isdoorOpenRunning = false;
  408. if (doorDeviceState != 0) {
  409. doorDeviceState = 0;
  410. doorIsOpen.value = false;
  411. }
  412. }
  413. }
  414. function handleCancel() {
  415. modalIsShow.value = false;
  416. modalTitle.value = '';
  417. modalType.value = '';
  418. selectData.autoRoManual = null;
  419. }
  420. onMounted(async () => {
  421. const { query } = unref(currentRoute);
  422. if (query['deviceType']) deviceType.value = query['deviceType'] as string;
  423. modelList.value = await getDictItems('fireDoorModel');
  424. });
  425. onBeforeUnmount(() => {
  426. removeCamera(playerRef);
  427. getDeviceBaseList();
  428. });
  429. onUnmounted(() => {
  430. if (timer) {
  431. clearTimeout(timer);
  432. timer = undefined;
  433. }
  434. });
  435. </script>
  436. ,
  437. <style lang="less" scoped>
  438. @import '/@/design/vent/modal.less';
  439. .scene-box {
  440. .bottom-tabs-box {
  441. height: 300px;
  442. }
  443. }
  444. .button-box {
  445. border: none !important;
  446. height: 34px !important;
  447. &:hover {
  448. background: linear-gradient(#2cd1ff55, #1eb0ff55) !important;
  449. }
  450. &::before {
  451. height: 27px !important;
  452. background: linear-gradient(#1fa6cb, #127cb5) !important;
  453. }
  454. &::after {
  455. top: 35px !important;
  456. }
  457. }
  458. :deep(.@{ventSpace}-tabs-tabpane-active) {
  459. height: 100%;
  460. }
  461. ::-webkit-scrollbar-thumb {
  462. -webkit-box-shadow: inset 0 0 5px rgba(0, 0, 0, 0.2);
  463. background: #4288a444;
  464. }
  465. :deep(.zxm-radio-disabled + span) {
  466. color: #fff !important;
  467. }
  468. :deep(.zxm-radio-disabled .zxm-radio-inner::after) {
  469. background-color: #127cb5 !important;
  470. }
  471. </style>