开通保存图片权限

直接粘贴就可以用 上干货 可以的话希望点个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)
  }
相关推荐
阿里云云原生3 小时前
Apache RocketMQ + “太乙” = 开源贡献新体验
apache·rocketmq
Rinleren10 小时前
Apache部署
apache
Fantasy丶夜雨笙歌2 天前
Apache HTTP Server 从安装到配置
网络协议·http·apache
蠢货爱好者2 天前
一分钟快速了解Apache
apache
麟城Lincoln2 天前
【Linux-云原生-笔记】Apache相关
linux·笔记·云原生·apache·webserver
ZZZKKKRTSAE2 天前
玩转rhel9 Apache
linux·运维·服务器·apache·web
HashData酷克数据3 天前
Apache Cloudberry 向量化实践(二):如何识别和定位向量化系统的性能瓶颈?
apache
HashData酷克数据4 天前
流批一体的“奥卡姆剃刀”:Apache Cloudberry 增量物化视图应用解析
apache