xiangpei
2025-06-05 1fa6ac40e2ce16e1174cec9ca538d45eeb660fdc
src/views/projectEngineering/projectLibrary/component/FileDialog.vue
@@ -17,13 +17,13 @@
      <template slot="default">
        <div v-if="!isImportOrExport" class="dialog-content">
          <el-upload
            ref="uploadRef"
            ref="upload"
            class="upload-demo"
            :action="uploadUrl"
            :action="upload.url"
            :limit="1"
            :accept="accept"
            :headers="uploadHeaders"
            :disabled="uploadIsUploading"
            :headers="upload.headers"
            :disabled="upload.isUploading"
            :on-progress="handleFileUploadProgress"
            :on-success="handleFileSuccess"
            :auto-upload="false"
@@ -37,9 +37,9 @@
        </div>
        <div v-else-if="isImportOrExport" class="dialog-content">
          <el-button class="export-button" @click="handleDownloadTargetList">导出目标列表内容</el-button>
          <el-button class="export-button">导出所有列表内容</el-button>
          <el-button class="export-button">导出目标项目详情</el-button>
          <el-button class="export-button">导出所有项目详情</el-button>
          <el-button class="export-button" @click="handleDownloadAllList">导出所有列表内容</el-button>
          <el-button class="export-button" @click="handleDownloadDetailList">导出目标项目详情</el-button>
          <el-button class="export-button" @click="handleDownloadAllList">导出所有项目详情</el-button>
        </div>
      </template>
      <template slot="footer">
@@ -54,7 +54,7 @@
</template>
<script>
import { globalHeaders } from '@/utils/request';
import {getToken} from "@/utils/auth";
export default {
@@ -73,17 +73,31 @@
      default: function () {
        return [];
      }
    }
    },
    dataIdList: {
      type: Array,
      default: function () {
        return [];
      }
    },
  },
  data() {
    return {
      queryParams: {},
      uploadRef: null,
      targetColumn: [],
      accept: `.zip`,
      uploadUrl: '/project/import',
      uploadHeaders: {},
      uploadIsUploading: false
      upload:{
        // 是否显示弹出层(用户导入)
        open: false,
        // 弹出层标题(用户导入)
        title: '',
        // 是否禁用上传
        isUploading: false,
        // 设置上传的请求头部
        headers: { Authorization: "Bearer " + getToken() },
        // 上传的地址
        url: process.env.VUE_APP_BASE_API + '/project/info/import'
      },
    };
  },
  methods: {
@@ -91,30 +105,20 @@
      console.log("子组件submit")
    },
    handleFileUploadProgress() {
      this.uploadIsUploading = true;
      this.upload.uploadIsUploading = true;
    },
    handleFileSuccess(response, file) {
      this.uploadIsUploading = false;
      if (this.uploadRef) {
        this.uploadRef.handleRemove(file);
      }
      if (response.code === 200) {
        this.$emit('fileDialogCancel');
        this.$message({
          message: response.msg,
          type: 'success'
        });
      } else {
        this.$message.error(response.msg);
      }
    // 文件上传成功处理
    handleFileSuccess(response, file, fileList) {
      this.upload.open = false;
      this.upload.isUploading = false;
      this.$refs.upload.clearFiles();
      this.$alert("<div style='overflow: auto;overflow-x: hidden;max-height: 70vh;padding: 10px 20px 0;'>" + response.msg + "</div>", "导入结果", { dangerouslyUseHTMLString: true });
    },
    handleDownloadFile() {
      this.download('/project/info/export/template', {}, `项目文件模板_${new Date().getTime()}.zip`)
    },
    submitFileForm() {
      if (this.uploadRef) {
        this.uploadRef.submit();
      }
        this.$refs.upload.submit();
    },
    closeDialog() {
      this.$emit('fileDialogCancel');
@@ -125,14 +129,23 @@
      this.download('project/info/export', {
          ...this.queryParams
        }, `项目库${new Date().getTime()}.xlsx`)
    },
    handleDownloadAllList() {
      this.queryParams.fieldList = this.currentColumns;
      this.queryParams.requireFile = false;
      this.download('project/info/export', {
        ...this.queryParams
      }, `项目库${new Date().getTime()}.xlsx`)
    },
    handleDownloadDetailList() {
      this.queryParams.dataIdList = this.dataIdList
      this.queryParams.requireFile = true;
      this.download('project/info/export', {
        ...this.queryParams
      }, `项目库${new Date().getTime()}.zip`)
    }
  },
  mounted() {
    this.uploadRef = this.$refs.uploadRef;
  },
  created() {
    this.isFileDialogVisible = this.fileDialogVisible;
  }
};
</script>