From d3b4f3cae65bbb251a05fefd15b9841f740ba452 Mon Sep 17 00:00:00 2001
From: fuliqi <fuliqi@qq.com>
Date: 星期二, 18 六月 2024 16:14:04 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/master'

---
 src/components/UploadC.vue |  132 ++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 132 insertions(+), 0 deletions(-)

diff --git a/src/components/UploadC.vue b/src/components/UploadC.vue
new file mode 100644
index 0000000..1a2e57f
--- /dev/null
+++ b/src/components/UploadC.vue
@@ -0,0 +1,132 @@
+<template>
+  <div>
+    <el-upload :action="uploadUrl" :show-file-list="true" :limit="uploadNum" :accept="acceptList" multiple
+      :file-list="fileUrl" :on-remove="handleRemove" :before-remove="beforeRemove" :on-success="handleUploadSuccess"
+      :before-upload="beforeUpload">
+      <el-button size="small" type="primary">鐐瑰嚮涓婁紶</el-button>
+      <div slot="tip" class="el-upload__tip">鍙兘涓婁紶pdf銆乵p4銆乤vi銆乸ng銆乯pg銆乯pge鏂囦欢锛屼笖涓嶈秴杩噞{ fileSizeLimitM }}M</div>
+      <div v-if="fileUrl && fileUrl.length > 0 && uploadNum === 1">
+        <video controls class="returnShow" v-if="fileType === 'video'" :src="'/api/files/' + fileUrl[0].url"></video>
+        <img class="returnShow" v-if="fileType === 'img'" :src="'/api/files/' + fileUrl[0].url" />
+      </div>
+    </el-upload>
+  </div>
+</template>
+
+<script>
+
+export default {
+  name: "UploadC",
+  props: {
+    uploadNum: {
+      required: false,
+      default: 1,
+      type: Number
+    },
+    fileType: {
+      required: false,
+      type: String
+    },
+    fileSizeLimitM: {
+      required: false,
+      default: 1,
+      type: Number
+    },
+    fileUrl: {
+      type: Array,
+      required: true,
+      default: () => []
+    }
+  },
+  data() {
+    return {
+      uploadUrl: "http://localhost:8000/api/upload/upload",
+      fileTypeList: {
+        'video': ['mp4', 'avi'],
+        'img': ['jpg', 'png', 'jpeg'],
+        'pdf': ['pdf'],
+        'file': ['doc', 'docx', 'xls', 'xlsx', 'ppt', 'pptx', 'txt', 'png', 'jpg', 'jpeg', 'pdf'],
+      }
+    };
+  },
+  methods: {
+    clearFile() {
+      this.fileUrl = [];
+    },
+    beforeRemove(file, fileList) {
+      if (file && file.status === "success") {
+        return this.$confirm(`纭畾绉婚櫎 ${file.name}锛焋);
+      }
+    },
+    handleRemove(file, fileList) {
+      this.$emit('removeFile', this.fileUrl, file.name);
+    },
+    handleUploadSuccess(res, file) {
+      this.fileUrl.push(res.data);
+      this.$emit('getUploadUrl', this.fileUrl);
+    },
+    beforeUpload(file) {
+      const { type } = file;
+      const typeList = this.fileTypeList[this.fileType];
+      let limitType = true;
+      if (typeList) {
+        const tempType = typeList.find(item => {
+          if (type.includes(item)) {
+            return true;
+          } else {
+            return false;
+          }
+        });
+        if (!tempType) {
+          this.$message.error(`璇蜂笂浼犳纭殑鏂囦欢鏍煎紡锛乣);
+          limitType = false;
+        }
+      }
+      const limit = file.size / 1024 / 1024 < this.fileSizeLimitM;
+      if (!limit) {
+        this.$message.error(`涓婁紶鏂囦欢澶у皬涓嶈兘瓒呰繃 ${this.fileSizeLimitM}MB!`);
+      }
+      return limitType && limit;
+    },
+  },
+  computed: {
+    acceptList() {
+      let temp = '.*';
+      if (this.fileTypeList[this.fileType]) {
+        temp = this.fileTypeList[this.fileType].map(item => '.' + item).join(',');
+      }
+      return temp;
+    }
+  }
+};
+</script>
+
+<style scoped>
+.returnShow {
+  width: 300px;
+  height: 200px;
+}
+
+.avatar-uploader {
+  text-align: center;
+  width: 100%
+}
+
+.avatar-uploader-icon:hover {
+  border-color: #409EFF;
+}
+
+.avatar-uploader-icon {
+  font-size: 28px;
+  color: #8c939d;
+  text-align: center;
+  border: 1px dashed #d9d9d9;
+  border-radius: 6px;
+  cursor: pointer;
+
+}
+
+.avatar {
+  display: block;
+}
+</style>

--
Gitblit v1.8.0