微信小程序开发 专题
专题目录
您的位置:微信小程序开发 > 微信小程序开发专题 > 微信小程序API 调起客户端小程序设置界面
微信小程序API 调起客户端小程序设置界面
作者:--    发布时间:2019-11-20

wx.opensetting(object)


基础库版本 1.1.0 开始支持,低版本需做兼容处理

调起客户端小程序设置界面,返回用户设置的操作结果

object 参数说明:

参数 类型 必填 说明
success function 否 接口调用成功的回调函数,返回内容详见返回参数说明。
fail function 否 接口调用失败的回调函数
complete function 否 接口调用结束的回调函数(调用成功、失败都会执行)

success返回参数说明:

参数 类型 说明
authsetting object 用户授权结果,其中 key 为 scope 值,value 为 bool 值,表示用户是否允许授权,详见 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

创建打开设置页面的按钮。

参数

string type

按钮的类型

type 的合法值:

值 说明
text 可以设置背景色和文本的按钮
image 只能设置背景贴图的按钮,背景贴图会直接拉伸到按钮的宽高

string text

按钮上的文本,仅当 type 为 text 时有效

string image

按钮的背景图片,仅当 type 为 image 时有效

object style

按钮的样式

属性 类型 默认值 是否必填 说明 支持版本
left number 是 左上角横坐标
top number 是 左上角纵坐标
width number 是 宽度
height number 是 高度
backgroundcolor string 是 背景颜色
bordercolor string 是 边框颜色
borderwidth number 是 边框宽度
borderradius number 是 边框圆角
textalign string 是 文本的水平居中方式
fontsize number 是 字号
lineheight number 是 文本的行高

style.textalign 的合法值:

值 说明
left 居左
center 居中
right 居右

返回值

opensettingbutton

示例代码

let button = wx.createopensettingbutton({
    type: 'text',
    text: '打开设置页面',
    style: {
        left: 10,
        top: 76,
        width: 200,
        height: 40,
        lineheight: 40,
        backgroundcolor: '#ff0000',
        color: '#ffffff',
        textalign: 'center',
        fontsize: 16,
        borderradius: 4
    }
})

wx.getsetting(object)


基础库 1.2.0 开始支持,低版本需做兼容处理

获取用户的当前设置

object 参数说明:

参数 类型 必填 说明
success function 否 接口调用成功的回调函数,返回内容详见返回参数说明。
fail function 否 接口调用失败的回调函数
complete function 否 接口调用结束的回调函数(调用成功、失败都会执行)

success返回参数说明:

参数 类型 说明
authsetting object 用户授权结果,其中 key 为 scope 值,value 为 bool 值,表示用户是否允许授权,详见 scope 列表

示例代码:

wx.getsetting({
  success: (res) => {
    /*
     * res.authsetting = {
     *   "scope.userinfo": true,
     *   "scope.userlocation": true
     * }
     */
  }
})


网站声明:
本站部分内容来自网络,如您发现本站内容
侵害到您的利益,请联系本站管理员处理。
联系站长
373515719@qq.com
关于本站:
编程参考手册