修复库存分布问题

This commit is contained in:
2025-10-31 14:50:19 +08:00
parent 331faa3971
commit 6431f0e0eb
6 changed files with 460 additions and 77 deletions

View File

@@ -152,6 +152,8 @@
</template>
<script>
import { listPlantStateCurrent, listPlantStateHistory } from '@/api/pocket/plantState'
export default {
// 响应式数据(替代 Vue 3 的 ref
data() {
@@ -173,22 +175,86 @@ export default {
// 生命周期钩子(替代 Vue 3 的 onMounted
mounted() {
this.getServerData() // 页面挂载后加载数据
this.loadCurrentState() // 加载当前状态
},
// 方法定义(所有函数需放在 methods 中)
methods: {
// 模拟从服务器获取数据
getServerData() {
setTimeout(() => {
const res = {
categories: ['2016', '2017', '2018', '2019', '2020', '2021'],
series: [
{ name: '目标值', data: [35, 36, 31, 33, 13, 34] },
{ name: '完成量', data: [18, 27, 21, 24, 6, 28] }
]
// 加载当前设备状态
loadCurrentState() {
uni.showLoading({ title: '加载中' })
listPlantStateCurrent({ pageNum: 1, pageSize: 10 }).then(response => {
uni.hideLoading()
if (response.code === 200 && response.rows) {
// 处理当前状态数据
console.log('当前状态数据:', response.rows)
// 可以根据实际需求更新status数据
}
// 深拷贝避免引用问题Vue 2 响应式兼容)
this.chartData = JSON.parse(JSON.stringify(res))
}, 500)
}).catch(error => {
uni.hideLoading()
console.error('加载设备状态失败:', error)
})
},
// 从服务器获取历史数据用于图表
getServerData() {
uni.showLoading({ title: '加载中' })
listPlantStateHistory({ pageNum: 1, pageSize: 20 }).then(response => {
uni.hideLoading()
if (response.code === 200 && response.rows && response.rows.length > 0) {
// 处理历史数据,转换为图表需要的格式
const categories = []
const targetData = []
const completeData = []
response.rows.forEach(item => {
// 根据实际数据结构调整
const dateStr = this.formatDate(item.insdate)
categories.push(dateStr)
// 这里使用value1和value2作为示例实际应根据业务需求调整
targetData.push(item.value1 || 0)
completeData.push(item.value2 || 0)
})
const res = {
categories: categories,
series: [
{ name: '目标值', data: targetData },
{ name: '完成量', data: completeData }
]
}
this.chartData = JSON.parse(JSON.stringify(res))
} else {
// 如果没有数据,使用默认数据
this.loadDefaultChartData()
}
}).catch(error => {
uni.hideLoading()
console.error('加载历史数据失败:', error)
// 加载失败时使用默认数据
this.loadDefaultChartData()
})
},
// 加载默认图表数据
loadDefaultChartData() {
const res = {
categories: ['2016', '2017', '2018', '2019', '2020', '2021'],
series: [
{ name: '目标值', data: [35, 36, 31, 33, 13, 34] },
{ name: '完成量', data: [18, 27, 21, 24, 6, 28] }
]
}
this.chartData = JSON.parse(JSON.stringify(res))
},
// 格式化日期
formatDate(dateStr) {
if (!dateStr) return ''
const date = new Date(dateStr)
return `${date.getMonth() + 1}/${date.getDate()}`
}
}
}