RiskHint.vue 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  1. <template>
  2. <div class="riskHint-container">
  3. <base-title title="风险提示" />
  4. <div class="hint-box" v-if="hintData1.length">
  5. <vue-seamless
  6. :data="hintData1"
  7. class="seamless-warp"
  8. :class-option="scrollOption"
  9. ref="seamlessScroll"
  10. >
  11. <div class="hint-content">
  12. <div
  13. class="hint-item"
  14. v-for="item of hintData1"
  15. :key="item.id"
  16. @click="openRiskDialog(item)"
  17. >
  18. <div
  19. class="title"
  20. :style="{
  21. 'background-image': `linear-gradient(90deg, ${
  22. riskColors[item.level].color
  23. } 2%, rgba(249, 40, 40, 0) 100%)`,
  24. }"
  25. >
  26. <img :src="require('@/assets/imgs/maps/img_dian.png')" alt="" />
  27. <span class="type">{{ riskColors[item.level].name }}</span>
  28. <span class="split"></span>
  29. <span class="time">{{
  30. Dayjs(item.eventTime).format("YYYY-MM-DD HH:mm:ss")
  31. }}</span>
  32. </div>
  33. <div class="content">{{ item.content }}</div>
  34. </div>
  35. </div>
  36. </vue-seamless>
  37. </div>
  38. <div class="hint-box no-data" v-else>暂无数据</div>
  39. </div>
  40. </template>
  41. <script>
  42. import BaseTitle from "./BaseTitle.vue";
  43. import VueSeamless from "vue-seamless-scroll";
  44. import Dayjs from "dayjs";
  45. import { getAlarmDataList } from "@/API/alarm";
  46. import { mapGetters } from "vuex";
  47. export default {
  48. name: "",
  49. components: { BaseTitle, VueSeamless },
  50. props: {
  51. hintData: {
  52. type: Array,
  53. default: () => [],
  54. },
  55. },
  56. data() {
  57. return {
  58. scrollOption: {
  59. limitMoveNum: 2.5,
  60. singleHeight: 81,
  61. waitTime: 2000,
  62. },
  63. dId: "",
  64. riskColors: {
  65. ["306001"]: { name: "重大级别", color: "#FF3636" },
  66. ["306002"]: { name: "较大级别", color: "#FF9F00" },
  67. ["306003"]: { name: "一般级别", color: "#F8E71C" },
  68. ["306004"]: { name: "低级别", color: "#53A3FF" },
  69. ["024001"]: { name: "一级", color: "#FF9F00" },
  70. ["024002"]: { name: "二级", color: "#F8E71C" },
  71. ["024003"]: { name: "三级", color: "#53A3FF" },
  72. },
  73. hintData1: [],
  74. };
  75. },
  76. computed: {
  77. ...mapGetters(["departmentId"]),
  78. },
  79. mounted() {
  80. this.getAlarmDataList();
  81. // this.startMqtt();
  82. let timer = null;
  83. if (!timer) {
  84. timer = setInterval(() => {
  85. this.getAlarmDataList();
  86. }, 5000);
  87. }
  88. this.$once("hook:beforeDestroy", () => {
  89. !!timer && clearTimeout(timer);
  90. timer = null;
  91. });
  92. },
  93. watch: {
  94. departmentId(newVal) {
  95. // console.log("部门id信息", newVal);
  96. this.dId = newVal;
  97. setTimeout(() => {
  98. this.getAlarmDataList();
  99. }, 200);
  100. },
  101. },
  102. methods: {
  103. Dayjs,
  104. async getAlarmDataList() {
  105. try {
  106. const params = {
  107. // pageSize: 10000,
  108. // pageIndex: 1,
  109. dealStatus: "", //0
  110. confirmStatus: "0",
  111. recoveryStatus: "",
  112. category: "",
  113. level: "",
  114. type: "",
  115. startTime: Dayjs(
  116. Dayjs(new Date()).subtract(7, "day").format("YYYY-MM-DD HH:mm:ss")
  117. ).format(),
  118. endTime: Dayjs(
  119. Dayjs(new Date()).format("YYYY-MM-DD HH:mm:ss")
  120. ).format(),
  121. key: "",
  122. tag: "",
  123. departmentId: this.dId,
  124. };
  125. const res = await getAlarmDataList(params);
  126. let alarmData = res.data.content;
  127. this.hintData1 = alarmData.map((e) => {
  128. return {
  129. id: e.id,
  130. level: e.level ? e.level : "024003",
  131. riskTime: e.eventTime,
  132. content:
  133. (e.departmentName ? e.departmentName : "") +
  134. (e.categoryStr ? e.categoryStr : "") +
  135. e.content,
  136. };
  137. });
  138. console.log("风险报警数据", alarmData, this.hintData1);
  139. } catch (err) {}
  140. },
  141. openRiskDialog(data) {
  142. console.log("风险报警数据", data);
  143. // let dialogConfig = {
  144. // dialogId: "risk_" + data.id,
  145. // show: true, //是否显示
  146. // title: "事件详情",
  147. // width: 500, //px宽度
  148. // height: 320, //px高度
  149. // center: true, //是否居中定位
  150. // zIndex: 10,
  151. // data,
  152. // };
  153. // this.$store.dispatch("dialog/addRiskDialog", dialogConfig);
  154. },
  155. startMqtt() {
  156. const topics = [
  157. "DataCommunication/TagData/xxx",
  158. "DataCommunication/TagData/xxx",
  159. "DataCommunication/TagData/xxx",
  160. "DataCommunication/TagData/xxx",
  161. "DataCommunication/TagData/xxx",
  162. "DataCommunication/TagData/xxx",
  163. ];
  164. const _this = this;
  165. this.$store.dispatch("mqtt/subscribe", {
  166. topic: topics,
  167. onMessage: (topic, message, packet) => {
  168. const content = message.toString();
  169. const data = JSON.parse(content);
  170. if (topic === "Visualization/Number/StationLevelCount") {
  171. const topicIndex = topics.indexOf(topic);
  172. if (topicIndex > -1) {
  173. _this.weatherList[topicIndex] = data.Value;
  174. _this.weatherList[topicIndex] = data.Unit;
  175. }
  176. }
  177. },
  178. });
  179. this.$once("hook:beforeDestroy", () => {
  180. this.$store.dispatch("mqtt/unsubscribe", topics);
  181. });
  182. },
  183. },
  184. };
  185. </script>
  186. <style lang="less" scoped>
  187. .riskHint-container {
  188. width: 410px;
  189. z-index: 2;
  190. .hint-box {
  191. width: 100%;
  192. height: 198px;
  193. overflow: hidden;
  194. padding: 0 15px;
  195. // display: flex;
  196. position: relative;
  197. .hint-content {
  198. padding-left: 20px;
  199. .hint-item:last-child {
  200. margin-bottom: 10px;
  201. }
  202. }
  203. .hint-item {
  204. width: 100%;
  205. height: 70px;
  206. margin: 10px;
  207. cursor: pointer;
  208. }
  209. .title {
  210. height: 27px;
  211. background-image: linear-gradient(
  212. 90deg,
  213. #f92828 2%,
  214. rgba(249, 40, 40, 0) 100%
  215. );
  216. display: flex;
  217. align-items: center;
  218. color: #fff;
  219. position: relative;
  220. img {
  221. width: 14px;
  222. height: 14px;
  223. position: absolute;
  224. left: -20px;
  225. }
  226. .type {
  227. margin-left: 5px;
  228. }
  229. .split {
  230. width: 2px;
  231. height: 10px;
  232. border-left: 2px solid #fff;
  233. margin: 0 8px;
  234. }
  235. }
  236. .content {
  237. padding: 10px 0;
  238. font-size: 13px;
  239. color: #ffffff;
  240. letter-spacing: 1px;
  241. font-weight: 400;
  242. }
  243. }
  244. .no-data {
  245. display: flex;
  246. justify-content: center;
  247. align-items: center;
  248. font-size: 18px;
  249. font-weight: 500;
  250. color: #fff;
  251. letter-spacing: 5px;
  252. }
  253. }
  254. </style>