Bladeren bron

fix:修复培训课程信息代码逻辑

sunqijun 2 weken geleden
bovenliggende
commit
e7e05775f0

+ 123 - 124
src/views/production-safety/safetyTrainingAndEducation/educationTrainingPlanManagementDept/components/addTrainingInformation.vue

@@ -1,5 +1,9 @@
 <script lang="ts" setup>
-  import { saveTrainingInformation, updateTrainingInformation, queryEducationTrainingPlanCourseDetail } from '@/api/production-education-training-plan-dept';
+  import {
+    saveTrainingInformation,
+    updateTrainingInformation,
+    queryEducationTrainingPlanCourseDetail,
+  } from '@/api/production-education-training-plan-dept';
   import { ref, reactive, onMounted, watch, shallowRef, computed, nextTick } from 'vue';
   import { UploadFilled, Plus, Delete, Download, ZoomIn } from '@element-plus/icons-vue';
   import { TRAINING_FORM_RULES } from '../configs/form';
@@ -29,7 +33,7 @@
       default: null,
     },
   });
-  
+
   const isViewMode = computed(() => props.state === 'view');
   const isEditMode = computed(() => props.state === 'edit');
   const isCreateMode = computed(() => props.state === 'add');
@@ -37,7 +41,7 @@
   const emit = defineEmits(['update:visible', 'refreshList', 'saveSuccess']);
   const formRef = ref();
   const rules = ref(TRAINING_FORM_RULES);
-   // 富文本编辑器
+  // 富文本编辑器
   const editorRef = shallowRef();
   const form = reactive({
     courseType: '',
@@ -63,21 +67,21 @@
     { label: '特种作业复训考核', value: 4 },
   ]);
 
-   // 上传文件
- const formatAttachment = async (data: any) => {
+  // 上传文件
+  const formatAttachment = async (data: any) => {
     if (!data) return data;
     const uuid = Math.random().toString(36).substring(2, 9);
     const timestamp = Date.now().toString();
     const random = Math.random().toString(36).substring(2, 4);
     const fileName = data.name;
     const res = await uploadFileApi({
-        bizType: UPLOAD_BIZ_TYPE.ATTACHMENT,
-        fileName: `${uuid}-${timestamp}-${random}`,
-        file: data,
+      bizType: UPLOAD_BIZ_TYPE.ATTACHMENT,
+      fileName: `${uuid}-${timestamp}-${random}`,
+      file: data,
     });
     return res;
-};
-const openState = ref(false)
+  };
+  const openState = ref(false);
   // 打开抽屉时的事件
   const openDrawerFn = async () => {
     await nextTick();
@@ -87,49 +91,49 @@ const openState = ref(false)
       await queryEducationTrainingPlanCourseDetail(props.currentId).then((res) => {
         // console.log(res, '课程详情',);
         Object.assign(form, {
-            courseType: res.courseType,
-            courseName: res.courseName,
-            trainingMethod: res.trainingMethod,
-            trainingTeacher: res.trainingTeacher,
-            planNumOfParticipants: res.planNumOfParticipants,
-            startDate: res.startDate ? new Date(res.startDate) : '',
-            endDate: res.endDate ? new Date(res.endDate) : '',
-            courseIntroduction: res.courseIntroduction,
-            isSign: res.isSign,
-        }); 
+          courseType: res.courseType,
+          courseName: res.courseName,
+          trainingMethod: res.trainingMethod,
+          trainingTeacher: res.trainingTeacher,
+          planNumOfParticipants: res.planNumOfParticipants,
+          startDate: res.startDate ? new Date(res.startDate) : '',
+          endDate: res.endDate ? new Date(res.endDate) : '',
+          courseIntroduction: res.courseIntroduction,
+          isSign: res.isSign,
+        });
         form.groupOfParticipants = res.groupOfParticipants ? res.groupOfParticipants.split(',').map(Number) : [];
         // 编辑和查看时 没有回显
-        if(res.courseImg){
-            form.courseImg = JSON.parse(res.courseImg)
-            courseImgList.value = JSON.parse(res.courseImg) || []
+        if (res.courseImg) {
+          form.courseImg = JSON.parse(res.courseImg);
+          courseImgList.value = JSON.parse(res.courseImg) || [];
         }
-        if(res.courseContent){
-            fileList.value =  JSON.parse(res.courseContent) || [];
-            form.courseContent = JSON.parse(res.courseContent)
+        if (res.courseContent) {
+          fileList.value = JSON.parse(res.courseContent) || [];
+          form.courseContent = JSON.parse(res.courseContent);
         }
       });
     } else if (props.state === 'add') {
-        // 新增模式,重置表单
-        fileList.value = [];
-        Object.assign(form, {
-          courseType: '',
-          courseName: '',
-          trainingMethod: '',
-          trainingTeacher: '',
-          planNumOfParticipants: '',
-          groupOfParticipants: [],
-          startDate: '',
-          endDate: '',
-          courseIntroduction: '',
-          courseContent: '', // [] as FileItem[],
-          isSign: 0,
-          courseImg: [] as FileItem[],
-        });
-        courseContentUpload.value?.clearFiles();
-        courseImgRef.value?.clearFiles();
+      // 新增模式,重置表单
+      fileList.value = [];
+      Object.assign(form, {
+        courseType: '',
+        courseName: '',
+        trainingMethod: '',
+        trainingTeacher: '',
+        planNumOfParticipants: '',
+        groupOfParticipants: [],
+        startDate: '',
+        endDate: '',
+        courseIntroduction: '',
+        courseContent: '', // [] as FileItem[],
+        isSign: 0,
+        courseImg: [] as FileItem[],
+      });
+      courseContentUpload.value?.clearFiles();
+      courseImgRef.value?.clearFiles();
     }
   };
-  
+
   const editorConfig = computed(() => ({
     placeholder: '请输入培训课程简述',
   }));
@@ -143,37 +147,37 @@ const openState = ref(false)
 
   //  上传图片
   const handleImageUploadChange = async (file: any, fileLists: any) => {
-    if(file.raw){
-        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
-            }
-            courseImgList.value = fileLists; 
-            form.courseImg = JSON.stringify(fileLists);
-            ElMessage.success('上传成功');
-        } catch (error) {
-            ElMessage.error('上传失败,请重试');
-            // 上传失败时,可以从 fileLists 中移除该文件
-            courseImgList.value = fileLists.filter(f => f.uid !== file.uid);
+    if (file.raw) {
+      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;
         }
+        courseImgList.value = fileLists;
+        form.courseImg = JSON.stringify(fileLists);
+        ElMessage.success('上传成功');
+      } catch (error) {
+        ElMessage.error('上传失败,请重试');
+        // 上传失败时,可以从 fileLists 中移除该文件
+        courseImgList.value = fileLists.filter((f) => f.uid !== file.uid);
+      }
     }
   };
   // 替换图片
   const courseImgRef = ref();
   const handleImageExceed = (files) => {
-    courseImgRef.value!.clearFiles(); 
+    courseImgRef.value!.clearFiles();
     const file = files[0] as UploadRawFile;
-    console.log(file)
+    console.log(file);
     if (!validateImage(file)) {
       return;
     }
-    courseImgRef.value!.handleStart(file); 
+    courseImgRef.value!.handleStart(file);
   };
-// 图片预览
+  // 图片预览
   const dialogVisible = ref(false);
   const dialogImageUrl = ref('');
   const handlePictureCardPreview = (file: any) => {
@@ -181,13 +185,13 @@ const openState = ref(false)
     dialogVisible.value = true;
   };
 
-  const handlePictureCardDelete = (file, fileLists)=>{
-    courseImgRef.value = fileLists.filter(f => f.uid !== file.uid);
-    console.log(courseImgRef.value)
+  const handlePictureCardDelete = (file, fileLists) => {
+    courseImgRef.value = fileLists.filter((f) => f.uid !== file.uid);
+    console.log(courseImgRef.value);
     form.courseImg = JSON.stringify(courseImgRef.value);
-  }
+  };
 
-// 图片格式校验
+  // 图片格式校验
   const validateImage = (file) => {
     const validMIME = [
       'image/jpeg',
@@ -223,15 +227,15 @@ const openState = ref(false)
   };
 
   // 验证文件类型
-    const allowedTypes = [
-      'application/rar',
-      'application/zip',
-      'application/msword',
-      'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
-      'application/vnd.openxmlformats-officedocument.presentationml.presentation',
-      'application/pdf',
-      'video/mp4',
-    ];
+  const allowedTypes = [
+    'application/rar',
+    'application/zip',
+    'application/msword',
+    'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
+    'application/vnd.openxmlformats-officedocument.presentationml.presentation',
+    'application/pdf',
+    'video/mp4',
+  ];
 
   const beforeUpload = (file) => {
     const isAllowedType = allowedTypes.includes(file.type);
@@ -257,8 +261,6 @@ const openState = ref(false)
     courseContentUpload.value!.handleStart(file); // 手动触发上传
   };
 
-
-
   // 课程内容文件上传
   const handleFileChange = async (file, fileLists) => {
     // console.log(file, fileLists, '文件列表')
@@ -272,45 +274,43 @@ const openState = ref(false)
       ElMessage.error('文件大小不能超过20MB');
       return;
     }
-    if(file.raw){
-        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.courseContent = JSON.stringify(fileList.value); 
-            ElMessage.success('上传成功');
-        } catch (error) {
-            ElMessage.error('上传失败,请重试');
-            // 上传失败时,可以从 fileLists 中移除该文件
-            fileList.value = fileLists.filter(f => f.uid !== file.uid);
+    if (file.raw) {
+      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.courseContent = JSON.stringify(fileList.value);
+        ElMessage.success('上传成功');
+      } catch (error) {
+        ElMessage.error('上传失败,请重试');
+        // 上传失败时,可以从 fileLists 中移除该文件
+        fileList.value = fileLists.filter((f) => f.uid !== file.uid);
+      }
     }
-
   };
   // 移除事件
-  const handleFileRemove = (file, fileLists)=>{
-    fileList.value = fileLists.filter(f => f.uid !== file.uid);
-    form.courseContent = JSON.stringify(fileList.value); 
-  }
+  const handleFileRemove = (file, fileLists) => {
+    fileList.value = fileLists.filter((f) => f.uid !== file.uid);
+    form.courseContent = JSON.stringify(fileList.value);
+  };
 
   // 提交保存/编辑
   const handleValidate = async () => {
     if (!formRef.value) return;
     try {
-        await formRef.value.validate();
-        return true;
+      await formRef.value.validate();
+      return true;
     } catch {
-        return false;
+      return false;
     }
   };
   const handleSave = debounce(async () => {
-    
-    if(form.startDate > form.endDate) {
+    if (form.startDate > form.endDate) {
       ElMessage.error('开始日期不能晚于结束日期');
       return;
     }
@@ -322,13 +322,12 @@ const openState = ref(false)
         ...form,
         petpiId: props.currentId,
       };
-    //   console.log('提交的表单数据:', basePayload);
-      
+      //   console.log('提交的表单数据:', basePayload);
+
       if (isCreateMode.value) {
         // 新增,创建接口
         await saveTrainingInformation(basePayload);
         ElMessage.success('创建成功');
-
       } else if (isEditMode.value && props.currentId) {
         // 编辑,更新接口
         await updateTrainingInformation({
@@ -336,7 +335,6 @@ const openState = ref(false)
           ...basePayload,
         });
         ElMessage.success('保存成功');
-
       }
       emit('saveSuccess');
     } catch (e) {
@@ -368,7 +366,7 @@ const openState = ref(false)
       direction="rtl"
       size="45%"
       @opened="openDrawerFn"
-      :title="state === 'add' ? '新增培训课程': state === 'edit' ? '编辑培训课程' : '查看培训课程'"
+      :title="state === 'add' ? '新增培训课程' : state === 'edit' ? '编辑培训课程' : '查看培训课程'"
       @close="$emit('update:visible', false)"
     >
       <el-form label-position="right" label-width="150px" :model="form" :rules="rules" ref="formRef">
@@ -466,13 +464,13 @@ const openState = ref(false)
             </template>
           </el-upload>
           <div class="file-list" v-else>
-          <div class="file-item" v-for="file in fileList" :key="file.fileId">
-            <span class="file-item--name">{{ file.name }}</span>
-            <div class="file-item--footer">
-              <el-button link type="primary" @click.stop="downloadFile(file.url, file.name)">下载</el-button>
+            <div class="file-item" v-for="file in fileList" :key="file.fileId">
+              <span class="file-item--name">{{ file.name }}</span>
+              <div class="file-item--footer">
+                <el-button link type="primary" @click.stop="downloadFile(file.url, file.name)">下载</el-button>
+              </div>
             </div>
           </div>
-        </div>
         </el-form-item>
 
         <el-form-item label="是否需要签名:" prop="isSign">
@@ -495,10 +493,11 @@ const openState = ref(false)
             :on-remove="handlePictureCardDelete"
             :on-preview="handlePictureCardPreview"
             :before-upload="validateImage"
-            list-type="picture-card">
-                <el-icon>
-                    <Plus />
-                </el-icon>
+            list-type="picture-card"
+          >
+            <el-icon>
+              <Plus />
+            </el-icon>
             <template #tip>
               <div class="el-upload__tip"> 支持格式:.jpg .png .jpeg,单个文件不能超过300k,设置一个默认图片。</div>
             </template>
@@ -517,7 +516,7 @@ const openState = ref(false)
             </template> -->
           </el-upload>
           <el-dialog v-model="dialogVisible">
-            <img w-full :src="dialogImageUrl" alt="Preview Image" style="width: 100%;" />
+            <img w-full :src="dialogImageUrl" alt="Preview Image" style="width: 100%" />
           </el-dialog>
         </el-form-item>
       </el-form>
@@ -589,12 +588,12 @@ const openState = ref(false)
   pre {
     white-space: pre-wrap;
   }
-  .file-item{
+  .file-item {
     display: flex;
     justify-content: flex-start;
     align-items: center;
     .file-item--name {
-        margin-right: 20px;
+      margin-right: 20px;
     }
   }
 </style>

+ 157 - 140
src/views/production-safety/safetyTrainingAndEducation/educationTrainingPlanManagementDept/components/educationTrainingPlanManagementDeptDetail.vue

@@ -60,27 +60,27 @@
         </template>
 
         <!-- 查询区 -->
-        <div  style="margin-bottom: 20px" v-if="details.status < 3">
-            <el-button type="primary" :icon="Plus" @click="handleAdd"> 新增课程 </el-button>
+        <div style="margin-bottom: 20px" v-if="details.status < 3">
+          <el-button type="primary" :icon="Plus" @click="handleAdd"> 新增课程 </el-button>
         </div>
         <el-form :inline="true" class="mb-12 flex align-middle act-search">
-            <section class="select-box">
-                <el-form-item>
-                    <el-input v-model="tableQuery.queryParam.courseName" placeholder="搜索培训课程名称" clearable />
-                </el-form-item>
-
-                <el-form-item>
-                    <el-date-picker
-                        v-model="dateRange"
-                        type="daterange"
-                        range-separator="至"
-                        start-placeholder="开始时间"
-                        end-placeholder="结束时间"
-                        value-format="YYYY-MM-DD"
-                        format="YYYY-MM-DD"
-                    />
-                </el-form-item>
-            </section>
+          <section class="select-box">
+            <el-form-item>
+              <el-input v-model="tableQuery.queryParam.courseName" placeholder="搜索培训课程名称" clearable />
+            </el-form-item>
+
+            <el-form-item>
+              <el-date-picker
+                v-model="dateRange"
+                type="daterange"
+                range-separator="至"
+                start-placeholder="开始时间"
+                end-placeholder="结束时间"
+                value-format="YYYY-MM-DD"
+                format="YYYY-MM-DD"
+              />
+            </el-form-item>
+          </section>
           <el-form-item class="search-btn">
             <el-button type="primary" @click="handleSearch"> 查询 </el-button>
             <el-button @click="handleReset"> 重置 </el-button>
@@ -89,7 +89,7 @@
         </el-form>
 
         <!-- 表格 -->
-         <div class="batch-table">
+        <div class="batch-table">
           <BasicTable
             ref="basicTableRef"
             :tableData="tableData"
@@ -109,70 +109,84 @@
         </div>
       </el-card>
     </div>
-    <AddTrainingInformation :state="type" v-model:visible="showAddTrainingInfo" :currentId="currentTableId" @save-success="handleSearch" />
+    <AddTrainingInformation
+      :state="type"
+      v-model:visible="showAddTrainingInfo"
+      :currentId="currentTableId"
+      @save-success="handleSearch"
+    />
     <!-- 签到名单 -->
     <el-dialog v-model="signInDialogVisible" width="70%" :title="'签到名单'">
-        <el-form>
-            <el-row >
-                <el-col :span="16">
-                    <el-row :gutter="12">
-                        <el-col :span="6">
-                            <el-form-item>
-                                <el-input v-model="signInParams.queryParam.keywords" placeholder="搜索工号/姓名" clearable />
-                            </el-form-item>
-                        </el-col>
-                        <el-col :span="8">
-                            <el-form-item>
-                                <el-select v-model="signInParams.queryParam.deptIds" collapse-tags collapse-tags-tooltip :max-collapse-tags="1" multiple  clearable placeholder="请选择使用部门" style="width: 100%;">
-                                    <el-option :label="item.deptName" :value="item.id"  v-for="item in deptTreeOne" :key="item.id" />
-                                </el-select>
-                                <!-- <el-cascader
-                                    v-model="signInParams.queryParam.deptIds"
-                                    :options="deptTreeOne"
-                                    :props="deptCascaderProps"
-                                    :show-all-levels="false"
-                                    placeholder="请选择使用部门"
-                                    filterable
-                                    collapse-tags
-                                    collapse-tags-tooltip
-                                    :max-collapse-tags="2"
-                                    style="width: 100%;"
-                                    clearable
-                                /> -->
-                            </el-form-item>
-                        </el-col>
-                        <el-col :span="9">
-                            <el-form-item>
-                                <el-date-picker
-                                    v-model="signInDateRange"
-                                    type="daterange"
-                                    range-separator="至"
-                                    start-placeholder="开始时间"
-                                    end-placeholder="结束时间"
-                                    value-format="YYYY-MM-DD"
-                                    format="YYYY-MM-DD"
-                                />
-                            </el-form-item>
-                        </el-col>
-                    </el-row>
-                </el-col>
-                <el-col :span="8">
-                    <div class="search-btn">
-                        <el-button type="primary" @click="handleSignInSearch"> 查询 </el-button>
-                        <el-button @click="handleSignInReset"> 重置 </el-button>
-                        <el-button @click="handleSignInExport"> 导出 </el-button>
-                    </div>
-                </el-col>
+      <el-form>
+        <el-row>
+          <el-col :span="16">
+            <el-row :gutter="12">
+              <el-col :span="6">
+                <el-form-item>
+                  <el-input v-model="signInParams.queryParam.keywords" placeholder="搜索工号/姓名" clearable />
+                </el-form-item>
+              </el-col>
+              <el-col :span="8">
+                <el-form-item>
+                  <el-select
+                    v-model="signInParams.queryParam.deptIds"
+                    collapse-tags
+                    collapse-tags-tooltip
+                    :max-collapse-tags="1"
+                    multiple
+                    clearable
+                    placeholder="请选择使用部门"
+                    style="width: 100%"
+                  >
+                    <el-option :label="item.deptName" :value="item.id" v-for="item in deptTreeOne" :key="item.id" />
+                  </el-select>
+                  <!-- <el-cascader
+                        v-model="signInParams.queryParam.deptIds"
+                        :options="deptTreeOne"
+                        :props="deptCascaderProps"
+                        :show-all-levels="false"
+                        placeholder="请选择使用部门"
+                        filterable
+                        collapse-tags
+                        collapse-tags-tooltip
+                        :max-collapse-tags="2"
+                        style="width: 100%;"
+                        clearable
+                    /> -->
+                </el-form-item>
+              </el-col>
+              <el-col :span="9">
+                <el-form-item>
+                  <el-date-picker
+                    v-model="signInDateRange"
+                    type="daterange"
+                    range-separator="至"
+                    start-placeholder="开始时间"
+                    end-placeholder="结束时间"
+                    value-format="YYYY-MM-DD"
+                    format="YYYY-MM-DD"
+                  />
+                </el-form-item>
+              </el-col>
             </el-row>
-        </el-form>
-            <div class="batch-table">
-                <BasicTable
-                    :tableData="signInTableData"
-                    :tableConfig="signInTableConfig"
-                    @update:pageSize="handleSignInSizeChange"
-                    @update:pageNumber="handleSignInCurrentChange"
-                />
+          </el-col>
+          <el-col :span="8">
+            <div class="search-btn">
+              <el-button type="primary" @click="handleSignInSearch"> 查询 </el-button>
+              <el-button @click="handleSignInReset"> 重置 </el-button>
+              <el-button @click="handleSignInExport"> 导出 </el-button>
             </div>
+          </el-col>
+        </el-row>
+      </el-form>
+      <div class="batch-table">
+        <BasicTable
+          :tableData="signInTableData"
+          :tableConfig="signInTableConfig"
+          @update:pageSize="handleSignInSizeChange"
+          @update:pageNumber="handleSignInCurrentChange"
+        />
+      </div>
     </el-dialog>
   </main>
 </template>
@@ -207,7 +221,7 @@
   const currentId = computed(() => Number(route.query.id));
 
   const isViewMode = computed(() => operate.value === 'education-training-plan-management-dept-view');
-  
+
   const details = reactive({
     trainingPlanName: '',
     categoryName: '',
@@ -223,7 +237,7 @@
     createdByName: '',
     createdAt: '',
     deptName: '',
-    status: 0
+    status: 0,
   });
 
   // 表格
@@ -231,7 +245,10 @@
 
   const { tableConfig, pagination } = useTableConfig(COURSE_TABLE_COLUMNS, TABLE_OPTIONS);
 
-  const { tableConfig:signInTableConfig, pagination:signInPagination } = useTableConfig(SIGN_IN_TABLE_COLUMNS, SIGN_IN_TABLE_CONFIG);
+  const { tableConfig: signInTableConfig, pagination: signInPagination } = useTableConfig(
+    SIGN_IN_TABLE_COLUMNS,
+    SIGN_IN_TABLE_CONFIG,
+  );
 
   const tableData = ref([]);
   const type = ref('add');
@@ -262,9 +279,9 @@
   const getDeptTreeData = async () => {
     try {
       const res = await getAllDepartments();
-      deptTreeOne.value = res?.[0]?.children.map(item => ({
+      deptTreeOne.value = res?.[0]?.children.map((item) => ({
         ...item,
-        children: []
+        children: [],
       }));
     } catch (e) {
       console.error('获取部门树失败:', e);
@@ -284,12 +301,12 @@
   };
 
   const handleSearch = () => {
-    showAddTrainingInfo.value = false
+    showAddTrainingInfo.value = false;
     pagination.pageNumber = 1;
     tableQuery.pageNumber = 1;
     getTableList();
   };
-  const handleReset = ()=>{
+  const handleReset = () => {
     pagination.pageNumber = 1;
     pagination.pageSize = 20;
     Object.assign(tableQuery, {
@@ -304,14 +321,14 @@
     });
     dateRange.value = [];
     handleSearch();
-  }
+  };
   const handleExport = async () => {
     try {
-      const response = await exportEducationTrainingPlanCourseData(tableQuery.queryParam)
+      const response = await exportEducationTrainingPlanCourseData(tableQuery.queryParam);
       if (response) {
-          const fileName = `培训课程信息_${new Date().toISOString().split('T')[0]}.xlsx`;
-          downloadByData(response, fileName);
-          ElMessage.success('导出成功');
+        const fileName = `培训课程信息_${new Date().toISOString().split('T')[0]}.xlsx`;
+        downloadByData(response, fileName);
+        ElMessage.success('导出成功');
       }
     } catch (e) {
       console.error('导出培训课程信息失败:', e);
@@ -349,28 +366,28 @@
       startDate: undefined,
       endDate: undefined,
     },
-  })
+  });
   // 打开签到名单弹窗
-  const handleSignInList = async (row)=>{
+  const handleSignInList = async (row) => {
     signInDialogVisible.value = true;
     signInParams.queryParam.id = row.id;
     signInTableData.value = [];
     getSignInList();
-  }
- // 查询签到名单
-  const handleSignInSearch = ()=>{
+  };
+  // 查询签到名单
+  const handleSignInSearch = () => {
     signInParams.pageNumber = 1;
-    if(signInDateRange.value){
-        signInParams.queryParam.startDate = signInDateRange.value[0];
-        signInParams.queryParam.endDate = signInDateRange.value[1];
+    if (signInDateRange.value) {
+      signInParams.queryParam.startDate = signInDateRange.value[0];
+      signInParams.queryParam.endDate = signInDateRange.value[1];
     } else {
-        signInParams.queryParam.startDate = undefined;
-        signInParams.queryParam.endDate = undefined;
+      signInParams.queryParam.startDate = undefined;
+      signInParams.queryParam.endDate = undefined;
     }
     getSignInList();
-  }
+  };
   // 重置签到名单搜索
-  const handleSignInReset = ()=>{
+  const handleSignInReset = () => {
     signInParams.pageNumber = 1;
     signInParams.queryParam.keywords = undefined;
     signInParams.queryParam.deptIds = undefined;
@@ -379,48 +396,48 @@
     signInDateRange.value = [];
     signInTableData.value = [];
     getSignInList();
-  }
+  };
   // 获取签到名单
-    const getSignInList = async ()=>{
-        signInTableConfig.loading = true;
-        try {
-           const res = await querySignInDepartmentList(signInParams);
-           if(res){
-                signInTableData.value = res.records || [];
-                signInPagination.total = res.totalRow;
-           }else {
-                signInTableData.value = [];
-                signInPagination.total = 0;
-           }
-        } catch (error) {
-            console.error('获取签到名单失败:', error);
-            signInTableData.value = [];
-            signInPagination.total = 0;
-        } finally {
-            signInTableConfig.loading = false;
-        }
+  const getSignInList = async () => {
+    signInTableConfig.loading = true;
+    try {
+      const res = await querySignInDepartmentList(signInParams);
+      if (res) {
+        signInTableData.value = res.records || [];
+        signInPagination.total = res.totalRow;
+      } else {
+        signInTableData.value = [];
+        signInPagination.total = 0;
+      }
+    } catch (error) {
+      console.error('获取签到名单失败:', error);
+      signInTableData.value = [];
+      signInPagination.total = 0;
+    } finally {
+      signInTableConfig.loading = false;
     }
-    // 导出签到名单
-  const handleSignInExport = async ()=>{
-    try {       
-       const response = await exportSignInDepartmentList(signInParams.queryParam)
-       if (response) {
-           const fileName = `签到名单_${new Date().toISOString().split('T')[0]}.xlsx`;
-           downloadByData(response, fileName);
-           ElMessage.success('导出成功');
-       }
+  };
+  // 导出签到名单
+  const handleSignInExport = async () => {
+    try {
+      const response = await exportSignInDepartmentList(signInParams.queryParam);
+      if (response) {
+        const fileName = `签到名单_${new Date().toISOString().split('T')[0]}.xlsx`;
+        downloadByData(response, fileName);
+        ElMessage.success('导出成功');
+      }
     } catch (e) {
       console.error('导出签到名单失败:', e);
-        ElMessage.error('导出失败,请重试');
+      ElMessage.error('导出失败,请重试');
     }
   };
   // 分页
-const handleSignInSizeChange = (value: number) => {
+  const handleSignInSizeChange = (value: number) => {
     signInPagination.pageSize = value;
     signInParams.pageSize = value;
     getSignInList();
   };
-//   分页
+  //   分页
   const handleSignInCurrentChange = (value: number) => {
     signInPagination.pageNumber = value;
     signInParams.pageNumber = value;
@@ -439,8 +456,8 @@ const handleSignInSizeChange = (value: number) => {
     tableConfig.loading = true;
     if (!currentId.value) return;
     try {
-      tableQuery.queryParam.dateStart = dateRange.value ? dateRange.value[0]: undefined
-      tableQuery.queryParam.dateEnd = dateRange.value ? dateRange.value[1]: undefined
+      tableQuery.queryParam.dateStart = dateRange.value ? dateRange.value[0] : undefined;
+      tableQuery.queryParam.dateEnd = dateRange.value ? dateRange.value[1] : undefined;
       const res = await queryTrainingTableData(tableQuery);
       if (res) {
         tableData.value = res.records || [];
@@ -466,9 +483,9 @@ const handleSignInSizeChange = (value: number) => {
   };
 
   onMounted(async () => {
-   await getDetail();
-   await getTableList();
-   await getDeptTreeData();
+    await getDetail();
+    await getTableList();
+    await getDeptTreeData();
   });
 </script>
 

+ 102 - 107
src/views/production-safety/safetyTrainingAndEducation/educationTrainingPlanManagementDept/educationTrainingPlanManagementDept.vue

@@ -6,8 +6,7 @@
     <main class="safety-platform-container__main">
       <div class="search-table-container">
         <header>
-          <div style="position: relative">                        
-          </div>
+          <div style="position: relative"> </div>
           <div class="act-search">
             <section class="select-box">
               <div class="select-box--item">
@@ -56,9 +55,7 @@
             <section class="search-btn">
               <el-button type="primary" @click="handleSearch">查询</el-button>
               <el-button @click="handleReset">重置</el-button>
-              <el-button plain  @click="handleDownload">
-                导出   
-              </el-button> 
+              <el-button plain @click="handleDownload"> 导出 </el-button>
             </section>
           </div>
         </header>
@@ -74,7 +71,7 @@
             <template #action="scope">
               <div class="action-container--div" style="justify-content: left">
                 <ActionButton text="查看" @click="handleView(scope.row.id)" />
-                <ActionButton text="小结" v-if="scope.row.status===2" @click="handleSummary(scope.row)" />
+                <ActionButton text="小结" v-if="scope.row.status === 2" @click="handleSummary(scope.row)" />
               </div>
             </template>
           </BasicTable>
@@ -92,39 +89,37 @@
       @update="handleUpdate"
     />
     <el-dialog v-model="dialogVisible" title="填写培训小结">
-        <el-form>
-            <el-form-item label="材料上传" required>
-                <el-upload
-                    action=""
-                    ref="courseContentUpload"
-                    :auto-upload="false"
-                    :on-change="handleFileChange"
-                    accept=".rar, .zip, .doc, .docx, .pdf, .mp4"
-                    :file-list="fileList"
-                >
-                    <el-button type="default">
-                    <el-icon style="margin-right: 6px">
-                        <UploadFilled />
-                    </el-icon>
-                    选择附件
-                    </el-button>
-                    <template #tip>
-                    <div class="el-upload__tip"> 支持格式:.rar .zip .doc .docx .pdf .mp4,单个文件不能超过20MB </div>
-                    </template>
-                </el-upload>
-            </el-form-item>
-            <el-form-item label="培训小结" required>
-                <el-input type="textarea" v-model="form.trainingSummary"></el-input>
-            </el-form-item>
-        </el-form>
-        <template #footer>
-            <div class="dialog-footer">
-                <el-button @click="handleCancel">取消</el-button>
-                <el-button type="primary" @click="saveSummary" >
-                    确认
-                </el-button>
-            </div>
-        </template>
+      <el-form>
+        <el-form-item label="材料上传" required>
+          <el-upload
+            action=""
+            ref="courseContentUpload"
+            :auto-upload="false"
+            :on-change="handleFileChange"
+            accept=".rar, .zip, .doc, .docx, .pdf, .mp4"
+            :file-list="fileList"
+          >
+            <el-button type="default">
+              <el-icon style="margin-right: 6px">
+                <UploadFilled />
+              </el-icon>
+              选择附件
+            </el-button>
+            <template #tip>
+              <div class="el-upload__tip"> 支持格式:.rar .zip .doc .docx .pdf .mp4,单个文件不能超过20MB </div>
+            </template>
+          </el-upload>
+        </el-form-item>
+        <el-form-item label="培训小结" required>
+          <el-input type="textarea" v-model="form.trainingSummary"></el-input>
+        </el-form-item>
+      </el-form>
+      <template #footer>
+        <div class="dialog-footer">
+          <el-button @click="handleCancel">取消</el-button>
+          <el-button type="primary" @click="saveSummary"> 确认 </el-button>
+        </div>
+      </template>
     </el-dialog>
   </div>
 </template>
@@ -138,7 +133,11 @@
   import { TABLE_OPTIONS, TABLE_COLUMNS, STATUS_OPTIONS } from './configs/tables';
   import { useRouter } from 'vue-router';
   import type { QueryPageRequest } from '@/types/basic-query';
-  import { getEducationAndTrainingProgramList, updateEducationTrainingPlanCourseSummary,exportTableData } from '@/api/production-education-training-plan-dept';
+  import {
+    getEducationAndTrainingProgramList,
+    updateEducationTrainingPlanCourseSummary,
+    exportTableData,
+  } from '@/api/production-education-training-plan-dept';
   import { downloadByData } from '@/utils/file/download';
   import BatchImport from '@/components/batch-import/BatchImport.vue';
   import { useGlobSetting } from '@/hooks/setting';
@@ -165,15 +164,15 @@
     { label: '生产作业安全培训', value: '生产作业安全培训' },
     { label: '安全管理人员培训', value: '安全管理人员培训' },
   ]);
-    // 验证文件类型
-    const allowedTypes = [
-      'application/rar',
-      'application/zip',
-      'application/msword',
-      'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
-      'application/pdf',
-      'video/mp4',
-    ];
+  // 验证文件类型
+  const allowedTypes = [
+    'application/rar',
+    'application/zip',
+    'application/msword',
+    'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
+    'application/pdf',
+    'video/mp4',
+  ];
 
   const tableQuery = reactive<QueryPageRequest<any>>({
     pageNumber: pagination.pageNumber,
@@ -191,16 +190,16 @@
       datePlanEnd: undefined,
     },
   });
-  const fileList = ref([])
-  const dialogVisible = ref(false)
-  const handleCancel = ()=>{
-    dialogVisible.value = false
-  }
+  const fileList = ref([]);
+  const dialogVisible = ref(false);
+  const handleCancel = () => {
+    dialogVisible.value = false;
+  };
   const form = reactive({
-    id:'',
+    id: '',
     uploadAttach: '',
-    trainingSummary: ''
-  })
+    trainingSummary: '',
+  });
   const beforeUpload = (file) => {
     const isAllowedType = allowedTypes.includes(file.type);
     const isLt20M = file.size / 1024 / 1024 < 20;
@@ -214,22 +213,22 @@
 
     return isAllowedType && isLt20M;
   };
-     // 上传文件
- const formatAttachment = async (data: any) => {
+  // 上传文件
+  const formatAttachment = async (data: any) => {
     if (!data) return data;
     const uuid = Math.random().toString(36).substring(2, 9);
     const timestamp = Date.now().toString();
     const random = Math.random().toString(36).substring(2, 4);
     const fileName = data.name;
     const res = await uploadFileApi({
-        bizType: UPLOAD_BIZ_TYPE.ATTACHMENT,
-        fileName: `${uuid}-${timestamp}-${random}`,
-        file: data,
+      bizType: UPLOAD_BIZ_TYPE.ATTACHMENT,
+      fileName: `${uuid}-${timestamp}-${random}`,
+      file: data,
     });
-   
-    return res
-};
-    // 文件选择更新
+
+    return res;
+  };
+  // 文件选择更新
   const courseContentUpload = ref();
   const handleFileExceed = (files) => {
     courseContentUpload.value!.clearFiles(); // 清空文件列表
@@ -239,9 +238,8 @@
     }
     courseContentUpload.value!.handleStart(file); // 手动触发上传
   };
-    // 课程内容文件上传
+  // 课程内容文件上传
   const handleFileChange = async (file, fileLists) => {
-
     if (!allowedTypes.includes(file.raw.type)) {
       ElMessage.error('不支持的文件格式');
       return;
@@ -251,33 +249,32 @@
       ElMessage.error('文件大小不能超过20MB');
       return;
     }
-    
-    if(file.raw){
-        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);
+
+    if (file.raw) {
+      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);
+      }
     }
-
   };
-  const saveSummary = async()=>{
-    if(!fileList.value.length){
+  const saveSummary = async () => {
+    if (!fileList.value.length) {
       ElMessage.error('请先上传材料');
       return;
     }
-    if(!form.trainingSummary){
+    if (!form.trainingSummary) {
       ElMessage.error('请输入小结内容');
       return;
     }
@@ -288,13 +285,13 @@
     } catch (e) {
       ElMessage.error('更新小结失败');
     }
-    dialogVisible.value = false
-  }
-   const handleSummary = async (row) => {
-    dialogVisible.value = true
-    form.id = row.id
-    form.trainingSummary = ''
-    form.uploadAttach = ''
+    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;
@@ -315,12 +312,12 @@
         pageNumber: tableQuery.pageNumber,
         pageSize: tableQuery.pageSize,
         queryParam: {
-            ...tableQuery.queryParam,
-            datePlanStart: dateRange.value ? dateRange.value[0] : undefined,
-            datePlanEnd: dateRange.value ? dateRange.value[1] : undefined,
-            status: tableQuery.queryParam.status==='全部'? undefined :tableQuery.queryParam.status
-        }
-      }
+          ...tableQuery.queryParam,
+          datePlanStart: dateRange.value ? dateRange.value[0] : undefined,
+          datePlanEnd: dateRange.value ? dateRange.value[1] : undefined,
+          status: tableQuery.queryParam.status === '全部' ? undefined : tableQuery.queryParam.status,
+        },
+      };
       const res = await getEducationAndTrainingProgramList(params);
       if (res) {
         // 映射返回数据字段到表格字段
@@ -364,8 +361,6 @@
     handleSearch();
   };
 
-
-
   // 批量导入
   const batchImportVisible = ref(false);
   const { urlPrefix } = useGlobSetting();
@@ -385,9 +380,9 @@
     try {
       const response = await exportTableData(tableQuery.queryParam);
       if (response) {
-          const fileName = `教育培训计划管理(部门)_${new Date().toISOString().split('T')[0]}.xlsx`;
-          downloadByData(response, fileName);
-          ElMessage.success('导出成功');
+        const fileName = `教育培训计划管理(部门)_${new Date().toISOString().split('T')[0]}.xlsx`;
+        downloadByData(response, fileName);
+        ElMessage.success('导出成功');
       }
     } catch (e) {
       console.error('导出教育培训计划管理(部门)失败:', e);