//切换发布版本 true:正式版,连接生产环境;false:测试版,连接测试环境。 var publish_version = true; //var publish_version = false; //是否是在公司总部的演示环境 var isdemo = false; //var isdemo = false; //接口服务器 var server, appId, curr_app_version = 1, //app当前内定版本号 checkReload = true, //图片识别请求路径 ocrReqUrl = "", //健康档案接口服务器 healthProfileServer = "", //图片文件的服务器路径 imgUrlDomain = ""; //设置全局变量 var CITY_CODE = "450800", //"450800" CITY_NAME = "贵港市"; //贵港市 if(publish_version == true) { appId = "wxad04e9c4c5255acf"; //接口服务器 server = server = "http://ggijk.yihu.com/wlyy/"; // 图片识别请求路径 ocrReqUrl = "http://ggijk.yihu.com/ocr/"; // 健康档案接口服务器 healthProfileServer = server; imgUrlDomain = "http://ggijk.yihu.com/"; } else if(isdemo == true) { appId = "wxeb86020158cf9141"; //接口服务器 server = "http://ehr.yihu.com/ssgg/"; // OCR测试地址 ocrReqUrl = "http://www.xmtyw.cn/ocr/"; // 健康档案接口服务器 healthProfileServer = server; //图片文件的服务器路径 imgUrlDomain = "http://www.xmtyw.cn/"; } else { appId = "wxd03f859efdf0873d"; // OCR测试地址 ocrReqUr = "http://192.168.131.132:3000/ocr"; //接口服务器 // server = "http://172.19.103.88:9092/wlyy/"; server = "http://192.168.131.24:8082/"; // 健康档案接口服务器 healthProfileServer = server; //图片文件的服务器路径 imgUrlDomain = "http://172.19.103.54/"; } function showErrorPage (msg) { plus.nativeUI.closeWaiting(); var errorWebview = plus.webview.getWebviewById('error'); if(errorWebview) { mui.fire(errorWebview, "refresh", {errorMsg: msg}); } else { mui.openWindow({ id: "error", url: "../../error/html/error.html", waiting:{ autoShow:false }, extras: { errorMsg: msg } }); } } function checkNetOrbackendError() { var noNetwork = plus.networkinfo.getCurrentType() == plus.networkinfo.CONNECTION_NONE; setTimeout(function() { showErrorPage(noNetwork?"网络有点问题哦,检查网络无误后,":"程序开了点小差, 请稍后重试!") },0); return noNetwork; } var isLoginOut; //newWay 新的处理错误请求的标识 function sendGet(url, params, custError, custSuccess,newWay,timeOut){ sendPost(url, params, custError, custSuccess, "GET", timeOut, newWay); } /** * 统一请求ajax发送方法 * url 请求地址:例如:patient/health_index/add * params 请求参数 * dataType 数据类型:json等 * reqType 请求方式:get 或 post * error 请求失败处理方法 * success 请求成功处理方法 * newWay 新的处理错误请求的标识 */ function sendPost(url, params, custError, custSuccess,dataType, timeOut, newWay) { if(dataType==undefined){ dataType="POST" } if(isLoginOut) { return } //发送ajax请求 console.log(server+url); // 增加绝对URL(含有http://及https://)的判断,以满足跨域请求(yzh) var reqUrl = server + url; if(url&&(url.indexOf("http://")>-1 || url.indexOf("https://")>-1)) { reqUrl = url; } mui.ajax(reqUrl, { data: params || {}, dataType: 'json', //crossDomain: true, type: dataType, timeout: timeOut || 60000, error: function(xht, type, throwErr) { if(type=="timeout"){ if(custError){ custError(type); return ; } } if(custError && $.isFunction(custError)) { var flag = custError(xht, type, throwErr); if(!flag) { return ; } } plus.nativeUI.closeWaiting(); var curWebview = plus.webview.currentWebview(); if(curWebview.id=="error") { return ; } if(newWay == undefined){ //旧的处理逻辑 if(type == "timeout" || type == "abort") { checkNetOrbackendError(); } else if(type == "error" || type == "parsererror" || type == "null") { setTimeout(function() { showErrorPage("程序开了点小差, 请稍后重试!") },0); } }else if(newWay){ mui.toast("数据加载失败,请检查网络无误后下拉刷新。"); } }, success: function(res) { var random = Math.random(); isLoginOut = window.localStorage.isLoginOut; if(isLoginOut) { return; } var tip = ""; if(res.status == 999) { window.localStorage.isLoginOut = random; if(window.localStorage.isLoginOut != random) { return; } tip = "此账号已在别处登录,请重新登录"; showConfirm(tip, 1); return; } else if(res.status == 998) { window.localStorage.isLoginOut = random; if(window.localStorage.isLoginOut != random) { return; } tip = "登录超时,请重新登录"; showConfirm(tip); return; } else if(res.status == 997) { window.localStorage.isLoginOut = random; if(window.localStorage.isLoginOut != random) { return; } tip = "此账号未登录,请先登录"; showConfirm(tip); return; } //添加无操作权限的返回结果 else if(res.status == 403){ mui.toast("观察者模式无法进行增删改操作"); plus.nativeUI.closeWaiting(); return; } custSuccess(res); } }); } /* * 选择退出登录 */ function exit2Login(beOut) { //beOut 参数,记录是否是因为账号在别处登录被挤掉 mui.openWindow('../../login/html/login.html', 'login', { extras: { exit: "exit", beOut: beOut }, createNew: true }); mui.later(function() { plus.webview.currentWebview().close("none"); }, 1000) } /* * 弹出框 */ function showConfirm(content, beOut) { mui.confirm(content, "提示", ["确定"], function() { exit2Login(beOut); plus.storage.removeItem("isLoginOut"); }); } function sendPostNoAsync(url, params, error, success) { //发送ajax请求 mui.ajax(server + url, { data: params || {}, async: false, dataType: 'json', //crossDomain: true, type: "POST", timeout: 20000, error: error || function(xht, type, throwErr) {}, success: success }); } /* * 获取时间 */ function getCurrDate(flag) { var weekStr = ["周日", "周一", "周二", "周三", "周四", "周五", "周六"]; var d = new Date(); var year = d.getFullYear(); var month = d.getMonth() + 1; var day = d.getDate(); var week = d.getDay(); var h = d.getHours(); var mins = d.getMinutes(); var s = d.getSeconds(); if(month < 10) month = "0" + month; if(day < 10) day = "0" + day; if(h < 10) h = "0" + h; if(mins < 10) mins = "0" + mins; if(s < 10) s = "0" + s; if(flag == "date") { return year + "-" + month + "-" + day; } else if(flag == "time") { return h + ":" + mins + ":" + s; } else if(flag == "week") { return year + "-" + month + "-" + day + " " + weekStr[week]; } return year + "-" + month + "-" + day + " " + h + ":" + mins + ":" + s; } function getSysDate(plus) { var d = new Date(); var year = d.getFullYear(); var month = d.getMonth() + 1; var day = d.getDate(); // var week = d.getDay(); var h = d.getHours(); var mins = d.getMinutes(); var s = d.getSeconds(); if(month < 10) month = "0" + month; if(day < 10) month = "0" + day; if(h < 10) h = "0" + h; if(mins < 10) mins = "0" + mins; if(s < 10) s = "0" + s; if(!plus) { return year + "-" + month + "-" + day + "" + h + ":" + mins + ":" + s; } else { return(year + 1) + "-" + month + "-" + day + "" + h + ":" + mins + ":" + s; } } function getSysDatePlus(plus) { var now = new Date(); var d = new Date(now.getTime() + plus * 24 * 3600 * 1000); var year = d.getFullYear(); var month = d.getMonth() + 1; var day = d.getDate(); // alert(year+" "+month+" "+day); // var h = d.getHours(); // var mins = d.getMinutes(); // var s = d.getSeconds(); if(month < 10) month = "0" + month; if(day < 10) day = "0" + day; // if (h < 10) h = "0" + h; // if (mins < 10) mins = "0" + mins; // if (s < 10) s = "0" + s; return year + "-" + month + "-" + day } /** * 用于把用utf16编码的字符转换成实体字符,以供后台存储 * @param {string} str 将要转换的字符串,其中含有utf16字符将被自动检出 * @return {string} 转换后的字符串,utf16字符将被转换成&#xxxx;形式的实体字符 */ function utf16toEntities(str) { var patt = /[\ud800-\udbff][\udc00-\udfff]/g; // 检测utf16字符正则 str = str.replace(patt, function(char) { var H, L, code; if(char.length === 2) { H = char.charCodeAt(0); // 取出高位 L = char.charCodeAt(1); // 取出低位 code = (H - 0xD800) * 0x400 + 0x10000 + L - 0xDC00; // 转换算法 return "&#" + code + ";"; } else { return char; } }); return str; } // 获取异步请求处理Promise对象 function getReqPromise(url, data,reqType,newWay) { return new Promise(function(resolve, reject) { sendPost(url, data, function queryFailed (xht, type, throwErr) { // dialog({contentType:'tipsbox', skin:'bk-popup' , content:'加载失败'}).show(); // mui.toast("程序开了点小差, 请稍后重试!"); if(type == "error" || type == "parsererror" || type == "null") { //mui.toast("程序开了点小差, 请稍后重试!"); //throw new Error("加载失败"); showErrorPage("程序开了点小差, 请稍后重试!"); } return true; } , function success(res) { resolve(res); },reqType, '', (newWay===false?false:true)); }); } /* * reqs: 请求的参数数组,格式:[{url:'a/xxx', reqType: 'POST', data:{...}},{url:'b/xxx',data:{...}}] * */ function getReqPromises(reqs, newWay) { if(!reqs || !reqs.length) { return new Promise(function(resolve, reject) { resolve([]); }); } reqs = _.filter(reqs,function(req) { return req!=null }); return Promise.all(_.map(reqs,function(param){ return getReqPromise(param.url,param.data, param.reqType, (newWay===false?false:true)); })); }; //获取链接上的参数 function GetRequest() { var url = location.search; //获取url中"?"符后的字串 var theRequest = new Object(); if (url.indexOf("?") != -1) { var str = url.substr(1); strs = str.split("&"); for(var i = 0; i < strs.length; i ++) { theRequest[strs[i].split("=")[0]]=(strs[i].split("=")[1]); } } return theRequest; } mui.plusReady(function() { setStatusbarRed(); }) function setStatusbarRed(){ // 设置系统状态栏背景色 plus.navigator.setStatusBarBackground("#17b3ec"); } /* * 获取图片路径 */ function getImgUrl(str){ if(typeof str != 'string'){ return ""; } if(str.length == 0){ return ""; }else{ if(str.indexOf("../")>-1){ //访问本地路径 return str; }else if((str.indexOf("http://")>-1) || (str.indexOf("https://")>-1)){ return str; }else{ //服务器上的图片路径 return imgUrlDomain + str; } } }