AppMain.vue 8.7 KB

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