home.vue 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315
  1. <template>
  2. <div class="home">
  3. <headComponent></headComponent>
  4. <notice v-if="noticeShowType" :noticeProps="noticeProps"></notice>
  5. <div class="home-page" v-if="!noticeShowType">
  6. <div class="home-left-box">
  7. <left-top></left-top>
  8. <left-bottom></left-bottom>
  9. </div>
  10. <div class="home-center-box">
  11. <center-top></center-top>
  12. <center-center></center-center>
  13. <div style="display: flex;">
  14. <center-bottom-left></center-bottom-left>
  15. <center-bottom-right></center-bottom-right>
  16. </div>
  17. </div>
  18. <div class="home-right-box">
  19. <right></right>
  20. </div>
  21. </div>
  22. <baseComponent></baseComponent>
  23. <alarmComponent v-if="alarmType" :alarmData="alarmData"></alarmComponent>
  24. </div>
  25. </template>
  26. <script>
  27. import mqtt from 'mqtt'
  28. import {
  29. laboratoryBigViewSelectTriggerInfo,
  30. iotSensorFindBySubId,
  31. iotCameraFindByCondition
  32. } from "@/api/index";
  33. import { dashboardsResearchUsage,dashboardsNotice } from "@/api/yiLi";
  34. import { getFloorMaps } from '@/utils/mapList'
  35. //head组件
  36. import headComponent from './components/headComponent.vue'
  37. import baseComponent from './components/baseComponent.vue'
  38. import leftTop from './components/left-top.vue'
  39. import leftBottom from './components/left-bottom.vue'
  40. import centerTop from './components/center-top.vue'
  41. import centerCenter from './components/center-center.vue'
  42. import centerBottomLeft from './components/center-bottom-left.vue'
  43. import centerBottomRight from './components/center-bottom-right.vue'
  44. import right from './components/right.vue'
  45. import notice from './components/notice.vue'
  46. //报警弹窗
  47. import alarmComponent from './components/subcomponent/alarmComponent.vue'
  48. export default {
  49. name: 'home',
  50. components: {
  51. headComponent,
  52. baseComponent,
  53. leftTop,
  54. leftBottom,
  55. centerTop,
  56. centerCenter,
  57. centerBottomLeft,
  58. centerBottomRight,
  59. right,
  60. notice,
  61. alarmComponent
  62. },
  63. data () {
  64. return {
  65. //预案MQTT
  66. planOpic:'lab/risk/plan/change',
  67. planClient:{},
  68. roomList:[],
  69. alarmType:false,
  70. alarmData:null,
  71. //预案查询定时器
  72. alarmTimer:null,
  73. //预案查询定时
  74. alarmSwitchTime:60000,
  75. //通知查询定时器
  76. noticeTimer:null,
  77. //通知查询定时
  78. noticeSwitchTime:600000,
  79. noticeShowType:false,
  80. //通知数据
  81. noticeProps:{},
  82. }
  83. },
  84. created(){
  85. },
  86. mounted(){
  87. this.offPlanMQTT('on');
  88. this.laboratoryBigViewSelectTriggerInfo();
  89. //开启预案定时查询
  90. this.alarmTimerFunction();
  91. //开启定时通知查询
  92. this.getDataTimerFunction();
  93. },
  94. methods:{
  95. getDataTimerFunction(){
  96. clearInterval(this.noticeTimer)
  97. this.dashboardsNotice();
  98. this.noticeTimer = window.setInterval(() => {
  99. if(this.noticeShowType){
  100. this.$set(this,'noticeShowType',false);
  101. }else{
  102. this.dashboardsNotice();
  103. }
  104. }, this.noticeSwitchTime);
  105. },
  106. //定时获取通知
  107. dashboardsNotice(){
  108. dashboardsNotice().then(res => {
  109. if(res.data){
  110. this.$set(this,'noticeProps',res.data[0]);
  111. this.$set(this,'noticeShowType',true);
  112. }
  113. })
  114. },
  115. /*************** 获取报警相关 ***************/
  116. laboratoryBigViewSelectTriggerInfo(){
  117. laboratoryBigViewSelectTriggerInfo().then(res => {
  118. let alarmRoom = getFloorMaps(res.data);
  119. if(alarmRoom[0]){
  120. this.dashboardsResearchUsage(alarmRoom);
  121. }else{
  122. this.$set(this,'alarmType',false);
  123. this.$set(this,'alarmData',null);
  124. }
  125. })
  126. },
  127. //获取房间数据
  128. dashboardsResearchUsage(list){
  129. dashboardsResearchUsage('roomNames='+list[0].roomNumName).then(res => {
  130. let obj = list[0];
  131. obj.list = JSON.parse(JSON.stringify(list));
  132. if(res.data[0]){
  133. obj = {...obj,...res.data[0]};
  134. obj.status = obj.runningStateName == '维修' ? '3':(obj.stateName == '租用'?'2':'1')
  135. if(obj.userName){
  136. if(obj.userName('-') != -1) {
  137. obj.userName = obj.userName.split('-')[0]
  138. }
  139. }
  140. if(obj.headName){
  141. if(obj.headName('-') != -1) {
  142. obj.headName = obj.headName.split('-')[0]
  143. }
  144. }
  145. //假数据
  146. // obj.monitorVisable = true;
  147. // obj.subId = '1955554621449019392';
  148. this.iotSensorFindBySubId(obj);
  149. }
  150. });
  151. },
  152. //查询传感器
  153. iotSensorFindBySubId(obj){
  154. let self = this;
  155. iotSensorFindBySubId({subId:obj.subId}).then(response => {
  156. obj.sensor = [];
  157. for(let i=0;i<obj.alarmData.triggerUploadData.length;i++){
  158. for(let o=0;o<response.data.length;o++){
  159. if(obj.alarmData.triggerUploadData[i].deviceNo == response.data[o].deviceNo){
  160. response.data[i].icon = response.data[i].icon?localStorage.getItem('fileBrowseEnvironment')+response.data[i].icon:null;
  161. // response.data[i].icon = 'http://192.168.1.8/statics/2025/08/25/9eec5108-2702-4ed0-942a-aced71fd1f57.svg';
  162. obj.sensor.push(response.data[i])
  163. }
  164. }
  165. }
  166. obj.videoList = [];
  167. //查询实验室监控
  168. if(obj.monitorVisable){
  169. let videoObj = {
  170. page:'1',
  171. pageSize:'10',
  172. buildId:'',
  173. floorId:'',
  174. passageway:'',
  175. subIds:[obj.subId],
  176. protocol:window.location.href.indexOf('https') !== -1?'wss':'ws',
  177. streamType:1,
  178. source:1,
  179. };
  180. iotCameraFindByCondition(videoObj).then(response => {
  181. for(let i=0;i<response.data.records.length;i++){
  182. obj.videoList.push(
  183. {
  184. fullShow:true,
  185. width: 708, //(宽度:非必传-默认600)
  186. height: 450, //(高度:非必传-默认338)
  187. url: response.data.records[i].streamUrl,
  188. cameraIndexCode: response.data.records[i].deviceNo,
  189. }
  190. )
  191. }
  192. self.$set(self,'alarmType',true);
  193. self.$set(self,'alarmData',obj);
  194. });
  195. }else{
  196. self.$set(self,'alarmType',true);
  197. self.$set(self,'alarmData',obj);
  198. }
  199. });
  200. },
  201. //预案查询定时器
  202. alarmTimerFunction(){
  203. const self = this;
  204. self.alarmTimer = window.setInterval(() => {
  205. checkAlarmUpdates();
  206. }, this.alarmSwitchTime);
  207. async function checkAlarmUpdates() {
  208. self.laboratoryBigViewSelectTriggerInfo();
  209. }
  210. },
  211. //预案-MQTT连接
  212. offPlanMQTT(type){
  213. let self = this;
  214. if(self.planClient.unsubscribe){
  215. self.planClient.unsubscribe(self.planOpic, error => {
  216. if (error) {
  217. // console.log('mqtt关闭连接错误:', error)
  218. }
  219. })
  220. self.planClient.end();
  221. this.$set(this,'planClient',{});
  222. }
  223. //判断传入参数如果存在 发起一次新的连接
  224. if(type){
  225. this.planMQTT();
  226. }
  227. },
  228. //预案-MQTT订阅
  229. planMQTT(){
  230. let self = this;
  231. this.planClient = mqtt.connect(localStorage.getItem('mqttUrl'), {
  232. username: localStorage.getItem('mqttUser'),
  233. password:localStorage.getItem('mqttPassword')
  234. });
  235. this.planClient.on("connect", e =>{
  236. this.planClient.subscribe(self.planOpic, (err) => {
  237. if (!err) {
  238. console.log("预案-订阅成功:" + self.planOpic);
  239. }else{
  240. // console.log("预案-连接错误:" + err);
  241. }
  242. });
  243. });
  244. this.planClient.on("message", (topic, message) => {
  245. if (message){
  246. console.log('MQTTmessage',message);
  247. //获取预案数据
  248. this.laboratoryBigViewSelectTriggerInfo();
  249. }
  250. });
  251. },
  252. },
  253. beforeDestroy() {
  254. clearInterval(this.alarmTimer);
  255. clearInterval(this.noticeTimer)
  256. //清除MQTT
  257. this.offPlanMQTT();
  258. },
  259. destroyed() {
  260. clearInterval(this.alarmTimer);
  261. clearInterval(this.noticeTimer)
  262. //清除MQTT
  263. this.offPlanMQTT();
  264. }
  265. }
  266. </script>
  267. <style scoped lang="scss">
  268. .home{
  269. /*width: 3072px;*/
  270. /*height: 1660px;*/
  271. /*分辨率调整*/
  272. width: 3840px;
  273. height: 2160px;
  274. flex:1;
  275. display: flex;
  276. flex-direction: column;
  277. position: relative;
  278. background-color: #020B15;
  279. background-image: url("../assets/ZDimages/dbg@1x.png");
  280. background-size: 100% 100%;
  281. .home-page{
  282. flex:1;
  283. overflow: hidden;
  284. display: flex;
  285. .home-left-box{
  286. display: flex;
  287. flex-direction: column;
  288. overflow: hidden;
  289. width: 950px;
  290. margin:0 0 0 46px;
  291. /*background-color: #8a6d3b;*/
  292. }
  293. .home-center-box{
  294. display: flex;
  295. flex-direction: column;
  296. overflow: hidden;
  297. width: 1757px;
  298. margin:0 46px;
  299. padding-top:18px;
  300. /*background-color: #13ce66;*/
  301. }
  302. .home-right-box{
  303. display: flex;
  304. flex-direction: column;
  305. overflow: hidden;
  306. width: 950px;
  307. margin:0 46px 0 0;
  308. /*background-color: #2f54eb;*/
  309. }
  310. }
  311. }
  312. </style>