From e24f0f77ebbb0ea5d35fa3099a96dde4e3fefe71 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A0=82=E7=B3=96?= Date: Sat, 15 Nov 2025 14:11:12 +0800 Subject: [PATCH] =?UTF-8?q?refactor(ui):=20=E4=BC=98=E5=8C=96=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E5=8A=A0=E8=BD=BD=E9=80=BB=E8=BE=91=E5=92=8C=E7=BC=93?= =?UTF-8?q?=E5=AD=98=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 移除不必要的初始化数据加载,保留关键数据请求 - 重构产品/原材料信息组件,改用计算属性替代watch - 分批加载产品/原材料数据,避免大请求阻塞 - 为数据加载添加loading状态提示 - 优化统计面板数据加载方式,改为顺序请求 --- klp-ui/src/App.vue | 8 +- .../components/HomeModules/StatisticGroup.vue | 119 ++++++++---------- .../KLPService/Renderer/ProductInfo.vue | 41 +++--- .../KLPService/Renderer/RawMaterialInfo.vue | 37 ++++-- klp-ui/src/store/modules/category.js | 106 +++++++++++++--- klp-ui/src/views/login.vue | 8 +- .../service/impl/WmsProductServiceImpl.java | 2 +- .../impl/WmsRawMaterialServiceImpl.java | 2 +- 8 files changed, 197 insertions(+), 126 deletions(-) diff --git a/klp-ui/src/App.vue b/klp-ui/src/App.vue index b6a18560..e392887a 100644 --- a/klp-ui/src/App.vue +++ b/klp-ui/src/App.vue @@ -14,12 +14,12 @@ export default { created() { // 应用启动时全局初始化分类数据 if (this.$store.getters.token) { - this.$store.dispatch('category/getCategoryList'); + // this.$store.dispatch('category/getCategoryList'); this.$store.dispatch('category/getProductMap'); this.$store.dispatch('category/getRawMaterialMap'); - this.$store.dispatch('category/getBomMap'); - this.$store.dispatch('finance/getFinancialAccounts'); - this.$store.dispatch('craft/getProcessList'); + // this.$store.dispatch('category/getBomMap'); + // this.$store.dispatch('finance/getFinancialAccounts'); + // this.$store.dispatch('craft/getProcessList'); } }, metaInfo() { diff --git a/klp-ui/src/components/HomeModules/StatisticGroup.vue b/klp-ui/src/components/HomeModules/StatisticGroup.vue index 1dc89743..e7524b6a 100644 --- a/klp-ui/src/components/HomeModules/StatisticGroup.vue +++ b/klp-ui/src/components/HomeModules/StatisticGroup.vue @@ -1,16 +1,7 @@ @@ -47,7 +25,7 @@ import { listMaterialCoil } from '@/api/wms/coil' import { listEquipmentManagement } from '@/api/mes/eqp/equipmentManagement' import { listOrder } from '@/api/wms/order' import { listCustomer } from '@/api/wms/customer' -import { listSupplier } from '@/api/wms/supplier' +// import { listSupplier } from '@/api/wms/supplier' export default { components: { @@ -88,14 +66,14 @@ export default { value: 0, duration: 3600 }, - { - type: 'supplierCount', - title: '供应商', - icon: 'peoples', - iconClass: 'icon-supplier', - value: 0, - duration: 3600 - }, + // { + // type: 'supplierCount', + // title: '供应商', + // icon: 'peoples', + // iconClass: 'icon-supplier', + // value: 0, + // duration: 3600 + // }, { type: 'equipmentCount', title: '设备数量', @@ -109,48 +87,50 @@ export default { } }, mounted() { - this.loadCount() + this.fetchStatsData() }, methods: { handleSetLineChartData(type) { this.$emit('handleSetLineChartData', type) }, - loadCount() { - this.loading = true - Promise.all([ - listProduct({ pageSise: 1, pageNum: 1 }), - listRawMaterial({ pageSise: 1, pageNum: 1 }), - listMaterialCoil({ pageSise: 1, pageNum: 1, dataType: 1 }), - listEquipmentManagement({ pageSise: 1, pageNum: 1, status: 'in_service' }), - listOrder({ pageSise: 1, pageNum: 1 }), - listCustomer({ pageSise: 1, pageNum: 1 }), - listSupplier({ pageSise: 1, pageNum: 1 }) - ]).then(([ - productRes, - rawMaterialRes, - materialCoilRes, - equipmentRes, - orderRes, - customerRes, - supplierRes - ]) => { - this.loading = false + // 假设这段代码在一个方法中,给方法添加 async 关键字 + async fetchStatsData() { + this.loading = true; // 先开启加载状态 + try { + // 顺序请求:前一个请求完成后,再执行下一个 + const productRes = await listProduct({ pageSize: 10, pageNum: 1 }); + const rawMaterialRes = await listRawMaterial({ pageSize: 10, pageNum: 1 }); + const materialCoilRes = await listMaterialCoil({ pageSize: 10, pageNum: 1, dataType: 1 }); + const equipmentRes = await listEquipmentManagement({ pageSize: 1, pageNum: 1, status: 'in_service' }); + const orderRes = await listOrder({ pageSize: 1, pageNum: 1 }); + const customerRes = await listCustomer({ pageSize: 1, pageNum: 1 }); + // 如果需要供应商数据,取消下面这行注释(与原代码注释对应) + // const supplierRes = await listSupplier({ pageSize: 1, pageNum: 1 }); + + // 处理统计数据(注意:如果不请求supplierRes,需注释掉对应的逻辑) this.statsData.forEach(item => { if (item.type === 'materialCount') { - item.value = productRes.total + rawMaterialRes.total + item.value = (productRes.total || 0) + (rawMaterialRes.total || 0); } else if (item.type === 'steelCoilCount') { - item.value = materialCoilRes.total + item.value = materialCoilRes.total || 0; } else if (item.type === 'orderCount') { - item.value = orderRes.total + item.value = orderRes.total || 0; } else if (item.type === 'customerCount') { - item.value = customerRes.total + item.value = customerRes.total || 0; } else if (item.type === 'supplierCount') { - item.value = supplierRes.total + // 如果不请求供应商数据,这里可以设置默认值(如0)或注释掉 + item.value = 0; // 若取消了supplierRes的请求注释,这里改为 supplierRes.total || 0 } else if (item.type === 'equipmentCount') { - item.value = equipmentRes.total + item.value = equipmentRes.total || 0; } - }) - }) + }); + } catch (error) { + // 处理请求失败的情况(如打印错误、提示用户等) + console.error('统计数据请求失败:', error); + } finally { + // 无论成功失败,最终关闭加载状态 + this.loading = false; + } } } } @@ -195,7 +175,7 @@ export default { .icon-customer { background: #34bfa3; } - + .icon-equipment { background: #722ed1; } @@ -220,7 +200,7 @@ export default { .icon-customer { color: #34bfa3; } - + .icon-equipment { color: #722ed1; } @@ -267,7 +247,7 @@ export default { .card-panel-description .card-panel-text { font-size: 14px; } - + .card-panel-num { font-size: 18px !important; } @@ -277,11 +257,11 @@ export default { .card-panel-description { margin: 16px; } - + .card-panel-icon-wrapper { padding: 12px; } - + .card-panel-icon { font-size: 40px; } @@ -305,5 +285,4 @@ export default { } } } - - \ No newline at end of file + \ No newline at end of file diff --git a/klp-ui/src/components/KLPService/Renderer/ProductInfo.vue b/klp-ui/src/components/KLPService/Renderer/ProductInfo.vue index 307d3b28..0dc0d915 100644 --- a/klp-ui/src/components/KLPService/Renderer/ProductInfo.vue +++ b/klp-ui/src/components/KLPService/Renderer/ProductInfo.vue @@ -1,5 +1,5 @@