Your Name
2022-04-06 37b718547bc441c7502f0bfcf86209efe253851b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
<template>
  <div style="display: flex">
      <el-input :disabled="true" type="text" size="medium" v-model="viewName" style="width: 60%" ></el-input>
      <el-upload
          v-if="!disabled"
          action=""
          multiple
          :limit="1"
          :file-list="fileList"
          :http-request="uploadSectionFile"
          :show-file-list="false"
          :before-upload="beforeUpload"
          :on-success="handleSuccess"
          :on-error="handleError"
      >
          <div style="">
              <el-button v-if="!fileName" type="primary" size="small" style="margin-left:25px;;width:65px;height:36px;display: flex;align-items: center;justify-content: center">上传<i class="el-icon-upload el-icon--right"></i></el-button>
          </div>
      </el-upload>
 
      <div style="display: flex">
          <a  v-if="!disabled&&fileName">
              <el-button @click="downLoadFile(downloadUrl)"  slot="tip" type="primary" size="small" style="margin-left:25px;width:65px;height:36px;display: flex;align-items: center;justify-content: center">
                  下载<i class="el-icon-download el-icon--right"></i>
              </el-button>
          </a>
          <el-button v-if="!disabled&&fileName" slot="tip" type="primary" size="small  " @click="handleClear" style="margin-left:5px;width:65px;height:36px;display: flex;align-items: center;justify-content: center"
          >清除<i class="el-icon-delete el-icon--right"></i></el-button>
      </div>
  </div>
</template>
 
<script>
 
    import {emergencyPlanUpload} from "@/api/emergencyplan.js";
 
export default {
    props: {
        name: {
            type: String
        },
        url: {
            type: String
        },
        disabled: {
            type: Boolean
        }
    },
  data() {
    return {
        action: '',
        viewName:'',
        fileName: '',
        filePath: '',
        downloadUrl: '',
        fileList: [],
    }
  },
    mounted() {
        setTimeout(() => {
            this.fileName = this.$props.name;
            this.downloadUrl = this.$props.url;
            this.viewName=this.$props.name
        }, 100);
    },
    watch: {
        name() {
            this.fileName = this.$props.name;
            this.downloadUrl = this.$props.url;
            this.viewName=this.$props.name;
        }
    },
  methods: {
 
      downLoadFile(fileUrl){
          let a = document.createElement('a')
          // a.href = this.defaultUrl+`/upload/downloadNew?path=`+encodeURI(fileUrl)
          a.href = process.env.BASE_API + '/upload/'+fileUrl
          a.click();
      },
 
      downloadFile(){
 
      },
      uploadSectionFile(param) {
          let form = new FormData();
          form.append('file', param.file);
          emergencyPlanUpload(form).then(res=>{
              if (res.data.code==200){
                  this.fileName = res.data.result.fileName;
                  this.viewName=res.data.result.fileName;
                  this.downloadUrl=res.data.result.fileUrl
                  this.$nextTick(() => {
                      this.$emit('uploadFileSuccess', {
                          fileName: this.fileName,
                          fileUrl: this.downloadUrl
                      });
                  });
                  this.$message({
                      type:'success',
                      message:'上传成功',
                      duration:2000,
                  })
              }else {
                  this.$message.error('上传失败,系统未知错误!错误码为【500】');
              }
          })
      },
 
      handleClear(){
          this.fileName = '';
          this.fileList = [];
          this.viewName=""
          this.$emit('uploadFileSuccess', {
              fileUrl: '',
              fileName: ''
          });
      },
 
      beforeUpload(file) {
      },
      handleError(err, file, fileList) {
          this.$message.error('上传失败,系统未知错误!错误码为【500】');
      },
      handleSuccess(err, file, fileList) {
      },
  }
}
</script>