签名优化

This commit is contained in:
bb_pan 2025-08-08 10:28:02 +08:00
parent 837bed87a6
commit a9e4b6766f
2 changed files with 62 additions and 6 deletions

View File

@ -26,6 +26,7 @@ import {
} from '@/services/signature.js'
import { toolsLeaseApplyInfoSign, updateLeaseApplyInfoSignApi } from '@/services/materialsStation'
import { baseURL } from '@/utils/http'
import { uploadImgSignUrl } from '@/utils/bnsBase'
let isCanvas = ref(false)
let imgPath = ref('')
@ -38,7 +39,7 @@ onLoad((opt) => {
// console.log('🚀 ~ onLoad ~ opt:', opt)
const params = opt.params ? JSON.parse(opt.params) : {}
Object.assign(opts, params)
if (opts.isLease || opts.isToolsLease) {
if (opts.isLease) {
signType.value = opts.leaseSignType
imgPath.value = opts.leaseSignUrl
}
@ -112,7 +113,10 @@ const complete = (e) => {
.replace(/^data:image\/(jpeg|png|webp);base64,/, '')
// console.log('🚀 ~ WebP base64:', webpBase64)
uploadSignUrl(webpBase64)
uploadImgSignUrl(webpBase64).then(item => {
console.log('🚀 ~ complete ~ item:', item)
uploadSignUrl(item.url)
})
}
}
@ -182,14 +186,16 @@ const onCameraError = (message) => {
const onCameraSuccess = (file) => {
isRotate.value = false
signType.value = 1
const signUrl = file
uploadSignUrl(signUrl)
uploadImgSignUrl(file).then(item => {
console.log('🚀 ~ complete ~ item:', item)
uploadSignUrl(item.url)
})
}
//
const uploadSignUrl = async (base64Data) => {
const uploadSignUrl = async (url) => {
try {
const signUrl = base64Data
const signUrl = url
if (opts.isLease) {
console.log('🚀 ~ uploadSignUrl ~ opts:', opts)
const params = {

50
src/utils/bnsBase.js Normal file
View File

@ -0,0 +1,50 @@
import { decryptWithSM4 } from './sm'
const generateRandomString = (length) => {
const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'
return Array.from({ length }, () => chars.charAt(Math.floor(Math.random() * chars.length))).join('')
}
export const uploadImgSignUrl = (file) => {
return new Promise((resolve, reject) => {
uni.request({
url: '/file/uploadBase64',
method: 'POST',
data: {
base64File: file,
fileName: `${generateRandomString(10)}_${Date.now()}.png`,
fileType: 'image/png',
},
success: (uploadRes) => {
try {
let result
if (typeof uploadRes.data === 'string') {
result = JSON.parse(decryptWithSM4(uploadRes.data))
} else {
result = uploadRes.data
}
if (result.code === 200) {
uni.showToast({ title: '上传成功', icon: 'none' })
resolve({
name: result.data.name,
url: result.data.url,
})
} else {
uni.showToast({ title: '上传失败', icon: 'none' })
reject(new Error(result.message || '上传失败'))
}
} catch (e) {
console.error('处理返回数据出错', e)
uni.showToast({ title: '上传失败', icon: 'none' })
reject(e)
}
},
fail: (err) => {
console.error('上传失败', err)
uni.showToast({ title: '上传失败', icon: 'none' })
reject(err)
},
})
})
}