cqf
2022-07-12 b75a4660d54caa29048f99215a9e6281ea884098
应急管理文件上传优化
已修改2个文件
102 ■■■■ 文件已修改
src/views/contingencyplan/index.vue 91 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/views/contingencyplan/uploadFile.vue 11 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/views/contingencyplan/index.vue
@@ -9,20 +9,23 @@
        </el-col>
        <el-col :span="5" style="text-align: center">
          <el-button type="primary" class="btns" icon="el-icon-search" @click="find()"
            >搜索</el-button
                    >搜索
                    </el-button
          >
          <el-button
            type="primary"
            icon="el-icon-plus"
            @click="emergencyPlanC('', '新增')"
            class="btns"
            >新增</el-button
                    >新增
                    </el-button
          >
            <el-button
                type="primary"
                class="btns"
                @click="reset()"
            >重置</el-button
                    >重置
                    </el-button
            >
        </el-col>
      </el-row>
@@ -39,7 +42,8 @@
        <el-table-column align="center" label="附件">
            <template slot-scope="scope">
                <div v-if="scope.row.fileType==0">
                    <img :src="envUrl+scope.row.fileList[0].fileUrl" @click="showViewer=true" style="max-width: 100px;height: auto"/>
                        <img :src="envUrl+scope.row.fileList[0].fileUrl" @click="showViewer=true"
                             style="max-width: 100px;height: auto"/>
                    <el-image-viewer
                        v-if="showViewer"
                        :on-close="()=>showViewer=false"
@@ -47,7 +51,8 @@
                    />
                </div>
                <div v-if="scope.row.fileType==1">
                    <span @click="downLoadFile(scope.row.fileList[0].fileUrl)" style="color: #3A71A8 ; cursor: pointer;">{{ scope.row.fileList[0].fileName }}</span>
                        <span @click="downLoadFile(scope.row.fileList[0].fileUrl)"
                              style="color: #3A71A8 ; cursor: pointer;">{{ scope.row.fileList[0].fileName }}</span>
                </div>
            </template>
        </el-table-column>
@@ -61,14 +66,16 @@
            @click="emergencyPlanC(scope.row, '编辑')"
            type="text"
            size="small"
            >编辑</el-button
                    >编辑
                    </el-button
          >
          <el-button
            type="text"
            size="small"
            @click="deleteById(scope.row.id)"
            style="color: red"
            >删除</el-button
                    >删除
                    </el-button
          >
        </template>
      </el-table-column>
@@ -96,11 +103,20 @@
          </el-radio-group>
        </el-form-item>
        <el-form-item v-if="form.fileType==0" label="图片上传">
            <upload-img :imgList="fileList"   @uploadImgSuccess="uploadImgSuccess" @removeImgSuccess="removeImgSuccess"></upload-img>
                    <upload-img :imgList="fileList" @uploadImgSuccess="uploadImgSuccess"
                                @removeImgSuccess="removeImgSuccess"></upload-img>
        </el-form-item>
        <el-form-item label="文件链接" v-if="form.fileType==1">
            <upload-file v-bind:url="fileUrl" v-bind:name="fileName"  @uploadFileSuccess="uploadFileSuccess" ></upload-file>
                <el-form-item label="文件链接" v-if="form.fileType==1" class="multiFile" v-for="(items,index) in files">
                    <upload-file v-bind:url="items.fileUrl" v-bind:name="items.fileName"
                                 @uploadFileSuccess="uploadFileSuccess($event,items)"
                                 @fileNameChange="fileNameChange($event,items)"></upload-file>
        </el-form-item>
                <el-form-item label="" v-if="form.fileType==1" class="multiFile">
                    <el-button @click="addFile">添加文件</el-button>
                </el-form-item>
        <el-form-item label="备注" prop="remark">
          <el-input v-model="form.remark" :rows="5" type="textarea"></el-input>
        </el-form-item>
@@ -122,6 +138,7 @@
  emergencyPlanMod,
  emergencyPlanDel,
} from "@/api/emergencyplan.js";
export default {
  components: { uploadImg , uploadFile ,elImageViewer},
  data() {
@@ -151,6 +168,13 @@
        fileUrl:"",
        fileList:[],
      list: [],
            fileIndex: 1,
            files: [
                {
                    fileName: "",
                    fileUrl: ""
                }
            ],
      rules: {
        name: [
          { required: true, message: "预案名称不能为空", trigger: "change" },
@@ -192,9 +216,13 @@
          this.fileList=[]
      },
      uploadFileSuccess(res){
          this.fileName=res.fileName
          this.fileUrl=res.fileUrl
        uploadFileSuccess(res, item) {
            item.fileName = res.fileName
            item.fileUrl = res.fileUrl
        },
        fileNameChange(res, item) {
            item.fileName = res;
      },
      uploadImgSuccess(res){
@@ -238,10 +266,12 @@
        this.form = {};
        this.fileUrl="";
        this.fileName="";
                this.files = []
        this.fileList=[]
      } else {
        this.title = "编辑";
          this.form=JSON.parse(JSON.stringify(value));
                this.files = this.form.fileList;
        if (this.form.fileType==0){
            this.fileList=value.fileList
        } else{
@@ -251,21 +281,25 @@
      }
    },
    addemergencyPlan() {
            console.log(this.files);
            // return ;
      this.$refs["form"].validate((valid) => {
        if (valid) {
            if (this.form.fileType==0){
                this.form.fileList=this.fileList
            }
            if (this.form.fileType==1){
                let fileList = []
                if (this.fileUrl!=""){
                    let file={
                        fileUrl:this.fileUrl,
                        fileName:this.fileName
                    }
                    fileList.push(file)
                }
                this.form.fileList=fileList
                        // let fileList = []
                        // if (this.fileUrl != "") {
                        //     let file = {
                        //         fileUrl: this.fileUrl,
                        //         fileName: this.fileName
                        //     }
                        //     fileList.push(file)
                        // }
                        this.form.fileList = this.files.filter(n => {
                            return n.fileUrl != null && n.fileUrl != '' && n.fileName != null && n.fileName != '';
                        })
            }
          if (this.title === "新增") {
            emergencyPlanAdd(this.form).then((res) => {
@@ -282,8 +316,7 @@
                  this.$message.error(res.data.message);
              }
            });
          }
         else {
                    } else {
          emergencyPlanMod(this.form).then((res) => {
            if (res.data.code === "200") {
              this.dialogVisible = false;
@@ -333,6 +366,12 @@
                this.listQuery.pageSize = val
                this.emergencyPlan();
            },
        addFile() {
            this.files.push({
                fileUrl: "",
                fileName: ""
            })
        },
            handleCurrentChange(val){
                this.listQuery.pageIndex = val
                this.emergencyPlan();
@@ -345,4 +384,8 @@
  background-color: #034EA2;
  border: 1px solid #034EA2;
}
>>> .el-input.is-disabled .el-input__inner {
    background-color: white;
}
</style>
src/views/contingencyplan/uploadFile.vue
@@ -1,6 +1,6 @@
<template>
  <div style="display: flex">
      <el-input :disabled="true" type="text" size="medium" v-model="viewName" style="width: 60%" ></el-input>
      <el-input :disabled="inputDisable" type="text" size="medium" v-model="viewName" style="width: 60%" @change="fileNameChange" ></el-input>
      <el-upload
          v-if="!disabled"
          action=""
@@ -53,6 +53,7 @@
        fileName: '',
        filePath: '',
        downloadUrl: '',
        inputDisable:true,
        fileList: [],
    }
  },
@@ -101,13 +102,14 @@
                      message:'上传成功',
                      duration:2000,
                  })
                  this.inputDisable = false;
              }else {
                  this.$message.error('上传失败,系统未知错误!错误码为【500】');
              }
          })
      },
      handleClear(){
      handleClear(index){
          this.fileName = '';
          this.fileList = [];
          this.viewName=""
@@ -115,6 +117,11 @@
              fileUrl: '',
              fileName: ''
          });
          this.inputDisable = true;
      },
      fileNameChange(event){
          this.$emit('fileNameChange', event);
      },
      beforeUpload(file) {