From 9dcad0c65f2564fc2fe43e21b23f9faf4a073d30 Mon Sep 17 00:00:00 2001
From: 董国庆 <364620639@qq.com>
Date: 星期二, 28 四月 2026 13:49:47 +0800
Subject: [PATCH] fix: 修复多个页面样式、交互及路由问题

---
 laboratory/src/views/dataManagement/sampleManage/addSample.vue |   48 ++++++++++++++++++++++++++++++++----------------
 1 files changed, 32 insertions(+), 16 deletions(-)

diff --git a/laboratory/src/views/dataManagement/sampleManage/addSample.vue b/laboratory/src/views/dataManagement/sampleManage/addSample.vue
index b6ebfd4..59dbcd4 100644
--- a/laboratory/src/views/dataManagement/sampleManage/addSample.vue
+++ b/laboratory/src/views/dataManagement/sampleManage/addSample.vue
@@ -313,24 +313,22 @@
   created() {
     const userInfo = JSON.parse(sessionStorage.getItem('userInfo') || '{}');
     this.userRole = userInfo.roleType || '';
-
-    // 获取路由参数
-    const { id, type } = this.$route.query;
-    if (id) {
-      this.pageType = type || 'detail';
-      this.getDetailData(id);
-    }
+    this.initPageMode();
+    this.initRouteData();
   },
   activated() {
     const routeId = this.$route.query.id;
     const routeName = this.$route.name;
-    console.log('routeName routeName',routeName)
-    
-    // 如果是编辑路由,且id发生变化,重新加载数据
-    if (routeName === "EditSample" && routeId && routeId !== this.sampleId) {
+
+    this.initPageMode();
+
+    // 如果是编辑/详情路由,且id发生变化,重新加载数据
+    if (
+      (routeName === "editSample" || routeName === "detailSample") &&
+      routeId &&
+      routeId !== this.sampleId
+    ) {
       this.sampleId = routeId;
-      const { type } = this.$route.query;
-      this.pageType = type || 'detail';
       this.getDetailData(routeId);
     }
     // 如果是新增路由,不重置表单,保留用户填写的数据
@@ -346,6 +344,23 @@
   },
   methods: {
     getFullUrl,
+    initPageMode() {
+      const routeName = this.$route.name;
+      if (routeName === 'editSample') {
+        this.pageType = 'edit';
+      } else if (routeName === 'detailSample') {
+        this.pageType = 'detail';
+      } else {
+        this.pageType = 'add';
+      }
+    },
+    initRouteData() {
+      const routeId = this.$route.query.id;
+      if ((this.pageType === 'edit' || this.pageType === 'detail') && routeId) {
+        this.sampleId = routeId;
+        this.getDetailData(routeId);
+      }
+    },
     // 获取详情数据
     async getDetailData(id) {
       this.sampleId = id;
@@ -485,10 +500,11 @@
       });
     },
     back() {
-      this.$router.back();
+      const currentPath = this.$route.path;
+      this.$router.push('/sampleManage/manage');
       this.$store.commit(
         "SET_TAGLIST",
-        this.tagList.filter((item) => item.path !== this.$route.path)
+        this.tagList.filter((item) => item.path !== currentPath)
       );
     },
     // 添加存草稿方法
@@ -678,4 +694,4 @@
     // margin-top: 20px;
   }
 }
-</style>
\ No newline at end of file
+</style>

--
Gitblit v1.7.1