日本免费高清视频-国产福利视频导航-黄色在线播放国产-天天操天天操天天操天天操|www.shdianci.com

學無先后,達者為師

網站首頁 編程語言 正文

微信授權與拒絕授權的彈窗處理

作者:~~big_dragon~~ 更新時間: 2023-10-10 編程語言

說明:微信授權頁面一經用戶拒絕過一次后后續就不會再彈出 只能手動點擊右上角打開設置去授權,此方法解決了不需要用戶手動打開設置授權 只要用戶拒絕過授權 下次進來就會以彈窗的形式詢問是否需要授權 是的話自動跳轉到設置頁面

1. 新建公共的js文件 commonAuth.js



let setting = null;
const dealAuth = (authSetting, key, content, callback) => {
    if (authSetting?.[key] === true) callback?.(true)
    if (authSetting?.[key] === false) {
        wx.showModal({
            title: '提示',
            content,
            success(res) {
                if (res.confirm) {
                    wx.openSetting({
                        withSubscriptions: true,
                        success(res) {
                            res.authSetting[key] && callback?.(true)
                            !res.authSetting[key] && callback?.(false)
                        },
                        // fail() { callback?.(false) }
                    })
                } else if (res.cancel) callback?.(false)
            }
        })
    }
    if (authSetting?.[key] === undefined) {
        wx.authorize({
            scope: key,
            success() { callback?.(true) },
            fail() { callback?.(false) }
        })
    }
}
module.exports.commonAuth = (key, content, callback) => {
    !setting && wx.getSetting({
        success(res) {
            setting = res
            dealAuth(res.authSetting, key, content, callback)
        }
    })
    setting && dealAuth(setting.authSetting, key, content, callback)
}

2. 使用方式

const  { commonAuth } = require('@/common/utils/commonAuth')

commonAuth('scope.record', '打開錄音授權頁面嗎?', (result) => {
// result true授權成功 可以使用對應api  false拒絕授權
    // 授權打開后開始調用相關api
        wx.startRecord()
 })
  

原文鏈接:https://blog.csdn.net/weixin_44147791/article/details/123201707

  • 上一篇:沒有了
  • 下一篇:沒有了
欄目分類
最近更新