topWarn.vue 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377
  1. <!-- 顶部警告 -->
  2. <template>
  3. <view class="top-warn" v-if="pageType">
  4. <view class="left-title">预警</view>
  5. <view class="text-view">{{text}}</view>
  6. <view class="button-view" @click="buttonClick" v-if="buttonType">处置</view>
  7. </view>
  8. </template>
  9. <script>
  10. import {
  11. itoOrVideoLimits
  12. } from '@/utils/index'
  13. import $mqtt from '@/utils/mqtt.min.js';
  14. import {
  15. controlsRestrictVerify
  16. } from '@/utils/index'
  17. import {
  18. laboratoryBigViewSelectTriggerInfo,
  19. laboratoryPlanCloseRiskPlan,
  20. laboratoryBigViewGetFloorByBigView,
  21. } from '@/pages_manage/api/index.js'
  22. export default {
  23. data() {
  24. return {
  25. pageType: false,
  26. buttonType:false,
  27. text: "",
  28. buildId: "",
  29. floorId: "",
  30. subId: "",
  31. //预案MQTT
  32. mtopic: 'lab/risk/plan/change',
  33. client: {},
  34. planData: {},
  35. }
  36. },
  37. created() {
  38. },
  39. mounted() {
  40. this.offPlanMQTT('on');
  41. this.laboratoryBigViewSelectTriggerInfo();
  42. },
  43. methods: {
  44. //预案-MQTT连接
  45. offPlanMQTT(type) {
  46. let self = this;
  47. if (self.client.unsubscribe) {
  48. self.client.unsubscribe(self.mtopic, error => {
  49. if (error) {
  50. // console.log('mqtt关闭连接错误:', error)
  51. }
  52. })
  53. self.client.end();
  54. this.$set(this, 'client', {});
  55. }
  56. //判断传入参数如果存在 发起一次新的连接
  57. if (type) {
  58. this.planMQTT();
  59. }
  60. },
  61. //预案-MQTT订阅
  62. planMQTT() {
  63. let self = this;
  64. this.client = $mqtt.connect('wxs://' + uni.getStorageSync('mqttUrl'), {
  65. username: uni.getStorageSync('mqttUser'),
  66. password: uni.getStorageSync('mqttPassword')
  67. });
  68. this.client.on("connect", e => {
  69. this.client.subscribe(this.mtopic, (err) => {
  70. if (!err) {
  71. console.log("预案订阅成功:" + this.mtopic);
  72. } else {
  73. // console.log("连接错误:" + err);
  74. }
  75. });
  76. });
  77. this.client.on("message", (topic, message) => {
  78. console.log('message', message);
  79. console.log('topic,', topic);
  80. if (message) {
  81. if (topic == this.mtopic) {
  82. //预案触发
  83. console.log('触发预案')
  84. this.laboratoryBigViewSelectTriggerInfo();
  85. }
  86. }
  87. });
  88. },
  89. //获取预案数据
  90. async laboratoryBigViewSelectTriggerInfo(type) {
  91. let self = this;
  92. const {
  93. data
  94. } = await laboratoryBigViewSelectTriggerInfo();
  95. if (data.code == 200) {
  96. // console.log('条幅触发',data.data);
  97. if (data.data[0]) {
  98. let list1 = [];
  99. let list2 = [];
  100. data.data.forEach((item)=>{
  101. if(itoOrVideoLimits(item.adminId)){
  102. list1.push(item);
  103. }else{
  104. list2.push(item);
  105. }
  106. })
  107. if(list1[0]){
  108. // console.log('条幅触发-有');
  109. this.$set(this, 'planData', list1);
  110. this.$set(this, 'text', list1[1] ? '有多个实验室发生预案' : '有实验室发生预案');
  111. this.$set(this, 'pageType', true);
  112. this.$set(this, 'buttonType', true);
  113. //传感器
  114. let planSensorList = [];
  115. list1.forEach((item) => {
  116. let list = JSON.parse(item.triggerUploadData)
  117. list.forEach((minItem) => {
  118. planSensorList.push(minItem.deviceNo)
  119. })
  120. })
  121. uni.setStorageSync("planSensorList", planSensorList);
  122. }else{
  123. this.$set(this, 'planData', list2);
  124. this.$set(this, 'text', list2[1] ? '有多个实验室发生预案' : '有实验室发生预案');
  125. this.$set(this, 'pageType', true);
  126. this.$set(this, 'buttonType', false);
  127. //传感器
  128. let planSensorList = [];
  129. list2.forEach((item) => {
  130. let list = JSON.parse(item.triggerUploadData)
  131. list.forEach((minItem) => {
  132. planSensorList.push(minItem.deviceNo)
  133. })
  134. })
  135. uni.setStorageSync("planSensorList", planSensorList);
  136. }
  137. } else {
  138. // console.log('条幅触发-无');
  139. this.$set(this, 'pageType', false);
  140. this.$set(this, 'buttonType', false);
  141. this.$set(this, 'planData', []);
  142. this.$set(this, 'text', '');
  143. uni.setStorageSync("planSensorList", []);
  144. }
  145. }
  146. },
  147. //条幅操作按钮
  148. buttonClick() {
  149. let self = this;
  150. let list = [];
  151. if (!controlsRestrictVerify('performEvacuation')) {
  152. list = ['查看'];
  153. } else {
  154. list = ['查看', '结束预案'];
  155. }
  156. uni.showActionSheet({
  157. itemList: list,
  158. success: function(res) {
  159. if (res.tapIndex == 0) {
  160. self.goPage();
  161. } else if (res.tapIndex == 1) {
  162. self.closePlan();
  163. }
  164. },
  165. fail: function(res) {
  166. console.log(res.errMsg);
  167. }
  168. });
  169. },
  170. //结束预案弹窗
  171. closePlan() {
  172. let self = this;
  173. if(self.planData[1]){
  174. let list = [];
  175. for(let i=0;i<self.planData.length;i++){
  176. list.push(self.planData[i].subName+'-'+self.planData[i].eventName)
  177. }
  178. uni.showActionSheet({
  179. itemList: list,
  180. success: function(res) {
  181. uni.showModal({
  182. content: '传感器数据监测异常,确定要强制结束预案?关闭报警后,3分钟内系统不再触发预案报警,请核实确认后再执行此操作?',
  183. cancelColor: "#999",
  184. confirmColor: "#0183FA",
  185. success: function(resData) {
  186. if (resData.confirm) {
  187. self.closeRiskPlan(res.tapIndex);
  188. } else if (resData.cancel) {
  189. }
  190. }
  191. });
  192. },
  193. fail: function(res) {
  194. // console.log(res.errMsg);
  195. }
  196. });
  197. }else{
  198. uni.showModal({
  199. content: '传感器数据监测异常,确定要强制结束预案?关闭报警后,3分钟内系统不再触发预案报警,请核实确认后再执行此操作?',
  200. cancelColor: "#999",
  201. confirmColor: "#0183FA",
  202. success: function(res) {
  203. if (res.confirm) {
  204. self.closeRiskPlan(0);
  205. } else if (res.cancel) {
  206. }
  207. }
  208. });
  209. }
  210. },
  211. //结束预案方法
  212. async closeRiskPlan(index) {
  213. console.log('index',index)
  214. let self = this;
  215. const {
  216. data
  217. } = await laboratoryPlanCloseRiskPlan({
  218. eventId: self.planData[index].eventId
  219. });
  220. if (data.code == 200) {
  221. uni.showToast({
  222. title: '操作成功',
  223. icon: "none",
  224. mask: true,
  225. duration: 2000
  226. });
  227. self.laboratoryBigViewSelectTriggerInfo();
  228. }
  229. },
  230. //查询实验室是否配置地图
  231. async laboratoryBigViewGetFloorByBigView(obj) {
  232. const {
  233. data
  234. } = await laboratoryBigViewGetFloorByBigView({
  235. id: obj.floorId
  236. })
  237. if (data.code == 200) {
  238. if(data.data[0]){
  239. if(data.data[0].buildLayoutVoList){
  240. if (data.data[0].buildLayoutVoList[0]) {
  241. uni.navigateTo({
  242. url: '/pages_manage/views/emergencyEvacuationBig?item=' + encodeURIComponent(JSON.stringify(
  243. obj))
  244. });
  245. }else{
  246. uni.showToast({
  247. title: '该实验室楼层未配置地图数据,请联系管理员.',
  248. icon: "none",
  249. mask: true,
  250. duration: 4000
  251. });
  252. }
  253. }else{
  254. uni.showToast({
  255. title: '该实验室楼层未配置地图数据,请联系管理员.',
  256. icon: "none",
  257. mask: true,
  258. duration: 4000
  259. });
  260. }
  261. }else{
  262. uni.showToast({
  263. title: '该实验室楼层未配置地图数据,请联系管理员.',
  264. icon: "none",
  265. mask: true,
  266. duration: 4000
  267. });
  268. }
  269. }
  270. },
  271. //页面跳转
  272. goPage() {
  273. let self = this;
  274. if(self.planData[1]){
  275. let list = [];
  276. for(let i=0;i<self.planData.length;i++){
  277. list.push(self.planData[i].subName+'-'+self.planData[i].eventName)
  278. }
  279. uni.showActionSheet({
  280. itemList: list,
  281. success: function(res) {
  282. let obj = {
  283. buildId: self.planData[res.tapIndex].buildId,
  284. floorId: self.planData[res.tapIndex].floorId,
  285. subId: self.planData[res.tapIndex].subId,
  286. adminId: self.planData[res.tapIndex].adminId,
  287. groupId: self.planData[res.tapIndex].eventId,
  288. }
  289. self.laboratoryBigViewGetFloorByBigView(obj);
  290. },
  291. fail: function(res) {
  292. // console.log(res.errMsg);
  293. }
  294. });
  295. }else{
  296. let obj = {
  297. buildId: self.planData[0].buildId,
  298. floorId: self.planData[0].floorId,
  299. subId: self.planData[0].subId,
  300. adminId: self.planData[0].adminId,
  301. groupId: self.planData[0].eventId,
  302. }
  303. self.laboratoryBigViewGetFloorByBigView(obj);
  304. }
  305. // let obj = {
  306. // buildId: this.planData[0].buildId,
  307. // floorId: this.planData[0].floorId,
  308. // subId: this.planData[0].subId,
  309. // groupId: this.planData[0].eventId,
  310. // }
  311. // uni.navigateTo({
  312. // url: '/pages_manage/views/emergencyEvacuationBig?item=' + encodeURIComponent(JSON.stringify(
  313. // obj))
  314. // });
  315. },
  316. },
  317. onHide() {
  318. //清除定时器
  319. let self = this;
  320. console.log('onHide')
  321. self.offPlanMQTT();
  322. },
  323. beforeDestroy() {
  324. //清除定时器
  325. let self = this;
  326. console.log('beforeDestroy')
  327. self.offPlanMQTT();
  328. },
  329. }
  330. </script>
  331. <style lang="stylus" scoped>
  332. .top-warn {
  333. height: 80rpx;
  334. line-height: 80rpx;
  335. background rgba(2550, 0, 0, 0.2);
  336. margin: 20rpx 30rpx 0;
  337. display flex;
  338. overflow hidden;
  339. border-radius: 20rpx;
  340. .left-title {
  341. width: 100rpx;
  342. height: 40rpx;
  343. text-align: center;
  344. line-height: 40rpx;
  345. margin: 20rpx 18rpx 0 30rpx;
  346. color: #fff;
  347. font-size: 28rpx;
  348. background-color: #FF0000;
  349. border-radius: 10rpx;
  350. }
  351. .text-view {
  352. color: #FF0000;
  353. flex: 1;
  354. white-space: nowrap;
  355. }
  356. .button-view {
  357. width: 120rpx;
  358. height: 48rpx;
  359. line-height: 48rpx;
  360. color: #FF0000;
  361. border: 1px solid #FF0000;
  362. text-align center;
  363. border-radius: 50rpx;
  364. margin: 16rpx 12rpx 0 0;
  365. }
  366. }
  367. </style>