11
huanghongfeng
5 天以前 f4c3f82a3bd142bc555ec7f632dabc66ef86f5af
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
<template>
  <div class="table-container">
    <table class="data-table">
      <thead>
        <tr>
          <th>货位信息</th>
          <th v-for="(status, index) in statusTypes" :key="index">
            {{ status }}
          </th>
        </tr>
      </thead>
      <tbody>
        <tr>
          <td>数量</td>
          <td v-for="(count, index) in statusCounts" :key="index">
            {{ count }}
          </td>
        </tr>
      </tbody>
    </table>
  </div>
</template>
 
<script>
import axios from 'axios';
 
export default {
  data() {
    return {
      statusTypes: ['有货', '空货位', '有货禁用', '锁定'], // 表头状态类型
      statusCounts: [0, 0, 0,0] // 对应状态的数量
    };
  },
  created() {
     this.fetchData();
  },
  methods: {
    fetchData() {
      axios.post("http://127.0.0.1:5000/api/LocationInfo/LocationStatus", null)
        .then((response) => {
          // 假设API返回的数据格式为:[{status: '有货', count: 9}, {status: '空货位', count: 2}, ...]
          const newCounts = [0, 0, 0,0];
          console.log(response.data)
          newCounts[0] = response.data.data[0].count;
          newCounts[1] = response.data.data[1].count;
          newCounts[2] = response.data.data[2].count;
          newCounts[3] = response.data.data[3].count;
 
          this.statusCounts = newCounts;
        })
        .catch((error) => {
          console.error("请求失败:", error);
          // 使用默认数据
          this.statusCounts = [0, 0, 0,0];
        });
    }
  }
};
</script>
 
<style scoped>
.table-container {
  width: 100%;
  overflow-x: auto;
}
 
.data-table {
  width: 100%;
  border-collapse: collapse;
  margin: 20px 0;
  font-family: Arial, sans-serif;
}
 
.data-table th {
  font-weight: bold;
  padding: 12px 15px;
  text-align: center;
  border-bottom: 2px solid #c5c5c5;
}
 
.data-table td {
  padding: 10px 15px;
  border-bottom: 1px solid #696969;
  text-align: center;
}
 
.data-table th:first-child,
.data-table td:first-child {
  text-align: left;
  font-weight: bold;
}
</style>