topHeader.vue 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. <template>
  2. <header>
  3. <h1>{{ title }}</h1>
  4. <!-- 下拉筛选 -->
  5. <div class="filterSec">
  6. <span>站点:</span>
  7. <select name="" id="" v-model="StationID">
  8. <option
  9. :value="item.StationID"
  10. v-for="item in siteList"
  11. :key="item.StationID"
  12. >
  13. {{ item.StationName }}
  14. </option>
  15. <option value="ss">ss</option>
  16. </select>
  17. </div>
  18. <!-- 当前时间 -->
  19. <time-menu></time-menu>
  20. <!-- 电子巡检小图标 -->
  21. <img
  22. class="time-icon"
  23. @click="goRecordTime()"
  24. src="@/assets/images/time-icon.png"
  25. alt=""
  26. ref="indexChart"
  27. :class="{ noPointer: routeName === 'recordTime' }"
  28. />
  29. </header>
  30. </template>
  31. <script>
  32. import TimeMenu from "@/components/TimeMenu";
  33. export default {
  34. name: "topHeader",
  35. components: {
  36. TimeMenu,
  37. },
  38. data() {
  39. return {
  40. title: "智慧安防数据分析看板",
  41. //当前路由
  42. routeName: this.$route.name,
  43. //站点数据
  44. siteList: [],
  45. StationID: "",
  46. };
  47. },
  48. watch: {
  49. "$store.state.wsInfo"(val) {
  50. this.messageHandle(val);
  51. },
  52. StationID(newVal, oldVal) {
  53. // console.log("watch时候的值");
  54. // console.log(newVal + ":" + oldVal);
  55. this.$store.commit("changeStationID", newVal);
  56. // console.log("放入store的值");
  57. // console.log(this.getStationId);
  58. //判断如果有站带,并且站点切换时,跳转至首页
  59. if (oldVal.length > 0) {
  60. if (this.$route.path == "/index") {
  61. this.$router.go(0);
  62. } else {
  63. this.$router.push("/index");
  64. }
  65. }
  66. },
  67. deep: true,
  68. },
  69. created() {
  70. this.global.sendWs({ CMD: "getStationInfo" });
  71. this.StationID = this.getStationId;
  72. },
  73. mounted() {
  74. this.navs();
  75. },
  76. computed: {
  77. getStationId() {
  78. return this.$store.state.StationID;
  79. },
  80. },
  81. destroyed() {},
  82. methods: {
  83. messageHandle(e) {
  84. if (e.data.search("{") != -1) {
  85. const redata = JSON.parse(e.data);
  86. if (redata.CMD == "getStationInfo") {
  87. this.siteList = redata.RESULT;
  88. if (this.getStationId.length == 0) {
  89. console.log("created走没有的逻辑");
  90. // 初始化时,获取下拉列表的第一个值 放入store里
  91. this.StationID = this.siteList[0].StationID;
  92. this.$store.commit("changeStationID", this.StationID);
  93. } else {
  94. console.log("created走有的逻辑");
  95. }
  96. }
  97. }
  98. },
  99. // 页面跳转至recordTime
  100. goRecordTime() {
  101. if (this.$route.path != "/recordTime") {
  102. this.$router.push("/recordTime");
  103. }
  104. },
  105. //根据路由判断显示不同的标题内容
  106. navs() {
  107. switch (this.$route.name) {
  108. case "recordTime":
  109. return [(this.title = "电子巡检记录列表")];
  110. }
  111. },
  112. },
  113. };
  114. </script>
  115. <style lang="scss" scoped>
  116. </style>