Blame view

HHECS.Web/src/views/main/index.vue 4.98 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
          >{{ $t("main.startProcessing") }}</el-button
王硕 authored
12
        >
13
14
15
16
17
        <el-button
          type="danger"
          size="small"
          icon="el-icon-video-pause"
          :disabled="!startDeal"
18
          @click="pause"
胡菁 authored
19
          >{{ $t("main.pauseProcessing") }}</el-button
王硕 authored
20
        >
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
27
          {{
            startDeal == true ? $t("main.running") : $t("main.notRunning")
          }}</el-tag
王硕 authored
28
        >
29
        <el-divider direction="vertical" />
胡菁 authored
30
        <el-switch
胡菁 authored
31
32
33
          v-model="autoSend"
          active-color="#13ce66"
          inactive-color="#909399"
胡菁 authored
34
          :active-text="$t('main.autoSend')"
胡菁 authored
35
          @change="autoSendStatusChanged"
36
        />
胡菁 authored
37
38
      </el-card>
    </div>
39
    <div class="app-container">
40
      <el-tabs v-model="activeName" @tab-click="handleClick">
胡菁 authored
41
        <el-tab-pane :label="$t('main.deviceMonitor')" name="deviceMonitor">
胡菁 authored
42
          <DeviceMonitor ref="deviceMonitor" :start-deal="startDeal" />
43
        </el-tab-pane>
胡菁 authored
44
        <el-tab-pane :label="$t('main.deviceData')" name="deviceData">
王硕 authored
45
          <DeviceData ref="deviceData" :start-deal="startDeal" />
46
        </el-tab-pane>
胡菁 authored
47
        <el-tab-pane :label="$t('main.stationData')" name="stationData">
王硕 authored
48
          <StationData ref="stationData" :start-deal="startDeal" />
49
        </el-tab-pane>
胡菁 authored
50
51
52
53
        <el-tab-pane
          :label="$t('main.taskCompensation')"
          name="taskCompensation"
        >
胡菁 authored
54
          <TaskCompensation ref="taskCompensation" />
55
56
57
        </el-tab-pane>
      </el-tabs>
    </div>
胡菁 authored
58
59
60
61
  </div>
</template>

<script>
62
import {
63
64
65
66
  getAutoSendStatus,
  getExecuteStatus,
  pause,
  resume,
王硕 authored
67
68
69
70
71
72
73
  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
74
75

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

<style lang="scss" scoped>
胡菁 authored
189
.main {
胡菁 authored
190
191
192
193
194
195
196
197
198
  &-container {
    margin: 30px;
  }
  &-text {
    font-size: 30px;
    line-height: 46px;
  }
}
</style>