topWarn.vue 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  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">处置</view>
  7. </view>
  8. </template>
  9. <script>
  10. import $mqtt from '@/utils/mqtt.min.js';
  11. import {
  12. controlsRestrictVerify
  13. } from '@/utils/index'
  14. import {
  15. laboratoryBigViewSelectTriggerInfo,
  16. laboratoryPlanCloseRiskPlan,
  17. } from '@/pages_manage/api/index.js'
  18. export default {
  19. data() {
  20. return {
  21. pageType: false,
  22. text: "",
  23. buildId: "",
  24. floorId: "",
  25. subId: "",
  26. //预案MQTT
  27. mtopic: 'lab/risk/plan/change',
  28. client: {},
  29. planData: {},
  30. }
  31. },
  32. created() {
  33. },
  34. mounted() {
  35. this.offPlanMQTT('on');
  36. this.laboratoryBigViewSelectTriggerInfo();
  37. },
  38. methods: {
  39. //预案-MQTT连接
  40. offPlanMQTT(type) {
  41. let self = this;
  42. if (self.client.unsubscribe) {
  43. self.client.unsubscribe(self.mtopic, error => {
  44. if (error) {
  45. // console.log('mqtt关闭连接错误:', error)
  46. }
  47. })
  48. self.client.end();
  49. this.$set(this, 'client', {});
  50. }
  51. //判断传入参数如果存在 发起一次新的连接
  52. if (type) {
  53. this.planMQTT();
  54. }
  55. },
  56. //预案-MQTT订阅
  57. planMQTT() {
  58. let self = this;
  59. this.client = $mqtt.connect('wxs://' + uni.getStorageSync('mqttUrl'), {
  60. username: uni.getStorageSync('mqttUser'),
  61. password: uni.getStorageSync('mqttPassword')
  62. });
  63. this.client.on("connect", e => {
  64. this.client.subscribe(this.mtopic, (err) => {
  65. if (!err) {
  66. console.log("预案订阅成功:" + this.mtopic);
  67. } else {
  68. // console.log("连接错误:" + err);
  69. }
  70. });
  71. });
  72. this.client.on("message", (topic, message) => {
  73. console.log('message', message);
  74. console.log('topic,', topic);
  75. if (message) {
  76. if (topic == this.mtopic) {
  77. //预案触发
  78. console.log('触发预案')
  79. this.laboratoryBigViewSelectTriggerInfo();
  80. }
  81. }
  82. });
  83. },
  84. //获取预案数据
  85. async laboratoryBigViewSelectTriggerInfo(type) {
  86. let self = this;
  87. const {
  88. data
  89. } = await laboratoryBigViewSelectTriggerInfo();
  90. if (data.code == 200) {
  91. // console.log('条幅触发',data.data);
  92. if (data.data[0]) {
  93. // console.log('条幅触发-有');
  94. this.$set(this, 'planData', data.data);
  95. this.$set(this, 'text', data.data[1] ? '有多个实验室发生预案' : '有实验室发生预案');
  96. this.$set(this, 'pageType', true);
  97. //传感器
  98. let planSensorList = [];
  99. data.data.forEach((item) => {
  100. let list = JSON.parse(item.triggerUploadData)
  101. list.forEach((minItem) => {
  102. planSensorList.push(minItem.deviceNo)
  103. })
  104. })
  105. uni.setStorageSync("planSensorList", planSensorList);
  106. } else {
  107. // console.log('条幅触发-无');
  108. this.$set(this, 'pageType', false);
  109. this.$set(this, 'planData', []);
  110. this.$set(this, 'text', '');
  111. uni.setStorageSync("planSensorList", []);
  112. }
  113. }
  114. },
  115. //条幅操作按钮
  116. buttonClick() {
  117. let self = this;
  118. let list = [];
  119. if (!controlsRestrictVerify('performEvacuation')) {
  120. list = ['查看'];
  121. } else {
  122. list = ['查看', '结束预案'];
  123. }
  124. uni.showActionSheet({
  125. itemList: list,
  126. success: function(res) {
  127. if (res.tapIndex == 0) {
  128. self.goPage();
  129. } else if (res.tapIndex == 1) {
  130. self.closePlan();
  131. }
  132. },
  133. fail: function(res) {
  134. console.log(res.errMsg);
  135. }
  136. });
  137. },
  138. //结束预案弹窗
  139. closePlan() {
  140. let self = this;
  141. uni.showModal({
  142. content: '传感器数据监测异常,确定要强制结束预案?关闭报警后,3分钟内系统不再触发预案报警,请核实确认后再执行此操作?',
  143. cancelColor: "#999",
  144. confirmColor: "#0183FA",
  145. success: function(res) {
  146. if (res.confirm) {
  147. self.closeRiskPlan();
  148. } else if (res.cancel) {
  149. }
  150. }
  151. });
  152. },
  153. //结束预案方法
  154. async closeRiskPlan() {
  155. const {
  156. data
  157. } = await laboratoryPlanCloseRiskPlan({
  158. eventId: this.planData[0].eventId
  159. });
  160. if (data.code == 200) {
  161. uni.showToast({
  162. title: '操作成功',
  163. icon: "none",
  164. mask: true,
  165. duration: 2000
  166. });
  167. this.laboratoryBigViewSelectTriggerInfo();
  168. }
  169. },
  170. //页面跳转
  171. goPage() {
  172. let obj = {
  173. buildId: this.planData[0].buildId,
  174. floorId: this.planData[0].floorId,
  175. subId: this.planData[0].subId,
  176. groupId: this.planData[0].eventId,
  177. }
  178. uni.navigateTo({
  179. url: '/pages_manage/views/emergencyEvacuationBig?item=' + encodeURIComponent(JSON.stringify(
  180. obj))
  181. });
  182. },
  183. },
  184. onHide() {
  185. //清除定时器
  186. let self = this;
  187. console.log('onHide')
  188. self.offPlanMQTT();
  189. },
  190. beforeDestroy() {
  191. //清除定时器
  192. let self = this;
  193. console.log('beforeDestroy')
  194. self.offPlanMQTT();
  195. },
  196. }
  197. </script>
  198. <style lang="stylus" scoped>
  199. .top-warn {
  200. height: 80rpx;
  201. line-height: 80rpx;
  202. background rgba(2550, 0, 0, 0.2);
  203. margin: 20rpx 30rpx 0;
  204. display flex;
  205. overflow hidden;
  206. border-radius: 20rpx;
  207. .left-title {
  208. width: 100rpx;
  209. height: 40rpx;
  210. text-align: center;
  211. line-height: 40rpx;
  212. margin: 20rpx 18rpx 0 30rpx;
  213. color: #fff;
  214. font-size: 28rpx;
  215. background-color: #FF0000;
  216. border-radius: 10rpx;
  217. }
  218. .text-view {
  219. color: #FF0000;
  220. flex: 1;
  221. white-space: nowrap;
  222. }
  223. .button-view {
  224. width: 120rpx;
  225. height: 48rpx;
  226. line-height: 48rpx;
  227. color: #FF0000;
  228. border: 1px solid #FF0000;
  229. text-align center;
  230. border-radius: 50rpx;
  231. margin: 16rpx 12rpx 0 0;
  232. }
  233. }
  234. </style>