136 lines
5.1 KiB
JavaScript
136 lines
5.1 KiB
JavaScript
/**
|
|
* 推送处理业务逻辑
|
|
* yinjihuan
|
|
*/
|
|
document.addEventListener("plusready", function() {
|
|
// 监听点击消息事件
|
|
plus.push.addEventListener("click", function(msg) {
|
|
//刷新个人中心
|
|
if (plus.webview.getWebviewById('views/user/userInfo.html') != null) {
|
|
plus.webview.getWebviewById('views/user/userInfo.html').reload();
|
|
}
|
|
// 判断是从本地创建还是离线推送的消息
|
|
var payload = msg.payload;
|
|
var title = msg.title;
|
|
var content = msg.content;
|
|
switch(payload) {
|
|
case "LocalMSG":
|
|
alert("点击本地创建消息启动:");
|
|
break;
|
|
default:
|
|
if (plus.os.name == "Android"){
|
|
try {
|
|
payload = JSON.parse(payload);
|
|
} catch(err) {
|
|
|
|
}
|
|
if (payload.type == "0") {
|
|
plus.ui.alert(title+"\n"+content);
|
|
} else if (payload.type == "1") {
|
|
plus.ui.alert(title+"\n"+content,function(){
|
|
if (payload.url == '/house/index') {
|
|
plus.webview.show('yfindex.html');
|
|
} else {
|
|
plus.webview.show(BASE_PATH + payload.url);
|
|
}
|
|
//切换选项卡高亮
|
|
var defaultTab = document.getElementById("defaultTab");
|
|
var quotations = document.getElementById("quotations");
|
|
var selfInfo = document.getElementById("selfInfo");
|
|
defaultTab.classList.remove("mui-active");
|
|
quotations.classList.remove("mui-active");
|
|
selfInfo.classList.remove("mui-active");
|
|
if (payload.url == '/quotations/index') {
|
|
quotations.classList.add("mui-active");
|
|
} else if(payload.url == '/selfInfo/index') {
|
|
selfInfo.classList.add("mui-active");
|
|
} else {
|
|
defaultTab.classList.add("mui-active");
|
|
}
|
|
});
|
|
} else if (payload.type == "2") {
|
|
plus.ui.alert(title+"\n"+content,function(){
|
|
openUrl(BASE_PATH+'/message/openView?url='+payload.url);
|
|
});
|
|
}
|
|
} else {
|
|
if (payload.type == "0") {
|
|
plus.ui.alert(content);
|
|
} else if (payload.type == "1") {
|
|
plus.ui.alert(content,function(){
|
|
if (payload.url == '/house/index') {
|
|
plus.webview.show('yfindex.html');
|
|
} else {
|
|
plus.webview.show(BASE_PATH + payload.url);
|
|
}
|
|
//切换选项卡高亮
|
|
var defaultTab = document.getElementById("defaultTab");
|
|
var quotations = document.getElementById("quotations");
|
|
var selfInfo = document.getElementById("selfInfo");
|
|
defaultTab.classList.remove("mui-active");
|
|
quotations.classList.remove("mui-active");
|
|
selfInfo.classList.remove("mui-active");
|
|
if (payload.url == '/quotations/index') {
|
|
quotations.classList.add("mui-active");
|
|
} else if(payload.url == '/selfInfo/index') {
|
|
selfInfo.classList.add("mui-active");
|
|
} else {
|
|
defaultTab.classList.add("mui-active");
|
|
}
|
|
});
|
|
} else if (payload.type == "2") {
|
|
plus.ui.alert(content,function(){
|
|
openUrl(BASE_PATH+'/message/openView?url='+payload.url);
|
|
});
|
|
}
|
|
}
|
|
|
|
break;
|
|
}
|
|
}, false);
|
|
|
|
// 监听在线消息事件, iOS透传消息在线时会进入这里进行处理
|
|
plus.push.addEventListener("receive", function(msg) {
|
|
//刷新个人中心
|
|
if (plus.webview.getWebviewById('views/user/userInfo.html') != null) {
|
|
plus.webview.getWebviewById('views/user/userInfo.html').reload();
|
|
}
|
|
var title = msg.title;
|
|
var content = msg.content;
|
|
var payload = msg.payload;
|
|
if (payload.type == "0") {
|
|
plus.ui.alert(title+"\n"+content);
|
|
} else if (payload.type == "1") {
|
|
plus.ui.alert(title+"\n"+content,function(){
|
|
if (payload.url == '/house/index') {
|
|
plus.webview.show('yfindex.html');
|
|
} else {
|
|
plus.webview.show(BASE_PATH + payload.url);
|
|
}
|
|
|
|
//切换选项卡高亮
|
|
var defaultTab = document.getElementById("defaultTab");
|
|
var quotations = document.getElementById("quotations");
|
|
var selfInfo = document.getElementById("selfInfo");
|
|
defaultTab.classList.remove("mui-active");
|
|
quotations.classList.remove("mui-active");
|
|
selfInfo.classList.remove("mui-active");
|
|
if (payload.url == '/quotations/index') {
|
|
quotations.classList.add("mui-active");
|
|
} else if(payload.url == '/selfInfo/index') {
|
|
selfInfo.classList.add("mui-active");
|
|
} else {
|
|
defaultTab.classList.add("mui-active");
|
|
}
|
|
});
|
|
} else if (payload.type == "2") {
|
|
plus.ui.alert(title+"\n"+content,function(){
|
|
openUrl(BASE_PATH+'/message/openView?url='+payload.url);
|
|
});
|
|
}
|
|
}, false);
|
|
}, false);
|
|
|
|
function openUrl(url){
|
|
clicked(url,true);
|
|
} |