This commit is contained in:
@@ -57,7 +57,8 @@
|
||||
import { Close, Document, UploadFilled } from '@element-plus/icons-vue'
|
||||
import type { UploadFile, UploadInstance, UploadRawFile } from 'element-plus'
|
||||
import { StorageService } from '@/api/modules'
|
||||
import type { RefundAttachment } from '@/types/api/refund'
|
||||
import type { RefundAttachment } from '@/types/api/refund'
|
||||
import type { FilePurpose } from '@/api/modules/storage'
|
||||
|
||||
interface Props {
|
||||
modelValue?: string[] | string
|
||||
@@ -65,13 +66,21 @@
|
||||
maxCount?: number
|
||||
accept?: string
|
||||
tip?: string
|
||||
purpose?: FilePurpose
|
||||
maxSizeMb?: number
|
||||
singleColumnCsv?: boolean
|
||||
maxCsvRows?: number
|
||||
}
|
||||
|
||||
const props = withDefaults(defineProps<Props>(), {
|
||||
voucherName: '凭证',
|
||||
maxCount: 5,
|
||||
accept: '',
|
||||
tip: ''
|
||||
tip: '',
|
||||
purpose: 'attachment',
|
||||
maxSizeMb: 0,
|
||||
singleColumnCsv: false,
|
||||
maxCsvRows: 0
|
||||
})
|
||||
|
||||
const emit = defineEmits<{
|
||||
@@ -185,6 +194,27 @@
|
||||
const file = uploadFile.raw
|
||||
if (!file) return
|
||||
|
||||
if (props.maxSizeMb > 0 && file.size > props.maxSizeMb * 1024 * 1024) {
|
||||
ElMessage.warning(`文件不能超过 ${props.maxSizeMb}MB`)
|
||||
removeUploadFile(uploadFile)
|
||||
return
|
||||
}
|
||||
|
||||
if (props.singleColumnCsv) {
|
||||
const content = await file.text()
|
||||
const rows = content.replace(/^\uFEFF/, '').split(/\r?\n/).filter(Boolean)
|
||||
if (props.maxCsvRows > 0 && Math.max(rows.length - 1, 0) > props.maxCsvRows) {
|
||||
ElMessage.warning(`CSV 数据行不能超过 ${props.maxCsvRows} 行`)
|
||||
removeUploadFile(uploadFile)
|
||||
return
|
||||
}
|
||||
if (rows.some((row) => row.includes(','))) {
|
||||
ElMessage.warning('CSV 只能包含一列资产标识')
|
||||
removeUploadFile(uploadFile)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
if (props.accept) {
|
||||
const accepted = props.accept.split(',').some((type) => {
|
||||
const value = type.trim().toLowerCase()
|
||||
@@ -220,7 +250,7 @@
|
||||
const uploadUrlRes = await StorageService.getUploadUrl({
|
||||
file_name: file.name,
|
||||
content_type: contentType,
|
||||
purpose: 'attachment'
|
||||
purpose: props.purpose
|
||||
})
|
||||
|
||||
if (uploadUrlRes.code !== 0) {
|
||||
|
||||
Reference in New Issue
Block a user