|
@@ -0,0 +1,278 @@
|
|
|
+<template>
|
|
|
+ <div>
|
|
|
+ <div class="file-area">
|
|
|
+ <span class="label-text">{{ labelText }}</span>
|
|
|
+ <div class="upload-box">
|
|
|
+ <el-upload
|
|
|
+ ref="upload"
|
|
|
+ class="file-uploader"
|
|
|
+ action="no"
|
|
|
+ :accept="acceptFileType"
|
|
|
+ :multiple="true"
|
|
|
+ :show-file-list="false"
|
|
|
+ :auto-upload="false"
|
|
|
+ :on-change="onFileChange"
|
|
|
+ >
|
|
|
+ <el-button>选取{{ labelText }}文件</el-button>
|
|
|
+ </el-upload>
|
|
|
+ <el-button size="small" type="primary" @click="uploadFiles">上传</el-button>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ <el-divider />
|
|
|
+ <div class="upload-tip">{{ uploadTip }}</div>
|
|
|
+ <ul slot="file-list" class="file-list">
|
|
|
+ <li v-for="(file, i) in file_info_list" :key="i">
|
|
|
+ <div class="file-name">
|
|
|
+ <span>
|
|
|
+ <SvgIcon :icon-class="iconClass" size="12" />
|
|
|
+ <span>{{ file.name }}</span>
|
|
|
+ <!-- <span>({{ file.size }})</span> -->
|
|
|
+ </span>
|
|
|
+ <span v-show="file.progress > 0">
|
|
|
+ <!-- <SvgIcon icon-class="progress" size="12" /> -->
|
|
|
+ {{ file.progress }}%
|
|
|
+ </span>
|
|
|
+ </div>
|
|
|
+ <SvgIcon icon-class="delete-black" size="12" @click="removeFile(file, i)" />
|
|
|
+ <SvgIcon v-show="moduleData.type == 'picture'" icon-class="mark" size="12" @click="viewDialog" />
|
|
|
+ </li>
|
|
|
+ </ul>
|
|
|
+
|
|
|
+ <FillDescribe :visible.sync="visible" @fillDescribeToFile="fillDescribeToFile" />
|
|
|
+ </div>
|
|
|
+</template>
|
|
|
+
|
|
|
+<script>
|
|
|
+import ModuleMixin from '../../common/ModuleMixin';
|
|
|
+import { fileUpload, GetFileStoreInfo } from '@/api/app';
|
|
|
+import { conversionSize } from '@/utils/common';
|
|
|
+import FillDescribe from '../../common/FillDescribe';
|
|
|
+
|
|
|
+export default {
|
|
|
+ name: 'UploadFile',
|
|
|
+ components: {
|
|
|
+ FillDescribe,
|
|
|
+ },
|
|
|
+ mixins: [ModuleMixin],
|
|
|
+ props: {
|
|
|
+ // 组件标签
|
|
|
+ labelText: {
|
|
|
+ type: String,
|
|
|
+ default: '',
|
|
|
+ },
|
|
|
+ // 上传支持的文件格式
|
|
|
+ acceptFileType: {
|
|
|
+ type: String,
|
|
|
+ default: '',
|
|
|
+ },
|
|
|
+ // 提示语
|
|
|
+ uploadTip: {
|
|
|
+ type: String,
|
|
|
+ default: '',
|
|
|
+ },
|
|
|
+ // 图标
|
|
|
+ iconClass: {
|
|
|
+ type: String,
|
|
|
+ default: '',
|
|
|
+ },
|
|
|
+ moduleData: {
|
|
|
+ type: Object,
|
|
|
+ default: () => ({}),
|
|
|
+ },
|
|
|
+ },
|
|
|
+ data() {
|
|
|
+ return {
|
|
|
+ conversionSize,
|
|
|
+ file_info_list: [],
|
|
|
+ visible: false,
|
|
|
+ form: {
|
|
|
+ title: '',
|
|
|
+ describe: '',
|
|
|
+ },
|
|
|
+ };
|
|
|
+ },
|
|
|
+ computed: {},
|
|
|
+ watch: {},
|
|
|
+ methods: {
|
|
|
+ // 显示自定义样式文件列表
|
|
|
+ onFileChange(file, fileList) {
|
|
|
+ this.afterSelectFile(file);
|
|
|
+
|
|
|
+ fileList.forEach((file) => {
|
|
|
+ if (!file.progress || file.progress <= 0) file.progress = 0;
|
|
|
+ });
|
|
|
+ this.file_info_list = fileList;
|
|
|
+ },
|
|
|
+
|
|
|
+ // 删除文件
|
|
|
+ removeFile(file, i) {
|
|
|
+ this.$confirm('是否删除当前文件?', '提示', {
|
|
|
+ confirmButtonText: '确定',
|
|
|
+ cancelButtonText: '取消',
|
|
|
+ type: 'warning',
|
|
|
+ })
|
|
|
+ .then(() => {
|
|
|
+ this.$refs.upload.handleRemove(file);
|
|
|
+ // this.file_info_list.splice(i, 1);
|
|
|
+ })
|
|
|
+ .catch(() => {});
|
|
|
+ },
|
|
|
+
|
|
|
+ // 文件校验
|
|
|
+ afterSelectFile(file) {
|
|
|
+ const fileName = file.name;
|
|
|
+ let singleSizeTip = '文件[' + fileName + ']大小超过 ' + conversionSize(this.moduleData.single_size) + ',被移除!';
|
|
|
+
|
|
|
+ if (file.size > this.moduleData.single_size * 1024 * 1024) {
|
|
|
+ this.$message.error(singleSizeTip);
|
|
|
+ this.$refs.upload.handleRemove(file);
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ const suffix = fileName.slice(fileName.lastIndexOf('.') + 1, fileName.length).toLowerCase();
|
|
|
+ let fileType = [];
|
|
|
+ let typeTip = '';
|
|
|
+
|
|
|
+ if (this.moduleData.type === 'audio') {
|
|
|
+ fileType = ['mp3', 'acc', 'wma'];
|
|
|
+ typeTip = '音频文件只能是 mp3、acc、wma 格式!';
|
|
|
+ } else if (this.moduleData.type === 'picture') {
|
|
|
+ fileType = ['jpg', 'png', 'jpeg'];
|
|
|
+ typeTip = '图片文件只能是 jpg、png、jpeg 格式!';
|
|
|
+ }
|
|
|
+ const isNeedType = fileType.includes(suffix);
|
|
|
+ if (!isNeedType) {
|
|
|
+ typeTip += ',[' + fileName + ']被移除!';
|
|
|
+ this.$message.error(typeTip);
|
|
|
+ this.$refs.upload.handleRemove(file);
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ },
|
|
|
+
|
|
|
+ // 上传文件
|
|
|
+ uploadFiles() {
|
|
|
+ const files = this.$refs.upload.uploadFiles || [];
|
|
|
+ const totalSize = files.reduce((sum, cur) => sum + Number(cur.size || 0), 0);
|
|
|
+ if (totalSize > this.moduleData.total_size * 1024 * 1024) {
|
|
|
+ this.$message.error('文件总大小不能超过' + conversionSize(this.moduleData.total_size));
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ var that = this;
|
|
|
+ files.forEach((file) => {
|
|
|
+ fileUpload('Mid', file, {
|
|
|
+ handleUploadProgress: function (progressEvent) {
|
|
|
+ var en = that.file_info_list.find((p) => p.uid == file.uid);
|
|
|
+ var per = Number((progressEvent.progress * 100).toFixed(2) || 0);
|
|
|
+ if (en) {
|
|
|
+ // var _i = that.file_info_list.findIndex((p) => p.uid == file.uid);
|
|
|
+ en.progress = per;
|
|
|
+ // that.$set(that.file_info_list, _i, en);
|
|
|
+ that.$forceUpdate();
|
|
|
+ }
|
|
|
+ },
|
|
|
+ }).then(({ file_info_list }) => {
|
|
|
+ if (file_info_list.length > 0) {
|
|
|
+ // console.log(file_info_list);
|
|
|
+ this.file_info_list = file_info_list;
|
|
|
+ }
|
|
|
+ });
|
|
|
+ });
|
|
|
+ },
|
|
|
+
|
|
|
+ // 显示弹窗
|
|
|
+ viewDialog() {
|
|
|
+ this.visible = true;
|
|
|
+ },
|
|
|
+
|
|
|
+ //给文件加介绍
|
|
|
+ fillDescribeToFile() {},
|
|
|
+ },
|
|
|
+};
|
|
|
+</script>
|
|
|
+
|
|
|
+<style lang="scss" scoped>
|
|
|
+.module-content {
|
|
|
+ .file-area {
|
|
|
+ display: flex;
|
|
|
+ column-gap: 16px;
|
|
|
+ align-items: center;
|
|
|
+
|
|
|
+ .label-text {
|
|
|
+ font-size: 14px;
|
|
|
+ color: #4e5969;
|
|
|
+ }
|
|
|
+
|
|
|
+ div {
|
|
|
+ flex: 1;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ .el-divider {
|
|
|
+ margin: 16px 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ .upload-tip {
|
|
|
+ margin-bottom: 16px;
|
|
|
+ font-size: 12px;
|
|
|
+ color: #86909c;
|
|
|
+ }
|
|
|
+
|
|
|
+ .upload-box {
|
|
|
+ display: flex;
|
|
|
+ justify-content: space-between;
|
|
|
+
|
|
|
+ .file-uploader {
|
|
|
+ flex: 1;
|
|
|
+
|
|
|
+ :deep .el-upload {
|
|
|
+ &--text {
|
|
|
+ width: 100%;
|
|
|
+ background-color: #f2f3f5;
|
|
|
+ border-radius: 2px 0 0 2px;
|
|
|
+
|
|
|
+ .el-button {
|
|
|
+ width: 100%;
|
|
|
+ color: #86909c;
|
|
|
+ text-align: left;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ .el-button {
|
|
|
+ border-radius: 0 2px 2px 0;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ .file-list {
|
|
|
+ display: flex;
|
|
|
+ flex-direction: column;
|
|
|
+ row-gap: 16px;
|
|
|
+
|
|
|
+ li {
|
|
|
+ display: flex;
|
|
|
+ column-gap: 12px;
|
|
|
+ align-items: center;
|
|
|
+
|
|
|
+ .file-name {
|
|
|
+ display: flex;
|
|
|
+ column-gap: 14px;
|
|
|
+ align-items: center;
|
|
|
+ justify-content: space-between;
|
|
|
+ width: 360px;
|
|
|
+ max-width: 360px;
|
|
|
+ padding: 8px 12px;
|
|
|
+ font-size: 14px;
|
|
|
+ color: #1d2129;
|
|
|
+ background-color: #f7f8fa;
|
|
|
+
|
|
|
+ span {
|
|
|
+ display: flex;
|
|
|
+ column-gap: 14px;
|
|
|
+ align-items: center;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+</style>
|