您的位置:首页 > 移动开发

Appcan后台数据库表交互,注册

2016-07-28 08:19 579 查看
//var ip = "192.168.1.102";

//分页初始数据
var pageNo = 1;
var pageSize = 8;

var serverURL = "http://192.168.1.66:8080/HelloWorld/"
function log(info) {
console.log(info);
if (uexLog) {
uexLog.sendLog(info);
}
}

function alertX(content) {
appcan.window.alert("提示", content);
}

function extend(target, source) {
for (var p in source) {
if (source.hasOwnProperty(p)) {
target[p] = source[p];
}
}

return target;
};

function openWin(opt) {
var defaultOpt = {
name : opt.name,
dataType : 0,
type : 0,
aniId : 2,
data : opt.name + ".html",
extraInfo : {

}
};
opt = extend(defaultOpt, opt);
log(opt);
appcan.window.open(opt);
}

function closeWin() {
appcan.window.close(-1);
}

function openLoading(info) {
var msg = '正在加载...';
if (info) {
msg = info;
}
appcan.window.openToast({
msg : msg,
duration : -1,
position : 5,
type : 1
});
}

function closeToast() {
appcan.window.closeToast();
}

function ajax(opt, loading) {
var isload = true;
if (loading == 1) {
isload = false;
}
var defaultOpt = {
url : "",
type : "GET",
data : {},
dataType : 'json',
timeout : 15000, //超时时间
loading : isload,
cache : false,
error : function(xhr, type) {
closeToast();
alert('Ajax error!');
}
};
opt.url = serverURL + opt.url;
opt = extend(defaultOpt, opt);

log("start request:" + opt.url + "--||--" + opt.type);
log("request data:" + JSON.stringify(opt.data));
if (opt.loading) {
opt.beforeSend = function(xhr, settings) {
openLoading();
};
}

if (opt.successx) {
opt.success = function(data, status) {
closeToast();
if (status != "success") {
alert('Server error!');
return;
}
log(JSON.stringify(data));
opt.successx(data);
}
}
appcan.request.ajax(opt);
}

function getFormField(selector) {
var arr = $(selector).serializeArray();
var param = {};
for (var i = 0; i < arr.length; i++) {
var p = arr[i];
param[p.name] = p.value;
}
return param;
}

function setWinParam(param) {
localStorage.winParam = null;
localStorage.winParam = JSON.stringify(param);
}

function getWinParam() {
var p = null;
if (localStorage.winParam) {
p = JSON.parse(localStorage.winParam);
localStorage.winParam = null;
}
return p;
}

function setUserId(userId) {
localStorage.currentUserId = userId;
}

function getUserId() {
return localStorage.currentUserId;
}

function setZW(zw) {
localStorage.currentZW = zw;
}

function getZW() {
return localStorage.currentZW;
}

function setReportLvType(type) {
localStorage.currentReportLvType = type;
}

function getReportLvType() {
return localStorage.currentReportLvType;
}

function initBounce(funcTop, funcBottom) {
uexWindow.setBounce("1");
if (!funcTop && !funcBottom) {
uexWindow.showBounceView("0", "rgba(255,255,255,0)", "0");
uexWindow.showBounceView("1", "rgba(255,255,255,0)", "0");
return;
}
var top = 0,
btm = 1;
uexWindow.onBounceStateChange = function(type, state) {

if (type == top && state == 2) {//顶部弹动
funcTop();
uexWindow.resetBounceView("0");
}
if (type == btm && state == 2) {//底部弹动
funcBottom();
uexWindow.resetBounceView("1");
}

}
if (funcTop) {
uexWindow.setBounceParams('0', "{'pullToReloadText':'下拉刷新','releaseToReloadText':'释放刷新','loadingText':'正在刷新,请稍候'}");
uexWindow.showBounceView(top, "rgba(255,255,255,0)", 1);
uexWindow.notifyBounceEvent(top, 1);
}
if (funcBottom) {
uexWindow.setBounceParams('1', "{'pullToReloadText':'加载更多','releaseToReloadText':'加载更多','loadingText':'加载中,请稍候'}");
uexWindow.showBounceView(btm, "rgba(255,255,255,0)", 1);
//设置弹动位置及效果([1:显示内容;0:不显示])
uexWindow.notifyBounceEvent(btm, 1);
//注册接收弹动事件([0:不接收onBounceStateChange方法回调;1:接收])
}
}

/**
* 获取当前日期
* 格式为:yyyy-MM-dd
*/
function getNowDate() {
var now = new Date();
y = now.getFullYear();
m = now.getMonth() + 1;
d = now.getDate();
m = m < 10 ? "0" + m : m;
d = d < 10 ? "0" + d : d;
return y + "-" + m + "-" + d;
}

/**
* 获取明天日期
* 格式为:yyyy-MM-dd
*/
function getTomorrowDate() {
var nd = new Date(getNowDate());
nd = nd.valueOf();
// nd = nd + 1 * 24 * 60 * 60 * 1000;
nd = new Date(nd);
var y = nd.getFullYear();
var m = nd.getMonth() + 1;
var d = nd.getDate();
if (m <= 9) {
m = "0" + m;
}

if (d <= 9) {
d = "0" + d;
}

return y + "-" + m + "-" + d;
}

/**
* 获取当前日期
* 格式为:HH
*/
function getNowDateHH() {
var now = new Date();
var i = now.getHours();
if (i < 10) {
i = "0" + i;
}
return i;

}

//监听安卓的返回功能

var closeflag = 0;
/**
* 拦截物理返回键
* 双击退出程序
*/
function doubleExit() {
var plat = uexWidgetOne.getPlatform();
if (plat) {
uexWindow.onKeyPressed = function(keyCode) {
if (keyCode == 0) {
if (closeflag == 1) {
uexWidgetOne.exit(0);
}
uexWindow.toast(0, 5, "再次点击退出程序", 2000);
closeflag = 1;
setTimeout(function() {
closeflag = 0;
}, 2000);
}
}
uexWindow.setReportKey(0, 1);
}
}

/**
* 为页面添加覆盖层
* 防止误操作或重复操作
* @param headId:页面head的id
* @param pageId:页面的id
*/

function open_cover(headId, pageId, popName, popHtml) {
headId = '#' + headId;
pageId = '#' + pageId;
var titHeight = $(headId).offset().height;
var page = window.getComputedStyle($(pageId)[0], null);
var pagew = parseInt(page.width);
var pageh = parseInt(page.height);
uexWindow.openPopover(popName, "0", popHtml, "", "0", titHeight, pagew, pageh, "2", "0");
}

/**
* 关闭pop窗口
* @param  popName
*/
function close_cover(popName) {
appcan.closePopover((popName) ? popName : 'coverpop');
}

/**
*获取上月日期
*/
function getLastMonth() {
var now = new Date();
y = now.getFullYear();
m = now.getMonth();
if (m == 0) {
m = 12;
y = y - 1;
}
m = m < 10 ? "0" + m : m;
return y + "年" + m;
}

/**
*解决后台mySql数据库中传来的datetime数据最后以.0结尾的问题
*/
function format(datetime) {
return datetime.substring(0, datetime.lastIndexOf('.'))
}

function checkVersion(state) {
var versionId = getLocVal('versionId');
if (!versionId) {
versionId = 0;
}
ajax({
url : "appcanAjax/appversion_checkVersion",
data : {
id : versionId,
},
dataType : "json",
successx : function(data) {
var versionId = data.id;
var versionNo = data.versionNo;
if (data.state == 1) {
uexWindow.cbConfirm = function(opId, dataType, data) {
if (data == 1)
updateVersion(versionId, versionNo);
}
uexWindow.confirm('提示', '发现有新的版本,是否立即更新?', ['下次再说', '立即更新']);
} else {
if (state == 1) {
//程序里手动检测版本
$toast('当前为最新版本!', 2000);
}else{
setLocVal('versionNo', versionNo);
setLocVal('versionId', versionId);
}

}
},
error : function(xhr, type) {
//$toast("网络连接超时", 3500);
}
}, 1);
}

function updateVersion(versionId, versionNo) {

//下载地址
var url = 'http://60.210.98.67:81/baoxiu.apk';
//存储路径
var path = 'wgt://data/down/baoxiu.apk';
uexFileMgr.deleteFileByPath(path);
uexDownloaderMgr.createDownloader(1);
uexDownloaderMgr.cbCreateDownloader = function(opCode, dataType, data) {
switch(dataType) {
case 0:
alert("uex.cText");
break;
case 1:
alert("uex.cJson");
break;
case 2:
if (data == 0) {
uexDownloaderMgr.download(1, url, path, '1');
}
break;
default:
alert("error");
}
}

uexDownloaderMgr.onStatus = function(opCode, fileSize, percent, status) {
switch (status) {
case 0:
$toast("下载进度:" + percent + "%");
break;
case 1:
$toast("下载完成", 2000);
uexDownloaderMgr.closeDownloader(1);
setTimeout(function() {
uexWidget.installApp(path);
setLocVal('versionNo', versionNo);
setLocVal('versionId', versionId);
}, 2000)
break;
case 2:
$toast("下载失败", 2000);
uexDownloaderMgr.closeDownloader(1);
break;
case 3:
$toast("已取消下载", 2000);
break;
}
}
}

// function findUsreLocation() {
// uexLocation.openLocation();
//
// // uexLocation.cbOpenLocation = function(opId, dataType, data) {
// // alert(opId + "," + dataType + "," + data);
// // }
//
// uexLocation.onChange =  function(lat,log) {
//
// //   alert(log+","+lat);
// }
// }


js
//注意

要先关闭写入的拦截器
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: