topWarn.vue 4.5 KB

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