|
@@ -188,7 +188,6 @@ async function getWxacodeBase64() {
|
|
|
const base64 = uni.arrayBufferToBase64(arrayBuffer)
|
|
const base64 = uni.arrayBufferToBase64(arrayBuffer)
|
|
|
const imageUrl = `data:image/jpeg;base64,${base64}`
|
|
const imageUrl = `data:image/jpeg;base64,${base64}`
|
|
|
const params = parseUrlParams(contentData)
|
|
const params = parseUrlParams(contentData)
|
|
|
- console.log(params, '获取到的参数')
|
|
|
|
|
shareRecordId.value = params[inviteCode.value.shareKey]
|
|
shareRecordId.value = params[inviteCode.value.shareKey]
|
|
|
return imageUrl
|
|
return imageUrl
|
|
|
}
|
|
}
|
|
@@ -636,70 +635,72 @@ async function drawQRCodeArea(ctx, canvas, qrCodeImg, width, height, scale) {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- if (!isPcWeixinMp()) {
|
|
|
|
|
- // 尝试使用临时文件方式
|
|
|
|
|
- try {
|
|
|
|
|
- // #ifdef MP-WEIXIN
|
|
|
|
|
- const fs = uni.getFileSystemManager()
|
|
|
|
|
- const tempFileName = `temp_qr_${Date.now()}.png`
|
|
|
|
|
- tempFilePath = `${uni.env.USER_DATA_PATH}/${tempFileName}`
|
|
|
|
|
-
|
|
|
|
|
- // 提取base64数据部分
|
|
|
|
|
- let base64Data = imgSrc
|
|
|
|
|
- if (imgSrc.includes('base64,')) {
|
|
|
|
|
- base64Data = imgSrc.split('base64,')[1]
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- fs.writeFileSync(tempFilePath, base64Data, 'base64')
|
|
|
|
|
- console.log('Base64已转换为临时文件:', tempFilePath)
|
|
|
|
|
- // #endif
|
|
|
|
|
- }
|
|
|
|
|
- catch (fileError) {
|
|
|
|
|
- console.warn('转换base64为临时文件失败,尝试直接使用base64:', fileError)
|
|
|
|
|
- // 清除临时文件路径,确保使用base64
|
|
|
|
|
- tempFilePath = ''
|
|
|
|
|
|
|
+ // 尝试使用临时文件方式
|
|
|
|
|
+ try {
|
|
|
|
|
+ // #ifdef MP-WEIXIN
|
|
|
|
|
+ const fs = uni.getFileSystemManager()
|
|
|
|
|
+ const tempFileName = `temp_qr_${Date.now()}.png`
|
|
|
|
|
+ tempFilePath = `${uni.env.USER_DATA_PATH}/${tempFileName}`
|
|
|
|
|
+
|
|
|
|
|
+ // 提取base64数据部分
|
|
|
|
|
+ let base64Data = imgSrc
|
|
|
|
|
+ if (imgSrc.includes('base64,')) {
|
|
|
|
|
+ base64Data = imgSrc.split('base64,')[1]
|
|
|
}
|
|
}
|
|
|
- } else {
|
|
|
|
|
- console.log('电脑版微信小程序,直接使用base64数据')
|
|
|
|
|
|
|
+
|
|
|
|
|
+ fs.writeFileSync(tempFilePath, base64Data, 'base64')
|
|
|
|
|
+ console.log('Base64已转换为临时文件:', tempFilePath)
|
|
|
|
|
+ // #endif
|
|
|
|
|
+ }
|
|
|
|
|
+ catch (fileError) {
|
|
|
|
|
+ console.warn('转换base64为临时文件失败,尝试直接使用base64:', fileError)
|
|
|
|
|
+ // 清除临时文件路径,确保使用base64
|
|
|
|
|
+ tempFilePath = ''
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
const qrImage = canvas.createImage()
|
|
const qrImage = canvas.createImage()
|
|
|
-
|
|
|
|
|
// 使用Promise确保图片加载完成
|
|
// 使用Promise确保图片加载完成
|
|
|
await new Promise((resolve, reject) => {
|
|
await new Promise((resolve, reject) => {
|
|
|
const timeout = setTimeout(() => {
|
|
const timeout = setTimeout(() => {
|
|
|
reject(new Error('图片加载超时'))
|
|
reject(new Error('图片加载超时'))
|
|
|
}, 10000) // 10秒超时
|
|
}, 10000) // 10秒超时
|
|
|
|
|
+ uni.getImageInfo({
|
|
|
|
|
+ src: tempFilePath || imgSrc,
|
|
|
|
|
+ success: (res) => {
|
|
|
|
|
+ qrImage.onload = () => {
|
|
|
|
|
+ console.log('图片加载成功:', res)
|
|
|
|
|
+ clearTimeout(timeout)
|
|
|
|
|
+ console.log('二维码图片加载成功', {
|
|
|
|
|
+ complete: qrImage.complete,
|
|
|
|
|
+ naturalWidth: qrImage.naturalWidth || qrCodeImg.width || res.width,
|
|
|
|
|
+ naturalHeight: qrImage.naturalHeight || qrCodeImg.height || res.height,
|
|
|
|
|
+ }, qrImage)
|
|
|
|
|
+
|
|
|
|
|
+ // 获取图片尺寸,兼容微信小程序环境
|
|
|
|
|
+ const imageWidth = qrImage.naturalWidth || qrImage.width || res.width
|
|
|
|
|
+ const imageHeight = qrImage.naturalHeight || qrImage.height || res.height
|
|
|
|
|
+ // 再次检查图片是否真正加载完成
|
|
|
|
|
+ if ((isPcWeixinMp() || qrImage.complete) && imageWidth > 0 && imageHeight > 0) {
|
|
|
|
|
+ resolve()
|
|
|
|
|
+ }
|
|
|
|
|
+ else {
|
|
|
|
|
+ reject(new Error('图片加载事件触发但尺寸无效'))
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ qrImage.onerror = (err) => {
|
|
|
|
|
+ clearTimeout(timeout)
|
|
|
|
|
+ console.error('加载二维码图片失败:', err)
|
|
|
|
|
+ reject(err)
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- qrImage.onload = () => {
|
|
|
|
|
- clearTimeout(timeout)
|
|
|
|
|
- console.log('二维码图片加载成功', {
|
|
|
|
|
- complete: qrImage.complete,
|
|
|
|
|
- naturalWidth: qrImage.naturalWidth || qrCodeImg.width,
|
|
|
|
|
- naturalHeight: qrImage.naturalHeight || qrCodeImg.height,
|
|
|
|
|
- }, qrImage)
|
|
|
|
|
-
|
|
|
|
|
- // 获取图片尺寸,兼容微信小程序环境
|
|
|
|
|
- const imageWidth = qrImage.naturalWidth || qrImage.width
|
|
|
|
|
- const imageHeight = qrImage.naturalHeight || qrImage.height
|
|
|
|
|
-
|
|
|
|
|
- // 再次检查图片是否真正加载完成
|
|
|
|
|
- if (qrImage.complete && imageWidth > 0 && imageHeight > 0) {
|
|
|
|
|
- resolve()
|
|
|
|
|
- }
|
|
|
|
|
- else {
|
|
|
|
|
- reject(new Error('图片加载事件触发但尺寸无效'))
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- qrImage.onerror = (err) => {
|
|
|
|
|
- clearTimeout(timeout)
|
|
|
|
|
- console.error('加载二维码图片失败:', err)
|
|
|
|
|
- reject(err)
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- // 优先使用临时文件路径,否则使用base64数据
|
|
|
|
|
- qrImage.src = tempFilePath || imgSrc
|
|
|
|
|
|
|
+ // 优先使用临时文件路径,否则使用base64数据
|
|
|
|
|
+ qrImage.src = res.path
|
|
|
|
|
+ },
|
|
|
|
|
+ fail: (fail) => {
|
|
|
|
|
+ reject(new Error('获取图片信息失败'))
|
|
|
|
|
+ },
|
|
|
|
|
+ })
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
const finalWidth = qrImage.naturalWidth || qrImage.width
|
|
const finalWidth = qrImage.naturalWidth || qrImage.width
|
|
@@ -717,6 +718,7 @@ async function drawQRCodeArea(ctx, canvas, qrCodeImg, width, height, scale) {
|
|
|
ctx.clip()
|
|
ctx.clip()
|
|
|
ctx.drawImage(qrImage, qrX, qrY, qrSize, qrSize)
|
|
ctx.drawImage(qrImage, qrX, qrY, qrSize, qrSize)
|
|
|
|
|
|
|
|
|
|
+
|
|
|
// 图片绘制成功后,添加一个精致的内边框
|
|
// 图片绘制成功后,添加一个精致的内边框
|
|
|
ctx.restore()
|
|
ctx.restore()
|
|
|
ctx.beginPath()
|
|
ctx.beginPath()
|