Sfoglia il codice sorgente

feat: 添加课程导出功能,优化部门列表获取逻辑,调整培训信息表单数据处理

sunqijun 1 mese fa
parent
commit
43a7978d57

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

@@ -12,6 +12,13 @@ export interface ProductionSafetyFileQuery {
   endDate?: string; // 上传日期范围-结束日期
 }
 
+// 课程参数
+export interface QueryType {
+  petpiId?:string | number;
+  courseName?: string | number;
+  dateStart?: string;
+  dateEnd?:string;
+}
 // 新增、编辑表单数据类型
 export interface FormDataType {
   id?: string; // 编辑时使用
@@ -125,6 +132,24 @@ export function queryEducationTrainingPlanCourseDetail(id: string | number) {
 }
 
 
+/**
+ * @description: 导出课程
+ * @param {QueryType} params
+ * @return {*}
+ */
+export function exportEducationTrainingPlanCourseData(params: QueryType){
+  return http.request(
+    {
+        url: '/educationTrainingPlanIssuance/exportEducationTrainingPlanCourse',
+        method: 'post',
+        responseType: 'blob',
+        params,
+        },
+        { isTransformResponse: false },
+    );
+}
+
+
 /**
  * 教育培训计划管理(部门)-详情
  */

+ 1 - 2
src/views/production-safety/risk-identification-and-control/equipment-high-alert/list.vue

@@ -195,8 +195,7 @@
   const getDeptList = async () => {
     try {
       let res = await deptList()
-      deptTreeList.value = res.records || []
-      console.log(res.records)
+      deptTreeList.value = res || []
     } catch (e) {
       console.error('获取部门树失败:', e);
       deptOptions.value = [];

+ 37 - 27
src/views/production-safety/safetyTrainingAndEducation/educationTrainingPlanManagementDept/components/addTrainingInformation.vue

@@ -12,6 +12,7 @@
   import { ElMessage, UploadRawFile } from 'element-plus';
   import { unformatAttachment, formatAttachmentList } from '@/components/UploadFiles/utils';
   import { uploadFileApi, UPLOAD_BIZ_TYPE } from '@/api/minio';
+  import { downloadFile } from '@/views/disaster/utils';
 
   import { debounce } from 'lodash-es';
   const props = defineProps({
@@ -49,9 +50,10 @@
     courseIntroduction: '',
     courseContent: '', //[] as FileItem[],
     isSign: 0,
-    courseImg: [] as FileItem[],
+    courseImg: '', //[] as FileItem[],
   });
   const fileList = ref<FileItem[]>([]);
+  const courseImgList = ref<FileItem[]>([]);
   const fileInfo = ref<any>(null);
 
   const categoryOptions = ref([
@@ -83,7 +85,7 @@ const openState = ref(false)
       // 编辑/查看模式,加载现有详情数据
       // 这里可以调用接口获取当前培训课程的信息,并填充到 form 中
       await queryEducationTrainingPlanCourseDetail(props.currentId).then((res) => {
-        console.log(res, '课程详情',);
+        // console.log(res, '课程详情',);
         Object.assign(form, {
             courseType: res.courseType,
             courseName: res.courseName,
@@ -98,12 +100,12 @@ const openState = ref(false)
         form.groupOfParticipants = res.groupOfParticipants ? res.groupOfParticipants.split(',').map(Number) : [];
         // 编辑和查看时 没有回显
         if(res.courseImg){
-            form.courseImg = [JSON.parse(res.courseImg)]
+            form.courseImg = JSON.parse(res.courseImg)
+            courseImgList.value = JSON.parse(res.courseImg) || []
         }
         if(res.courseContent){
-            // handleFileExceed(JSON.parse(res.courseContent))
-            // fileList.value =  JSON.parse(res.courseContent) || [];
-            // form.courseContent = res.courseContent
+            fileList.value =  JSON.parse(res.courseContent) || [];
+            form.courseContent = JSON.parse(res.courseContent)
         }
       });
     } else if (props.state === 'add') {
@@ -145,13 +147,24 @@ const openState = ref(false)
   };
 
   //  上传图片
-  const handleImageUploadChange = async (uploadFile: any, uploadFiles: any) => {
-    form.courseImg = uploadFiles;
-    if(uploadFile.raw){
-        let res = await formatAttachment(uploadFile.raw)
-        console.log(res, '图片上传')
-        if(res){
-            ElMessage.success('上传成功')
+  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);
         }
     }
   };
@@ -275,16 +288,7 @@ const openState = ref(false)
             fileList.value = fileLists.filter(f => f.uid !== file.uid);
         }
     }
-    if(file.raw){
-        let res = await formatAttachment(file.raw)
-        console.log(res, '文件上传')
-        if(res){
-            ElMessage.success('上传成功')
-        }
-    }
-    // // 直接替换为新文件
-    // fileList.value = [file.raw]; 
-    // form.courseContent = file; // 更新表单数据
+
   };
 
   // 提交保存/编辑
@@ -304,9 +308,8 @@ const openState = ref(false)
       const basePayload = {
         ...form,
         petpiId: props.currentId,
-        courseImg: form.courseImg[0],
       };
-      console.log('提交的表单数据:', basePayload);
+    //   console.log('提交的表单数据:', basePayload);
       
       if (isCreateMode.value) {
         // 新增,创建接口
@@ -417,7 +420,6 @@ const openState = ref(false)
             <Editor
               style="height: 400px; overflow-y: auto"
               v-model="form.courseIntroduction"
-              mode="disabled"
               :disabled="isViewMode"
               :defaultConfig="editorConfig"
               @on-created="handleEditorCreated"
@@ -446,6 +448,14 @@ const openState = ref(false)
               <div class="el-upload__tip"> 支持格式:.rar .zip .doc .docx .pdf .mp4,单个文件不能超过20MB </div>
             </template>
           </el-upload>
+          <div class="file-list" >
+          <div class="file-item" v-for="file in fileList" :key="file.fileId">
+            <span class="file-item--name">{{ file.fileName }}</span>
+            <div class="file-item--footer">
+              <el-button link type="primary" @click.stop="downloadFile(file.fileUrl, file.fileName)">下载</el-button>
+            </div>
+          </div>
+        </div>
         </el-form-item>
 
         <el-form-item label="是否需要签名:" prop="isSign">
@@ -460,7 +470,7 @@ const openState = ref(false)
             class="image-uploader"
             ref="courseImgRef"
             action="#"
-            :file-list="form.courseImg"
+            :file-list="courseImgList"
             :disabled="isViewMode"
             :auto-upload="false"
             :limit="1"

+ 16 - 4
src/views/production-safety/safetyTrainingAndEducation/educationTrainingPlanManagementDept/components/educationTrainingPlanManagementDeptDetail.vue

@@ -84,7 +84,7 @@
 
         <!-- 表格 -->
         <el-table :data="tableData" border stripe>
-          <el-table-column prop="id" label="编号" width="80" fixed="left" />
+          <el-table-column type="index" label="编号" width="80" fixed="left" />
           <el-table-column prop="courseName" label="培训课程名称" width="240" fixed="left" />
           <el-table-column prop="trainingDate" width="230" label="培训时间" />
           <el-table-column prop="courseTypeName" label="课程所属分类" width="180" />
@@ -128,11 +128,12 @@
     queryTrainingTableData,
     queryEducationAndTrainingProgramDetail,
     deleteTrainingInformation,
+    exportEducationTrainingPlanCourseData,
     type TableParamsType,
   } from '@/api/production-education-training-plan-dept';
   import AddTrainingInformation from './addTrainingInformation.vue';
   import type { QueryPageRequest } from '@/types/basic-query';
-  import { id, pa } from 'element-plus/es/locale';
+  import { downloadByData } from '@/utils/file/download';
   const router = useRouter();
   const route = useRoute();
 
@@ -202,8 +203,19 @@
     getTableList();
   };
 
-  const handleExport = () => {
-    ElMessage.success('点击了导出');
+  const handleExport = async () => {
+    
+    try {
+      const response = await exportEducationTrainingPlanCourseData(tableQuery.queryParam)
+      if (response) {
+          const fileName = `培训课程信息_${new Date().toISOString().split('T')[0]}.xlsx`;
+          downloadByData(response, fileName);
+          ElMessage.success('导出成功');
+      }
+    } catch (e) {
+      console.error('导出培训课程信息失败:', e);
+      ElMessage.error('导出失败,请重试');
+    }
   };
 
   const handleAdd = () => {