Explorar el Código

Merge branch 'cc-dev' into 'dev'

完成添加下一条整改

See merge request product-group-fe/sfy-safety-group/sfy-safety!58
陈昶 hace 10 meses
padre
commit
c28ba2c1e4

+ 22 - 8
src/views/disaster/components/Upload.vue

@@ -2,13 +2,20 @@
   <div class="upload-wrapper">
     <!-- 上传按钮 -->
     <div class="upload-button-container">
-      <label for="fileInput" class="upload-button" :class="{ 'disabled': isUploadDisabled }">
+      <label for="fileInput" class="upload-button" :class="{ disabled: isUploadDisabled }">
         <el-icon><UploadFilled /></el-icon>
         <span>{{ label }}</span>
       </label>
       <span class="upload-button-support">支持pdf、word、excel文件</span>
     </div>
-    <input type="file" id="fileInput" multiple accept=".pdf,.docx,.xls,.xlsx,.ppt,.pptx" @change="handleFileSelect" :disabled="isUploadDisabled" />
+    <input
+      type="file"
+      id="fileInput"
+      multiple
+      accept=".pdf,.docx,.xls,.xlsx,.ppt,.pptx"
+      @change="handleFileSelect"
+      :disabled="isUploadDisabled"
+    />
 
     <!-- 总体进度条 -->
     <div class="progress-container" v-show="showProgress">
@@ -103,15 +110,15 @@
     const files = Array.from(input.files);
     let validFiles = 0;
     tempFiles.value = [];
-    
+
     // 计算可以上传的文件数量
     const remainingSlots = MAX_COUNT.value - fileList.value.length;
-    
+
     // 检查是否超出最大文件数量限制
     if (files.length > remainingSlots) {
       ElMessage.warning(`最多只能上传${MAX_COUNT.value}个文件`);
     }
-    
+
     // 只处理允许数量的文件
     const filesToProcess = files.slice(0, remainingSlots);
 
@@ -186,7 +193,7 @@
     ElMessageBox.confirm('确定删除该文件吗?', '提示', {
       confirmButtonText: '确定',
       cancelButtonText: '取消',
-      customClass: 'customMessageBox--warn'
+      customClass: 'customMessageBox--warn',
     }).then(() => {
       const index = fileList.value.findIndex((item) => item.fileId === id);
       if (index !== -1) {
@@ -196,6 +203,10 @@
     });
   };
 
+  const removeAllFiles = () => {
+    fileList.value = [];
+  };
+
   const simulateFileUpload = () => {
     // 设置初始进度为5%,让用户立即看到进度
     progress.value = 5;
@@ -233,6 +244,9 @@
     }, interval);
   };
   const emit = defineEmits(['uploadSuccess']);
+  defineExpose({
+    removeAllFiles,
+  });
   watch(
     () => props.fileList,
     (newVal) => {
@@ -277,12 +291,12 @@
       background-color: $primary-color;
       color: $white-color;
     }
-    
+
     &.disabled {
       background-color: #f5f5f5;
       color: #aaa;
       cursor: not-allowed;
-      
+
       &:hover {
         background-color: #f5f5f5;
         color: #aaa;

+ 1 - 0
src/views/disaster/disaster-control/PageDisposalManagement.vue

@@ -395,6 +395,7 @@
     if (!confirmed) return;
     await deleteDisasterHandleTask(id);
     ElMessage.success('删除成功');
+    await getDisposalData();
     await getDisposalTableData();
   };
 

+ 96 - 27
src/views/disaster/disaster-control/PageDisposalRectificationItem.vue

@@ -62,7 +62,7 @@
               <span class="label">损失描述:</span>
               <span class="value">{{ LossReportItemFormData?.description }}</span>
             </div>
-            <div class="disaster-information__content--item" v-if="LossReportItemFormData?.images">
+            <div class="disaster-information__content--item" v-if="JSON.parse(LossReportItemFormData?.images).length">
               <span class="label">受灾图片:</span>
               <div class="image-container">
                 <el-image
@@ -93,17 +93,17 @@
         </div>
         <BasicForm ref="basicFormRef" :formData="ruleFormData" :formRules="formRules" :formConfig="ruleFormConfig">
           <template #fixImages>
-            <UploadImages @uploadSuccess="handleUploadImageSuccess" />
+            <UploadImages ref="uploadImagesRef" @uploadSuccess="handleUploadImageSuccess" />
           </template>
           <template #fixMaterials>
-            <Upload label="上传文件" @uploadSuccess="handleUploadFileSuccess" />
+            <UploadFiles ref="uploadFilesRef" label="上传材料" @uploadSuccess="handleUploadFileSuccess" />
           </template>
         </BasicForm>
       </section>
     </main>
     <footer class="disaster-precaution-container__footer">
       <el-button @click="router.back()">取消</el-button>
-      <el-button type="primary" v-if="isShowNextSubmit">提交,并处置下一条</el-button>
+      <el-button type="primary" v-if="isShowNextSubmit" @click="handleNextSubmit">提交,并处置下一条</el-button>
       <el-button type="primary" @click="handleSubmit">提交</el-button>
     </footer>
     <UploadLoading :form-loading="formLoading" v-if="formLoading" />
@@ -116,8 +116,8 @@
   import UploadLoading from '@/components/UploadLoading.vue';
   import BasicForm from '@/components/BasicForm.vue';
   import UploadImages from './src/components/UploadImages.vue';
-  import Upload from '@/views/disaster/components/Upload.vue';
-  import { ref, onMounted } from 'vue';
+  import UploadFiles from '@/views/disaster/components/UploadFiles.vue';
+  import { ref, onMounted, watch, computed, onUnmounted } from 'vue';
   import { useDisasterControlHook } from './src/hook';
   import { useFormConfigHook } from '@/hooks/useFormConfigHook';
   import { useUserInfoHook } from '@/views/disaster/hooks/userInfo';
@@ -133,6 +133,8 @@
   import { ElMessage } from 'element-plus';
 
   const basicFormRef = ref<InstanceType<typeof BasicForm>>();
+  const uploadImagesRef = ref<InstanceType<typeof UploadImages>>();
+  const uploadFilesRef = ref<InstanceType<typeof UploadFiles>>();
 
   const LossReportItemFormData = ref<disasterReportRecordDetailListResponse>();
   const { getLossReportItem, getSafetyLevel, getSafetyLevelDict } = useDisasterControlHook();
@@ -140,12 +142,12 @@
 
   const router = useRouter();
   const route = useRoute();
-  const id = Number(route.params.id);
+  const id = ref<number>(Number(route.params.id));
   const handleTaskId = Number(route.query.handleTaskId);
   const fixTaskId = Number(route.query.fixTaskId);
   const formLoading = ref(false);
   const getLossReportItemData = async () => {
-    const res = await getLossReportItem(handleTaskId, id);
+    const res = await getLossReportItem(handleTaskId, id.value);
     LossReportItemFormData.value = res;
   };
   const { ruleFormConfig, ruleFormData, formRules, cloneRuleFormData, beforeRouteLeave } =
@@ -155,7 +157,9 @@
       DISPOSAL_RECTIFICATION_FORM_RULES,
     );
   const rectificationIds = ref<number[]>([]);
-  const isShowNextSubmit = ref(false);
+  const isShowNextSubmit = computed(() => {
+    return rectificationIds.value.length > 1 && rectificationIds.value.includes(id.value);
+  });
   const handleUploadImageSuccess = (files: File[]) => {
     ruleFormData.uploadImages = files;
   };
@@ -184,44 +188,109 @@
       fileId,
     };
   };
+  const submitDisposalRectification = async () => {
+    const imagesListRes: string[] = await Promise.all(
+      (ruleFormData.uploadImages || []).map((item) => formatImageList(item)),
+    );
+    const fileListRes: FileItem[] = await Promise.all(
+      (ruleFormData.uploadFiles || []).map((item) => formatFileList(item)),
+    );
+    const imagesListString = JSON.stringify(imagesListRes);
+    const fileListString = JSON.stringify(fileListRes);
+    ruleFormData.fixImages = imagesListString;
+    ruleFormData.fixMaterials = fileListString;
+    await createDisposalRectification({
+      fixTaskId,
+      ...ruleFormData,
+    });
+    ElMessage.success('提交成功');
+    cloneRuleFormData();
+  };
   const handleSubmit = async () => {
     if (!basicFormRef.value) return;
     const validateResult = await basicFormRef.value.validateForm();
     if (!validateResult) return;
     formLoading.value = true;
     try {
-      const imagesListRes: string[] = await Promise.all(
-        (ruleFormData.uploadImages || []).map((item) => formatImageList(item)),
-      );
-      const fileListRes: FileItem[] = await Promise.all(
-        (ruleFormData.uploadFiles || []).map((item) => formatFileList(item)),
-      );
-      const imagesListString = JSON.stringify(imagesListRes);
-      const fileListString = JSON.stringify(fileListRes);
-      ruleFormData.fixImages = imagesListString;
-      ruleFormData.fixMaterials = fileListString;
-      await createDisposalRectification({
-        fixTaskId,
-        ...ruleFormData,
-      });
-      ElMessage.success('提交成功');
-      cloneRuleFormData();
+      await submitDisposalRectification();
       router.back();
     } finally {
       formLoading.value = false;
     }
   };
-  onMounted(() => {
+  const defaultRouterName = 'disaster-control-disposal-rectification-item';
+  const handleNextSubmit = async () => {
+    if (!basicFormRef.value) return;
+    const validateResult = await basicFormRef.value.validateForm();
+    if (!validateResult) return;
+    try {
+      await submitDisposalRectification();
+    } finally {
+      formLoading.value = false;
+    }
+    // 查找当前id在数组中的索引
+    const currentIndex = rectificationIds.value.indexOf(id.value);
+
+    if (currentIndex !== -1) {
+      // 从数组中移除当前id
+      rectificationIds.value.splice(currentIndex, 1);
+
+      // 确定下一个要处理的id
+      let nextId;
+      if (currentIndex < rectificationIds.value.length) {
+        // 如果不是最后一个元素,取当前索引位置的元素(移除当前id后,下一个id会自动前移)
+        nextId = rectificationIds.value[currentIndex];
+      } else {
+        // 如果是最后一个元素,取第一个元素
+        nextId = rectificationIds.value[0];
+      }
+
+      // 保存更新后的数组到sessionStorage
+      sessionStorage.setItem('rectificationIds', JSON.stringify(rectificationIds.value));
+      router.replace({
+        name: defaultRouterName,
+        params: {
+          id: nextId,
+        },
+        query: {
+          handleTaskId,
+          fixTaskId,
+        },
+      });
+    }
+
+    const mainElement = document.querySelector('.disaster-precaution-container__main');
+    if (!mainElement) return;
+    mainElement.scrollTop = 0;
+  };
+  const initRuleFormCreatedBy = () => {
     ruleFormData.createdBy = userId;
     ruleFormData.createdByName = realname;
+  };
+  onMounted(() => {
+    initRuleFormCreatedBy();
     cloneRuleFormData();
     beforeRouteLeave();
     getLossReportItemData();
     getSafetyLevelDict();
     const sessionRectificationIds = sessionStorage.getItem('rectificationIds') || '[]';
     rectificationIds.value = JSON.parse(sessionRectificationIds);
-    isShowNextSubmit.value = rectificationIds.value.length > 1 && rectificationIds.value.includes(id);
   });
+  onUnmounted(() => {
+    sessionStorage.removeItem('rectificationIds');
+  });
+  watch(
+    () => route.params.id,
+    (newId) => {
+      id.value = Number(newId);
+      getLossReportItemData();
+      basicFormRef.value?.clearValidate();
+      initRuleFormCreatedBy();
+      uploadImagesRef.value?.removeAllImages();
+      uploadFilesRef.value?.removeAllFiles();
+      cloneRuleFormData();
+    },
+  );
 </script>
 
 <style lang="scss" scoped>

+ 16 - 6
src/views/disaster/disaster-control/src/components/UploadImages.vue

@@ -46,9 +46,9 @@
 </template>
 
 <script lang="ts" setup>
-  import { ref, reactive, computed, watch } from 'vue';
+  import { ref, reactive, computed, watch, onUnmounted } from 'vue';
   import { Camera, Plus } from '@element-plus/icons-vue';
-  import { ElMessage } from 'element-plus';
+  import { ElMessage, ElMessageBox } from 'element-plus';
   import type { ImageItem } from '@/types/disaster-control';
 
   const props = defineProps({
@@ -176,10 +176,17 @@
   };
 
   const removeImage = (index: number) => {
-    // 释放对象URL以避免内存泄漏
-    URL.revokeObjectURL(uploadedImages[index].url);
-    uploadedImages.splice(index, 1);
-    emitChange();
+    ElMessageBox.confirm('确定删除该图片吗?', '提示', {
+      confirmButtonText: '确定',
+      cancelButtonText: '取消',
+      customClass: 'customMessageBox--warn',
+    }).then(() => {
+      // 释放对象URL以避免内存泄漏
+      URL.revokeObjectURL(uploadedImages[index].url);
+      uploadedImages.splice(index, 1);
+      ElMessage.success('删除成功');
+      emitChange();
+    });
   };
 
   const removeAllImages = () => {
@@ -209,6 +216,9 @@
       uploadedImages.push(...urlList);
     },
   );
+  onUnmounted(() => {
+    removeAllImages();
+  });
 </script>
 
 <style lang="scss" scoped>

+ 3 - 3
src/views/disaster/disaster-precaution/PageTaskManagement.vue

@@ -177,7 +177,7 @@
     isBatchDelete.value = Boolean(selectionItems.value.length === publishIds.length);
   };
   const handleBatchPublish = async () => {
-    const confirmed = await openMessageBox('','确认发布任务吗?','warn');
+    const confirmed = await openMessageBox('', '确认发布任务吗?', 'warn');
     if (!confirmed) return;
     const publishIds = getSelectionIds(ACTIVE_STATUS.NOT_EFFECTIVE);
     try {
@@ -188,7 +188,7 @@
     }
   };
   const handleBatchWithdraw = async () => {
-    const confirmed = await openMessageBox('','确认撤回已发布任务吗?','warn');
+    const confirmed = await openMessageBox('', '确认撤回已发布任务吗?', 'warn');
     if (!confirmed) return;
     const withdrawIds = getSelectionIds(ACTIVE_STATUS.ACTIVE);
     try {
@@ -200,7 +200,7 @@
   };
   const basicTableRef = ref<InstanceType<typeof BasicTable>>();
   const handleBatchDelete = async () => {
-    const confirmed = await openMessageBox('','删除后任务不可恢复,确认删除吗?','warn');
+    const confirmed = await openMessageBox('', '删除后任务不可恢复,确认删除吗?', 'warn');
     if (!confirmed) return;
     const deleteIds = getSelectionIds(ACTIVE_STATUS.NOT_EFFECTIVE);
     await deleteTaskManagementItem(deleteIds);

+ 2 - 2
src/views/disaster/disaster-warning/src/components/CreateDefenseNoticeItem.vue

@@ -23,7 +23,7 @@
           </el-select>
         </template>
         <template #attachmentListRes>
-          <Upload label="上传附件" @uploadSuccess="handleUploadSuccess" />
+          <UploadFiles label="上传附件" ref="uploadFilesRef" @uploadSuccess="handleUploadSuccess" />
         </template>
         <template #isPush>
           <el-radio-group v-model="ruleFormData.isPush">
@@ -44,7 +44,7 @@
 
 <script setup lang="ts">
   import BasicForm from '@/components/BasicForm.vue';
-  import Upload from '@/views/disaster/components/Upload.vue';
+  import UploadFiles from '@/views/disaster/components/UploadFiles.vue';
   import { useFormConfigHook } from '@/hooks/useFormConfigHook';
   import { DEFENSE_NOTICE_FROM_CONFIG, DEFENSE_NOTICE_FROM_DATA, DEFENSE_NOTICE_FROM_RULES } from '../config';
   import { IS_PUSH } from '@/views/disaster/constant';

+ 2 - 2
src/views/disaster/disaster-warning/src/components/EditDefenseNoticeItem.vue

@@ -23,7 +23,7 @@
           </el-select>
         </template>
         <template #attachmentListRes>
-          <Upload label="上传附件" :fileList="ruleFormData.attachmentListRes" @uploadSuccess="handleUploadSuccess" />
+          <UploadFiles label="上传附件" ref="uploadFilesRef" :fileList="ruleFormData.attachmentListRes" @uploadSuccess="handleUploadSuccess" />
         </template>
         <template #isPush>
           <el-radio-group v-model="ruleFormData.isPush">
@@ -44,7 +44,7 @@
 
 <script setup lang="ts">
   import BasicForm from '@/components/BasicForm.vue';
-  import Upload from '@/views/disaster/components/Upload.vue';
+  import UploadFiles from '@/views/disaster/components/UploadFiles.vue';
   import { useFormConfigHook } from '@/hooks/useFormConfigHook';
   import { DEFENSE_NOTICE_FROM_CONFIG, DEFENSE_NOTICE_FROM_DATA, DEFENSE_NOTICE_FROM_RULES } from '../config';
   import { onMounted, ref } from 'vue';