//根据浏览器中的地址初始化WS的路径 function initWsUrl() { //http://ibms.fzzygf.com //http://127.0.0.1:8080/igds var href = window.location.href; var arrUrl = href.split("//"); href = arrUrl[1]; arrUrl = href.split("/"); //如果没有配置contextPath if (arrUrl.length == 1) { return "ws://" + arrUrl[0] + "/websocket"; } //如果contextPath = igds if ("igds" == arrUrl[1]) { return "ws://" + arrUrl[0] + "/" + arrUrl[1] + "/websocket"; } //如果contextPath = zxlk if ("zxlk" == arrUrl[1]) { return "ws://" + arrUrl[0] + "/" + arrUrl[1] + "/websocket"; } return "ws://" + arrUrl[0] + "/websocket"; }; /** * * @param deptId 分库编码 * @param bizType 业务编号 * @param bizTag 自定义业务标签 如果为null默认取common * @param userId 当前用户Id */ function initWS(deptId, bizType, bizTag, userId) { if (null == bizTag) bizTag = "common"; var wsPath = initWsUrl() + "/" + deptId + "/" + bizType + "/" + bizTag + "/" + userId; if (typeof (WebSocket) == "undefined") { layer.msg("您的浏览器不支持WebSocket,请使用主流浏览器"); return; } // 创建连接 var socket = new WebSocket(wsPath); // 打开事件 socket.onopen = function () { socket.send(bizType); }; // 获得消息事件是后台穿件的WebPocket对象信息 socket.onmessage = function (result) { var pocket = JSON.parse(result.data); socketOnMessage(pocket); }; // 关闭事件 socket.onclose = function () { console.log("Socket closed……"); }; // 关闭WebSocket连接 function closeWebSocket() { socket.close(); } // 发生了错误事件 socket.onerror = function () { alert("Socket error……"); }; $(window).unload(function () { closeWebSocket(); }); } // 出入库专用连接,添加流程节点参数 function initInoutWS(companyId, bizType, progress, userId) { var wsPath = initWsUrl() + "/" + companyId + "/" + bizType + "/" + progress + "/" + userId; if (typeof (WebSocket) == "undefined") { layer.msg("您的浏览器不支持WebSocket,请使用主流浏览器"); return; } // 实现化WebSocket对象,指定要连接的服务器地址与端口  建立连接 var socket = new WebSocket(wsPath); // 打开事件 socket.onopen = function () { socket.send(bizType); }; // 获得消息事件是后台穿件的WebPocket对象信息 socket.onmessage = function (result) { var pocket = JSON.parse(result.data); socketOnMessage(pocket); }; // 关闭事件 socket.onclose = function () { console.log("Socket closed……"); }; // 关闭WebSocket连接 function closeWebSocket() { socket.close(); } // 发生了错误事件 socket.onerror = function () { alert("Socket error……"); } $(window).unload(function () { socket.close(); }); }; function INOUT_PROGRESS_MSG(code) { if (InoutProgress.REGISTER == code) return "登记"; if (InoutProgress.CHECK == code) return "化验"; if (InoutProgress.HANDLE == code) return "值仓"; if (InoutProgress.WEIGHT_TAG == code) return "称重"; if (InoutProgress.WEIGHT_FULL == code) return "满车称重"; if (InoutProgress.WEIGHT_EMPTY == code) return "空车称重"; if (InoutProgress.PAY == code) return "支付"; if (InoutProgress.CARD_BACK == code) return "卡回收"; if (InoutProgress.RECORD == code) return "流程完成"; return "未知"; }; /** * 根据状态编码返回中文 * @param code */ function DEPOT_STATUS_MSG(code) { if (code == DepotStatus.S_01) return "空仓"; if (code == DepotStatus.S_02) return "满仓"; if (code == DepotStatus.S_03) return "入库中"; if (code == DepotStatus.S_04) return "出库中"; if (code == DepotStatus.S_05) return "气调中"; if (code == DepotStatus.S_06) return "熏蒸中"; if (code == DepotStatus.S_07) return "通风中"; if (code == DepotStatus.S_08) return "维修中"; return code; } /** * fmt 时间格式化例如:yyyy-MM-dd hh:mm:ss date 时间 return 字符串 */ function dateFtt(fmt, date) { if (!date) return ""; var o = { "M+": date.getMonth() + 1, // 月份 "d+": date.getDate(), // 日 "h+": date.getHours(), // 小时 "m+": date.getMinutes(), // 分 "s+": date.getSeconds(), // 秒 "q+": Math.floor((date.getMonth() + 3) / 3), // 季度 "S": date.getMilliseconds() // 毫秒 }; if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (date.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; } function dateFtt2(fmt, date) { if (!date) return ""; var date2 = new Date(date); return dateFtt(fmt, date2); }