//切换发布版本 true:正式版,连接生产环境;false:测试版,连接测试环境。 var publish_version = true; //var publish_version = false; var curr_app_version = 5; //app当前内定版本号 //接口服务器 var server; //档案信息服务器 var templateServer; var appId; var checkReload = true; // 图片识别请求路径 var ocrReqUrl = ""; // 健康档案接口服务器 var healthProfileServer = ""; //上饶县人民医院机构代码 var srOrgCode = "49229004X"; if(publish_version == true) { appId = "wxad04e9c4c5255acf"; //接口服务器 server = "http://srijk.yihu.com/wlyy/"; // 图片识别请求路径 ocrReqUrl = "http://www.xmtyw.cn/ocr/"; // 健康档案接口服务器 healthProfileServer = server; //图片文件的服务器路径 var imgUrlDomain = "http://srijk.yihu.com/"; templateServer = ""; // 健康档案(上饶)服务地址 profileServer = "http://srijk.yihu.com/wlyy" } else { appId = "wxd03f859efdf0873d"; // OCR小温测试地址 ocrReqUrl = "http://192.168.131.132:3000/ocr"; templateServer = "http://172.19.103.73:8080/app-ehr/html/mytemplate/html/visit-record-list.html"; //接口服务器 server = "http://172.19.103.72:9096/csijk/"; //server = "http://192.168.131.115:8081/";//张丹 // server = "http://192.168.131.24:8082/";//仕杰 // server = "http://192.168.131.250:8081/";//伟达 // server = "http://192.168.131.133:8080/";//文杰 server = "http://192.168.131.24:8082/";//文彬 // server = "http://192.168.131.127:8060/";//逸祥 // 健康档案接口服务器 healthProfileServer = server; //图片文件的服务器路径 var imgUrlDomain = "http://172.19.103.54/"; // 健康档案(上饶)服务地址 profileServer = "http://ehr.yihu.com/csijk" } 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(plus.networkinfo.getCurrentType() == plus.networkinfo.CONNECTION_NONE) { // if(newWay == undefined){ // showErrorPage("网络有点问题哦,检查网络无误后,"); // return ; // }else if(newWay){ // mui.toast("数据加载失败,请检查网络无误后下拉刷新。"); // } // } 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, { // mui.ajax( url, { data: params || {}, dataType: 'json', //crossDomain: true, type: dataType, timeout: timeOut || 60000, error: function(xht, type, throwErr) { console.log(reqUrl+" "+type + " : " + throwErr); // var random = Math.random(); // isLoginOut = window.localStorage.isLoginOut; // if(isLoginOut) { // return; // } // // var tip = ""; 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") { //window.localStorage.isLoginOut = random; //if(window.localStorage.isLoginOut != random) { //return; //} // tip = "您的网络有点问题哦,请检查网络无误后重试~"; // // if(checkReload){ // mui.confirm(tip, "提示", ["重试", "重新登录"], function(e) { // if(e.index == 0){ // plus.webview.currentWebview().reload(); // } else { // exit2Login(); // } // }); // return; // } // // showConfirm(tip); checkNetOrbackendError(); } else if(type == "error" || type == "parsererror" || type == "null") { //window.localStorage.isLoginOut = random; //if(window.localStorage.isLoginOut != random) { // return; //} setTimeout(function() { showErrorPage("程序开了点小差, 请稍后重试!") },0); } }else if(newWay){ mui.toast("数据加载失败,请检查网络无误后下拉刷新。"); } /* if(checkReload){ window.localStorage.isLoginOut = random; if(window.localStorage.isLoginOut != random) { return; } mui.confirm("您的网络有点问题哦,请检查网络后重试~", "提示", ["重试", "重新登录"], function(e) { if(e.index == 0){ plus.webview.currentWebview().reload(); } else { exit2Login(); } }); return; } if(custError){ custError(xht, type, throwErr); return; } var tip = "" if(type == "timeout") { window.localStorage.isLoginOut = random; if(window.localStorage.isLoginOut != random) { return; } tip = "您的网络有点问题哦,请检查网络后重试~"; } if(type == "abort") { window.localStorage.isLoginOut = random; if(window.localStorage.isLoginOut != random) { return; } tip = "您的网络有点问题哦,请检查网络后重试~"; } if(type == "error" || type == "parsererror" || type == "null") { window.localStorage.isLoginOut = random; if(window.localStorage.isLoginOut != random) { return; } tip = "您的网络有点问题哦,请检查网络后重试~"; } showConfirm(tip);*/ }, success: function(res) { var random = Math.random(); isLoginOut = window.localStorage.isLoginOut; // console.error(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 参数,记录是否是因为账号在别处登录被挤掉 // var loginWv = plus.webview.getWebviewById("login"); // console.error(loginWv); // if(loginWv) { // loginWv.show("auto"); // } else { 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, { // mui.ajax( 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 } /** * 图片批量上传 * @param {Object} images 图片数组 * @param {Function} callBackHandler 上传结果处理方法 */ //function uploadImages(images, callBackHandler) { // var task = plus.uploader.createUpload(server + '/upload/image', { // method: "POST" // }, callBackHandler); // // task.addData("client", "HelloH5+"); // // task.addData("uid", getUid()); // for (var i = 0; i < images.length; i++) { // var image = images[i]; // task.addFile(image, {}); // } // task.start(); //} /** * 群组消息推送 * @param {Object} group_id 群组ID * @param {Object} from_id 发送者ID * @param {Object} content 消息内容 */ //function group_sendMsg(group_id,from_id,content) //{ // mui.ajax(group_sendmsg, { // data: {group_id:group_uid,content:content,from_id:from_id}, // dataType: 'json', // type: "POST", // timeout: 10000, // error: function(xht, type, throwErr) { // // }, // success: function(result){ // // } // }); //} function getsuifangUrl() { var userAgent = plus.storage.getItem("userAgent"); userAgentJson = JSON.parse(userAgent); var id = userAgentJson.id; var uid = userAgentJson.uid; var imei = userAgentJson.imei; var token = userAgentJson.token; var platform = 2; var openid = "123456"; var sf_url = sf_serverip + "index.php?m=FvDoctor&c=index" + "&id=" + id + "&uid=" + uid + "&imei=" + imei + "&token=" + token + "&platform=" + platform + "&openid=" + openid; // console.error(sf_url); return sf_url; } /** * 用于把用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; } } }