<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>
|