From 86c6153f294e61c0ee2268b2651c63313abb56ee Mon Sep 17 00:00:00 2001
From: hejianhao <15708179461@qq.com>
Date: 星期四, 15 五月 2025 17:59:23 +0800
Subject: [PATCH] Merge branch 'main' of http://120.76.84.145:10101/gitblit/r/H5/leshan-laboratory

---
 laboratory/src/components/DynamicComponent/addTableData.vue |   94 ++++++++++++++++++++++++++++-------------------
 1 files changed, 56 insertions(+), 38 deletions(-)

diff --git a/laboratory/src/components/DynamicComponent/addTableData.vue b/laboratory/src/components/DynamicComponent/addTableData.vue
index b8956ac..22fcbb7 100644
--- a/laboratory/src/components/DynamicComponent/addTableData.vue
+++ b/laboratory/src/components/DynamicComponent/addTableData.vue
@@ -62,6 +62,7 @@
                     :disabled="!checkEditPermission(header)"
                   >
                     <i class="el-icon-plus"></i>
+                    <!-- <div slot="tip" class="el-upload__tip">暂未连接服务器,使用默认图片</div> -->
                   </el-upload>
                 </el-form-item>
                 <el-form-item
@@ -143,6 +144,8 @@
 </template>
   
 <script>
+import { listByRole } from './service';
+
 export default {
   name: "AddDialog",
   props: {
@@ -171,13 +174,8 @@
       rules: {},
       photoList: [],
       spectrumList: [],
-      userOptions: [
-        { value: '1', label: '用户1' },
-        { value: '2', label: '用户2' },
-        { value: '3', label: '用户3' },
-        { value: '4', label: '用户4' },
-        { value: '5', label: '用户5' }
-      ]
+      defaultImageUrl: 'https://fuss10.elemecdn.com/e/5d/4a731a90594a4af544c0c25941171jpeg.jpeg', // 默认图片地址
+      userOptions: []
     };
   },
   computed: {
@@ -198,7 +196,6 @@
     visible: {
       handler(newVal) {
         if (newVal) {
-          console.log('弹窗打开,初始化数据');
           this.showHeaderList = JSON.parse(JSON.stringify(this.headerList));
           this.$forceUpdate();
           if (this.isEdit && this.editData) {
@@ -209,8 +206,6 @@
             this.initFormData();
           }
           this.initRules();
-          console.log('初始化后的表单数据:', this.form);
-          console.log('初始化后的校验规则:', this.rules);
         }
       },
     },
@@ -218,7 +213,6 @@
       immediate: true,
       handler(newVal) {
         if (newVal && newVal.length) {
-          console.log('headerList变化,重新初始化');
           if (this.isEdit && this.editData) {
             this.setFormData(this.editData);
           } else {
@@ -228,18 +222,22 @@
         }
       },
     },
-    showHeaderList: {
-      immediate: true,
-      handler(newVal) {
-        if (newVal ) {
-         
-          console.log("222222222222222222", JSON.stringify(newVal));
-          
-        }
-      },
-    },
   },
   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;
@@ -262,7 +260,6 @@
           }
         });
       }
-      console.log('生成的校验规则:', rules);
       this.rules = rules;
     },
     initFormData() {
@@ -286,8 +283,6 @@
       Object.keys(formData).forEach(key => {
         this.$set(this.form, key, formData[key]);
       });
-      
-      console.log('初始化后的表单数据:', this.form);
     },
     setFormData(data) {
       // 设置基础表单数据
@@ -355,23 +350,32 @@
       this.initFormData();
     },
     handleSubmit() {
-      console.log('开始提交表单');
-      console.log('表单数据:', this.form);
-      console.log('校验规则:', this.rules);
       
       this.$refs.form.validate((valid) => {
-        console.log('表单验证结果:', valid);
         if (valid) {
           const submitData = {
             ...this.form,
             photos: this.photoList,
             spectrums: this.spectrumList,
           };
-          console.log('提交数据:', submitData);
+          
+          // 为用户类型字段添加用户完整信息
+          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 {
-          console.log('表单验证失败');
           this.$message.error('请填写必填项');
         }
       });
@@ -381,20 +385,31 @@
       this.$refs.form.validateField("photos");
     },
     handleSpectrumChange(file, fileList) {
-      this.spectrumList = fileList;
+      // 使用默认图片替代实际上传
+      this.spectrumList = [{
+        name: '默认图片.jpg',
+        url: this.defaultImageUrl,
+        status: 'success'
+      }];
+      
+      // 同时更新form中对应的字段值以通过表单验证
+      const imageHeader = this.headerList.find(h => h.type === 'image');
+      if (imageHeader && imageHeader.name) {
+        // 保存图片URL,这样在表格中可以直接使用
+        this.$set(this.form, imageHeader.name, this.defaultImageUrl);
+        console.log('设置图片字段:', imageHeader.name, this.defaultImageUrl);
+      }
+      
       this.$refs.form.validateField("spectrums");
     },
     handleSpectrumRemove(file) {
-      // 处理文件移除逻辑
+      this.spectrumList = [];
     },
 
-    handleIPadSpectrum() {
-      // TODO: 调用 iPad 选择图谱功能
-      console.log("调用 iPad 选择图谱功能");
-    },
   },
   mounted() {
-    console.log("初始headerList:", this.headerList);
+    // 获取用户列表数据
+    this.getUserOptions();
   },
 };
 </script>
@@ -431,7 +446,7 @@
     .form-content {
       flex: 1;
       overflow-y: auto;
-      padding: 0 10px;
+      padding: 10px 10px;
       max-height: calc(90vh - 250px); // 设置内容区域最大高度
 
       &::-webkit-scrollbar {
@@ -447,6 +462,9 @@
         background: #f5f7fa;
       }
     }
+    .el-form-item::after{
+      height: 10px !important;
+    }
   }
 }
 

--
Gitblit v1.7.1