解决了写一个我自己的
没有想象的那么困难是我自己想复杂了
function onNetChange() {
var nt = plus.networkinfo.getCurrentType();
if (nt == "2" || nt == "3" || nt == "5" || nt == "6") {
mui.toast("在线模式");
plus.device.vibrate();
s = plus.audio.createPlayer("../audio/NetYes.mp3");
var num = s.getDuration(); //获取音频总长度number
setTimeout(function() { //延时获取,否则可能没有返回长度
var num = s.getDuration();
// alert(num)
}, 100)
s.play(function() { //播放完成回调
// alert("Audio play success!");
}, function(e) { //失败回调
// alert("Audio play error: " + e.message);
});
var tx = db.transaction("users", READ_WRITE);
var store = tx.objectStore("users");
var index = store.index("Ifnet");
var req = index.openCursor(IDBKeyRange.only("1"));
var odiv = document.getElementById("tijiao");
if (odiv.style.display = "none") {
odiv.style.display = "block";
}
req.onsuccess = function(evt) {
var res = evt.target.result;
if (res) {
var net = [res.value]
var j = 0;
function submit(){
if(j>=net.length){
return;
}
mui.ajax('http://', {
data: {
tugwork_s_id: net[j].TUGWORK_S_ID,
IsMooring: net[j].If_mooring,
IsPickup: net[j].ISPICKUP,
godate: net[j].Godate,
startdate: net[j].Startdate,
enddate: net[j].Enddate,
backdate: net[j].Backdate
},
dataType: 'json', //服务器返回json格式数据
type: 'post', //HTTP请求类型
timeout: 5000, //超时时间设置为10秒;
success: function(req) {
console.log(JSON.stringify(req));
j++;
submit();
},
error: function(xhr, type, errorThrown) {
console.log('Update_local');
}
});
}
submit();
res.continue();
}
};
req.onerror = function(evt) {
console.error("UpData error:", evt.target.errorCode || evt.target.error);
};
setTimeout(function(){odiv.style.display = "none";}, 3000);
} else {
mui.toast("离线模式");
plus.device.vibrate();
s = plus.audio.createPlayer("../audio/NetNo.mp3");
var num = s.getDuration(); //获取音频总长度number
setTimeout(function() { //延时获取,否则可能没有返回长度
var num = s.getDuration();
// alert(num)
}, 100)
s.play(function() { //播放完成回调
// alert("Audio play success!");
}, function(e) { //失败回调
// alert("Audio play error: " + e.message);
});
}
}