开通保存图片权限

直接粘贴就可以用 上干货 可以的话希望点个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)
  }
相关推荐
小宇的天下13 小时前
Cadence allegro---assign net
服务器·php·apache
软件派1 天前
Apache Paimon终极教程——流批一体存储引擎深度解析(附Flink集成案例+性能调优代码)
apache·性能调优·流批一体·实时数据处理·paimon教程·flink集成·湖仓架构
三水不滴1 天前
Apache RocketMQ的原理与实践
经验分享·apache·rocketmq
whale fall2 天前
celery -A tool.src.main worker --loglevel=info --queues=worker1_queue & 什么意思
python·学习·apache
TracyCoder1233 天前
ElasticSearch核心引擎Apache Lucene(五):相关性算分 (Scoring)
elasticsearch·apache·lucene
码上上班3 天前
一文学会apache httpd
apache
野生技术架构师3 天前
Spring Boot 3 集成 Apache Calcite:多数据源查询的终极解决方案
spring boot·后端·apache
TracyCoder1233 天前
ElasticSearch核心引擎Apache Lucene(四):段 (Segment) 的设计与合并
elasticsearch·apache·lucene
TracyCoder1233 天前
ElasticSearch核心引擎Apache Lucene(三):数值与空间数据索引
elasticsearch·apache·lucene
Elastic 中国社区官方博客4 天前
Elasticsearch:Apache Lucene 2025 年终总结
大数据·人工智能·elasticsearch·搜索引擎·apache·lucene