3 Commits 7b6f0bcd40 ... 54b001e9f6

Author SHA1 Message Date
  wwj 54b001e9f6 Merge remote-tracking branch 'origin/master' 2 weeks ago
  wwj eba8a7f109 Merge branch 'master' of http://gogs.gisvg.com/YDM/museums-ui 2 weeks ago
  wwj a8f8c3e4cc Merge branch 'master' of http://gogs.gisvg.com/YDM/museums-ui 2 months ago
2 changed files with 32 additions and 20 deletions
  1. 27 16
      src/views/Home/Index.vue
  2. 5 4
      src/views/Home/echarts-data.ts

+ 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)
 })
 
 

+ 5 - 4
src/views/Home/echarts-data.ts

@@ -85,11 +85,12 @@ const returnNum = return1.map(return1 => return1.number);
 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;
-console.log(out)
+enterNumber1.value = enter[monthNum].number;
+outNumber1.value = out[monthNum].number;
+
+console.log('out',enter,out,return1,outNumber1.value,enterNumber1.value)
 // TODO 这里
-returnNumber1.value = return1[monthNum-1].number;
+returnNumber1.value = return1[monthNum].number;
 
 //月环比
 enterRatio.value = (enterNumber.value-enterNumber1.value)/enterNumber.value*100;