教程 框架 组件 接口 工具 其他

弹窗 prompt

接口声明

{ "name": "system.prompt" }

导入模块

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

接口定义

prompt.showToast(OBJECT)

显示 Toast

参数:

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

示例:

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

prompt.showDialog(OBJECT)

显示对话框

参数:

参数名类型必填说明
titleString标题
messageString内容
buttonsArray按钮的数组,按钮结构:{text:'text',color:'#333333'},color 可选:buttons 的第 1 项为 positive button;buttons 的第 2 项(如果有)为 negative button;buttons 的第 3 项(如果有)为 neutral button。最多支持 3 个 button
autocancel 1060+Boolean是否在点击遮罩时关闭对话框,默认为true
successFunction成功回调
cancelFunction取消回调
completeFunction执行结束后的回调
success 返回值:
参数名类型说明
indexInteger选中按钮在 buttons 数组中的序号

示例:

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

prompt.showContextMenu(OBJECT)

显示上下文菜单

参数:

参数名类型必填说明
itemListArray按钮的文字数组
itemColorHexColor按钮颜色
successFunction成功回调
cancelFunction取消回调
completeFunction执行结束后的回调
success 返回值:
参数名类型说明
indexInteger选中按钮在 itemList 数组中的序号

示例:

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

后台运行限制

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

条匹配 "" 的结果

    没有搜索到与 "" 相关的内容