Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

WeChat small program API to adjust the client small program settings interface


May 19, 2021 WeChat Mini Program Development Document


Table of contents


wx.openSetting(OBJECT)


Base library version 1.1.0 starts to support, and low versions need to be compatible

Call up the client program settings interface and return the results of the user-set operation

Object parameter description:

Parameters Type Required Description
success Function Whether The interface calls the successful callback function, and the return is detailed in the return parameter description.
fail Function Whether The interface calls the failed callback function
complete Function Whether Callback function at end of interface call (call succeeds, fails are executed)

Success returns a description of the parameters:

Parameters Type Description
authSetting Object The user authorization result, where key is scope value and value is Bool value, indicates whether the user allows authorization, see scope list

Example code:

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

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


Supported version

Create a button to open the settings page.

Parameters

string type

The type of button

The legal value of type:

Value Description
text You can set buttons for background colors and text
image You can only set the button for the background map, which stretches directly to the width of the button

string text

The text on the button is only valid if type is text

string image

The background picture of the button, valid only if type is image

Object style

The style of the button

Property Type The default Is it required Description The supported version
left number Is The horizontal coordinates in the upper left corner
top number Is Top left ordinate
width number Is Width
height number Is Height
backgroundColor string Is The background color
borderColor string Is Border color
borderWidth number Is The width of the border
borderRadius number Is Border fillets
textAlign string Is The horizontal centering of the text
fontSize number Is Size
lineHeight number Is The line height of the text

The legal value of style.textAlign:

Value Description
left Left
center Center
right Right

Returns a value

OpenSettingButton

The sample code

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)


Base library 1.2.0 starts to support, and low versions need to be compatible

Gets the user's current settings

Object parameter description:

Parameters Type Required Description
success Function Whether The interface calls the successful callback function, and the return is detailed in the return parameter description.
fail Function Whether The interface calls the failed callback function
complete Function Whether Callback function at end of interface call (call succeeds, fails are executed)

Success returns a description of the parameters:

Parameters Type Description
authSetting Object The user authorization result, where key is scope value and value is Bool value, indicates whether the user allows authorization, see scope list

Example code:

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