add pdf base64
This commit is contained in:
@@ -618,11 +618,11 @@
|
|||||||
|
|
||||||
<script setup>
|
<script setup>
|
||||||
import { apiApi, apiKeysApi, consoleApi, formConfigApi, productApi, subscriptionApi } from '@/api'
|
import { apiApi, apiKeysApi, consoleApi, formConfigApi, productApi, subscriptionApi } from '@/api'
|
||||||
|
import { useUserStore } from '@/stores/user'
|
||||||
import { ElMessage } from 'element-plus'
|
import { ElMessage } from 'element-plus'
|
||||||
import { marked } from 'marked'
|
import { marked } from 'marked'
|
||||||
import { computed, nextTick, onMounted, reactive, ref, watch } from 'vue'
|
import { computed, nextTick, onMounted, reactive, ref, watch } from 'vue'
|
||||||
import { useRoute, useRouter } from 'vue-router'
|
import { useRoute, useRouter } from 'vue-router'
|
||||||
import { useUserStore } from '@/stores/user'
|
|
||||||
|
|
||||||
import CodeDisplay from '@/components/common/CodeDisplay.vue'
|
import CodeDisplay from '@/components/common/CodeDisplay.vue'
|
||||||
|
|
||||||
@@ -951,6 +951,11 @@ const isBase64ImageOnlyField = (field) => {
|
|||||||
return getFieldValidationText(field).includes('Base64图片')
|
return getFieldValidationText(field).includes('Base64图片')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** PDF 专用 Base64 字段(与后端 validBase64PDF:仅 PDF、≤500KB) */
|
||||||
|
const isBase64PDFField = (field) => {
|
||||||
|
return getFieldValidationText(field).includes('仅PDF')
|
||||||
|
}
|
||||||
|
|
||||||
const isBase64UploadField = (field) => {
|
const isBase64UploadField = (field) => {
|
||||||
if (field?.type !== 'textarea') return false
|
if (field?.type !== 'textarea') return false
|
||||||
const validationText = getFieldValidationText(field)
|
const validationText = getFieldValidationText(field)
|
||||||
@@ -958,6 +963,9 @@ const isBase64UploadField = (field) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const getUploadAcceptByField = (field) => {
|
const getUploadAcceptByField = (field) => {
|
||||||
|
if (isBase64PDFField(field)) {
|
||||||
|
return 'application/pdf,.pdf'
|
||||||
|
}
|
||||||
if (isBase64ImageOnlyField(field)) {
|
if (isBase64ImageOnlyField(field)) {
|
||||||
return 'image/jpeg,image/jpg,image/png,image/bmp'
|
return 'image/jpeg,image/jpg,image/png,image/bmp'
|
||||||
}
|
}
|
||||||
@@ -965,6 +973,9 @@ const getUploadAcceptByField = (field) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const getUploadButtonTextByField = (field) => {
|
const getUploadButtonTextByField = (field) => {
|
||||||
|
if (isBase64PDFField(field)) {
|
||||||
|
return '上传 PDF 授权书'
|
||||||
|
}
|
||||||
return isBase64ImageOnlyField(field) ? '上传图片(JPG/BMP/PNG)' : '上传文件(JPG/BMP/PNG/PDF)'
|
return isBase64ImageOnlyField(field) ? '上传图片(JPG/BMP/PNG)' : '上传文件(JPG/BMP/PNG/PDF)'
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -973,18 +984,27 @@ const handleImageUpload = (file, fieldName, field) => {
|
|||||||
const fileObj = file.raw || file
|
const fileObj = file.raw || file
|
||||||
|
|
||||||
// 验证文件类型
|
// 验证文件类型
|
||||||
const allowedTypes = isBase64ImageOnlyField(field)
|
let allowedTypes
|
||||||
? ['image/jpeg', 'image/jpg', 'image/png', 'image/bmp']
|
let typeErrMsg
|
||||||
: ['image/jpeg', 'image/jpg', 'image/png', 'image/bmp', 'application/pdf']
|
if (isBase64PDFField(field)) {
|
||||||
|
allowedTypes = ['application/pdf']
|
||||||
|
typeErrMsg = '仅支持 PDF 文件'
|
||||||
|
} else if (isBase64ImageOnlyField(field)) {
|
||||||
|
allowedTypes = ['image/jpeg', 'image/jpg', 'image/png', 'image/bmp']
|
||||||
|
typeErrMsg = '只支持 JPG、BMP、PNG 格式的图片'
|
||||||
|
} else {
|
||||||
|
allowedTypes = ['image/jpeg', 'image/jpg', 'image/png', 'image/bmp', 'application/pdf']
|
||||||
|
typeErrMsg = '只支持 JPG、BMP、PNG、PDF 格式的文件'
|
||||||
|
}
|
||||||
if (!allowedTypes.includes(fileObj.type)) {
|
if (!allowedTypes.includes(fileObj.type)) {
|
||||||
ElMessage.error(isBase64ImageOnlyField(field) ? '只支持 JPG、BMP、PNG 格式的图片' : '只支持 JPG、BMP、PNG、PDF 格式的文件')
|
ElMessage.error(typeErrMsg)
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
// 验证文件大小(限制为5MB)
|
// PDF 授权书与后端 huibo decode 一致 ≤500KB;其它 Base64 上传仍为 5MB
|
||||||
const maxSize = 5 * 1024 * 1024 // 5MB
|
const maxSize = isBase64PDFField(field) ? 500 * 1024 : 5 * 1024 * 1024
|
||||||
if (fileObj.size > maxSize) {
|
if (fileObj.size > maxSize) {
|
||||||
ElMessage.error('文件大小不能超过 5MB')
|
ElMessage.error(isBase64PDFField(field) ? 'PDF 大小不能超过 500KB' : '文件大小不能超过 5MB')
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user