Overview.vue 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383
  1. <template>
  2. <div class="page_container">
  3. <base-title title="今日报警" />
  4. <div class="page_top">
  5. <div
  6. class="top-item"
  7. v-for="(item, index) in todayTotalData"
  8. :key="item.code"
  9. >
  10. <div class="top-item-img">
  11. <img class="rotate" :src="item.img" />
  12. </div>
  13. <div class="top_value_box" @click="gotoAlarmList(undefined, index)">
  14. <div class="top-item-value">{{ item.total }}</div>
  15. <div class="top-item-name">{{ item.title }}</div>
  16. </div>
  17. </div>
  18. </div>
  19. <div class="page_bottom">
  20. <div
  21. class="bottom-item"
  22. :class="['level' + categoryList[key].level]"
  23. v-for="key in Object.keys(categoryList)"
  24. :key="key"
  25. @click="gotoAlarmList(key)"
  26. >
  27. <div class="item-name">{{ categoryList[key].name }}</div>
  28. <div class="item-count">{{ categoryList[key].value }}</div>
  29. </div>
  30. </div>
  31. </div>
  32. </template>
  33. <script>
  34. import BaseTitle from "./BaseTitle.vue";
  35. import Dayjs from "dayjs";
  36. import { getAlarmDataList } from "@/API/alarm";
  37. import { mapGetters } from "vuex";
  38. export default {
  39. name: "Overview",
  40. components: { BaseTitle },
  41. data() {
  42. return {
  43. todayTotalData: [
  44. {
  45. code: "1",
  46. title: "未处理",
  47. total: 0,
  48. img: require("@/assets/imgs/overview/img_BJ_bg_01.png"),
  49. },
  50. {
  51. code: "2",
  52. title: "报警总数",
  53. total: 0,
  54. img: require("@/assets/imgs/overview/img_BJ_bg_02.png"),
  55. },
  56. {
  57. code: "3",
  58. title: "未确认",
  59. total: 0,
  60. img: require("@/assets/imgs/overview/img_BJ_bg_03.png"),
  61. },
  62. ],
  63. categoryList: {
  64. 100001: {
  65. code: "101",
  66. name: "人员报警",
  67. value: "",
  68. level: "024000",
  69. },
  70. 100002: {
  71. code: "101",
  72. name: "周界报警",
  73. value: "",
  74. level: "024000",
  75. },
  76. 100003: {
  77. code: "101",
  78. name: "火灾报警",
  79. value: "",
  80. level: "024000",
  81. },
  82. 100004: {
  83. code: "101",
  84. name: "泄漏检测",
  85. value: "",
  86. level: "024000",
  87. },
  88. 100005: {
  89. code: "101",
  90. name: "工业视频",
  91. value: "",
  92. level: "024000",
  93. },
  94. 100006: {
  95. code: "101",
  96. name: "门禁报警",
  97. value: "",
  98. level: "024000",
  99. },
  100. 100015: {
  101. code: "101",
  102. name: "110报警",
  103. value: "",
  104. level: "024000",
  105. },
  106. 100888: {
  107. code: "101",
  108. name: "系统事件",
  109. value: "",
  110. level: "024000",
  111. },
  112. // 100001: {
  113. // code: "101",
  114. // name: "可燃气体浓度",
  115. // value: 0,
  116. // level: "024000",
  117. // },
  118. },
  119. dId: "",
  120. };
  121. },
  122. computed: {
  123. ...mapGetters(["departmentId"]),
  124. },
  125. mounted() {
  126. this.getAlarmDataList();
  127. // this.startMqtt();
  128. },
  129. watch: {
  130. departmentId(newVal) {
  131. // console.log("部门id信息", newVal);
  132. this.dId = newVal;
  133. setTimeout(() => {
  134. this.getAlarmDataList();
  135. }, 200);
  136. },
  137. },
  138. methods: {
  139. startMqtt() {
  140. const topics = [
  141. // 'Visualization/Number/TodayTotal',
  142. // 'Visualization/Number/TodayCategoryCount',
  143. "Visualization/Alarm/0/TodayTotal",
  144. "Visualization/Alarm/0/TodayCategoryCount",
  145. ];
  146. const _this = this;
  147. this.$store.dispatch("mqtt/subscribe", {
  148. topic: topics,
  149. onMessage: (topic, message, packet) => {
  150. const content = message.toString();
  151. const data = JSON.parse(content);
  152. if (topic === "Visualization/Alarm/0/TodayTotal") {
  153. // console.log("今日报警数据", data);
  154. // if (topic === 'Visualization/Number/TodayTotal') {
  155. data.forEach((item, index) => {
  156. data.length = 3;
  157. // console.log(item);
  158. if (item && item.name && item.value) {
  159. _this.todayTotalData[index].title = item.name;
  160. _this.todayTotalData[index].total = item.value;
  161. }
  162. });
  163. }
  164. if (topic === "Visualization/Alarm/0/TodayCategoryCount") {
  165. // if (topic === 'Visualization/Number/TodayCategoryCount') {
  166. //console.log(topic, data);
  167. // console.log("报警数据", data);
  168. _this.categoryList = {};
  169. data.length = 6;
  170. data.forEach((item) => {
  171. // _this.categoryList[item.category] = {
  172. // code: item.category,
  173. // name: item.categoryName,
  174. // value: item.unDealed,
  175. // level: item.unDealedLevel,
  176. // };
  177. _this.categoryList[item.code] = {
  178. code: item.code,
  179. name: item.name,
  180. value: item.undealedValue,
  181. level: item.undealedLevel,
  182. };
  183. });
  184. }
  185. },
  186. });
  187. this.$once("hook:beforeDestroy", () => {
  188. this.$store.dispatch("mqtt/unsubscribe", topics);
  189. });
  190. },
  191. gotoAlarmList(category, index) {
  192. console.log("params", category, index);
  193. if (category && category.startsWith("0")) return;
  194. let dealStatus = undefined;
  195. let confirmStatus = undefined;
  196. if (index === 0) {
  197. dealStatus = "0";
  198. } else if (index === 2) {
  199. confirmStatus = "0";
  200. }
  201. let p = {
  202. category,
  203. dateRange: "24H",
  204. dealStatus,
  205. confirmStatus,
  206. departmentId: this.dId,
  207. };
  208. const query = JSON.stringify(p)
  209. .replace("{", "")
  210. .replace("}", "")
  211. .replace(/\",\"/g, "&")
  212. .replace(/,\"/g, "&")
  213. .replace(/:/g, "=")
  214. .replace(/\":\"/g, "=")
  215. .replace(/\"/g, "");
  216. // console.log("报警列表参数", query);
  217. this.$router.push("/alarmlist?" + query);
  218. },
  219. async getAlarmDataList() {
  220. try {
  221. const params = {
  222. pageSize: 1000,
  223. pageIndex: 1,
  224. dealStatus: "", //0
  225. confirmStatus: "",
  226. recoveryStatus: "",
  227. category: "",
  228. level: "",
  229. type: "",
  230. startTime: Dayjs(
  231. Dayjs(new Date()).subtract(1, "day").format("YYYY-MM-DD HH:mm:ss")
  232. ).format(),
  233. endTime: Dayjs(
  234. Dayjs(new Date()).format("YYYY-MM-DD HH:mm:ss")
  235. ).format(),
  236. key: "",
  237. tag: "",
  238. departmentId: this.dId ? this.dId : "",
  239. };
  240. const res = await getAlarmDataList(params);
  241. let alarmData = res.data.content;
  242. this.todayTotalData[0].total = alarmData.filter(
  243. (e) => e.dealStatus === 0
  244. ).length; //未处理
  245. this.todayTotalData[1].total = alarmData ? alarmData.length : 0; //总数
  246. this.todayTotalData[2].total = alarmData.filter(
  247. (e) => e.confirmStatus === 0
  248. ).length; //未确认
  249. // console.log("统计报警数据", alarmData);
  250. } catch (err) {}
  251. },
  252. },
  253. };
  254. </script>
  255. <style lang="less" scoped>
  256. .page_container {
  257. width: 410px;
  258. z-index: 2;
  259. .page_top {
  260. width: 100%;
  261. height: 140px;
  262. display: flex;
  263. justify-content: space-between;
  264. align-items: center;
  265. .top-item {
  266. // background-size: 100% 100%;
  267. // background-repeat: no-repeat;
  268. color: #ffffff;
  269. cursor: pointer;
  270. position: relative;
  271. .top-item-img {
  272. width: 120px;
  273. height: 120px;
  274. img {
  275. width: 100%;
  276. height: 100%;
  277. }
  278. }
  279. .top_value_box {
  280. position: absolute;
  281. top: 0;
  282. left: 0;
  283. width: 100%;
  284. height: 100%;
  285. // padding-left: 10px;
  286. display: flex;
  287. flex-direction: column;
  288. justify-content: center;
  289. align-items: center;
  290. .top-item-value {
  291. font-size: 26px;
  292. letter-spacing: 0;
  293. font-weight: 700;
  294. }
  295. .top-item-name {
  296. opacity: 0.8;
  297. font-size: 13px;
  298. color: #ffffff;
  299. letter-spacing: 0;
  300. font-weight: 400;
  301. }
  302. }
  303. }
  304. .top-item:nth-child(1) {
  305. .top-item-value {
  306. color: #44c3ff;
  307. }
  308. }
  309. .top-item:nth-child(2) {
  310. .top-item-value {
  311. color: #44ffa6;
  312. }
  313. }
  314. .top-item:nth-child(3) {
  315. .top-item-value {
  316. color: #44edff;
  317. }
  318. }
  319. }
  320. .page_bottom {
  321. height: 180px;
  322. border: 0px dotted red;
  323. display: flex;
  324. flex-wrap: wrap;
  325. justify-content: space-between;
  326. .bottom-item {
  327. min-width: 186px;
  328. width: 186px;
  329. height: 40px;
  330. background-size: 100% 100%;
  331. background-repeat: no-repeat;
  332. color: #ffffff;
  333. cursor: pointer;
  334. font-family: "Microsoft YaHei";
  335. .item-name {
  336. display: inline-block;
  337. margin: 12px 0 0 60px;
  338. width: 97px;
  339. }
  340. .item-count {
  341. display: inline-block;
  342. }
  343. &:hover {
  344. font-weight: 600;
  345. }
  346. }
  347. .level024000 {
  348. background-image: url("~@/assets/imgs/overview/img_dangerous_Class 0@2x.png");
  349. }
  350. .level024001 {
  351. background-image: url("~@/assets/imgs/overview/img_dangerous_Class A@2x.png");
  352. color: #ffd9d9 !important;
  353. }
  354. .level024002 {
  355. background-image: url("~@/assets/imgs/overview/img_dangerous_Class B@2x.png");
  356. color: #fff2cb !important;
  357. }
  358. .level024003 {
  359. background-image: url("~@/assets/imgs/overview/img_dangerous_Class D@2x.png");
  360. color: #d9f1ff !important;
  361. }
  362. }
  363. // 旋转动画
  364. .rotate {
  365. animation: rotate 3s linear infinite;
  366. }
  367. @keyframes rotate {
  368. 0% {
  369. transform: rotate(0deg);
  370. }
  371. 100% {
  372. transform: rotate(360deg);
  373. }
  374. }
  375. }
  376. </style>