签名优化
This commit is contained in:
parent
837bed87a6
commit
a9e4b6766f
|
|
@ -26,6 +26,7 @@ import {
|
||||||
} from '@/services/signature.js'
|
} from '@/services/signature.js'
|
||||||
import { toolsLeaseApplyInfoSign, updateLeaseApplyInfoSignApi } from '@/services/materialsStation'
|
import { toolsLeaseApplyInfoSign, updateLeaseApplyInfoSignApi } from '@/services/materialsStation'
|
||||||
import { baseURL } from '@/utils/http'
|
import { baseURL } from '@/utils/http'
|
||||||
|
import { uploadImgSignUrl } from '@/utils/bnsBase'
|
||||||
|
|
||||||
let isCanvas = ref(false)
|
let isCanvas = ref(false)
|
||||||
let imgPath = ref('')
|
let imgPath = ref('')
|
||||||
|
|
@ -38,7 +39,7 @@ onLoad((opt) => {
|
||||||
// console.log('🚀 ~ onLoad ~ opt:', opt)
|
// console.log('🚀 ~ onLoad ~ opt:', opt)
|
||||||
const params = opt.params ? JSON.parse(opt.params) : {}
|
const params = opt.params ? JSON.parse(opt.params) : {}
|
||||||
Object.assign(opts, params)
|
Object.assign(opts, params)
|
||||||
if (opts.isLease || opts.isToolsLease) {
|
if (opts.isLease) {
|
||||||
signType.value = opts.leaseSignType
|
signType.value = opts.leaseSignType
|
||||||
imgPath.value = opts.leaseSignUrl
|
imgPath.value = opts.leaseSignUrl
|
||||||
}
|
}
|
||||||
|
|
@ -112,7 +113,10 @@ const complete = (e) => {
|
||||||
.replace(/^data:image\/(jpeg|png|webp);base64,/, '')
|
.replace(/^data:image\/(jpeg|png|webp);base64,/, '')
|
||||||
|
|
||||||
// console.log('🚀 ~ WebP base64:', webpBase64)
|
// 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) => {
|
const onCameraSuccess = (file) => {
|
||||||
isRotate.value = false
|
isRotate.value = false
|
||||||
signType.value = 1
|
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 {
|
try {
|
||||||
const signUrl = base64Data
|
const signUrl = url
|
||||||
if (opts.isLease) {
|
if (opts.isLease) {
|
||||||
console.log('🚀 ~ uploadSignUrl ~ opts:', opts)
|
console.log('🚀 ~ uploadSignUrl ~ opts:', opts)
|
||||||
const params = {
|
const params = {
|
||||||
|
|
|
||||||
|
|
@ -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)
|
||||||
|
},
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue