|
@@ -165,6 +165,7 @@ import {
|
|
|
signConfirm,
|
|
signConfirm,
|
|
|
pushTaskOrder,
|
|
pushTaskOrder,
|
|
|
createSafetyCheckRecord,
|
|
createSafetyCheckRecord,
|
|
|
|
|
+ uploadSignImage,
|
|
|
} from '@/api/sign'
|
|
} from '@/api/sign'
|
|
|
import { getDynamicTbVal } from '@/api/task'
|
|
import { getDynamicTbVal } from '@/api/task'
|
|
|
import { getStandardTemplate } from '@/api/index'
|
|
import { getStandardTemplate } from '@/api/index'
|
|
@@ -189,6 +190,7 @@ const pdfSource = ref<ArrayBuffer | Blob | null>(null)
|
|
|
const pdfViewerRef = ref<any>(null)
|
|
const pdfViewerRef = ref<any>(null)
|
|
|
const showSignImg = ref('')
|
|
const showSignImg = ref('')
|
|
|
const signImg = ref('')
|
|
const signImg = ref('')
|
|
|
|
|
+const uploadedSignUrl = ref('')
|
|
|
const signImgStyle = ref<any>({})
|
|
const signImgStyle = ref<any>({})
|
|
|
const signTime = ref('')
|
|
const signTime = ref('')
|
|
|
const fwdInputPhone = ref('')
|
|
const fwdInputPhone = ref('')
|
|
@@ -491,6 +493,94 @@ const handleCancelSign = () => {
|
|
|
signStatus.value = 'empty'
|
|
signStatus.value = 'empty'
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+const base64ToFile = (base64Data: string, fileName: string = 'signature.png'): File | null => {
|
|
|
|
|
+ // #ifdef H5
|
|
|
|
|
+ try {
|
|
|
|
|
+ const arr = base64Data.split(',')
|
|
|
|
|
+ const mime = arr[0].match(/:(.*?);/)?.[1] || 'image/png'
|
|
|
|
|
+ const bstr = atob(arr[1])
|
|
|
|
|
+ let n = bstr.length
|
|
|
|
|
+ const u8arr = new Uint8Array(n)
|
|
|
|
|
+ while (n--) {
|
|
|
|
|
+ u8arr[n] = bstr.charCodeAt(n)
|
|
|
|
|
+ }
|
|
|
|
|
+ return new File([u8arr], fileName, { type: mime })
|
|
|
|
|
+ } catch (e) {
|
|
|
|
|
+ console.error('base64 转 File 失败:', e)
|
|
|
|
|
+ return null
|
|
|
|
|
+ }
|
|
|
|
|
+ // #endif
|
|
|
|
|
+
|
|
|
|
|
+ // #ifndef H5
|
|
|
|
|
+ return null
|
|
|
|
|
+ // #endif
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+const base64ToTempFilePath = (base64Data: string): Promise<string> => {
|
|
|
|
|
+ return new Promise((resolve, reject) => {
|
|
|
|
|
+ // #ifdef H5
|
|
|
|
|
+ const file = base64ToFile(base64Data)
|
|
|
|
|
+ if (file) {
|
|
|
|
|
+ resolve('') // H5 使用 File 对象
|
|
|
|
|
+ } else {
|
|
|
|
|
+ reject(new Error('转换失败'))
|
|
|
|
|
+ }
|
|
|
|
|
+ // #endif
|
|
|
|
|
+
|
|
|
|
|
+ // #ifndef H5
|
|
|
|
|
+ const fs = uni.getFileSystemManager()
|
|
|
|
|
+ const filePath = `${uni.env.USER_DATA_PATH}/signature_${Date.now()}.png`
|
|
|
|
|
+
|
|
|
|
|
+ // 移除 data:image/png;base64, 前缀
|
|
|
|
|
+ const base64 = base64Data.replace(/^data:image\/\w+;base64,/, '')
|
|
|
|
|
+
|
|
|
|
|
+ fs.writeFile({
|
|
|
|
|
+ filePath,
|
|
|
|
|
+ data: base64,
|
|
|
|
|
+ encoding: 'base64',
|
|
|
|
|
+ success: () => {
|
|
|
|
|
+ resolve(filePath)
|
|
|
|
|
+ },
|
|
|
|
|
+ fail: (err) => {
|
|
|
|
|
+ reject(err)
|
|
|
|
|
+ }
|
|
|
|
|
+ })
|
|
|
|
|
+ // #endif
|
|
|
|
|
+ })
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+const uploadSignature = async (base64Data: string): Promise<string> => {
|
|
|
|
|
+ try {
|
|
|
|
|
+ // #ifdef H5
|
|
|
|
|
+ const file = base64ToFile(base64Data)
|
|
|
|
|
+ if (!file) {
|
|
|
|
|
+ throw new Error('签名图片转换失败')
|
|
|
|
|
+ }
|
|
|
|
|
+ const fd = new FormData()
|
|
|
|
|
+ fd.append('file', file)
|
|
|
|
|
+ const resp: any = await uploadSignImage(fd)
|
|
|
|
|
+ if (resp?.code === 0 && resp?.data) {
|
|
|
|
|
+ return resp.data
|
|
|
|
|
+ }
|
|
|
|
|
+ throw new Error(resp?.msg || '上传失败')
|
|
|
|
|
+ // #endif
|
|
|
|
|
+
|
|
|
|
|
+ // #ifndef H5
|
|
|
|
|
+ const filePath = await base64ToTempFilePath(base64Data)
|
|
|
|
|
+ const resp: any = await uploadSignImage(filePath)
|
|
|
|
|
+ const data = JSON.parse(resp.data)
|
|
|
|
|
+ console.log('resp......', data)
|
|
|
|
|
+ if (data?.code === 0 && data?.data) {
|
|
|
|
|
+ return data.data
|
|
|
|
|
+ }
|
|
|
|
|
+ throw new Error(resp?.msg || '上传失败')
|
|
|
|
|
+ // #endif
|
|
|
|
|
+ } catch (error) {
|
|
|
|
|
+ console.error('签名图片上传失败:', error)
|
|
|
|
|
+ throw error
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
// 确认签名
|
|
// 确认签名
|
|
|
const confirmSign = async () => {
|
|
const confirmSign = async () => {
|
|
|
if (!signatureRef.value) return
|
|
if (!signatureRef.value) return
|
|
@@ -500,6 +590,8 @@ const confirmSign = async () => {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
try {
|
|
|
|
|
+ uni.showLoading({ title: '正在保存...' })
|
|
|
|
|
+
|
|
|
const path = await signatureRef.value.getImage()
|
|
const path = await signatureRef.value.getImage()
|
|
|
signImg.value = path
|
|
signImg.value = path
|
|
|
showSignImg.value = path
|
|
showSignImg.value = path
|
|
@@ -516,11 +608,23 @@ const confirmSign = async () => {
|
|
|
},
|
|
},
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
|
|
+ // 上传签名图片
|
|
|
|
|
+ try {
|
|
|
|
|
+ const uploadedUrl = await uploadSignature(path)
|
|
|
|
|
+ uploadedSignUrl.value = uploadedUrl
|
|
|
|
|
+ console.log('签名图片上传成功:', uploadedUrl)
|
|
|
|
|
+ } catch (uploadError) {
|
|
|
|
|
+ console.error('签名图片上传失败,继续使用原图片:', uploadError)
|
|
|
|
|
+ uni.showToast({ title: '签名保存成功,上传失败', icon: 'none' })
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
const now = new Date()
|
|
const now = new Date()
|
|
|
signTime.value = `${now.getFullYear()}年${now.getMonth() + 1}月${now.getDate()}日`
|
|
signTime.value = `${now.getFullYear()}年${now.getMonth() + 1}月${now.getDate()}日`
|
|
|
|
|
|
|
|
signStatus.value = 'signed'
|
|
signStatus.value = 'signed'
|
|
|
|
|
+ uni.hideLoading()
|
|
|
} catch (err) {
|
|
} catch (err) {
|
|
|
|
|
+ uni.hideLoading()
|
|
|
console.error('转换失败:', err)
|
|
console.error('转换失败:', err)
|
|
|
uni.showToast({ title: '签名失败', icon: 'error' })
|
|
uni.showToast({ title: '签名失败', icon: 'error' })
|
|
|
}
|
|
}
|
|
@@ -530,6 +634,7 @@ const confirmSign = async () => {
|
|
|
const handleDelSign = () => {
|
|
const handleDelSign = () => {
|
|
|
signImg.value = ''
|
|
signImg.value = ''
|
|
|
showSignImg.value = ''
|
|
showSignImg.value = ''
|
|
|
|
|
+ uploadedSignUrl.value = ''
|
|
|
signTime.value = ''
|
|
signTime.value = ''
|
|
|
signStatus.value = 'empty'
|
|
signStatus.value = 'empty'
|
|
|
}
|
|
}
|
|
@@ -561,7 +666,7 @@ const submitConfirm = async () => {
|
|
|
try {
|
|
try {
|
|
|
const params: any = {
|
|
const params: any = {
|
|
|
id: orderId.value,
|
|
id: orderId.value,
|
|
|
- signUrl: signImg.value,
|
|
|
|
|
|
|
+ signUrl: uploadedSignUrl.value || signImg.value,
|
|
|
businessType: routeType.value ? businessTypeMap[routeType.value] : '',
|
|
businessType: routeType.value ? businessTypeMap[routeType.value] : '',
|
|
|
orderItemId: orderItemId.value || undefined,
|
|
orderItemId: orderItemId.value || undefined,
|
|
|
}
|
|
}
|