//根据浏览器中的地址初始化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 "封仓-温控中"; if (code == DepotStatus.S_09) 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); } // 刷新时间 function initTime() { setInterval(function () { $("#navBarDate").html(formatDate('mm月dd日', new Date())); $("#navBarTime").html(formatDate('HH:MM:SS', new Date())); $("#navBarWeek").html(getWeekDate()); }, 1000); } /** * 格式化日期 * * @param fmt * @param date * @return {*} */ function formatDate(fmt, date) { var ret; var opt = { "Y+": date.getFullYear().toString(), // 年 "m+": (date.getMonth() + 1).toString(), // 月 "d+": date.getDate().toString(), // 日 "H+": date.getHours().toString(), // 时 "M+": date.getMinutes().toString(), // 分 "S+": date.getSeconds().toString() // 秒 // 有其他格式化字符需求可以继续添加,必须转化成字符串 }; for (var k in opt) { ret = new RegExp("(" + k + ")").exec(fmt); if (ret) { fmt = fmt.replace(ret[1], (ret[1].length == 1) ? (opt[k]) : (opt[k].padStart(ret[1].length, "0"))) } } return fmt; } /** * 获取当前星期几 */ function getWeekDate() { var now = new Date(); var day = now.getDay(); var weeks = new Array("星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"); var week = weeks[day]; return week; } /** * 切换页面 * @param pageTag */ function changePage(pageTag) { var url = "../dept-board/index"; if ("inout" == pageTag) { url = "../dept-board/inout"; } if ("ai" == pageTag) { url = "../dept-board/ai"; } if ("video" == pageTag) { url = "../dept-board/video"; } //后台管理首页 if ("backstage" == pageTag) { url = "../index"; window.parent.open(url, "_self"); return; } window.location.href = url; }