From 3f2b7a46eea73c79183447a2a8ba066e662d5afd Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E2=80=9Cyiyousong=E2=80=9D?= <鈥測ousong_yi@foxmail.com鈥�>
Date: Tue, 9 Jul 2024 11:03:02 +0800
Subject: [PATCH] =?UTF-8?q?perf:=20=E4=BC=98=E5=8C=96=E9=A6=96=E9=A1=B5?=
 =?UTF-8?q?=E6=95=B0=E6=8D=AE=E8=8E=B7=E5=8F=96?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 admin_2/src/pages/home/Home.vue | 47 +++++++++++----------------------
 1 file changed, 16 insertions(+), 31 deletions(-)

diff --git a/admin_2/src/pages/home/Home.vue b/admin_2/src/pages/home/Home.vue
index c2a97f2..fd38e42 100644
--- a/admin_2/src/pages/home/Home.vue
+++ b/admin_2/src/pages/home/Home.vue
@@ -191,40 +191,25 @@ export default {
         let { data } = res.data;
         let { thirtyPhStatList, thirtyPjStatList, thirtyStatList } = data;
         this.homeData = data;
-        this.totalDataset.source = thirtyStatList
-          .map((item) => {
-            return {
-              name: `${item.year}-${String(item.month).padStart(
-                2,
-                "0"
-              )}-${String(item.day).padStart(2, "0")}`,
 
-              value: item.count,
-            };
-          })
-          .reverse();
-        this.phDataset.source = thirtyPhStatList
-          .map((item) => {
-            return {
-              name: `${item.year}-${String(item.month).padStart(
+        const formatData = (list, valueKey) => {
+          return list
+            .map((item) => {
+              let formattedDate = `${item.year}-${String(item.month).padStart(
                 2,
                 "0"
-              )}-${String(item.day).padStart(2, "0")}`,
-              value: item.phCount,
-            };
-          })
-          .reverse();
-        this.pjDataset.source = thirtyPjStatList
-          .map((item) => {
-            return {
-              name: `${item.year}-${String(item.month).padStart(
-                2,
-                "0"
-              )}-${String(item.day).padStart(2, "0")}`,
-              value: item.pjCount,
-            };
-          })
-          .reverse();
+              )}-${String(item.day).padStart(2, "0")}`;
+              return {
+                name: formattedDate,
+                value: item[valueKey],
+              };
+            })
+            .reverse();
+        };
+
+        this.totalDataset.source = formatData(thirtyStatList, "count");
+        this.phDataset.source = formatData(thirtyPhStatList, "phCount");
+        this.pjDataset.source = formatData(thirtyPjStatList, "pjCount");
       }
     },
   },
-- 
2.24.3