longyvfengyun
2023-12-25 d8d792a6842832e8f6af6604274c438b25053afe
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
<template>
  <content-box :title="fullStationName" class="mgl8">
    <flex-layout>
      <div class="flex-page-content">
        <el-tabs type="border-card" class="flex-layout noborder top-border" v-model="acTabs"
                 @tab-click="tabsChange">
          <el-tab-pane label="模拟量" name="analog">
            <analog-tab-pane ref="analog" :name="acTabs" :info="info"></analog-tab-pane>
          </el-tab-pane>
          <el-tab-pane label="告警量" name="warn">
            <warn-tab-pane :name="acTabs" :info="info"></warn-tab-pane>
          </el-tab-pane>
          <el-tab-pane label="状态量" name="state">
            <state-tab-pane :name="acTabs" :info="info"></state-tab-pane>
          </el-tab-pane>
        </el-tabs>
      </div>
    </flex-layout>
  </content-box>
</template>
<script>
import AnalogTabPane from "@/pages/dataMager/components/AnalogTabPane";
import WarnTabPane from "@/pages/dataMager/components/WarnTabPane";
import StateTabPane from "@/pages/dataMager/components/StateTabPane";
import {getPowerInfo} from "@/pages/dataMager/js";
import {Timeout} from "@/assets/js/tools";
import ContentBox from "@/components/ContentBox";
 
export default {
  components: {
    ContentBox,
    StateTabPane,
    WarnTabPane,
    AnalogTabPane,
  },
  data() {
    return {
      timer: new Timeout(),
      acTabs: 'analog',
      info: getPowerInfo(),
      socket: "",
      isOpen: false,
      powerInfo: {
        powerDeviceId: 0,
        stationId: 0,
        stationName: "",
        stationName1: "",
        stationName2: "",
        stationName3: "",
        stationName4: " ",
        stationName5: "",
      },
    }
  },
  watch: {
    "$route.params.powerDeviceId"(powerDeviceId) {
      this.$nextTick(() => {
        this.getPowerInfo(powerDeviceId);
      });
    },
    "$store.state.theme.collapse"() {
      this.$nextTick(() => {
        this.resize();
      });
    },
  },
  methods: {
    getPowerInfo(powerDeviceId) {
      this.powerInfo.powerDeviceId = powerDeviceId;
      this.$apis.dataMager.powerMager.getInfoById({
        powerDeviceId: powerDeviceId
      }).then(res => {
        let rs = JSON.parse(res.data.result);
        console.log(rs);
        if (rs.code == 1) {
          this.powerInfo = rs.data;
        } else {
          this.powerInfo = {
            powerDeviceId: 0,
            stationId: 0,
            stationName: "",
            stationName1: "",
            stationName2: "",
            stationName3: "",
            stationName4: " ",
            stationName5: "",
          };
        }
        // 启动查询
        this.startSearch();
      }).catch(error => {
        console.log(error);
      });
    },
    tabsChange() {
      // 重置图表的大小
      this.resize();
    },
    resize() {
      switch (this.acTabs) {
        case "analog":
          this.$refs.analog.resize();
          break;
        case "isolatingDevice":
          this.$refs.isolatingDevice.resize();
          break;
        case "chargerStatus":
          this.$refs.chargerStatus.resize();
          break;
      }
    },
    startSearch() {
      this.timer.start(()=>{
          this.$axios.all([this.searchPowerACDCInfo()]).then(()=>{
            // 启动循环
            this.timer.open();
          }).catch(error=>{
            // 启动循环
            this.timer.open();
          });
      }, 4000);
    },
    searchPowerACDCInfo() {
      this.$apis.dataMager.powerMager.getACDCData(this.powerInfo.powerDeviceId).then(res=>{
          let rs = JSON.parse(res.data.result);
          console.log(JSON.parse(res.data.result));
          if (rs.code == 1 && rs.data.length != 0) {
            this.info = rs.data[0];
          } else {
            this.info = getPowerInfo();
          }
      }).catch(error=>{
        console.log(error);
      });
    },
  },
  computed: {
    fullStationName() {
      let powerInfo = this.powerInfo;
      if (powerInfo.powerDeviceId) {
        return powerInfo.stationName1 + "-" + powerInfo.stationName2
            + "-" + powerInfo.stationName5 + "-" + powerInfo.stationName3 + "-" + powerInfo.powerDeviceName;
        return "未知站点名称";
      } else {
        return "未知站点名称";
      }
    }
  },
  mounted() {
    // 获取电源信息
    let powerDeviceId = this.$route.params.powerDeviceId;
    if (powerDeviceId) {
      this.getPowerInfo(powerDeviceId);
    }
    // 改变大小
    this.resize();
    // 窗口大小改变重置内容大小
    let self = this;
    // 启动监听
    window.addEventListener('resize', this.resize);
  },
  destroyed() {
    // 关闭监听
    window.removeEventListener('resize', this.resize);
    //  关闭计时器
    this.timer.stop();
  }
}
</script>
<style scoped>
.mgl8 {
  margin-left: 8px;
}
 
.flex-page-content {
  padding: 4px 4px 0 4px;
  box-sizing: border-box;
}
</style>