topHeader.vue 2.9 KB

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