Selaa lähdekoodia

feat: 添加状态和材料小结功能,优化文件上传逻辑

sunqijun 2 kuukautta sitten
vanhempi
commit
93bd2b1f10

+ 2 - 0
src/api/production-education-training-plan/index.ts

@@ -25,6 +25,8 @@ export interface FormDataType {
   assessmentMethod: string;
   responsibleDeptIds: string[];
   studyHours: number | string;
+  status: number | string;
+  dets:any
 }
 // -------------管理端--------------
 /**

+ 41 - 2
src/views/production-safety/safetyTrainingAndEducation/educationTrainingPlanManagement/components/educationTrainingPlanManagementDetail.vue

@@ -75,6 +75,26 @@
         <el-input v-model.number="form.studyHours" placeholder="输入学时,如6、2、8等,单位时" :disabled="isViewMode" />
       </el-form-item>
     </el-form>
+
+    <!-- 小结内容 -->
+     <section v-if="form.status===2">
+        <h5 class="border-b">材料小结</h5>
+        <div v-if="form.dets.length!==0" v-for="item in form.dets">
+            <el-form  label-width="150px" style="max-width: 600px" label-position="left">
+                <el-form-item label="材料上传" v-if="item.uploadAttach" required>
+                    <ul>
+                        <li  v-for="file in JSON.parse(item.uploadAttach)">
+                            {{ file.name }} <el-button link @click="downloadFn(file)">下载</el-button>
+                        </li>
+                    </ul>
+                </el-form-item>
+                <el-form-item label="培训小结" v-if="item.trainingSummary" required>
+                    <el-input v-model="item.trainingSummary" :disabled="isViewMode"></el-input>
+                </el-form-item>
+            </el-form>
+        </div>
+        
+     </section>
     <!-- 提交按钮 -->
     <footer class="safety-platform-container__footer">
       <el-button @click="router.back()">返回</el-button>
@@ -100,6 +120,7 @@
   import { DeptTree } from '@/types/dept/type';
   import { getAllDepartments } from '@/api/auth/dept';
   import { debounce } from 'lodash-es';
+import { downloadFile } from '@/views/disaster/utils';
   const router = useRouter();
   const route = useRoute();
 
@@ -122,6 +143,8 @@
     assessmentMethod: '',
     responsibleDeptIds: [],
     studyHours: '',
+    status: 0,
+    dets:[]
   });
 
   // 分类名称选项
@@ -148,7 +171,7 @@
     const result = await getAllDepartments();
     deptTree.value = result[0].children;
   };
-
+  const fileList = ref([])
   // 表单引用
   const formRef = ref<FormInstance>();
 
@@ -183,12 +206,20 @@
           ...res,
           responsibleDeptIds: parseDeptIds(res.responsibleDeptIds),
         });
+        fileList.value = res.uploadAttach ? JSON.parse(res.uploadAttach): []
       }
     } catch (e) {
       ElMessage.error('获取详情失败');
     }
   };
-
+  const downloadFn = (item)=>{
+    if(item.url){
+        downloadFile(
+            item.url,
+            item.name,
+        )
+    }
+  }
   const handleSubmit = debounce(async () => {
     const res = await handleValidate();
     if (!res) return;
@@ -229,4 +260,12 @@
   .el-form-item {
     margin-bottom: 25px;
   }
+  li{
+    list-style: none;
+  }
+  .border-b{
+    border-bottom: 1px solid #efefef;
+    padding-bottom:10px;
+    margin-bottom:10px;
+  }
 </style>

+ 22 - 23
src/views/production-safety/safetyTrainingAndEducation/educationTrainingPlanManagementDept/educationTrainingPlanManagementDept.vue

@@ -107,8 +107,6 @@
                     :on-change="handleFileChange"
                     accept=".rar, .zip, .doc, .docx, .pdf, .mp4"
                     :file-list="fileList"
-                    :limit="1"
-                    :on-exceed="handleFileExceed"
                 >
                     <el-button type="default">
                     <el-icon style="margin-right: 6px">
@@ -229,17 +227,8 @@
         fileName: `${uuid}-${timestamp}-${random}`,
         file: data,
     });
-    const fileType = data.fileType;
-    const fileSize = data.fileSize;
-    const fileId = data.fileId;
-    const fileUrl = res.url;
-    return {
-        fileName,
-        fileType,
-        fileSize,
-        fileUrl,
-        fileId,
-    };
+   
+    return res
 };
     // 文件选择更新
   const courseContentUpload = ref();
@@ -252,7 +241,7 @@
     courseContentUpload.value!.handleStart(file); // 手动触发上传
   };
     // 课程内容文件上传
-  const handleFileChange = async (file, fileList) => {
+  const handleFileChange = async (file, fileLists) => {
 
     if (!allowedTypes.includes(file.raw.type)) {
       ElMessage.error('不支持的文件格式');
@@ -265,17 +254,24 @@
     }
     
     if(file.raw){
-        let res = await formatAttachment(file.raw)
-        console.log(res, '文件上传')
-        // form.uploadAttach = 
-        
-        if(res){
-            ElMessage.success('上传成功')
+        try {
+            const res = await formatAttachment(file.raw);
+            
+            const targetFile = fileLists.find(f => f.uid === file.uid);
+            if (targetFile) {
+                targetFile.url = res.url; 
+                targetFile.contentType = res.contentType
+            }
+            fileList.value = fileLists; 
+            form.uploadAttach = JSON.stringify(fileList.value); 
+            ElMessage.success('上传成功');
+        } catch (error) {
+            ElMessage.error('上传失败,请重试');
+            // 上传失败时,可以从 fileLists 中移除该文件
+            fileList.value = fileLists.filter(f => f.uid !== file.uid);
         }
     }
-    // 直接替换为新文件
-    fileList.value = [file.raw]; 
-    form.uploadAttach = file; // 更新表单数据
+
   };
   const saveSummary = async()=>{
     try {
@@ -285,10 +281,13 @@
     } catch (e) {
       ElMessage.error('更新小结失败');
     }
+    dialogVisible.value = false
   }
    const handleSummary = async (row) => {
     dialogVisible.value = true
     form.id = row.id
+    form.trainingSummary = ''
+    form.uploadAttach = ''
   };
   const handleSizeChange = (value: number) => {
     pagination.pageSize = value;