PatchApp Class
阿波罗手机端jsbridge
继承自dpapp-core,dpapp-core部分可参考http://efte.github.io/dpapp/#概述
Methods
- ajax
- closeWindow
- downloadImage
- getCityId
- getContactList
- getDeviceInfo
- getLocation
- getNetworkType
- getUA
- getUserInfo
- getWifiInfo
- isSupportEIM
- jumpToScheme
- logout
- openEIM
- openScheme
- publish
- ready
- setBackgroundColor
- setLLButton
- setLRButton
- setPullDown
- setRLButton
- setRRButton
- setTitle
- showPhoto
- stopPullDown
- subscribe
Properties
Events
lib/patch-app.js:25
Methods
ajax
ajax
(
-
opts
)
发送一个请求,获取服务器端的数据
Parameters:
name | type | flag | description | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
opts
| Object |
|
Example:
import dpappApollo from 'dpapp-apollo';
dpappApollo.ajax({
method:'post',
url:'https://a.dper.com/demo/demo',
data:{
name:'app'
},
success:function(data){
console.dir('成功');
},
fail:function(){
console.dir('失败');
}
});
closeWindow
closeWindow
()
关闭webview
downloadImage
downloadImage
(
-
opts
)
下载图片,下载完成后,图片会出现在用户设备的资源库中
Parameters:
name | type | flag | description | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
opts
| Object |
|
Example:
import dpappApollo from 'dpapp-apollo';
dpappApollo.downloadImage({
type: 1,
imageUrl: "http://img5.douban.com/view/note/large/public/p22307117.jpg",
success: function(result){
alert("下载到相册");
}
});
dpappApollo.downloadImage({
type: 0,
imageUrl: "http://img5.douban.com/view/note/large/public/p22307117.jpg",
success: function(result){
alert(result.imageData);
}
});
getCityId
getCityId
(
-
opt
)
获取城市信息
Parameters:
name | type | flag | description | ||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
opt
| Object |
|
Example:
import dpappApollo from 'dpapp-apollo';
dpappApollo.getCityId({
success:function(e){
console.dir(e.cityId); //切换城市
console.dir(e.locCityId);//定位城市
}
});
getContactList
getContactList
(
-
opt
)
获取联系人列表
Parameters:
name | type | flag | description | ||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
opt
| Object |
|
Example:
import dpappApollo from 'dpapp-apollo';
dpappApollo.getContactList({
success:function(e){
e.contactList.forEach(function(people){
alert(e.lastName); // 姓
alert(e.firstName); // 名
alert(e.phone); // 号码
});
alert(e.authorized); // 用户是否授权
}
});
getDeviceInfo
getDeviceInfo
(
-
opt
)
获取手机端基本信息
Parameters:
name | type | flag | description | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
opt
| Object |
|
Example:
return {
getLocation
getLocation
(
-
opt
)
获取地理位置信息
Parameters:
name | type | flag | description | ||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
opt
| Object |
|
Example:
import dpappApollo from 'dpapp-apollo';
dpappApollo.getLocation({
success: function(result){
console.dir(result.lat);
console.dir(result.lng);
}
});
getNetworkType
getNetworkType
(
-
opts
)
获取网络状态
Parameters:
name | type | flag | description | ||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
opts
| Object |
|
Example:
import dpappApollo from 'dpapp-apollo';
dpappApollo.getNetworkType({
success: function(e){
alert(e.networkType); // 2g, 3g, 4g, wifi
}
});
getUA
getUA
(
-
opt
)
Object
获取用户所使用的浏览器的代理信息
Parameters:
name | type | flag | description | ||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
opt
| Object | 参数传递
|
Returns:
Example:
import dpappApollo from 'dpapp-apollo';
let ua = dpappApollo.getUA();
console.dir(ua.platform); //平台信息
console.dir(ua.appName); //app名字
console.dir(ua.packageId);
console.dir(ua.appVersion);//版本考
console.dir(ua.osName);
console.dir(ua.osVersion);
getUserInfo
getUserInfo
(
-
opt
)
获取用户信息
Parameters:
name | type | flag | description | ||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
opt
| Object |
|
Example:
import dpappApollo from 'dpapp-apollo';
dpappApollo.getUserInfo({
success:function(e){
console.dir(e.dpid); //用户的dpid
console.dir(e.userId); //用户id
console.dir(e.token); //用户token
}
})
getWifiInfo
getWifiInfo
(
-
opt
)
获取wifi信息
Parameters:
name | type | flag | description | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
opt
| Object |
|
isSupportEIM
isSupportEIM
(
-
callback
)
private
Parameters:
name | type | flag | description |
---|---|---|---|
callback
| Function |
jumpToScheme
jumpToScheme
(
-
opt
)
打开新的webview,并关闭原窗口。
Parameters:
name | type | flag | description | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
opt
| Object |
|
logout
logout
()
退出用户登陆
openEIM
openEIM
(
-
data
)
打开企业QQ
Parameters:
name | type | flag | description |
---|---|---|---|
data
| Object | 各环境打开的url |
Example:
import dpappApollo from 'dpapp-apollo';
dpappApollo.openEIM({
android:"mqqwpa:\/\/im\/chat?chat_type=wpa&uin=2850297910",
ios:"eimwpa:\/\/im\/chat?chat_type=wpa&uin=2850297910&version=1&src_type=web&web_src=null",
pc:"qqeim:\/\/message?uin=14a3396e3211e36575e5e64086e40359a0d96398df048a14&src=200441309&flag=0&token=55e27e19d8757b47fe103f540267ca5d6788f28fb30e26c38cc3826e0618d3c900d074e31e80d0140768957d4833ec7d"
});
openScheme
openScheme
(
-
opt
)
打开新的webview,extra参数会用于拼url,并做对value做encode
Parameters:
name | type | flag | description | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
opt
| Object |
|
Example:
import dpappApollo from 'dpapp-apollo';
dpappApollo.openScheme({
url: "dpcrm://web",
extra: {
url:'http://www.dianping.com'
},
success: function(){
// 跳转成功
}
});
publish
publish
(
-
opts
)
发布消息
Parameters:
name | type | flag | description | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
opts
| Object |
|
Example:
import dpappApollo from 'dpapp-apollo';
dpappApollo.publish({
action: 'myMessageName',
data: {
'info': 'detail'
},
success: function(){
alert("发送成功");
}
});
ready
ready
(
-
callback
)
Null
等待整个native就绪后执行回调里的逻辑
Parameters:
name | type | flag | description |
---|---|---|---|
callback
| Function | 需要执行的回调方法 |
Returns:
Example:
import dpappApollo from 'dpapp-apollo';
dpappApollo.ready(()=>{
//页面主逻辑
console.dir('页面主逻辑');
});
setBackgroundColor
setBackgroundColor
(
-
opts
)
设置webview背景色
Parameters:
name | type | flag | description | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
opts
| Object |
|
setLLButton
setLLButton
(
-
opts
)
设置按钮(icon或文字)
标题栏从左到右4个位置设置的方法分别为setLLButton,setLRButton,setRLButton,setRRButton。 使用方法一致。
注意base64代码的data:image/png;base64,部分不需要 base64的图片大小控制为 尺寸44X44(icon本身22X22)的三倍图,即132X132的画布,66X66的icon大小
Parameters:
name | type | flag | description | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
opts
| Object |
|
setLRButton
setLRButton
(
-
opts
)
设置按钮(icon或文字)
标题栏从左到右4个位置设置的方法分别为setLLButton,setLRButton,setRLButton,setRRButton。 使用方法一致。
注意base64代码的data:image/png;base64,部分不需要 base64的图片大小控制为 尺寸44X44(icon本身22X22)的三倍图,即132X132的画布,66X66的icon大小
Parameters:
name | type | flag | description | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
opts
| Object |
|
setPullDown
setPullDown
(
-
opt
)
下拉页面刷新,需要配合stopPullDown一起使用
Parameters:
name | type | flag | description | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
opt
| Object |
|
Example:
import dpappApollo from 'dpapp-apollo';
dpappApollo.setPullDown({
handle: function(){
dpappApollo.ajax({
url:'',
success: function(){
dpappApollo.stopPullDown();
}
});
}
});
setRLButton
setRLButton
(
-
opts
)
设置按钮(icon或文字)
标题栏从左到右4个位置设置的方法分别为setLLButton,setLRButton,setRLButton,setRRButton。 使用方法一致。
注意base64代码的data:image/png;base64,部分不需要 base64的图片大小控制为 尺寸44X44(icon本身22X22)的三倍图,即132X132的画布,66X66的icon大小
Parameters:
name | type | flag | description | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
opts
| Object |
|
setRRButton
setRRButton
(
-
opts
)
设置按钮(base64)
标题栏从左到右4个位置设置的方法分别为setLLButton,setLRButton,setRLButton,setRRButton。 使用方法一致。
注意base64代码的data:image/png;base64,部分不需要 base64的图片大小控制为 尺寸44X44(icon本身22X22)的三倍图,即132X132的画布,66X66的icon大小
Parameters:
name | type | flag | description | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
opts
| Object |
|
setTitle
setTitle
(
-
opts
)
设置标题
Parameters:
name | type | flag | description | ||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
opts
| Object |
|
showPhoto
showPhoto
(
-
opt
)
调用native的图片查看功能展示图片
Parameters:
name | type | flag | description | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
opt
| Object |
|
stopPullDown
stopPullDown
(
-
opt
)
停止下拉刷新,需要配合setPullDown一起使用
Parameters:
name | type | flag | description | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
opt
| Object |
|
Example:
import dpappApollo from 'dpapp-apollo';
dpappApollo.setPullDown({
handle: function(){
dpappApollo.ajax({
url:'',
success: function(){
dpappApollo.stopPullDown({
});
}
});
}
});
subscribe
subscribe
(
-
opts.action
-
opts.data
-
opts.success
)
广播功能
Parameters:
name | type | flag | description |
---|---|---|---|
opts.action
| String | 取消订阅的消息名称 | |
opts.data
| Object | 需要传递的数据 | |
opts.success
| Function |
Example:
import dpappApollo from 'dpapp-apollo';
dpappApollo.subscribe({
action: 'myMessageName',
data: {
'info': 'detail'
},
success: function(){
alert("发送成功");
},
handle: function(e){
alert("广播触发");
}
});