微信小程序API 調(diào)起客戶端小程序設(shè)置界面

2022-05-10 15:59 更新

wx.openSetting(OBJECT)


基礎(chǔ)庫版本 1.1.0 開始支持,低版本需做兼容處理

調(diào)起客戶端小程序設(shè)置界面,返回用戶設(shè)置的操作結(jié)果

Object 參數(shù)說明:

參數(shù) 類型 必填 說明
success Function 接口調(diào)用成功的回調(diào)函數(shù),返回內(nèi)容詳見返回參數(shù)說明。
fail Function 接口調(diào)用失敗的回調(diào)函數(shù)
complete Function 接口調(diào)用結(jié)束的回調(diào)函數(shù)(調(diào)用成功、失敗都會執(zhí)行)

success返回參數(shù)說明:

參數(shù) 類型 說明
authSetting Object 用戶授權(quán)結(jié)果,其中 key 為 scope 值,value 為 Bool 值,表示用戶是否允許授權(quán),詳見 scope 列表

示例代碼:

wx.openSetting({
  success: (res) => {
    /*
     * res.authSetting = {
     *   "scope.userInfo": true,
     *   "scope.userLocation": true
     * }
     */
  }
})

OpenSettingButton wx.createOpenSettingButton(string type, string text, string image, Object style)


支持版本 >= 2.0.7

創(chuàng)建打開設(shè)置頁面的按鈕。

參數(shù)

string type

按鈕的類型

type 的合法值:

說明
text 可以設(shè)置背景色和文本的按鈕
image 只能設(shè)置背景貼圖的按鈕,背景貼圖會直接拉伸到按鈕的寬高

string text

按鈕上的文本,僅當(dāng) type 為 text 時有效

string image

按鈕的背景圖片,僅當(dāng) type 為 image 時有效

Object style

按鈕的樣式

屬性 類型 默認(rèn)值 是否必填 說明 支持版本
left number 左上角橫坐標(biāo)
top number 左上角縱坐標(biāo)
width number 寬度
height number 高度
backgroundColor string 背景顏色
borderColor string 邊框顏色
borderWidth number 邊框?qū)挾?/td>
borderRadius number 邊框圓角
textAlign string 文本的水平居中方式
fontSize number 字號
lineHeight number 文本的行高

style.textAlign 的合法值:

說明
left 居左
center 居中
right 居右

返回值

OpenSettingButton

示例代碼

let button = wx.createOpenSettingButton({
    type: 'text',
    text: '打開設(shè)置頁面',
    style: {
        left: 10,
        top: 76,
        width: 200,
        height: 40,
        lineHeight: 40,
        backgroundColor: '#ff0000',
        color: '#ffffff',
        textAlign: 'center',
        fontSize: 16,
        borderRadius: 4
    }
})

wx.getSetting(OBJECT)


基礎(chǔ)庫 1.2.0 開始支持,低版本需做兼容處理

獲取用戶的當(dāng)前設(shè)置

Object 參數(shù)說明:

參數(shù) 類型 必填 說明
success Function 接口調(diào)用成功的回調(diào)函數(shù),返回內(nèi)容詳見返回參數(shù)說明。
fail Function 接口調(diào)用失敗的回調(diào)函數(shù)
complete Function 接口調(diào)用結(jié)束的回調(diào)函數(shù)(調(diào)用成功、失敗都會執(zhí)行)

success返回參數(shù)說明:

參數(shù) 類型 說明
authSetting Object 用戶授權(quán)結(jié)果,其中 key 為 scope 值,value 為 Bool 值,表示用戶是否允許授權(quán),詳見 scope 列表

示例代碼:

wx.getSetting({
  success: (res) => {
    /*
     * res.authSetting = {
     *   "scope.userInfo": true,
     *   "scope.userLocation": true
     * }
     */
  }
})


以上內(nèi)容是否對您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號
微信公眾號

編程獅公眾號