import { BASE_URL, DEFAULT_REQUEST_HEADER } from '../../http/request-model' import requestMethod, { UPLOAD_PATH } from '../../api/system-log/file' import { ResultModel } from '../../http/result-model' import { LogFile } from '../../entity/system-log/log-file' import { BaseUtil } from '../../utils/base-util' type InsertFnType = (url: string, alt: string, href: string) => void /** * 自定义插入的上传方式 */ export const configUploadImage = () => { const headers: { [key: string]: string } = {} Object.entries(DEFAULT_REQUEST_HEADER().data).map(([key, value]) => { headers[key] = typeof value === 'string' ? value : value() }) return { server: BASE_URL + UPLOAD_PATH, // form-data fieldName ,默认值 'wangeditor-uploaded-image' fieldName: 'file', // 单个文件的最大体积限制,默认为 2M maxFileSize: 10 * 1024 * 1024, // 最多可上传几个文件,默认为 100 maxNumberOfFiles: 10, // 选择文件时的类型限制,默认为 ['image/*'] 。如不想限制,则设置为 [] allowedFileTypes: ['image/*'], // 超时时间,默认为 10 秒 timeout: 60 * 1000, // 自定义增加 http header headers, // 自定义插入图片 customInsert(data: ResultModel, insertFn: InsertFnType) { const fileData = data.data const url = BaseUtil.getUploadPath(fileData.uploadPath) insertFn(url, fileData.oldFileName || '', url) } } } /** * 全自定义上传方式 */ export const configCustomUploadImage = { // 自定义上传功能 customUpload(file: File, insertFn: InsertFnType) { requestMethod.upload(file).then((data: ResultModel) => { const fileData = data.data const url = BaseUtil.getUploadPath(fileData.uploadPath) insertFn(url, fileData.oldFileName || '', url) }) } }