dcloud开发心得,一些小技巧总结

2017-1-19 mubrand mui

openWindow方法

mui.openWindow({"url":"reg_wx.html","extras":{
"openId":openid

}

这样传值到reg_wx.html

在reg_wx.html里

function plusReady(){
var currentView = plus.webview.currentWebview();
document.getElementById("wx_appid").value = currentView.openId;
}
document.addEventListener('plusready',plusReady,false);

这么获取值

=============关于跨域==============================
通过mui的ajax请求是可以实现跨域的。
跨域是浏览器安全里的一个名词。记住了 是浏览器。
而我们的是app,请求并不是走浏览器脚本,而是用的H5+底层请求的。所以不存在什么跨域。直接调用。

===========获取应用入口页面的方法======================

var h=plus.webview.getWebviewById( plus.runtime.appid );
console.log( "应用首页Webview窗口:"+h.getURL() );

==========判断plus对象是否生效=======================

if(window.plus){
plusReady();
}else{
document.addEventListener("plusready",plusReady,false);
}

============获取上一页(获取父页面)的方法==============================

var preUrl = plus.webview.currentWebview().opener().getURL();
console.log(preUrl);

===========双击回退按钮后关闭app的方法==========================


//首页返回键处理
//处理逻辑:1秒内,连续两次按返回键,则退出应用;
var first = null;
mui.back = function() {
//首次按键,提示‘再按一次退出应用’
if (!first) {
first = new Date().getTime();
mui.toast('再按一次退出应用');
setTimeout(function() {
first = null;
}, 1000);
} else {
if (new Date().getTime() - first < 1000) {
plus.runtime.quit();
}
}

};



============手机网络状态========================================


document.addEventListener( "netchange", function() {
var network = plus.networkinfo.getCurrentType();
if(network < 2) {
if(this.network > 1) {
plus.nativeUI.toast('您的网络已断开', undefined, '期待乐');
}
}

if(this.network == 3 &amp;&amp; network &gt; 3) {
plus.nativeUI.toast('您网络已从wifi切换到蜂窝网络,浏览会产生流量', undefined, '期待乐', '我知道了');
}

this.network = network; 
});


==========手机回退键的触发======================================


function plusReady(){
ws=plus.webview.currentWebview();
// Android处理返回键
plus.key.addEventListener('backbutton',function(){
back();
},false);
compatibleAdjust();
}


=============有选择项的提示框==========


//退出登录
doLogout:function(){
var btnArray = ['再逛逛','是的'];
mui.confirm('你确定退出登录吗?', '提示', btnArray, function(e) {
if (e.index == 1) {
$.get(const_server_url+"/1/login/logout.json",function(data){
if(data.code == "200"){
m_login.clear();
mui.openWindow({
id:"registerPhone"
});
}else{
mui.alert(data.message);
}
});
}
}); 
}


===========微信支付中提示"支付权限检查失败"=========
微信支付有两个,一个是微信公众号的微信支付,
还有一个就是上面这个地址里面的微信支付,这两个微信支付不一样。
所以存在两个APPID、mch_id。
你用对了么

标签: hbuilder mui

联系我(QQ/PHONE/WX):18603469707 晋ICP备20004855号-1

晋公网安备 14010602060801号