1. 程式人生 > >mui之上拉重新整理和mui-content結合解決ios上拉不回彈的bug

mui之上拉重新整理和mui-content結合解決ios上拉不回彈的bug

var globalphone; mui.init({ swipeBack: true, //啟用右滑關閉功能 pullRefresh: { container: '#pullrefresh', up: { auto: true, //自動上拉重新整理一次 contentrefresh: '正在載入...', callback: pullupRefresh } } }); mui.plusReady(function
() {
console.log("plus api 載入完畢!"); }); var page = 1; var hasMore_no = false; var hasMore_yes = false; function pullupRefresh() { var wd = plus.nativeUI.showWaiting(); console.log("上拉重新整理開始...當前頁"
+ page); if(hasMore_no && hasMore_yes) { mui('#pullrefresh').pullRefresh().endPullupToRefresh(true); //引數為true代表沒有更多資料了。 } else { mui('#pullrefresh').pullRefresh().endPullupToRefresh(false); //引數為true代表沒有更多資料了。 } var
data = plus.webview.currentWebview(); var type = data.type; var title = data.title; h("#title").html(title); if(type <= 2) { //已處理.未處理 h(".no").html("未處理"); h(".yes").html("已處理"); h(".deal").html("處理"); } if(type > 2) { //已喚醒,未喚醒 h(".no").html("未喚醒"); h(".yes").html("已喚醒"); h(".deal").html("喚醒"); } initdata(page++, 25, data.type); wd.close(); } mui.ready(function() { console.log("DOM構建 完畢!"); h(".vipdata-yes").hide(); //隱藏未處理模版 h(".vipdata-no").hide(); //隱藏已處理模版 Date.prototype.Format = function(fmt) { var o = { "M+": this.getMonth() + 1, //月份 "d+": this.getDate(), //日 "h+": this.getHours(), //小時 "m+": this.getMinutes(), //分 "s+": this.getSeconds(), //秒 "q+": Math.floor((this.getMonth() + 3) / 3), //季度 "S": this.getMilliseconds() //毫秒 }; if(/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length)); for(var k in o) if(new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length))); return fmt; } }); //------------------------------------android監聽通話狀態---------------------------------------------------- /** * 自定義一個全域性函式,賦值函式給全域性變數 Native */ var Native = (function($) { var native = {}; var receiver, main, context, TelephonyManager; //新增監聽事件的函式,此函式可接收一個回撥函式 native.listenTelPhone = function(callback) { $.plusReady(function() { context = plus.android.importClass('android.content.Context'); //上下文 TelephonyManager = plus.android.importClass('android.telephony.TelephonyManager'); //通話管理 main = plus.android.runtimeMainActivity(); //獲取activity receiver = plus.android.implements('io.dcloud.feature.internal.reflect.BroadcastReceiver', { onReceive: doReceive //實現onReceiver回撥函式 }); var IntentFilter = plus.android.importClass('android.content.IntentFilter'); var Intent = plus.android.importClass('android.content.Intent'); var filter = new IntentFilter(); filter.addAction(TelephonyManager.ACTION_PHONE_STATE_CHANGED); //監聽電話狀態 main.registerReceiver(receiver, filter); //註冊監聽 }); function doReceive(context, intent) { plus.android.importClass(intent); var phoneNumber = intent.getStringExtra(TelephonyManager.EXTRA_INCOMING_NUMBER), telephony = context.getSystemService(context.TELEPHONY_SERVICE), state = telephony.getCallState(); switch(state) { case TelephonyManager.CALL_STATE_RINGING: callback && callback(1, phoneNumber); window.console.log("[Broadcast]等待接電話=" + phoneNumber); break; case TelephonyManager.CALL_STATE_IDLE: callback && callback(0, phoneNumber); window.console.log("[Broadcast]電話結束通話=" + phoneNumber); break; case TelephonyManager.CALL_STATE_OFFHOOK: callback && callback(2, phoneNumber); window.console.log("[Broadcast]通話中=" + phoneNumber); break; } } }, //取消監聽事件的函式 native.removeListenTelPhone = function() { if(receiver) { main = plus.android.runtimeMainActivity(); //獲取activity main.unregisterReceiver(receiver); //刪除監聽 console.log("取消android通話監聽事件"); receiver = null; } } return native; }(mui)); //androidRecord(); function postData(url, data, callback, waitingDialog) { mui.ajax(url, { data: data, dataType: 'json', crossDomain: true, type: 'post', timeout: 60000, success: callback, error: function(xhr, type, errorThrown) { waitingDialog.close(); mui.alert("<網路連線失敗,請重新嘗試一下>", "錯誤", "OK", null); } }); }; //page當前頁,size頁大小,type型別(參考介面) function initdata(page, size, type) { //未處理 console.log("未處理...........:"); getdata(page, size, type, 0, function(data) { //伺服器返回響應,根據響應結果,分析是否登入成功; if(data.status != "1") { console.log("網路請求頁面資料---失敗!"); mui.alert(data.info); return; } if(data.status == "1") { console.log("網路請求頁面資料---成功!"); console.log("未處理資料大小:" + data.listhrvip.length); if(data.listhrvip.length == 0) { console.log("沒有更多資料了!"); hasMore_no = true; // mui('#pullrefresh').pullRefresh().endPullupToRefresh(true); return; } //新增未處理會員列表 adddatano(data); } }); //已處理 console.log("已處理..........."); getdata(page, size, type, 1, function(data) { //伺服器返回響應,根據響應結果,分析是否登入成功; if(data.status != "1") { console.log("網路請求頁面資料---失敗!"); // mui.alert(data.info); return; } if(data.status == "1") { console.log("網路請求頁面資料---成功!"); console.log("已處理資料大小:" + data.listhrvip.length); if(data.listhrvip.length == 0) { console.log("沒有更多資料了!"); hasMore_yes = true; // mui('#pullrefresh').pullRefresh().endPullupToRefresh(true); return; } //新增已處理會員列表 adddatayes(data); } }); } function adddatayes(data) { var vipdatas = new Array(); vipdatas = data.listhrvip; for(var i = 0; i < vipdatas.length; i++) { var yesli = h(".vipdata-yes").clone(); yesli.show(); yesli.find(".vipid").html(vipdatas[i].vipid); //會員id yesli.find(".vipname").html(vipdatas[i].vipname); //會員名字 yesli.find(".integral").html("積分:" + vipdatas[i].integral); //會員積分 yesli.find(".cardtype").html("卡型別:" + vipdatas[i].typename); //會員卡號 yesli.appendTo(".deal-yes"); } } function adddatano(data) { var vipdatas = new Array(); vipdatas = data.listhrvip; for(var i = 0; i < vipdatas.length; i++) { var noli = h(".vipdata-no").clone(); noli.show(); noli.find(".vipid").html(vipdatas[i].vipid); //會員id noli.find(".vipname").html(vipdatas[i].vipname); //會員名稱 // console.log("會員名:---------------" + vipdatas[i].vipname); noli.find(".integral").html("積分:" + vipdatas[i].integral); //會員積分 noli.find(".cardtype").html("卡型別:" + vipdatas[i].typename); //會員卡號 noli.appendTo(".deal-no"); } } function getdata(page, size, type, status, callback) { console.log("網路請求 頁面資料---開始"); mui.post(plus.storage.getItem("url"), { act: "usertasklist", username: plus.storage.getItem('TOKEN_USER'), key: plus.storage.getItem('TOKEN_LOGIN'), page: page, size: size, searchkey: "", type: type, status: status }, callback, 'json'); } //點選頭像進入詳情頁面 mui("#pullrefresh").on('tap', 'img', function() { console.log(h(this).next().html()); var wd = plus.nativeUI.showWaiting(); var vipid = h(this).next().html(); var data = { "act": "getvipdetail ", "username": plus.storage.getItem('TOKEN_USER'), "key": plus.storage.getItem('TOKEN_LOGIN'), "vipid": vipid }; mui.post(plus.storage.getItem("url"), data, function(data) { wd.close(); if(data.status != "1") { mui.alert(data.info); return; } mui.openWindow({ url: '../customs.html', extras: data }); }, 'json'); }); //群發簡訊事件 function sendMessage() { // alert("發簡訊"); mui.openWindow({ url: 'message.html', }); } //打電話 mui("#item1").on('tap', '.mui-icon-phone', function() { androidRecord(); call(this); }); function call(t) { console.log(h(t).parent().parent().parent().find(".vipid").html()); //會員id var wd = plus.nativeUI.showWaiting(); var vipid = h(t).parent().parent().parent().find(".vipid").html(); var data = { "act": "getvipdetail", "username": plus.storage.getItem('TOKEN_USER'), "key": plus.storage.getItem('TOKEN_LOGIN'), "vipid": vipid }; mui.post(plus.storage.getItem("url"), data, function(data) { wd.close(); if(data.status != "1") { mui.alert(data.info); return; } console.log("電話號碼:" + data.mobil); var btnArray = ['撥打', '取消']; var phone = data.mobil; globalphone = phone; mui.confirm('是否撥打' + phone + '?', '提示', btnArray, function(e) { //撥打 if(e.index == 0) { if(mui.os.ios) { //新增ios通話記錄監聽事件 createCall(phone); } // android通話 plus.device.dial(phone, false); } else { //取消 if(mui.os.android) { Native.removeListenTelPhone(); //取消通話監聽事件 console.log("取消監聽事件..."); } } }); }, 'json'); } /** *記錄android通話 */ function androidRecord() { var sTime, endTime; mui.os.android && Native.listenTelPhone(function(code, number) { if(code === 2) { //接通 sTime = new Date(); } if(code === 0) { //結束通話 endTime = new Date(); var secn = parseInt((endTime.getTime() - sTime.getTime()) / 1000); // alert(secn) console.log("通話時間間隔secn:" + secn); if(secn > 3) { var wd = plus.nativeUI.showWaiting(); var vipdata = plus.webview.currentWebview(); var data = { "act": "addstorecall", "username": plus.storage.getItem('TOKEN_USER'), "key": plus.storage.getItem('TOKEN_LOGIN'), "addjson": JSON.stringify([{ "phone": globalphone, "phonetimes": secn, "phoneaddtime": sTime.Format("yyyy-MM-dd hh:mm:ss"), "phonetype": "撥出" }]) }; console.log(JSON.stringify(data)); console.log("電話號碼" + globalphone); postData(plus.storage.getItem("url"), data, function(data) { wd.close() if(data.status != "1") { console.log("網路請求失敗!" + data.info); mui.alert(data.info); return; } console.log("成功新增通話記錄!"); Native.removeListenTelPhone(); //取消通話監聽事件 }, wd ); } } }); }; //------------------ios通話監聽-------------------------------------------- /** * ios通話記錄監聽 * @param {Object} phone 電話號碼 */ function createCall(phone) { var starttime; var endtime; mui.plusReady(function() { document.addEventListener("pause", function() { starttime = new Date(); console.log(starttime.getTime() / 1000 + " 應用從前臺切換到後臺"); mui.toast(" 應用從前臺切換到後臺"); }, false); document.addEventListener("resume", function() { endtime = new Date(); console.log(endtime.getTime() / 1000 + " 應用從後臺切換到前臺"); mui.toast("應用從後臺切換到前臺"); addIOSPhoneData(starttime, endtime); }, false); }); } /** * 新增ios通話記錄 * @param {Object} starttime 開始監聽時間 * @param {Object} endtime 結束監聽時間 */ function addIOSPhoneData(starttime, endtime) { // document.removeEventListener("pause", true); // document.removeEventListener("resume", true); // console.log("取消事件..."); // 對Date的擴充套件,將 Date 轉化為指定格式的String // 月(M)、日(d)、小時(h)、分(m)、秒(s)、季度(q) 可以用 1-2 個佔位符, // 年(y)可以用 1-4 個佔位符,毫秒(S)只能用 1 個佔位符(是 1-3 位的數字) // 例子: // (new Date()).Format("yyyy-MM-dd hh:mm:ss.S") ==> 2006-07-02 08:09:04.423 // (new Date()).Format("yyyy-M-d h:m:s.S") ==> 2006-7-2 8:9:4.18 Date.prototype.Format = function(fmt) { //author: meizz var o = { "M+": this.getMonth() + 1, //月份 "d+": this.getDate(), //日 "h+": this.getHours(), //小時 "m+": this.getMinutes(), //分 "s+": this.getSeconds(), //秒 "q+": Math.floor((this.getMonth() + 3) / 3), //季度 "S": this.getMilliseconds() //毫秒 }; if(/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length)); for(var k in o) if(new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length))); return fmt; } var end = endtime.getTime() / 1000; var start = starttime.getTime() / 1000; var secn = end - start; console.log("時間差:" + Math.floor(secn)); var phoneaddtime = starttime.Format("yyyy-MM-dd hh:mm:ss"); var data = { "act": "addstorecall", "username": plus.storage.getItem('TOKEN_USER'), "key": plus.storage.getItem('TOKEN_LOGIN'), "addjson": JSON.stringify([{ "phone": globalphone, "phonetimes": Math.floor(secn), "phoneaddtime": phoneaddtime, "phonetype": "撥出" }]) }; mui.post(plus.storage.getItem("url"), data, function(data) { if(data.status != "1") { mui.alert(data.info); return; } mui.toast("成功新增本次通話記錄!"); }, 'json'); } //發簡訊事件 mui("#item1").on('tap', '.mui-icon-email', function() { send(this); }); /** * 發簡訊事件 * @param {Object} t */ function send(t) { console.log("vipid=" + h(t).parent().parent().parent().find(".vipid").html()); //會員id var wd = plus.nativeUI.showWaiting(); var vipid = h(t).parent().parent().parent().find(".vipid").html(); var data = { "act": "getvipdetail ", "username": plus.storage.getItem('TOKEN_USER'), "key": plus.storage.getItem('TOKEN_LOGIN'), "vipid": vipid }; mui.post(plus.storage.getItem("url"), data, function(data) { wd.close(); if(data.status != "1") { mui.alert(data.info); return; } console.log("電話號碼:" + data.mobil); var vipid = h(t).parent().parent().parent().find(".vipid").html(); var phoneNumber = data.mobil; // console.log("通過id獲取會員詳情:"+JSON.stringify(data)); var vipname = data.vipname; mui.openWindow({ url: 'one-message.html', extras: { "vipid": vipid, "phoneNumber": phoneNumber, "vipname": vipname } }); }, 'json'); } //已處理事件 mui("#item1").on('tap', '.deal', function() { deal(this); }); /** * 已處理事件 * @param {Object} t */ function deal(t) { console.log("要處理的vipid:" + h(t).parent().parent().find(".vipid").html()); console.log("要處理的vipname:" + h(t).parent().parent().find(".vipname").html()); var wd = plus.nativeUI.showWaiting(); var vipid = h(t).parent().parent().find(".vipid").html(); var name = h(t).parent().parent().find(".vipname").html(); var data = { "act": "updateuserstatus ", "username": plus.storage.getItem('TOKEN_USER'), "key": plus.storage.getItem('TOKEN_LOGIN'), "vipid": vipid, "name": name }; mui.post(plus.storage.getItem("url"), data, function(data) { wd.close(); if(data.status != "1") { mui.alert(data.info); return; } var noli = h(t).parent().parent().clone(); //必須先克隆一個出來才能追加 noli.find(".call").hide(); //隱藏電話圖示 noli.find(".deal").hide(); //隱藏已處理按鈕 noli.find('.msg').hide(); //隱藏簡訊圖示 noli.prependTo(".deal-yes"); //追加到已處理列表頭部 h(t).parent().parent().hide(); //如果點選 已處理 按鈕,則隱藏 mui.toast(data.info); //最後彈出 toast 提示 }, 'json'); }