提交 466a9d89 authored 作者: 王鹏飞's avatar 王鹏飞

bug fixes

上级 d128e96a
......@@ -2,28 +2,19 @@
import type { UploadProps, UploadUserFile } from 'element-plus'
import { ElMessage } from 'element-plus'
import { Plus } from '@element-plus/icons-vue'
import md5 from 'blueimp-md5'
import { getSignature } from '@/api/base'
import { upload as localUpload } from '@/utils/upload'
const isSchool = import.meta.env.MODE === 'school'
import { upload } from '@/utils/upload'
interface Props {
modelValue: string | { name: string; url: string }[]
prefix?: string
size?: number
limit?: number
beforeUpload?: (file: any) => void
}
const props = withDefaults(defineProps<Props>(), {
prefix: 'upload/saas-lab/'
})
const props = defineProps<Props>()
const emit = defineEmits(['update:modelValue', 'success'])
const uploadData = ref()
const fileList = ref<UploadUserFile[]>([])
watchEffect(() => {
......@@ -44,21 +35,6 @@ const handleBeforeUpload = async (file: any) => {
ElMessage.error(`文件大小不能超过${props.size / 1024 / 1024}M`)
return false
}
if (!isSchool) {
const fileName = file.name
const key = props.prefix + md5(fileName + new Date().getTime()) + '/' + fileName
const response: Record<string, any> = await getSignature()
uploadData.value = {
key,
host: response.host,
OSSAccessKeyId: response.accessid,
policy: response.policy,
signature: response.signature,
success_action_status: '200',
url: `${response.host}/${key}`,
}
file.url = `${response.host}/${key}`
}
if (props.beforeUpload) {
return props.beforeUpload(file)
}
......@@ -118,15 +94,11 @@ const handleRemove: UploadProps['onRemove'] = (file, files) => {
}
}
// 学校模式 — 本地服务器上传
// 统一使用上传工具,由上传工具根据当前环境选择上传方式
const customRequest = async (options: any) => {
try {
const url = await localUpload(options.file)
fileList.value.forEach((item: any) => {
if (item.uid === options.file.uid) {
item.url = url
}
})
const url = await upload(options.file)
options.file.url = url
options.onSuccess({ url }, options.file)
} catch (err) {
options.onError(err)
......@@ -141,9 +113,7 @@ const handlePreview: UploadProps['onPreview'] = uploadFile => {
<template>
<el-upload
:action="isSchool ? '#' : uploadData?.host"
:data="uploadData"
:http-request="isSchool ? customRequest : undefined"
:http-request="customRequest"
:show-file-list="showFileList"
:before-upload="handleBeforeUpload"
:on-exceed="handleExceed"
......
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论