pw-open-js
v0.0.7
Published
pw-open-js
Readme
pw-open-js
pw-open-js
Install
npm install --save pw-open-jsUsage
返回结果以 callback 形式回传至 H5,所有方法可以通过传递 onSuccess/onFail 参数拿到结果/处理失败情况
参数对象:
key | type | require | default | description
--|:--:|--:|--:|--:|
onSuccess | Func | false | | 方法调查成功回调
onFail | Func | false | | 方法调查失败回调
app
getVersion
返回 app 原生版本号
pw.app.getVersion({
onSuccess: function(data) {
alert(`appVersion:${data}`)
}
})getJSVersion
返回 jsbundle 版本号
pw.app.getJSVersion({
onSuccess: function(data) {
alert(`jsVersion:${data}`)
}
})share
调起分享菜单,可以分享 url 至微信/朋友圈/微博/QQ/qzone
参数对象:
key | type | require | default | description
--|:--:|--:|--:|--:|
title | String | true | | 分享标题
description | String | true | | 分享描述
url | String | true | | 分享url
thumbImage | String | false | https://dakaapp.troila.com/static/icon.png | 分享图标
options | Array | false | ['wechat', 'friend', 'weibo', 'qq', 'qzone'] | 分享目标
options 对应选项
key | target --|:--:| wechat | 微信 friend | 朋友圈 weibo | 微博 qq | QQ qzone | qzone
pw.app.share({
title: 'test',
description: 'des',
url: 'www.baidu.com',
onSuccess: function(data){
alert('success')
},
onFail: function(err){
alert(err.message)
}
})scan
扫码二维码或从相册识别二维码
pw.app.scan({
onSuccess: function(data) {
alert(`scanResult:${data}`)
}
})getPhoneInfo
获取手机信息
返回数据 data:
key | type | description
--|:--:|--:|
uniqueId | String | uuid
deviceId | String | 设备id
systemName | String | 系统名称 Android/iOS
systemVersion | String | 系统版本
version | String | app版本
brand | String | 手机品牌
model | String | 手机型号
screenHeight | number | 屏幕高度
screenWeight | number | 屏幕宽度
pw.app.getPhoneInfo({
onSuccess: function(data) {
alert(`uniqueId:${data.uniqueId}`)
}
})getNetworkInfo
获取手机信息
返回数据 data:
key | type | description
--|:--:|--:|
type | String | 网络类型
isConnected | boolean | 网络是否连接,注意此状态不代表是否可以访问网络
isInternetReachable | boolean | 是否可以访问网络
isWifiEnabled | boolean | 是否连接至wifi(Android Only)
details | object | 详细信息,根据type返回对应字段
pw.app.getNetworkInfo({
onSuccess: function(data) {
alert(`type:${data.type}`)
}
})vibrate
调用手机震动
参数对象:
key | type | require | default | description
--|:--:|--:|--:|--:|
duration | number | false | | 震动时长(Android Only, iOS默认400ms)
pw.app.vibrate({
onSuccess: function(data) {
alert(`success`)
}
})showLoading
显示 loading 动画
pw.app.showLoading({
onSuccess: function(data) {
alert(`success`)
}
})hideLoading
隐藏 loading 动画
pw.app.hideLoading({
onSuccess: function(data) {
alert(`success`)
}
})toast
弹出 toast 提示信息
参数对象:
key | type | require | default | description
--|:--:|--:|--:|--:|
text | String | true | | 提示信息
pw.app.toast({
text: 'toast',
onSuccess: function(data) {
alert(`success`)
}
})alert
弹出 alert 提示框
参数对象:
key | type | require | default | description
--|:--:|--:|--:|--:|
title | String | true | | 提示框标题
content | String | true | | 提示框内容
icon | String | false | none | 提示框图标
confirmText | String | false | 确定 | 提示框确定文本
cancelText | String | false | 取消 | 提示框取消文本, 不传不显示取消按钮
pw.app.alert({
title: 'title',
content: 'centent',
icon: 'none',
confirmText: '确定',
cancelText: '取消',
onSuccess: function(data) {
if (data === 'confirm') {
alert(`用户点击确定`)
}
if (data === 'cancel') {
alert(`用户点击取消`)
}
}
})setItem
app 存储数据
参数对象:
key | type | require | default | description
--|:--:|--:|--:|--:|
key | String | true | | 数据存储key
value | any | true | | 数据存储value
pw.app.setItem({
key: 'key',
value: 'value',
onSuccess: function(data) {
alert(`success`)
}
})getItem
app 获取存储数据
参数对象:
key | type | require | default | description
--|:--:|--:|--:|--:|
key | String | true | | 数据存储key
pw.app.getItem({
key: 'key',
onSuccess: function(data) {
alert(`data: ${data}`)
}
})removeItem
app 移除存储数据
参数对象:
key | type | require | default | description
--|:--:|--:|--:|--:|
key | String | true | | 数据存储key
pw.app.removeItem({
key: 'key',
onSuccess: function(data) {
alert(`success`)
}
})getCurrentLocation
获取一次当前地点
返回数据 data:
key | type | description
--|:--:|--:|
latitude | number | 经度
longitude | number | 纬度
accuracy | number | 精度
altitude | number | 海拔(米)
speed | number | 速度(m/s)
direction | number | 方向
pw.app.getCurrentLocation({
onSuccess: function(data) {
alert(`Current Latitude: ${data.latitude}`)
}
})startLocationListener
开启定位监听,持续获取当前位置
返回数据 data:
key | type | description
--|:--:|--:|
latitude | number | 经度
longitude | number | 纬度
accuracy | number | 精度
altitude | number | 海拔(米)
speed | number | 速度(m/s)
direction | number | 方向
pw.app.startLocationListener({
onSuccess: function(data) {
alert(`Keep Getting Current Latitude: ${data.latitude}`)
}
})removeLocationListener
移除定位监听,停止定位
pw.app.removeLocationListener({
onSuccess: function(data) {
alert(`Success`)
}
})previewImage
预览图片
参数对象:
key | type | require | default | description
--|:--:|--:|--:|--:|
imageArray | Array<String> | true | | 预览图片的url数组
index | number | false | 0 | 预览图片序号
showCount | boolean | false | false | 是否显示底部计数
pw.app.previewImage({
imageArray: ['someImageUrl.png'],
index: 0,
showCount: false,
onSuccess: function(data) {
alert(`Success`)
}
})openFile
打开文件
参数对象:
key | type | require | default | description
--|:--:|--:|--:|--:|
url | String | true | | 文件下载地址
type | String | true | | 文件类型后缀名
size | number | true | | 文件大小
name | String | true | | 文件名称
pw.app.openFile({
url: 'someFileUrl.xlsx',
type: 'xlsx',
size: 0,
name: 'fileName',
onSuccess: function(data) {
alert(`Success`)
}
})user
getUserId
获取当前 userid
pw.user.getUserId({
onSuccess: function(data) {
alert(`userid: ${data}`)
}
})getToken
获取 token
pw.user.getToken({
onSuccess: function(data) {
alert(`token: ${data}`)
}
})getCurrentEnterpriseInfo
获取用户当前企业信息,返回数据结构同接口数据
pw.user.getCurrentEnterpriseInfo({
onSuccess: function(data) {
alert(JSON.stringify(data))
}
})getEmployeeInfoByIds
通过员工 id 获取员工信息
参数对象:
key | type | require | default | description
--|:--:|--:|--:|--:|
enterprise_id | String | true | | 企业id
employee_ids | Array | true | | 员工id数组
pw.user.getEmployeeInfoByIds({
enterprise_id: 'id',
employee_ids: ['ids'],
onSuccess: function(data) {
alert(JSON.stringify(data))
}
})getDepartmentInfoByIds
通过部门 id 获取部门信息
参数对象:
key | type | require | default | description
--|:--:|--:|--:|--:|
enterprise_id | String | true | | 企业id
department_ids | Array | true | | 部门id数组
pw.user.getDepartmentInfoByIds({
enterprise_id: 'id',
department_ids: ['ids'],
onSuccess: function(data) {
alert(JSON.stringify(data))
}
})getAllEmployeeInfo
通过部门 id 获取部门信息
参数对象:
key | type | require | default | description
--|:--:|--:|--:|--:|
enterprise_id | String | true | | 企业id
pw.user.getAllEmployeeInfo({
enterprise_id: 'id',
onSuccess: function(data) {
alert(JSON.stringify(data))
}
})navigation
navigate
跳转 app 页面
参数对象:
key | type | require | default | description
--|:--:|--:|--:|--:|
page | String | true | | 页面名称
pageParams | object | false | undefined | 页面参数
pw.navigation.navigate({
page: 'SomePage',
pageParams: { params: 'params' }
onSuccess: function(data) {
alert(`success`)
}
})replace
跳转 app 页面并关闭当前页面
参数对象:
key | type | require | default | description
--|:--:|--:|--:|--:|
page | String | true | | 页面名称
pageParams | object | false | undefined | 页面参数
pw.navigation.replace({
page: 'SomePage',
pageParams: { params: 'params' }
onSuccess: function(data) {
alert(`success`)
}
})goBack
关闭当前页面
pw.navigation.goBack({
onSuccess: function(data) {
alert(`success`)
}
})openWebPage
参数对象:
key | type | require | default | description
--|:--:|--:|--:|--:|
url | String | true | | 路径地址
enterprise_id | String | false | `` | 企业id
打开另一个web页面
pw.navigation.openWebPage({
url: 'http://someUrl.com',
enterprise_id: 'id',
onSuccess: function(data) {
alert(`success`)
}
})setRightButton
设置标题栏右侧按钮
参数对象:
key | type | require | default | description
--|:--:|--:|--:|--:|
display | boolean | true | false | 是否显示按钮
title | String | false | | 按钮文字
color | String | false | | 按钮文字颜色
pw.navigation.setRightButton({
display: true,
title: '',
color: '#333',
onSuccess: function(data) {
alert(`buttonClick`)
}
})setTitle
设置标题
参数对象:
key | type | require | default | description
--|:--:|--:|--:|--:|
title | String | true | | 标题文字
pw.navigation.setTitle({
title: 'title',
onSuccess: function(data) {
alert(`success`)
}
})setCloseButton
设置左侧关闭按钮
参数对象:
key | type | require | default | description
--|:--:|--:|--:|--:|
show | boolean | true | false | 是否显示关闭按钮
pw.navigation.setCloseButton({
show: true,
onSuccess: function(data) {
alert(`success`)
}
})setHeaderStyle
设置标题栏样式
参数对象:
key | type | require | default | description
--|:--:|--:|--:|--:|
headerStyle | object | false | | 标题栏容器样式
headerTintColor | String | false | | 标题栏图标、字体颜色
headerTitleStyle | object | false | | 标题文字样式
pw.navigation.setHeaderStyle({
headerStyle: { backgroundColor: '#586BFB' },
headerTintColor: '#fff',
headerTitleStyle: { fontSize: 24 }
onSuccess: function(data) {
alert(`success`)
}
})selectEmployee
跳转 app 选择员工页面并返回选择结果
参数对象:
key | type | require | default | description
--|:--:|--:|--:|--:|
enterprise_id | String | true | | 企业id
title | String | false | 请选择 | 选人页面标题
radio | boolean | false | false | 是否单选
maxLength | number | false | | 最多选择数量
selectedIds | array | false | | 已选择员工id列表
filterIds | array | false | | 筛选不显示的员工id
返回数据: 员工 object 的列表,object 结构同接口结构
pw.navigation.selectEmployee({
enterprise_id: '121',
title: '请选择',
radio: false,
maxLength: 5,
selectedIds: ['1'],
filterIds: ['2', '3'],
onSuccess: function(data) {
alert(JSON.stringify(data))
}
})selectDepartment
跳转 app 选择部门页面并返回选择结果
参数对象:
key | type | require | default | description
--|:--:|--:|--:|--:|
enterprise_id | String | true | | 企业id
title | String | false | 请选择 | 选人页面标题
radio | boolean | false | false | 是否单选
maxLength | number | false | | 最多选择数量
selectedIds | array | false | | 已选择员工id列表
返回数据: 部门object的列表,object结构同接口结构
pw.navigation.selectDepartment({
enterprise_id: '121',
title: '请选择',
radio: false,
maxLength: 5,
selectedIds: ['1'],
onSuccess: function(data) {
alert(JSON.stringify(data))
}
})