import {ElMessage, ElMessageBox} from "element-plus"; export default class DSJFile { listType = "picture-card"; //文件列表的类型 buttonLabel = "点击上传"; //按钮标签 sizeMB = 10; //大小限制 isSliceUpload = false; //分片上传 tip = () => { return `文件大小不超过 ${this.sizeMB}MB`; }; validate = (file: { size: number; }) => { if (this.isSliceUpload) return true; let vaild = false; let vaildSize = file.size / 1024 / 1024 < this.sizeMB; if (vaildSize) { vaild = true; } return vaild; }; action = ((window as any).dsjOptions).fileAction || "/api/single/resource/endpoint/oss/put-file-by-name"; //上传的地址 sliceUrl = ((window as any).dsjOptions).sliceUrl || "/api/single/resource/endpoint/oss/put-split-file"; //分片上传的地址 mergeUrl = ((window as any).dsjOptions).mergeUrl || "/api/single/resource/endpoint/oss/marge-split-file"; //分片合并的地址 chunkSize = 10 * 1024 * 1024; //分片大小 headers = { "Dsj-Auth": localStorage.getItem("token"), Authorization: localStorage.getItem("token"), }; //设置上传的请求头部 multiple = false; //是否支持多选文件 data = {}; //上传时附带的额外参数 name = "file"; //上传的文件字段名 withCredentials = false; //支持发送 cookie 凭证信息 showFileList = true; //是否显示已上传文件列表 drag = false; //是否启用拖拽上传 accept = ""; //接受上传的文件类型(thumbnail-mode 模式下此参数无效) onPreview = () => { }; //点击文件列表中已上传的文件时的钩子 onRemove = () => { }; //文件列表移除文件时的钩子 onSuccess = () => { }; //文件上传成功时的钩子 onError = () => { }; //文件上传失败时的钩子 onProgress = () => { }; //文件上传时的钩子 onChange = (file: any) => { }; // 文件状态改变时的钩子,添加文件、上传成功和上传失败时都会被调用 sliceUpload = async (file: any) => { }; beforeUpload = (file: any) => { let ret = this.validate(file); if (!ret) { ElMessage({type: "warning", message: this.tip()}); } return ret; }; //上传文件之前的钩子,参数为上传的文件,若返回 false 或者返回 Promise 且被 reject,则停止上传。 beforeRemove = () => { }; //删除文件之前的钩子,参数为上传的文件和文件列表,若返回 false 或者返回 Promise 且被 reject,则停止删除。 autoUpload = true; //是否在选取文件后立即进行上传 fileList = []; //上传的文件列表, 例如: [{name: 'food.jpg', url: 'https://xxx.cdn.com/xxx.jpg'}] disabled = false; //是否禁用 removeDisabled = false; //禁用删除 limit = 1; //最大允许上传个数 onExceed = () => { ElMessage({type: "warning", message: "超过最大上传数量"}); }; //文件超出个数限制时的钩子 update = (opt?: any) => { //更新配置 Object.assign(this, opt); }; constructor(opt?: any) { this.update(opt); } }