Blame view

HHECS.Web/src/views/main/index.vue 4.8 KB
胡菁 authored
1
<template>
胡菁 authored
2
  <div>
胡菁 authored
3
4
    <div>
      <el-card shadow="always">
5
6
7
8
9
        <el-button
          type="success"
          size="small"
          icon="el-icon-video-play"
          :disabled="startDeal"
10
          @click="resume"
王硕 authored
11
12
          >开始处理</el-button
        >
13
14
15
16
17
        <el-button
          type="danger"
          size="small"
          icon="el-icon-video-pause"
          :disabled="!startDeal"
18
          @click="pause"
王硕 authored
19
20
          >暂停处理</el-button
        >
21
        <el-divider direction="vertical" />
22
        <el-tag :type="startDeal ? 'success' : 'info'" effect="dark">
23
24
          <i v-if="startDeal" class="el-icon-loading" />
          <i v-else class="el-icon-warning-outline" />
王硕 authored
25
26
          {{ startDeal == true ? "运行中" : "未运行" }}</el-tag
        >
27
        <el-divider direction="vertical" />
胡菁 authored
28
        <el-switch
胡菁 authored
29
30
31
32
33
          v-model="autoSend"
          active-color="#13ce66"
          inactive-color="#909399"
          active-text="自动下发"
          @change="autoSendStatusChanged"
34
        />
胡菁 authored
35
36
      </el-card>
    </div>
37
    <div class="app-container">
38
      <el-tabs v-model="activeName" @tab-click="handleClick">
胡菁 authored
39
        <el-tab-pane label="设备监控" name="deviceMonitor">
胡菁 authored
40
          <DeviceMonitor ref="deviceMonitor" :start-deal="startDeal" />
41
        </el-tab-pane>
胡菁 authored
42
        <el-tab-pane label="设备数据" name="deviceData">
王硕 authored
43
          <DeviceData ref="deviceData" :start-deal="startDeal" />
44
        </el-tab-pane>
胡菁 authored
45
        <el-tab-pane label="站台数据" name="stationData">
王硕 authored
46
          <StationData ref="stationData" />
47
        </el-tab-pane>
胡菁 authored
48
        <el-tab-pane label="执行与日志" name="taskCompensation">
胡菁 authored
49
          <TaskCompensation ref="taskCompensation" />
50
51
52
        </el-tab-pane>
      </el-tabs>
    </div>
胡菁 authored
53
54
55
56
  </div>
</template>

<script>
57
import {
58
59
60
61
  getAutoSendStatus,
  getExecuteStatus,
  pause,
  resume,
王硕 authored
62
63
64
65
66
67
68
  setAutoSendStatus,
} from "@/api/main";
import { mapGetters } from "vuex";
import DeviceData from "./components/DeviceData.vue"; // 设备数据组件
import DeviceMonitor from "./components/DeviceMonitor.vue"; // 设备监控组件
import StationData from "./components/StationData.vue"; // 站台数据组件
import TaskCompensation from "./components/TaskCompensation.vue"; // 定时任务补偿组件
胡菁 authored
69
70

export default {
王硕 authored
71
  name: "MainPage",
王硕 authored
72
73
74
75
  components: {
    DeviceMonitor,
    DeviceData,
    StationData,
王硕 authored
76
    TaskCompensation,
王硕 authored
77
  },
胡菁 authored
78
79
80
81
  data() {
    return {
      startDeal: false, // 开始处理中
      autoSend: false, // 是否自动下发
王硕 authored
82
83
84
      activeName: "deviceMonitor", // 默认显示
      interval: null,
    };
胡菁 authored
85
  },
胡菁 authored
86
  computed: {
王硕 authored
87
    ...mapGetters(["name"]),
胡菁 authored
88
  },
胡菁 authored
89
  mounted() {
胡菁 authored
90
    this.interval = setInterval(() => {
王硕 authored
91
92
93
94
      this.refreshExecuteStatus();
      this.refreshAutoSendStatus();
    }, 5000);
    this.$refs.deviceMonitor.start();
胡菁 authored
95
96
  },
  beforeDestroy() {
王硕 authored
97
    clearInterval(this.interval);
胡菁 authored
98
  },
胡菁 authored
99
  methods: {
100
    // 开始处理
胡菁 authored
101
    resume() {
102
      resume()
胡菁 authored
103
        .then((response) => {
王硕 authored
104
          this.refreshExecuteStatus();
胡菁 authored
105
        })
106
        .catch((err) => {
王硕 authored
107
108
          console.log(err);
        });
胡菁 authored
109
110
    },
111
    // 暂停处理
胡菁 authored
112
    pause() {
113
      pause()
胡菁 authored
114
        .then((response) => {
王硕 authored
115
          this.refreshExecuteStatus();
胡菁 authored
116
        })
117
        .catch((err) => {
王硕 authored
118
119
          console.log(err);
        });
胡菁 authored
120
    },
121
122
    // 刷新执行状态
123
124
125
    refreshExecuteStatus() {
      getExecuteStatus()
        .then((response) => {
王硕 authored
126
          this.startDeal = response.data.status == "Running";
127
128
        })
        .catch((err) => {
王硕 authored
129
130
          console.log(err);
        });
胡菁 authored
131
    },
胡菁 authored
132
133
    // 刷新自动下发状态
胡菁 authored
134
    refreshAutoSendStatus() {
135
      // 获取自动下发状态
136
137
      getAutoSendStatus()
        .then((response) => {
王硕 authored
138
          this.autoSend = response.data;
139
140
        })
        .catch((err) => {
王硕 authored
141
142
          console.log(err);
        });
胡菁 authored
143
144
    },
145
    // 自动下发状态改变事件
146
    autoSendStatusChanged(e) {
147
      // 获取自动下发状态
148
      setAutoSendStatus(e)
胡菁 authored
149
        .then((response) => {
王硕 authored
150
          this.refreshAutoSendStatus();
胡菁 authored
151
        })
152
        .catch((err) => {
王硕 authored
153
154
          console.log(err);
        });
胡菁 authored
155
156
    },
胡菁 authored
157
    handleClick(tab, event) {
王硕 authored
158
159
160
161
      this.$refs.deviceMonitor.stop();
      this.$refs.deviceData.stop();
      this.$refs.stationData.stop();
      this.$refs.taskCompensation.stop();
胡菁 authored
162
      switch (this.activeName) {
王硕 authored
163
164
165
166
167
168
169
170
171
172
173
174
        case "deviceMonitor":
          this.$refs.deviceMonitor.start();
          break;
        case "deviceData":
          this.$refs.deviceData.start();
          break;
        case "stationData":
          this.$refs.stationData.start();
          break;
        case "taskCompensation":
          this.$refs.taskCompensation.start();
          break;
胡菁 authored
175
        default:
王硕 authored
176
          break;
胡菁 authored
177
      }
王硕 authored
178
179
180
    },
  },
};
胡菁 authored
181
182
183
</script>

<style lang="scss" scoped>
胡菁 authored
184
.main {
胡菁 authored
185
186
187
188
189
190
191
192
193
  &-container {
    margin: 30px;
  }
  &-text {
    font-size: 30px;
    line-height: 46px;
  }
}
</style>