app-plusex

1.0.1 • Public • Published

plus api 使用指北

安装与使用

安装

npm i app-plusex -S

项目中使用

import {plusEx, onPlusReady} from 'app-plusex'
Vue.prototype.$plus = plusEx

onPlusReady 是为了使用dcloud原生的方法所定义的方法

使用方法

this.$plus('apiname', {})
  .then(() => {})
  .catch(() => {})

plus方法返回的是一个Promise对象,有些同步方法也可不监听回调

注意点

如果在应用启动的时候需要调用plus方法,因为框架注入plus的限制,需要做延时处理

api分类

plus.native 启动一个原生页面
plus.shareEx 显示系统分享的PopupWindow
plus.encrypt 秘钥生成及字段存储
plus.listener 监听器
plus.permission 权限
plus.payEx 支付相关
plus.calendar 日程相关
plus.log 日志相关
plus.config app配置
plus.upgrade app执行升级
plus.app app版本相关
plus.deviceEx 设备相关
plus.debug debug调试

启动一个原生页面

name 方法名 options 参数名称 参数类型 是否必填 默认值 回调函数返回值 promise返回值
start 启动一个页面,类似于扫码页面 name 页面名称 string true -- -- then:{msg: 'xxxx'}
catch: {code: -1, msg: 'xxxx'}
extras 页面启动参数 string false null --
success 成功回调函数 function true -- 不同页面会返回不同数据
error 失败回调函数 function true -- 不同页面会返回不同数据

显示系统分享的PopupWindow

name 方法名 options 参数名称 参数类型 是否必填 默认值 promise返回值
systemShare 显示系统分享的PopupWindow content 分享内容的字符串 string true -- then:{msg: 'xxxx'}
catch: {code: -1, msg: 'xxxx'}

秘钥生成及字段存储

name 方法名 options 参数名称 参数类型 是否必填 默认值 promise返回值
genKeyPair 通过RSA算法生成一对公钥和私钥 -- -- -- -- -- then:{ "RSAPublicKey": "123456", "RSAPrivateKey": "654321" }
catch: { code: -1, msg: 'xxxx' }
setSecurityValue 加密保存指定key的value name 保存的key string true -- then:{ msg: 'xxxx' }
catch: { code: -1, msg: 'xxxx' }
value 保存的value string true --
getSecurityValue 取得加密指定key的value name 保存的key string true -- then:{ data: 'xxxxx' }
catch: { code: -1, msg: 'xxxx' }

监听器

name 方法名 options 参数名称 参数类型 是否必填 默认值 回调函数返回值 promise返回值
registerListener 注册监听器 name 监听主题 string true -- -- then:{msg: 'xxxx'}
catch: {code: -1, msg: 'xxxx'}
success 监听主题发生变化时成功时回调 function true -- 视监听主题而定
error 监听主题发生变化时失败时的回调 function true -- 视监听主题而定
unregisterListener 取消注册监听器 name 监听主题 string true -- -- then:{msg: 'xxxx'}
catch: {code: -1, msg: 'xxxx'}

权限

name 方法名 options 参数名称 参数类型 是否必填 默认值 回调函数返回值 promise返回值
permissionRequset 请求权限 names 权限名称列表 string | array true -- -- then:{msg: 'xxxx'}
catch: {code: -1, msg: 'xxxx'}
success 监听主题发生变化时成功时回调 function true -- {"authorized": ["xxx"]}
error 监听主题发生变化时失败时的回调 function true -- {"denied": ["xxx","xxx"]}
option 请求参数(以下参数不传时都跟随全局设置) hint(bool) - 权限被拒绝后,是否需要弹出提示对话框 operation(OPER) - 当弹出提示对话框时,[确认]按钮的具体操作。对话框中[取消]按钮无操作,直接返回结果到H5。该参数需要在hint为true时才有效,否则会返回code:-1 OPER = { SETTING : 1 - [确认]按钮会显示为[去设置],点击后可跳转至App权限设置页 RETRY : 2 - [确认]按钮会重试权限申请,仅Android有效。 }" object false {hint: true, retry: true, settings: false} --
hasPermission 查询是否拥有某些权限 names 权限名称列表 array true -- -- then:{data: {"authorized": ["xxx"],"denied": ["xx"] }}
catch: {code: -1, msg: 'xxxx'}

支付相关

name 方法名 options 参数名称 参数类型 是否必填 默认值 回调函数返回值 promise返回值
getChannels 取得所有支持的支付渠道(不包含dcloud中自带的) id 支付渠道id string false -- -- then:{msg: 'xxxx', data: {}}
catch: {code: -1, msg: 'xxxx'}
requestPay 请求支付 channel 支付通道 id(从getChannels中获得) string true -- -- then:{msg: 'xxxx', data: {}}
catch: {code: -1, msg: 'xxxx'}
statement 支付订单信息 string true -- --
success 成功回调函数 function true -- 视情况而定
error 失败回调函数 function true -- 视情况而定

日程相关

name 方法名 options 参数名称 参数类型 是否必填 默认值 promise返回值
addSchedule 添加日程 title 日程标题 string true -- then:{msg: 'xxxx', data: {}}
catch: {code: -1, msg: 'xxxx'}
description 日程描述 string true --
startTime 日程开始时间(单位毫秒) number true --
endTime 日程结束时间(单位毫秒) number true --
previousTime 如果需要提醒,日程提前提醒时间(单位分钟) number false 0
deleteSchedule 删除日程 scheduleId 日程标题 string true -- then:{msg: 'xxxx'}
catch: {code: -1, msg: 'xxxx'}
findSchedule 查找日程 type 查找类型 1 查找标题 2 查找描述 number false 1 then:{msg: 'xxxx', data: {}}
catch: {code: -1, msg: 'xxxx'}
keyword 查找关键字 string false ''
option 请求参数 fuzzy- 是否模糊查找 object false {fuzzy: false}

日志相关

name 方法名 options 参数名称 参数类型 是否必填 默认值 回调函数返回值 promise返回值
log 记录日志 message 日志内容 string true -- -- then:{msg: 'xxxx'}
catch: {code: -1, msg: 'xxxx'}
tag 日志标签 string false '日志' --
level 日志级别 number false 1 --
isLoggable 是否开启记录日志 -- -- -- -- -- -- then:{msg: 'xxxx', data: {}}
catch: {code: -1, msg: 'xxxx'}
setLoggable 设置是否开启记录日志 loggable 日志开关 boolean true -- -- then:{msg: 'xxxx'}
catch: {code: -1, msg: 'xxxx'}
upload 上传日志到指定位置 url 上传地址 string true -- -- then:{msg: 'xxxx'}
catch: {code: -1, msg: 'xxxx'}
option 上传参数 fileName - 日志文件名 start - 日志起始点时间戳(毫秒) end - 日志结束点时间戳(毫秒) object false { fileName: `日志${new Date().getTime()}.zip`, start: new Date().getTime(), end: new Date().getTime() } --
success 成功回调函数 function true -- 视接口情况而定
error 失败回调函数 function true -- 视接口情况而定

app配置

name 方法名 options 参数名称 参数类型 是否必填 默认值 promise返回值
setProperty 运行时设置app的属性 key 属性名称 目前支持的值:host string true -- then:{msg: 'xxxx'}
catch: {code: -1, msg: 'xxxx'}
value 属性值 string/number/bool等基本类型 true --

app执行升级

name 方法名 options 参数名称 参数类型 是否必填 默认值 promise返回值
upgrade 执行升级 path 已下载的apk路径 string true -- then:{msg: 'xxxx'}
catch: {code: -1, msg: 'xxxx'}

app版本相关

name 方法名 options 参数名称 参数类型 是否必填 默认值 promise返回值
version 获取app版本字符串 -- -- -- -- -- then:{msg: 'xxxx',data: {}}
catch: {code: -1, msg: 'xxxx'}
versionCode 获取app版本Code -- -- -- -- -- then:{msg: 'xxxx',data: {}}
catch: {code: -1, msg: 'xxxx'}
appName 获取app名称 -- -- -- -- -- then:{msg: 'xxxx',data: {}}
catch: {code: -1, msg: 'xxxx'}

设备相关

name 方法名 options 参数名称 参数类型 是否必填 默认值 promise返回值
deviceVersion 获取设备版本 -- -- -- -- -- then:{msg: 'xxxx',data: {}}
catch: {code: -1, msg: 'xxxx'}
deviceManufacturer 获取设备制造商 -- -- -- -- -- then:{msg: 'xxxx',data: {}}
catch: {code: -1, msg: 'xxxx'}
deviceModel 获取设备型号 -- -- -- -- -- then:{msg: 'xxxx',data: {}}
catch: {code: -1, msg: 'xxxx'}
deviceBrand 获取设备品牌 -- -- -- -- -- then:{msg: 'xxxx',data: {}}
catch: {code: -1, msg: 'xxxx'}
deviceLanguage 获取设备当前语言 -- -- -- -- -- then:{msg: 'xxxx',data: {}}
catch: {code: -1, msg: 'xxxx'}
deviceScreenInfo 获取设备屏幕信息 -- -- -- -- -- then:{msg: 'xxxx',data: {}}
catch: {code: -1, msg: 'xxxx'}
deviceDeviceInfo 获取设备信息 -- -- -- -- -- then:{msg: 'xxxx',data: {}}
catch: {code: -1, msg: 'xxxx'}
deviceNotificationHeight 获取通知栏高度 -- -- -- -- -- then:{msg: 'xxxx',data: {}}
catch: {code: -1, msg: 'xxxx'}

plus.debug

debug

name 方法名 options 参数名称 参数类型 是否必填 默认值 promise返回值
doraemon 获显示/隐藏哆啦A梦调试工具取设备版本 show 是否显示 boolean true -- then:{msg: 'xxxx'}
catch: {code: -1, msg: 'xxxx'}

Readme

Keywords

none

Package Sidebar

Install

npm i app-plusex

Weekly Downloads

1

Version

1.0.1

License

ISC

Unpacked Size

43.5 kB

Total Files

16

Last publish

Collaborators

  • bigcanz