|
@@ -2,22 +2,63 @@
|
|
|
var prescriptionPrintWebsocket = null;
|
|
|
var lockReconnect = false; //避免ws重复连接
|
|
|
var lastPatient = '';
|
|
|
-
|
|
|
//取药队列
|
|
|
-var lineUpList = getLocalStorage("lineUpList",[]);
|
|
|
+var lineUpList = getLocalStorage("lineUpList", []);
|
|
|
//待取药队列
|
|
|
-var currentList = getLocalStorage("currentList",[]);
|
|
|
+var currentList = getLocalStorage("currentList", []);
|
|
|
//过号名单队列
|
|
|
-var pastList = getLocalStorage("pastList",[]);
|
|
|
-/*var ip = 'webhis.thyy.cn:81';
|
|
|
-var ip = '172.16.30.22:8089';*/
|
|
|
-function openSocket(type) {
|
|
|
-
|
|
|
+var pastList = getLocalStorage("pastList", []);
|
|
|
|
|
|
+function openSocket(type) {
|
|
|
//判断当前浏览器是否支持WebSocket
|
|
|
try {
|
|
|
if ('WebSocket' in window) {
|
|
|
- prescriptionPrintWebsocket = new WebSocket("ws://webhis.thyy.cn:81/thmz/prescriptionPrintSocket/" + type);
|
|
|
+ request({
|
|
|
+ method: 'GET',
|
|
|
+ url: '/getWebSocketHost'
|
|
|
+ }).then((res) => {
|
|
|
+ prescriptionPrintWebsocket = new WebSocket(res.data + "prescriptionPrintSocket/" + type);
|
|
|
+ //连接发生错误的回调方法
|
|
|
+ prescriptionPrintWebsocket.onerror = function () {
|
|
|
+ console.log(type + "连接prescriptionPrintSocket发生错误")
|
|
|
+ };
|
|
|
+ //连接成功建立的回调方法
|
|
|
+ prescriptionPrintWebsocket.onopen = function (event) {
|
|
|
+ number = 0;
|
|
|
+ console.log(type + "连接prescriptionPrintSocket连接成功");
|
|
|
+ var chk_value = '';
|
|
|
+ $('input[name="aotoPrint"]:checked').each(function () {
|
|
|
+ chk_value = $(this).val();
|
|
|
+ });
|
|
|
+ if (type == 'PY' && chk_value != '') {//配药处方自动打印
|
|
|
+ printPrescriptions(chk_value);
|
|
|
+ }
|
|
|
+ };
|
|
|
+ //页面接收到消息的回调方法
|
|
|
+ prescriptionPrintWebsocket.onmessage = function (event) {
|
|
|
+ var data = JSON.parse(event.data);
|
|
|
+ if (type == 'PY' && data.groupNo == groupNo) {
|
|
|
+ dispensingMessage(data);
|
|
|
+ } else if (type == 'FY') {
|
|
|
+ sendMedicineMessage(data);
|
|
|
+ } else if (type == 'JH') {
|
|
|
+ cellNumberMessage(data);
|
|
|
+ }
|
|
|
+ };
|
|
|
+ //连接关闭的回调方法
|
|
|
+ prescriptionPrintWebsocket.onclose = function (event) {
|
|
|
+ console.log(type + "连接prescriptionPrintSocket连接关闭 code:" + event.code + ",原因:" + event.reason + ",是否正常关闭:" + event.wasClean);
|
|
|
+ if (event.code == '1001' || event.code == '1006') {//1001:终端离开, 可能因为服务端错误 1006:没有发送关闭帧
|
|
|
+ reconnect(type);
|
|
|
+ }
|
|
|
+ };
|
|
|
+ //监听窗口关闭事件,当窗口关闭时,主动去关闭websocket连接,防止连接还没断开就关闭窗口,server端会抛异常。
|
|
|
+ window.onbeforeunload = function () {
|
|
|
+ prescriptionPrintWebsocket.close();
|
|
|
+ }
|
|
|
+ }).catch(() => {
|
|
|
+ reconnect(type);
|
|
|
+ });
|
|
|
} else {
|
|
|
alert('当前浏览器不支持WebSocket,请更换浏览器');
|
|
|
}
|
|
@@ -25,49 +66,6 @@ function openSocket(type) {
|
|
|
reconnect(type);
|
|
|
console.log(e);
|
|
|
}
|
|
|
-
|
|
|
-//连接发生错误的回调方法
|
|
|
- prescriptionPrintWebsocket.onerror = function () {
|
|
|
- console.log(type + "连接prescriptionPrintSocket发生错误")
|
|
|
- };
|
|
|
-
|
|
|
-//连接成功建立的回调方法
|
|
|
- prescriptionPrintWebsocket.onopen = function (event) {
|
|
|
- number = 0;
|
|
|
- console.log(type + "连接prescriptionPrintSocket连接成功");
|
|
|
- var chk_value = '';
|
|
|
- $('input[name="aotoPrint"]:checked').each(function () {
|
|
|
- chk_value = $(this).val();
|
|
|
- });
|
|
|
- if (type == 'PY' && chk_value != '') {//配药处方自动打印
|
|
|
- printPrescriptions(chk_value);
|
|
|
- }
|
|
|
- };
|
|
|
-
|
|
|
-//页面接收到消息的回调方法
|
|
|
- prescriptionPrintWebsocket.onmessage = function (event) {
|
|
|
- var data = JSON.parse(event.data);
|
|
|
- if (type == 'PY' && data.groupNo == groupNo) {
|
|
|
- dispensingMessage(data);
|
|
|
- } else if (type == 'FY') {
|
|
|
- sendMedicineMessage(data);
|
|
|
- } else if (type == 'JH') {
|
|
|
- cellNumberMessage(data);
|
|
|
- }
|
|
|
- };
|
|
|
-
|
|
|
-//连接关闭的回调方法
|
|
|
- prescriptionPrintWebsocket.onclose = function (event) {
|
|
|
- console.log(type + "连接prescriptionPrintSocket连接关闭 code:" + event.code + ",原因:" + event.reason + ",是否正常关闭:" + event.wasClean);
|
|
|
- if (event.code == '1001' || event.code == '1006') {//1001:终端离开, 可能因为服务端错误 1006:没有发送关闭帧
|
|
|
- reconnect(type);
|
|
|
- }
|
|
|
- };
|
|
|
-
|
|
|
-//监听窗口关闭事件,当窗口关闭时,主动去关闭websocket连接,防止连接还没断开就关闭窗口,server端会抛异常。
|
|
|
- window.onbeforeunload = function () {
|
|
|
- prescriptionPrintWebsocket.close();
|
|
|
- }
|
|
|
}
|
|
|
|
|
|
//重新连接
|
|
@@ -150,7 +148,7 @@ function sendMedicineMessage(data) {
|
|
|
*/
|
|
|
function cellNumberMessage(data) {
|
|
|
if (data.type == 'JF') {//来自缴费后的消息
|
|
|
- currentList = removeObjArrayByProperty(currentList,data,'patient_id');
|
|
|
+ currentList = removeObjArrayByProperty(currentList, data, 'patient_id');
|
|
|
/*currentListClear(data);*/
|
|
|
//添加等待取药列表
|
|
|
currentList[currentList.length] = {name: data.name, patient_id: data.patient_id};
|
|
@@ -164,19 +162,19 @@ function cellNumberMessage(data) {
|
|
|
//设置正在取药,清除过号队列
|
|
|
let rightPersonName = data.name;
|
|
|
for (let i = 0; i < lineUpList.length; i++) {
|
|
|
- if(data.patient_id === lineUpList[i].patient_id){
|
|
|
- if(rightPersonName.length > 3){
|
|
|
- rightPersonName = ((lineUpList[i].lineUp!==10000?'<span style="font-size:32px; "><span class="number-name"> '+lineUpList[i].lineUp+' </span> ':'')+rightPersonName+"</span>");
|
|
|
- }else{
|
|
|
- rightPersonName = ((lineUpList[i].lineUp!==10000?'<span class="number-name"> '+lineUpList[i].lineUp+' </span> ':'')+rightPersonName);
|
|
|
+ if (data.patient_id === lineUpList[i].patient_id) {
|
|
|
+ if (rightPersonName.length > 3) {
|
|
|
+ rightPersonName = ((lineUpList[i].lineUp !== 10000 ? '<span style="font-size:32px; "><span class="number-name"> ' + lineUpList[i].lineUp + ' </span> ' : '') + rightPersonName + "</span>");
|
|
|
+ } else {
|
|
|
+ rightPersonName = ((lineUpList[i].lineUp !== 10000 ? '<span class="number-name"> ' + lineUpList[i].lineUp + ' </span> ' : '') + rightPersonName);
|
|
|
}
|
|
|
break
|
|
|
}
|
|
|
}
|
|
|
$('#rightPerson').html(rightPersonName);
|
|
|
rightPerson = data;
|
|
|
- currentList = removeObjArrayByProperty(currentList,data,'patient_id');
|
|
|
- pastList = removeObjArrayByProperty(pastList,data,'patient_id');
|
|
|
+ currentList = removeObjArrayByProperty(currentList, data, 'patient_id');
|
|
|
+ pastList = removeObjArrayByProperty(pastList, data, 'patient_id');
|
|
|
/*currentListClear(data);
|
|
|
pastListClear(data);*/
|
|
|
if (data.type == 'JH') {
|
|
@@ -190,8 +188,8 @@ function cellNumberMessage(data) {
|
|
|
rightPerson = null;
|
|
|
$('#rightPerson').text("");
|
|
|
}
|
|
|
- currentList = removeObjArrayByProperty(currentList,data,'patient_id');
|
|
|
- pastList = removeObjArrayByProperty(pastList,data,'patient_id');
|
|
|
+ currentList = removeObjArrayByProperty(currentList, data, 'patient_id');
|
|
|
+ pastList = removeObjArrayByProperty(pastList, data, 'patient_id');
|
|
|
window.localStorage["currentList"] = JSON.stringify(currentList);
|
|
|
window.localStorage["pastList"] = JSON.stringify(pastList);
|
|
|
//currentListClear(data);
|
|
@@ -260,14 +258,14 @@ function getLineUpData(data) {
|
|
|
for (let i = 0; i < data.length; i++) {
|
|
|
let flag = true;
|
|
|
for (let j = 0; j < lineUpList.length; j++) {
|
|
|
- let id = data[i].patientId==null?data[i].patient_id:data[i].patientId;
|
|
|
+ let id = data[i].patientId == null ? data[i].patient_id : data[i].patientId;
|
|
|
if (id == lineUpList[j].patient_id) {
|
|
|
data[i].lineUp = lineUpList[j].lineUp;
|
|
|
flag = false;
|
|
|
break
|
|
|
}
|
|
|
}
|
|
|
- if(flag){
|
|
|
+ if (flag) {
|
|
|
data[i].lineUp = 10000;
|
|
|
}
|
|
|
}
|