| | |
| | | <template> |
| | | <div class="table-container"> |
| | | <table class="data-table"> |
| | | <thead> |
| | | <tr> |
| | | <th v-for="(header, index) in headers" :key="index"> |
| | | {{ header }} |
| | | </th> |
| | | </tr> |
| | | </thead> |
| | | <tbody> |
| | | <tr v-for="(row, rowIndex) in tableData" :key="rowIndex"> |
| | | <td v-for="(cell, cellIndex) in row" :key="cellIndex"> |
| | | {{ cell }} |
| | | </td> |
| | | </tr> |
| | | </tbody> |
| | | </table> |
| | | </div> |
| | | </template> |
| | | |
| | | <script> |
| | | <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 { |
| | | headers: ['è´§ä½ä¿¡æ¯', 'æ°é'], |
| | | tableData: [] |
| | | statusTypes: ['æè´§', '空货ä½', 'æè´§ç¦ç¨', 'éå®'], // è¡¨å¤´ç¶æç±»å |
| | | statusCounts: [0, 0, 0,0] // 对åºç¶æçæ°é |
| | | }; |
| | | }, |
| | | created() { |
| | | this.fetchData(); |
| | | this.fetchData(); |
| | | }, |
| | | methods: { |
| | | fetchData() { |
| | | axios.post("http://172.21.1.139:5000/api/LocationInfo/LocationStatus", null) |
| | | axios.post("http://127.0.0.1:5000/api/LocationInfo/LocationStatus", null) |
| | | .then((response) => { |
| | | this.tableData = []; |
| | | response.forEach(item => { |
| | | this.tableData.push([ |
| | | item.status, |
| | | item.count |
| | | ]); |
| | | }); |
| | | // å设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.tableData = [ |
| | | ['空货ä½', 0], |
| | | ['æè´§', 0], |
| | | ['å ç¨', 0] |
| | | ]; |
| | | // 使ç¨é»è®¤æ°æ® |
| | | 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: left; |
| | | border-bottom: 2px solid #c9aeae; |
| | | } |
| | | |
| | | .data-table td { |
| | | padding: 10px 15px; |
| | | border-bottom: 1px solid #ddd; |
| | | } |
| | | </style> |
| | | |
| | | <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> |