田源
2024-07-02 b81638e53bd74ed789215ad34ff9861c2e380609
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
<template>
  <el-dialog
    v-dialogDrag
    :close-on-click-modal="false"
    :destroy-on-close="true"
    :visible.sync="visible"
    :width="width"
    append-to-body
    class="avue-dialog"
    title="上传文件"
    style="margin-top: -20vh !important;"
  >
    <Divider left="30px" text="导入提示"></Divider>
    <ul>
      <li>
        请点击浏览文件进行上传
      </li>
    </ul>
    <Divider left="30px" text="选择文件后会自动上传"></Divider>
    <el-upload
      :before-upload="beforeUpload"
      :data="fileData"
      :headers="uploadHeaders"
      :on-change="uploadChange"
      :on-error="onError"
      :on-success="onSuccess"
      :show-file-list="false"
      action="/api/vciFileUploadController/uploadFile"
      class="upload-demo">
      <el-button size="small" style="margin: 15px 35px" type="primary">浏览文件</el-button>
    </el-upload>
    <template #footer>
      <el-button size="small" @click="visible = false">关闭</el-button>
    </template>
  </el-dialog>
</template>
 
<script>
// import {downloadErrorFile,downloadBatchImportApplyTemplate} from '@/api/template/templateAttr'
import {getToken} from "@/util/auth";
import func from "@/util/func";
import {validatenull} from "@/util/validate";
 
export default {
  name: "upload-file",
  props: {
    paramVOS: {
      type: Object,
      default: {}
    },
    sourceData: {
      //所属区域的上一区域选中数据
      type: Object,
      default: {}
    },
    dataStore: {
      //弹窗时按钮所属区域选中数据
      type: Array,
      default: []
    },
  },
  data() {
    return {
      flga: true,
      pageLoading: null,
      downloadLoading: false,
      visible: false,
    }
  },
  created() {
    console.log(this.sourceData);
  },
  watch: {
    visible: {
      handler(newval, oldval) {
        // console.log('newval',newval)
      }
    }
  },
  computed: {
    uploadHeaders() {
      return {
        "Authorizationtoken": getToken(),
      };
    },
    fileData() {
      return {
        ownbizOid: this.sourceData.oid,
        ownBtmName: this.sourceData.btmname,
        secretGrade: -1,
        fileDocClassify: '',
        updateFileFlag: true,
      }
    },
    width() {
      if (!validatenull(this.paramVOS.width)) {
        if (this.paramVOS.width.includes("px") || this.paramVOS.width.includes("%")) {
          return this.paramVOS.width;
        } else {
          return this.paramVOS.width + "px";
        }
      } else {
        return "40%";
      }
    },
    fullscreen() {
      console.log(this.paramVOS)
      if (this.paramVOS.width || this.paramVOS.height) {
        return false;
      } else if (this.paramVOS.form) {
        return false;
      }
      return true;
    }
  },
  methods: {
    //文件上传前
    async beforeUpload(file) {
      // 获取文件扩展名
      const fileExtension = file.name.split(".").pop().toLowerCase(); // 转换为小写以避免大小写不匹配的问题
      const allowedExtensions = this.paramVOS.fileType || ['css', 'csv', 'doc', 'gif', 'html', 'jpe', 'jpg', 'jpeg', 'png', 'js', 'json',
        'mp3', 'mp4', 'xlsx', 'xml', 'zip', 'xhtml', 'wps', 'ppt', 'xls', 'word', 'pdf', 'txt'];
 
      // 检查文件扩展名是否在允许的文件扩展名数组中
      if (!allowedExtensions.includes(fileExtension)) {
        // 上传格式不符合要求,提示错误信息并取消上传
        this.$message.error(`只允许上传${allowedExtensions.toString()}格式的文件`);
        return Promise.reject(false);
      }
 
      this.pageLoading = this.$loading({
        lock: true,
        text: "文件上传中",
        spinner: "el-icon-loading",
        background: "rgba(0, 0, 0, 0.7)",
      });
 
      return true;
    },
    // 文件上传成功
    onSuccess(resbonse) {
      if (resbonse.code === 200) {
        this.$message.success("上传成功!");
        this.dialogVisible = false;
      }else {
        this.$message.error(resbonse.msg);
      }
    },
    //文件上传失败
    onError(res) {
      this.pageLoading.close();
      this.$message.error(res);
    },
    //文件状态改变
    uploadChange(file) {
      if (file.status === "success" || file.status === "error") {
        this.pageLoading.close();
      }
    }
  }
}
</script>
 
<style lang="scss" scoped>
ul {
  color: rgb(188, 188, 188);
  margin: 20px 0 20px 0;
  padding: 0 0 0 30px;
  list-style: none;
 
  li {
    margin-bottom: 5px;
    font-size: 13px;
  }
}
</style>