| | |
| | | </th> |
| | | </tr> |
| | | </thead> |
| | | <tbody> |
| | | <tr v-for="(row, rowIndex) in tableData" :key="rowIndex"> |
| | | <tbody ref="tableBody"> |
| | | <tr v-for="(row, rowIndex) in visibleData" :key="rowIndex"> |
| | | <td v-for="(cell, cellIndex) in row" :key="cellIndex"> |
| | | {{ cell }} |
| | | </td> |
| | |
| | | data() { |
| | | return { |
| | | headers: ['车å','è½®å', 'æ°é'], |
| | | tableData: [], // åå¨APIè¿åçæ°æ® |
| | | tableData: [], // åå¨APIè¿åçæææ°æ® |
| | | visibleData: [], // å½åæ¾ç¤ºçæ°æ® |
| | | loading: false, |
| | | error: null |
| | | error: null, |
| | | currentIndex: 0, // å½åæ¾ç¤ºæ°æ®çèµ·å§ç´¢å¼ |
| | | visibleRows: 12, // æ¯æ¬¡æ¾ç¤ºçè¡æ° |
| | | scrollInterval: null, // æ»å¨å®æ¶å¨ |
| | | scrollSpeed: 5000 // æ»å¨é度(毫ç§) |
| | | } |
| | | }, |
| | | created() { |
| | | this.fetchData(); |
| | | }, |
| | | mounted() { |
| | | this.startAutoScroll(); |
| | | }, |
| | | beforeDestroy() { |
| | | this.stopAutoScroll(); |
| | | }, |
| | | methods: { |
| | | fetchData() { |
| | | axios.post("http://172.21.1.139:5000/api/Dt_WheelsStock/InventoryStatistics", null) |
| | | this.loading = true; |
| | | axios.post("http://127.0.0.1:5000/api/Dt_WheelsStock/InventoryStatistics", null) |
| | | .then((response) => { |
| | | this.tableData = []; |
| | | response.forEach(item => { |
| | | response.data.data.slice(0, 12).forEach(item => { |
| | | this.tableData.push([ |
| | | item.wheels_CarType, |
| | | item.wheels_ldxh, |
| | | item.count |
| | | ]); |
| | | }); |
| | | this.updateVisibleData(); |
| | | this.loading = false; |
| | | }) |
| | | .catch((error) => { |
| | | console.error("请æ±å¤±è´¥:", error); |
| | | this.tableData = [ |
| | | ['ææ æ°æ®', 'ææ æ°æ®', 'ææ æ°æ®'], |
| | | ]; |
| | | this.error = "æ°æ®å 载失败"; |
| | | this.loading = false; |
| | | }); |
| | | }, |
| | | startAutoScroll() { |
| | | this.stopAutoScroll(); // å
忢已æç宿¶å¨ |
| | | this.scrollInterval = setInterval(() => { |
| | | if (this.tableData.length > this.visibleRows) { |
| | | this.currentIndex = (this.currentIndex + 1) % this.tableData.length; |
| | | this.updateVisibleData(); |
| | | } |
| | | }, this.scrollSpeed); |
| | | }, |
| | | stopAutoScroll() { |
| | | if (this.scrollInterval) { |
| | | clearInterval(this.scrollInterval); |
| | | this.scrollInterval = null; |
| | | } |
| | | }, |
| | | updateVisibleData() { |
| | | if (this.tableData.length === 0) return; |
| | | |
| | | // è·åå½åå¯è§çæ°æ® |
| | | const endIndex = this.currentIndex + this.visibleRows; |
| | | if (endIndex <= this.tableData.length) { |
| | | this.visibleData = this.tableData.slice(this.currentIndex, endIndex); |
| | | } else { |
| | | // å¤çå¾ªç¯æ»å¨ |
| | | const firstPart = this.tableData.slice(this.currentIndex); |
| | | const secondPart = this.tableData.slice(0, endIndex - this.tableData.length); |
| | | this.visibleData = [...firstPart, ...secondPart]; |
| | | } |
| | | } |
| | | } |
| | | } |
| | |
| | | overflow-x: auto; |
| | | position: relative; |
| | | min-height: 200px; |
| | | max-height: 700px; /* éå¶å®¹å¨é«åº¦ */ |
| | | overflow-y: hidden; /* éèåç´æ»å¨æ¡ */ |
| | | } |
| | | |
| | | .data-table { |
| | |
| | | font-weight: bold; |
| | | padding: 12px 15px; |
| | | text-align: left; |
| | | border-bottom: 2px solid #c9aeae; |
| | | border-bottom: 2px solid #c5c5c5; |
| | | |
| | | position: sticky; |
| | | top: 0; |
| | | } |
| | | |
| | | .data-table td { |
| | | padding: 10px 15px; |
| | | border-bottom: 1px solid #ddd; |
| | | height: 25px; |
| | | border-bottom: 1px solid #696969; |
| | | } |
| | | |
| | | |
| | | .loading, .error { |
| | | padding: 20px; |
| | |
| | | .error { |
| | | color: #f56c6c; |
| | | } |
| | | |
| | | /* æ·»å å¹³æ»æ»å¨ææ */ |
| | | .data-table tbody { |
| | | transition: transform 1s ease-in-out; |
| | | } |
| | | </style> |