AppMain.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397
  1. <template>
  2. <section class="app-main">
  3. <div class="app-main-top-text-box" v-if="textType">
  4. <p>{{text}}</p>
  5. <p @click="buttonClick">查看</p>
  6. <p v-if="closePlan">丨</p>
  7. <p v-if="closePlan" @click="offButton">结束预案</p>
  8. </div>
  9. <div class="app-main-top-text-box-two" :class="workType == 1?'work-color-a':(workType == 2?'work-color-b':'')" v-if="!textType&&(workType == 1 || workType == 2)">
  10. <p>{{textWork}}</p>
  11. <p @click="goWorkPage">立即完成</p>
  12. <p class="el-icon-circle-close" @click="workClickOff"></p>
  13. </div>
  14. <transition name="fade-transform" mode="out-in">
  15. <!--<keep-alive :include="cachedViews">-->
  16. <router-view :key="key" />
  17. <!--</keep-alive>-->
  18. </transition>
  19. </section>
  20. </template>
  21. <script>
  22. import { getListStatus,closeRiskPlan } from '@/api/bigData/index.js'
  23. import { selectTriggerInfo} from '@/api/evacuationBigData/index.js'
  24. import store from '@/store'
  25. import mqtt from 'mqtt'
  26. export default {
  27. name: 'AppMain',
  28. computed: {
  29. cachedViews() {
  30. return this.$store.state.tagsView.cachedViews
  31. },
  32. key() {
  33. return this.$route.path
  34. }
  35. },
  36. data() {
  37. return {
  38. //MQTT请求参数-传感器
  39. mtopic:"lab/riskPlan/trigger/notice",
  40. mtopicTwo:"manage/work"+localStorage.getItem('userId'),
  41. textType:false,
  42. closePlan:false,
  43. text:"",
  44. textWork:"",
  45. workType:"",
  46. userType:"",
  47. buttonId:"",
  48. buildingId:"",
  49. address:"",
  50. buildId:null,
  51. floorId:null,
  52. subId:null,
  53. groupId:null,
  54. }
  55. },
  56. created() {
  57. // this.getListStatus();
  58. },
  59. mounted(){
  60. this.userType = localStorage.getItem('userType')
  61. if(this.userType != 22){
  62. this.selectTriggerInfo();
  63. this.subscriptionMQTT();
  64. }
  65. },
  66. methods:{
  67. workClickOff(){
  68. this.workType = "";
  69. },
  70. goWorkPage(){
  71. let self = this;
  72. const h = this.$createElement;
  73. this.$msgbox({
  74. title: '',
  75. message: h('p', null, [
  76. h('p', { style:'font-size:16px;margin:20px 0;' }, self.textWork),
  77. ]),
  78. showCancelButton: true,
  79. confirmButtonText: '完成',
  80. cancelButtonText: '取消',
  81. beforeClose: (action, instance, done) => {
  82. if (action === 'confirm') {
  83. //执行
  84. this.$router.push({
  85. path: "/laboratory/gradeManageWork"
  86. })
  87. done();
  88. } else {
  89. //取消
  90. done();
  91. }
  92. }
  93. }).then(action => {
  94. //成功回掉
  95. });
  96. },
  97. //MQTT订阅
  98. subscriptionMQTT(){
  99. let self = this;
  100. this.client = mqtt.connect(localStorage.getItem('mqttUrl'), {
  101. username: localStorage.getItem('mqttUser'),
  102. password: localStorage.getItem('mqttPassword')
  103. });
  104. this.client.on("connect", e =>{
  105. console.log("连接成功");
  106. this.client.subscribe(this.mtopic, (err) => {
  107. if (!err) {
  108. console.log("警报通道订阅成功:" + this.mtopic);
  109. }
  110. });
  111. this.client.subscribe(this.mtopicTwo, (err) => {
  112. if (!err) {
  113. console.log("工作通道订阅成功:" + this.mtopicTwo);
  114. }
  115. });
  116. });
  117. this.client.on("message", (topic, message) => {
  118. if (message){
  119. console.log("topic",topic);
  120. let data = JSON.parse(message)
  121. console.log("data",data);
  122. if(topic == this.mtopic){
  123. //报警
  124. // this.getListStatus();
  125. store.dispatch('settings/setPlanData', data)
  126. self.selectTriggerInfo();
  127. }
  128. if(topic == this.mtopicTwo){
  129. //工作通知
  130. console.log("工作通知",data);
  131. this.textWork = data.msg;
  132. this.workType = data.type;
  133. }
  134. }
  135. });
  136. },
  137. //结束预案
  138. closeRiskPlan(){
  139. closeRiskPlan({id:this.groupId}).then(response => {
  140. this.msgSuccess("操作成功");
  141. this.getListStatus();
  142. });
  143. },
  144. //查询报警信息
  145. async getListStatus(){
  146. let self = this;
  147. const { data } = await getListStatus();
  148. // console.log("getListStatusgetListStatusgetListStatusgetListStatus",data);
  149. if(data.code==200){
  150. if(data.data[0]){
  151. if(data.data[0].floorId != 7){
  152. self.text = data.data[0].buildName + data.data[0].floorName + data.data[0].roomName + data.data[0].subjectName + '发生应急预案';
  153. self.textName = data.data[0].subjectName;
  154. self.subjectId = data.data[0].subjectId;
  155. self.textType = self.userType != '22';
  156. self.closePlan =data.data[0].closePlan;
  157. self.closeId = data.data[0].id;
  158. self.buttonId = data.data[0].floorId;
  159. self.buildingId = data.data[0].buildId;
  160. self.address = data.data[0].deptName +'-'+data.data[0].buildName+''+data.data[0].floorName;
  161. }
  162. }
  163. }
  164. },
  165. //结束预案
  166. offButton(){
  167. let self = this;
  168. this.$confirm('确定要结束预案吗?', "警告", {
  169. confirmButtonText: "确定",
  170. cancelButtonText: "取消",
  171. type: "warning"
  172. }).then(function() {
  173. self.closeRiskPlan();
  174. }).then(() => {
  175. }).catch(() => {});
  176. },
  177. //执行按钮
  178. buttonClick(){
  179. let self = this;
  180. if(this.$route.path == '/emergencyManagement/newPerformEvacuation'){
  181. return
  182. }
  183. const h = this.$createElement;
  184. this.$msgbox({
  185. title: '',
  186. message: h('p', null, [
  187. h('i', { style: 'color: #ea9518;font-size:100px;' ,class:"el-icon-warning-outline"}),
  188. h('p', { style:'font-size:16px;margin:20px 0;' }, self.text+',是否立即查看? '),
  189. ]),
  190. showCancelButton: true,
  191. confirmButtonText: '查看',
  192. cancelButtonText: '取消',
  193. beforeClose: (action, instance, done) => {
  194. if (action === 'confirm') {
  195. //执行
  196. this.$router.push({
  197. path: "/emergencyManagement/newPerformEvacuation",
  198. query: {
  199. buildId: self.buildId,
  200. floorId:self.floorId,
  201. subId:self.subId,
  202. }
  203. })
  204. done();
  205. } else {
  206. // this.$router.push({
  207. // path: "/emergencyEvacuationBig",
  208. // query: {
  209. // subId: self.subjectId,
  210. // text:self.textName,
  211. // buttonId:self.buttonId,
  212. // buildingId:self.buildingId,
  213. // address:self.address,
  214. // type:"2",
  215. // }
  216. // })
  217. //取消
  218. done();
  219. }
  220. }
  221. }).then(action => {
  222. //成功回掉
  223. });
  224. },
  225. //查询当前用户下的预案触发数据
  226. selectTriggerInfo(){
  227. let self = this;
  228. selectTriggerInfo().then(response => {
  229. if(response.data[0]){
  230. this.$set(this,'text',response.data.length>1?'有多个实验室发生预案':'有实验室发生预案');
  231. this.$set(this,'buildId',response.data[0].buildId);
  232. this.$set(this,'floorId',response.data[0].floorId);
  233. this.$set(this,'subId',response.data[0].subId);
  234. this.$set(this,'groupId',response.data[0].groupId);
  235. if(response.data[0].riskAttribute == 1){
  236. this.$set(this,'closePlan',true);
  237. }
  238. this.$set(this,'textType',true);
  239. //没有火焰预案并且没有查看过
  240. for(let i=0;i<response.data.length;i++){
  241. if(response.data[i].riskAttribute != '1'&&response.data[i].ifCheck != '1'){
  242. console.log('跳转2',self.$route.path);
  243. //如果就在应急预案页面责终止跳转
  244. if(self.$route.path == '/emergencyManagement/newPerformEvacuation' || self.$route.path == '/newEvacuationBigData'){
  245. return
  246. }
  247. this.$router.push({
  248. path: "/emergencyManagement/newPerformEvacuation",
  249. query: {
  250. buildId: response.data[i].buildId,
  251. floorId:response.data[i].floorId,
  252. subId:response.data[i].subId,
  253. groupId:response.data[i].groupId,
  254. }
  255. })
  256. return
  257. }
  258. }
  259. }else{
  260. this.$set(this,'textType',false);
  261. }
  262. })
  263. },
  264. }
  265. }
  266. </script>
  267. <style lang="scss" scoped>
  268. .app-main {
  269. /* 50= navbar 50 */
  270. /*min-height: calc(100vh - 50px);*/
  271. width: 100%;
  272. position: relative;
  273. overflow: hidden;
  274. display: flex;
  275. flex-direction: column;
  276. }
  277. .work-color-a{
  278. background: rgba(30,144,255,0.2);
  279. p{
  280. color:#0045AF;
  281. }
  282. }
  283. .work-color-b{
  284. background: rgba(255,0,0,0.2);
  285. p{
  286. color:#FF0000;
  287. }
  288. }
  289. .app-main-top-text-box-two{
  290. margin:10px 20px 0 10px;
  291. border-radius:10px;
  292. padding:0 0 0 20px;
  293. display: flex;
  294. p{
  295. line-height:60px;
  296. font-size:16px;
  297. margin:0;
  298. }
  299. p:nth-child(1){
  300. flex:1;
  301. }
  302. p:nth-child(2){
  303. width:100px;
  304. cursor: pointer;
  305. }
  306. p:nth-child(3){
  307. font-size:22px;
  308. margin-right:20px;
  309. cursor: pointer;
  310. }
  311. }
  312. .app-main-top-text-box{
  313. background: rgba(255,0,0,0.2);
  314. margin:10px 20px 0 10px;
  315. border-radius:10px;
  316. padding:0 0 0 20px;
  317. display: flex;
  318. p{
  319. line-height:60px;
  320. font-size:16px;
  321. margin:0;
  322. }
  323. p:nth-child(1){
  324. flex:1;
  325. color:#FF0000;
  326. }
  327. p:nth-child(2){
  328. width:100px;
  329. color:#0045AF;
  330. cursor: pointer;
  331. text-align: center;
  332. }
  333. p:nth-child(3){
  334. color:#0045AF;
  335. text-align: center;
  336. width:30px;
  337. font-weight:500;
  338. }
  339. p:nth-child(4){
  340. width:100px;
  341. color:#0045AF;
  342. cursor: pointer;
  343. text-align: center;
  344. }
  345. }
  346. .app-main-position-max-box{
  347. position: fixed;
  348. height:100%;
  349. width:100%;
  350. background: rgba(0,0,0,0.2);
  351. z-index: 100;
  352. .app-main-position-big-box{
  353. .app-main-position-box{
  354. position: absolute;
  355. top: 50%;
  356. left: 50%;
  357. background: #fff;
  358. width:500px;
  359. height:300px;
  360. margin-left:-250px;
  361. margin-top:-150px;
  362. border-radius:10px;
  363. box-shadow: 0 0 8px 2px rgba(0, 0, 0, 0.1);
  364. .app-main-position-box-bottom-button-box{
  365. display: flex;
  366. }
  367. }
  368. }
  369. }
  370. .fixed-header+.app-main {
  371. padding-top: 50px;
  372. }
  373. .hasTagsView {
  374. .app-main {
  375. /* 84 = navbar + tags-view = 50 + 34 */
  376. /*min-height: calc(100vh - 84px);*/
  377. }
  378. .fixed-header+.app-main {
  379. padding-top: 84px;
  380. }
  381. }
  382. </style>
  383. <style lang="scss">
  384. // fix css style bug in open el-dialog
  385. .el-popup-parent--hidden {
  386. .fixed-header {
  387. padding-right: 15px;
  388. }
  389. }
  390. </style>