直接粘贴就可以用 上干货 可以的话希望点个start
javascript
/* 小程序特有相关 */
'mp-weixin': {
appid: VITE_WX_APPID,
setting: {
urlCheck: false,
minified : true //是否压缩js
},
usingComponents: true,
"lazyCodeLoading": "requiredComponents", //按需注入
"permission" : { // 这里
"scope.writePhotosAlbum" : {
"desc" : "申请保存图片到相册"
}
}
// __usePrivacyCheck__: true,
},
javascript
// 保存二维码
const saveCode = () => {
if (!codeUrl.value) return
// 检查权限状态
uni.getSetting({
success: (res) => {
if (!res.authSetting['scope.writePhotosAlbum']) {
// 没有权限,请求权限
uni.authorize({
scope: 'scope.writePhotosAlbum',
success: () => {
saveQrCode()
},
fail: () => {
// 用户拒绝授权,引导用户去设置页面开启
uni.showModal({
title: '提示',
content: '需要开启保存到相册权限才能保存二维码,是否去设置?',
success: (res) => {
if (res.confirm) {
// 打开设置页面
uni.openSetting({
success: (settingRes) => {
if (settingRes.authSetting['scope.writePhotosAlbum']) {
saveQrCode()
}
}
})
}
}
})
}
})
} else {
// 已有权限,直接保存
saveQrCode()
}
}
})
}
// 执行保存操作
const saveQrCode = () => {
uni.showLoading({ title: '正在保存' })
setTimeout(() => {
qrcode.value.save({
success: () => {
uni.hideLoading()
uni.showToast({ title: '保存成功' })
},
fail: (err) => {
uni.hideLoading()
uni.showToast({ title: '保存失败', icon: 'error' })
console.error('保存失败:', err)
}
})
}, 400)
}