From b3f4499793fa7b21f6c5d1e099d6ed170ecbe47a Mon Sep 17 00:00:00 2001
From: 董国庆 <364620639@qq.com>
Date: 星期四, 15 五月 2025 16:38:45 +0800
Subject: [PATCH] 实验方案管理

---
 laboratory/src/components/DynamicComponent/addTableData.vue |   45 +++++++++++++++++++++++++++++++++++++--------
 1 files changed, 37 insertions(+), 8 deletions(-)

diff --git a/laboratory/src/components/DynamicComponent/addTableData.vue b/laboratory/src/components/DynamicComponent/addTableData.vue
index 95267e6..22fcbb7 100644
--- a/laboratory/src/components/DynamicComponent/addTableData.vue
+++ b/laboratory/src/components/DynamicComponent/addTableData.vue
@@ -144,6 +144,8 @@
 </template>
   
 <script>
+import { listByRole } from './service';
+
 export default {
   name: "AddDialog",
   props: {
@@ -173,13 +175,7 @@
       photoList: [],
       spectrumList: [],
       defaultImageUrl: 'https://fuss10.elemecdn.com/e/5d/4a731a90594a4af544c0c25941171jpeg.jpeg', // 默认图片地址
-      userOptions: [
-        { value: '1', label: '用户1' },
-        { value: '2', label: '用户2' },
-        { value: '3', label: '用户3' },
-        { value: '4', label: '用户4' },
-        { value: '5', label: '用户5' }
-      ]
+      userOptions: []
     };
   },
   computed: {
@@ -228,6 +224,20 @@
     },
   },
   methods: {
+    getUserOptions() {
+      listByRole().then(res => {
+        if (res) {
+          this.userOptions = res.map(user => ({
+            value: user.userId,
+            label: user.nickName || user.userName
+          }));
+        } else {
+          this.$message.error('获取用户列表失败');
+        }
+      }).catch(err => {
+        console.error('获取用户列表失败', err);
+      });
+    },
     checkEditPermission(header) {
       if (!header.role || !Array.isArray(header.role)) {
         return true;
@@ -348,6 +358,21 @@
             photos: this.photoList,
             spectrums: this.spectrumList,
           };
+          
+          // 为用户类型字段添加用户完整信息
+          if (this.headerList && this.headerList.length) {
+            this.headerList.forEach(header => {
+              if (header.type === 'user' && Array.isArray(submitData[header.name])) {
+                // 为每个用户类型字段添加userInfo属性,包含用户完整信息
+                submitData[`${header.name}_userInfo`] = submitData[header.name].map(userId => {
+                  const userInfo = this.userOptions.find(user => user.value === userId);
+                  return userInfo ? userInfo : { value: userId, label: userId };
+                });
+              }
+            });
+          }
+          
+          console.log(submitData,'修改的数据')
           this.$emit("success", submitData);
           this.handleClose();
         } else {
@@ -370,7 +395,9 @@
       // 同时更新form中对应的字段值以通过表单验证
       const imageHeader = this.headerList.find(h => h.type === 'image');
       if (imageHeader && imageHeader.name) {
-        this.$set(this.form, imageHeader.name, '默认图片');
+        // 保存图片URL,这样在表格中可以直接使用
+        this.$set(this.form, imageHeader.name, this.defaultImageUrl);
+        console.log('设置图片字段:', imageHeader.name, this.defaultImageUrl);
       }
       
       this.$refs.form.validateField("spectrums");
@@ -381,6 +408,8 @@
 
   },
   mounted() {
+    // 获取用户列表数据
+    this.getUserOptions();
   },
 };
 </script>

--
Gitblit v1.7.1