快应用 弹窗

2020-08-10 13:49 更新

接口声明

{"name": "system.prompt"}

导入模块

import prompt from '@system.prompt' 或 const prompt = require('@system.prompt')

接口定义

prompt.showToast(OBJECT)

显示Toast

参数:

参数名 类型 必填 说明
message String 要显示的文本
duration Number 0为短时,1为长时,默认0

示例:

prompt.showToast({
  message: 'message'
})

prompt.showDialog(OBJECT)

显示对话框

参数:

参数名 类型 必填 说明
title String 标题
message String 内容
buttons Array 按钮的数组,按钮结构:{text:'text',color:'#333333'},color可选:buttons的第1项为positive button;buttons的第2项(如果有)为negative button;buttons的第3项(如果有)为neutral button。最多支持3个button
success Function 成功回调
cancel Function 取消回调
complete Function 执行结束后的回调
success返回值:
参数名 类型 说明
index Integer 选中按钮在buttons数组中的序号

示例:

prompt.showDialog({
  title: 'title',
  message: 'message',
  buttons: [
    {
      text: 'btn',
      color: '#33dd44'
    }
  ],
  success: function (data) {
    console.log('handling callback')
  },
  cancel: function (data) {
    console.log('handling cancel')
  },
  fail: function (data, code) {
    console.log(`handling fail, code = ${code}`)
  }
})

prompt.showContextMenu(OBJECT)

显示上下文菜单

参数:

参数名 类型 必填 说明
itemList Array 按钮的文字数组
itemColor HexColor 按钮颜色
success Function 成功回调
cancel Function 取消回调
complete Function 执行结束后的回调
success返回值:
参数名 类型 说明
index Integer 选中按钮在itemList数组中的序号

示例:

prompt.showContextMenu({
  itemList: [
    'item1',
    'item2'
  ],
  itemColor: '#ff33ff',
  success: function (data) {
    console.log('handling callback')
  },
  cancel: function (data) {
    console.log('handling cancel')
  },
  fail: function (data, code) {
    console.log(`handling fail, code = ${code}`)
  }
})

后台运行限制

禁止使用。后台运行详细用法参见 后台运行脚本


以上内容是否对您有帮助:
在线笔记
App下载
App下载

扫描二维码

下载编程狮App

公众号
微信公众号

编程狮公众号