dlt.showActionSheet
Introduction
Displays an action sheet menu.
Usage Restrictions
Supported in the base library version 3.0.0 or higher.
Parameters
Object object
| Property | Type | Default | Required | Description |
|---|---|---|---|---|
| alertText | string | No | Alert text | |
| itemList | string[] | Yes | Menu configuration items, at least 1 and up to 6 | |
| itemColor | string | #000000 | No | The text color of the buttons |
| type | string | text | No | Type - text: the action is centered text - icon: the action is text with an icon aligned to the left |
| title | string | No | Title (if not provided, the title will not be displayed) | |
| showCancel | boolean | true | No | Whether to show the cancel button |
| cancelText | string | Cancel | No | The text of the cancel button |
| cancelColor | string | #191F2B | No | The text color of the cancel button, supports AHEX format |
| actions | Actions[] | Yes | Menu configuration items, at least 1 and up to 6 (actions or itemList is required) | |
| success | function | No | Callback function for a successful API call | |
| fail | function | No | Callback function for a failed API call | |
| complete | function | No | Callback function that will be executed when the API call is complete (both successful and failed calls) |
Action Explanation
| Property | Type | Default | Required | Description |
|---|---|---|---|---|
| text | string | Yes | Button text, can be used for multi-language scenarios | |
| color | string | #FF191F2B | No | Button default color |
| disabledColor | string | #4D191F2B | No | Button disabled color |
| enable | boolean | true | No | Button state, true for enabled, false for disabled (if disabled, disabledColor will be used, otherwise color) |
| icon | string | No | Menu icon, relative address or CDN address Note: Only valid when type is icon | |
| maskColor | string | #0F191F2B | No | Button press mask, supports AHEX format |
success Callback Function
Parameters
Object res
| Property | Type | Description |
|---|---|---|
| success | string | true - successful |
| tapIndex | number | The index of the button that the user clicked, starting from 0 in top-to-bottom order |
| content | string | The content of the clicked action item |
fail Callback Function
Parameters
Object res
| Property | Type | Description |
|---|---|---|
| errMsg | string | 1. Parameter error: AS10001 2. ${type} is not supported: AS10002 3. Invalid ${size}, must be between ${MIN_SIZE} and ${MAX_SIZE} : AS10003 |
| success | string | false - failed |
Example Code
// pages/index/index.js
Page({
showActionSheet() {
dlt.showActionSheet({
itemList: ["A", "B", "C"],
success(res) {
console.log(res.tapIndex);
},
fail(res) {
console.log(res.errMsg);
},
});
},
});