修复库存分布问题
This commit is contained in:
@@ -173,6 +173,8 @@
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import { listPlantStateCurrent, listPlantStateHistory } from '@/api/pocket/plantState'
|
||||
|
||||
export default {
|
||||
// 3. 响应式数据(替代 Vue 3 的 ref)
|
||||
data() {
|
||||
@@ -190,23 +192,77 @@ export default {
|
||||
// 4. 生命周期钩子(替代 Vue 3 的 onMounted)
|
||||
mounted() {
|
||||
this.getServerData(); // 页面挂载后加载图表数据
|
||||
this.loadCurrentState(); // 加载当前状态
|
||||
},
|
||||
// 5. 方法定义(所有数据处理与逻辑)
|
||||
methods: {
|
||||
// 模拟从服务器获取图表数据
|
||||
// 加载当前设备状态
|
||||
loadCurrentState() {
|
||||
listPlantStateCurrent({ pageNum: 1, pageSize: 10 }).then(response => {
|
||||
if (response.code === 200 && response.rows) {
|
||||
console.log('当前状态数据:', response.rows)
|
||||
// 可以根据实际需求更新页面数据
|
||||
}
|
||||
}).catch(error => {
|
||||
console.error('加载设备状态失败:', error)
|
||||
})
|
||||
},
|
||||
|
||||
// 从服务器获取图表数据
|
||||
getServerData() {
|
||||
setTimeout(() => {
|
||||
// 模拟服务器返回的图表数据
|
||||
const serverRes = {
|
||||
categories: ["2016", "2017", "2018", "2019", "2020", "2021"],
|
||||
series: [
|
||||
{ name: "目标值", data: [35, 36, 31, 33, 13, 34] },
|
||||
{ name: "完成量", data: [18, 27, 21, 24, 6, 28] }
|
||||
]
|
||||
};
|
||||
// 深拷贝避免 Vue 2 响应式引用问题
|
||||
this.chartData = JSON.parse(JSON.stringify(serverRes));
|
||||
}, 500);
|
||||
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)
|
||||
targetData.push(item.value1 || 0)
|
||||
completeData.push(item.value2 || 0)
|
||||
})
|
||||
|
||||
const serverRes = {
|
||||
categories: categories,
|
||||
series: [
|
||||
{ name: "目标值", data: targetData },
|
||||
{ name: "完成量", data: completeData }
|
||||
]
|
||||
}
|
||||
|
||||
this.chartData = JSON.parse(JSON.stringify(serverRes))
|
||||
} else {
|
||||
this.loadDefaultChartData()
|
||||
}
|
||||
}).catch(error => {
|
||||
uni.hideLoading()
|
||||
console.error('加载历史数据失败:', error)
|
||||
this.loadDefaultChartData()
|
||||
})
|
||||
},
|
||||
|
||||
// 加载默认图表数据
|
||||
loadDefaultChartData() {
|
||||
const serverRes = {
|
||||
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(serverRes))
|
||||
},
|
||||
|
||||
// 格式化日期
|
||||
formatDate(dateStr) {
|
||||
if (!dateStr) return ''
|
||||
const date = new Date(dateStr)
|
||||
return `${date.getMonth() + 1}/${date.getDate()}`
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user