Browse Source

Merge branch 'master' of http://gogs.gisvg.com/YDM/museums-ui

wwj 3 days ago
parent
commit
eba8a7f109
1 changed files with 27 additions and 16 deletions
  1. 27 16
      src/views/Home/Index.vue

+ 27 - 16
src/views/Home/Index.vue

@@ -198,6 +198,7 @@ const returnRatio = ref(0);
 
 //初始化
 onMounted(async () => {
+  console.log(123123)
   const { samples } = await WorkbenchApi.getSpecimenTypeList();
   totalSamples.value = samples['标本总数'];
   mineralCount.value = samples['矿物'];
@@ -213,25 +214,35 @@ onMounted(async () => {
   const returnSpecimen = ref();
   const year = new Date().getFullYear()
 
-  //本月出、入、回库数
+// 获取本月出、入、回库数
   enterSpecimen.value = await WorkbenchApi.getEnterSpecimenList(year);
   outSpecimen.value = await WorkbenchApi.getOutSpecimenList(year);
   returnSpecimen.value = await WorkbenchApi.getReturnSpecimenList(year);
-  const enter = enterSpecimen.value.data
-  const out = outSpecimen.value.data
-  const return1 = returnSpecimen.value.data
-  enterNumber.value = enter[monthNum].number;
-  outNumber.value = out[monthNum].number;
-  returnNumber.value = return1[monthNum].number;
-  enterNumber1.value = enter[monthNum-1].number;
-  outNumber1.value = out[monthNum-1].number;
-  // TODO 这里
-  console.log('return1',return1)
-
-  returnNumber1.value = return1[monthNum-1].number;
-  enterRatio.value = (enterNumber.value - enterNumber1.value) / enterNumber.value * 100;
-  outRatio.value = (outNumber.value - outNumber1.value) / outNumber.value * 100;
-  returnRatio.value = (returnNumber.value - returnNumber1.value) / returnNumber.value * 100;
+
+  const enter = enterSpecimen.value.data || [];
+  const out = outSpecimen.value.data || [];
+  const return1 = returnSpecimen.value.data || [];
+
+  enterNumber.value = enter[monthNum]?.number || 0;
+  outNumber.value = out[monthNum]?.number || 0;
+  returnNumber.value = return1[monthNum]?.number || 0;
+
+  if (monthNum > 0) {
+    enterNumber1.value = enter[monthNum - 1]?.number || 0;
+    outNumber1.value = out[monthNum - 1]?.number || 0;
+    returnNumber1.value = return1[monthNum - 1]?.number || 0;
+  } else {
+    enterNumber1.value = 0;
+    outNumber1.value = 0;
+    returnNumber1.value = 0;
+  }
+
+  // 计算比率
+  enterRatio.value = enterNumber.value !== 0 ? ((enterNumber.value - enterNumber1.value) / enterNumber.value * 100) : 0;
+  outRatio.value = outNumber.value !== 0 ? ((outNumber.value - outNumber1.value) / outNumber.value * 100) : 0;
+  returnRatio.value = returnNumber.value !== 0 ? ((returnNumber.value - returnNumber1.value) / returnNumber.value * 100) : 0;
+
+  console.log('return1', return1)
 })