f
This commit is contained in:
@@ -181,17 +181,17 @@
|
|||||||
<span v-if="field.required" class="text-red-500 ml-1">*</span>
|
<span v-if="field.required" class="text-red-500 ml-1">*</span>
|
||||||
</label>
|
</label>
|
||||||
|
|
||||||
<!-- 图片上传字段(photo_data) -->
|
<!-- Base64字段上传(根据后端校验规则自动识别) -->
|
||||||
<div v-if="field.name === 'photo_data' || field.name === 'vlphoto_data' && field.type === 'textarea'" class="space-y-2">
|
<div v-if="isBase64UploadField(field)" class="space-y-2">
|
||||||
<div class="flex gap-2 mb-2">
|
<div class="flex gap-2 mb-2">
|
||||||
<el-upload
|
<el-upload
|
||||||
:auto-upload="false"
|
:auto-upload="false"
|
||||||
:show-file-list="false"
|
:show-file-list="false"
|
||||||
accept="image/jpeg,image/jpg,image/png,image/bmp"
|
:accept="getUploadAcceptByField(field)"
|
||||||
:on-change="(file) => handleImageUpload(file, field.name)"
|
:on-change="(file) => handleImageUpload(file, field.name, field)"
|
||||||
class="flex-1">
|
class="flex-1">
|
||||||
<el-button type="primary" size="small">
|
<el-button type="primary" size="small">
|
||||||
<i class="el-icon-upload"></i> 上传图片(JPG/BMP/PNG)
|
<i class="el-icon-upload"></i> {{ getUploadButtonTextByField(field) }}
|
||||||
</el-button>
|
</el-button>
|
||||||
</el-upload>
|
</el-upload>
|
||||||
<el-button v-if="formData[field.name]" type="danger" size="small" @click="clearImageData(field.name)">
|
<el-button v-if="formData[field.name]" type="danger" size="small" @click="clearImageData(field.name)">
|
||||||
@@ -423,7 +423,7 @@
|
|||||||
</el-button>
|
</el-button>
|
||||||
</div>
|
</div>
|
||||||
<!-- 解密加载状态 -->
|
<!-- 解密加载状态 -->
|
||||||
<div v-else-if="debugging && debugResult && debugResult.success && debugResult.response?.data?.data"
|
<div v-else-if="debugging && debugResult && debugResult.success && debugResult.response?.data?.data"
|
||||||
class="mt-3 pt-3 border-t border-gray-200">
|
class="mt-3 pt-3 border-t border-gray-200">
|
||||||
<div class="flex items-center gap-2 text-sm text-gray-500">
|
<div class="flex items-center gap-2 text-sm text-gray-500">
|
||||||
<svg class="animate-spin h-4 w-4 text-gray-500" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24">
|
<svg class="animate-spin h-4 w-4 text-gray-500" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24">
|
||||||
@@ -749,12 +749,12 @@ watch(
|
|||||||
if (newProductId === oldProductId) {
|
if (newProductId === oldProductId) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// 如果正在选择产品,不重复执行
|
// 如果正在选择产品,不重复执行
|
||||||
if (isSelectingProduct.value) {
|
if (isSelectingProduct.value) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if (newProductId && userProducts.value.length > 0) {
|
if (newProductId && userProducts.value.length > 0) {
|
||||||
await autoSelectProduct(newProductId)
|
await autoSelectProduct(newProductId)
|
||||||
} else if (!newProductId && userProducts.value.length > 0 && !selectedProduct.value) {
|
} else if (!newProductId && userProducts.value.length > 0 && !selectedProduct.value) {
|
||||||
@@ -771,13 +771,13 @@ const autoSelectProduct = async (productId) => {
|
|||||||
console.log('正在选择产品,跳过重复请求')
|
console.log('正在选择产品,跳过重复请求')
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// 如果已经选择了相同的产品,不重复选择
|
// 如果已经选择了相同的产品,不重复选择
|
||||||
if (lastSelectedProductId.value === productId && selectedProduct.value) {
|
if (lastSelectedProductId.value === productId && selectedProduct.value) {
|
||||||
console.log('产品已选择,跳过重复选择:', productId)
|
console.log('产品已选择,跳过重复选择:', productId)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// 如果用户产品列表为空,等待加载完成
|
// 如果用户产品列表为空,等待加载完成
|
||||||
if (!userProducts.value.length) {
|
if (!userProducts.value.length) {
|
||||||
console.log('等待用户产品列表加载完成...')
|
console.log('等待用户产品列表加载完成...')
|
||||||
@@ -883,13 +883,13 @@ const loadApiKeys = async () => {
|
|||||||
const selectProduct = async (product) => {
|
const selectProduct = async (product) => {
|
||||||
// 防止重复选择相同产品
|
// 防止重复选择相同产品
|
||||||
const productId = product.product_id || product.id
|
const productId = product.product_id || product.id
|
||||||
if (selectedProduct.value &&
|
if (selectedProduct.value &&
|
||||||
(selectedProduct.value.id === productId || selectedProduct.value.product_id === productId) &&
|
(selectedProduct.value.id === productId || selectedProduct.value.product_id === productId) &&
|
||||||
!isSelectingProduct.value) {
|
!isSelectingProduct.value) {
|
||||||
console.log('产品已选择,跳过重复加载:', productId)
|
console.log('产品已选择,跳过重复加载:', productId)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// 确保API密钥已经加载
|
// 确保API密钥已经加载
|
||||||
if (!debugForm.accessId || !debugForm.secretKey) {
|
if (!debugForm.accessId || !debugForm.secretKey) {
|
||||||
ElMessage.warning('正在加载API密钥,请稍候...')
|
ElMessage.warning('正在加载API密钥,请稍候...')
|
||||||
@@ -934,24 +934,51 @@ const loadFormConfig = async (apiCode) => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 处理图片上传并转换为base64
|
const getFieldValidationText = (field) => {
|
||||||
const handleImageUpload = (file, fieldName) => {
|
return typeof field?.validation === 'string' ? field.validation : ''
|
||||||
|
}
|
||||||
|
|
||||||
|
const isBase64ImageOnlyField = (field) => {
|
||||||
|
return getFieldValidationText(field).includes('Base64图片')
|
||||||
|
}
|
||||||
|
|
||||||
|
const isBase64UploadField = (field) => {
|
||||||
|
if (field?.type !== 'textarea') return false
|
||||||
|
const validationText = getFieldValidationText(field)
|
||||||
|
return validationText.includes('Base64图片') || validationText.includes('Base64编码') || validationText.toLowerCase().includes('base64')
|
||||||
|
}
|
||||||
|
|
||||||
|
const getUploadAcceptByField = (field) => {
|
||||||
|
if (isBase64ImageOnlyField(field)) {
|
||||||
|
return 'image/jpeg,image/jpg,image/png,image/bmp'
|
||||||
|
}
|
||||||
|
return 'image/jpeg,image/jpg,image/png,image/bmp,application/pdf,.pdf'
|
||||||
|
}
|
||||||
|
|
||||||
|
const getUploadButtonTextByField = (field) => {
|
||||||
|
return isBase64ImageOnlyField(field) ? '上传图片(JPG/BMP/PNG)' : '上传文件(JPG/BMP/PNG/PDF)'
|
||||||
|
}
|
||||||
|
|
||||||
|
// 处理文件上传并转换为base64(支持按字段规则限制类型)
|
||||||
|
const handleImageUpload = (file, fieldName, field) => {
|
||||||
const fileObj = file.raw || file
|
const fileObj = file.raw || file
|
||||||
|
|
||||||
// 验证文件类型
|
// 验证文件类型
|
||||||
const allowedTypes = ['image/jpeg', 'image/jpg', 'image/png', 'image/bmp']
|
const allowedTypes = isBase64ImageOnlyField(field)
|
||||||
|
? ['image/jpeg', 'image/jpg', 'image/png', 'image/bmp']
|
||||||
|
: ['image/jpeg', 'image/jpg', 'image/png', 'image/bmp', 'application/pdf']
|
||||||
if (!allowedTypes.includes(fileObj.type)) {
|
if (!allowedTypes.includes(fileObj.type)) {
|
||||||
ElMessage.error('只支持 JPG、BMP、PNG 格式的图片')
|
ElMessage.error(isBase64ImageOnlyField(field) ? '只支持 JPG、BMP、PNG 格式的图片' : '只支持 JPG、BMP、PNG、PDF 格式的文件')
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
// 验证文件大小(限制为5MB)
|
// 验证文件大小(限制为5MB)
|
||||||
const maxSize = 5 * 1024 * 1024 // 5MB
|
const maxSize = 5 * 1024 * 1024 // 5MB
|
||||||
if (fileObj.size > maxSize) {
|
if (fileObj.size > maxSize) {
|
||||||
ElMessage.error('图片大小不能超过 5MB')
|
ElMessage.error('文件大小不能超过 5MB')
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
// 读取文件并转换为base64
|
// 读取文件并转换为base64
|
||||||
const reader = new FileReader()
|
const reader = new FileReader()
|
||||||
reader.onload = (e) => {
|
reader.onload = (e) => {
|
||||||
@@ -959,13 +986,13 @@ const handleImageUpload = (file, fieldName) => {
|
|||||||
// 移除 data:image/xxx;base64, 前缀,只保留纯base64数据
|
// 移除 data:image/xxx;base64, 前缀,只保留纯base64数据
|
||||||
const base64Data = base64String.includes(',') ? base64String.split(',')[1] : base64String
|
const base64Data = base64String.includes(',') ? base64String.split(',')[1] : base64String
|
||||||
formData.value[fieldName] = base64Data
|
formData.value[fieldName] = base64Data
|
||||||
ElMessage.success('图片上传成功,已转换为base64')
|
ElMessage.success('文件上传成功,已转换为base64')
|
||||||
}
|
}
|
||||||
reader.onerror = () => {
|
reader.onerror = () => {
|
||||||
ElMessage.error('图片读取失败,请重试')
|
ElMessage.error('文件读取失败,请重试')
|
||||||
}
|
}
|
||||||
reader.readAsDataURL(fileObj)
|
reader.readAsDataURL(fileObj)
|
||||||
|
|
||||||
return false // 阻止自动上传
|
return false // 阻止自动上传
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1142,7 +1169,7 @@ const convertFieldTypes = (data) => {
|
|||||||
if (!formFields.value || formFields.value.length === 0) {
|
if (!formFields.value || formFields.value.length === 0) {
|
||||||
return data
|
return data
|
||||||
}
|
}
|
||||||
|
|
||||||
const processedData = { ...data }
|
const processedData = { ...data }
|
||||||
formFields.value.forEach(field => {
|
formFields.value.forEach(field => {
|
||||||
const value = processedData[field.name]
|
const value = processedData[field.name]
|
||||||
@@ -1150,7 +1177,7 @@ const convertFieldTypes = (data) => {
|
|||||||
if (value === '' || value === null || value === undefined) {
|
if (value === '' || value === null || value === undefined) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// 根据字段类型进行转换
|
// 根据字段类型进行转换
|
||||||
if (field.type === 'number') {
|
if (field.type === 'number') {
|
||||||
// 将字符串转换为数字(整数)
|
// 将字符串转换为数字(整数)
|
||||||
@@ -1160,7 +1187,7 @@ const convertFieldTypes = (data) => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
return processedData
|
return processedData
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1197,7 +1224,7 @@ const encryptWithAES = async (data, secretKey) => {
|
|||||||
|
|
||||||
// 解析JSON字符串(如果是字符串)
|
// 解析JSON字符串(如果是字符串)
|
||||||
let parsedData = typeof data === 'string' ? JSON.parse(data) : data
|
let parsedData = typeof data === 'string' ? JSON.parse(data) : data
|
||||||
|
|
||||||
// 根据字段类型进行类型转换
|
// 根据字段类型进行类型转换
|
||||||
parsedData = convertFieldTypes(parsedData)
|
parsedData = convertFieldTypes(parsedData)
|
||||||
|
|
||||||
@@ -1282,7 +1309,7 @@ const handleDebug = async () => {
|
|||||||
debugResult.value = null
|
debugResult.value = null
|
||||||
decryptedData.value = null
|
decryptedData.value = null
|
||||||
await nextTick() // 确保DOM更新
|
await nextTick() // 确保DOM更新
|
||||||
|
|
||||||
const startTime = new Date()
|
const startTime = new Date()
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|||||||
Reference in New Issue
Block a user