|
@@ -52,8 +52,11 @@ const tenantId = getUserInfo().tenantId;
|
|
|
const proxy = getCurrentInstance().proxy;
|
|
|
const tabType = ref("home");
|
|
|
const msgCount = ref(0);
|
|
|
+const socket = ref(null);
|
|
|
+const intervalId = ref(null);
|
|
|
+
|
|
|
const socketInit = () => {
|
|
|
- window.ws = new WebSocket(
|
|
|
+ socket.value = new WebSocket(
|
|
|
"ws://" +
|
|
|
process.env.VUE_APP_IP +
|
|
|
process.env.VUE_APP_WS_API +
|
|
@@ -62,11 +65,16 @@ const socketInit = () => {
|
|
|
// 'ws://192.168.1.97:8300/webStock/' + window.localStorage.getItem('token')
|
|
|
);
|
|
|
//申请一个WebSocket对象,参数是服务端地址,同http协议使用http://开头一样,WebSocket协议的url使用ws://开头,另外安全的WebSocket协议使用wss://开头
|
|
|
- window.ws.onopen = function () {
|
|
|
+ socket.value.onopen = function () {
|
|
|
//当WebSocket创建成功时,触发onopen事件
|
|
|
console.log("open");
|
|
|
+
|
|
|
+ //立马发送一次心跳
|
|
|
+ sendSocketMsg();
|
|
|
+ // 设置定时器,每30秒执行一次myFunction
|
|
|
+ intervalId.value = setInterval(sendSocketMsg, 1000 * 30);
|
|
|
};
|
|
|
- window.ws.onmessage = function (e) {
|
|
|
+ socket.value.onmessage = function (e) {
|
|
|
//当客户端收到服务端发来的消息时,触发onmessage事件,参数e.data包含server传递过来的数据
|
|
|
//在data.value前面插入
|
|
|
const res = JSON.parse(e.data);
|
|
@@ -88,8 +96,16 @@ const socketInit = () => {
|
|
|
});
|
|
|
}
|
|
|
}
|
|
|
- if (res.type == 2) {
|
|
|
+ if (res.type == 2 && res.count != "0") {
|
|
|
msgCount.value = res.count * 1;
|
|
|
+ if (res.title) {
|
|
|
+ uni.postMessage({
|
|
|
+ data: {
|
|
|
+ type: "push",
|
|
|
+ content: res.title,
|
|
|
+ },
|
|
|
+ });
|
|
|
+ }
|
|
|
}
|
|
|
if (res.type == 3) {
|
|
|
// ElNotification({
|
|
@@ -100,17 +116,45 @@ const socketInit = () => {
|
|
|
// })
|
|
|
}
|
|
|
};
|
|
|
- window.ws.onclose = function (e) {
|
|
|
+ socket.value.onclose = function (e) {
|
|
|
//当客户端收到服务端发送的关闭连接请求时,触发onclose事件
|
|
|
console.log("close");
|
|
|
};
|
|
|
- window.ws.onerror = function (e) {
|
|
|
+ socket.value.onerror = function (e) {
|
|
|
//如果出现连接、处理、接收、发送数据失败的时候触发onerror事件
|
|
|
console.log(e);
|
|
|
};
|
|
|
};
|
|
|
+
|
|
|
+const sendSocketMsg = () => {
|
|
|
+ let jsonData = {
|
|
|
+ cmd: "heartbeat",
|
|
|
+ };
|
|
|
+ socket.value.send(JSON.stringify(jsonData));
|
|
|
+ console.log("Timer executed!");
|
|
|
+};
|
|
|
+
|
|
|
socketInit();
|
|
|
|
|
|
+const getSubscriptCount = () => {
|
|
|
+ setInterval(() => {
|
|
|
+ proxy
|
|
|
+ .post("/flowExample/getToBeProcessedPage", { pageNum: 1, pageSize: 999 })
|
|
|
+ .then((res) => {
|
|
|
+ if (res.data) {
|
|
|
+ let count = res.data.total || -1;
|
|
|
+ uni.postMessage({
|
|
|
+ data: {
|
|
|
+ type: "message",
|
|
|
+ count: count,
|
|
|
+ },
|
|
|
+ });
|
|
|
+ }
|
|
|
+ })
|
|
|
+ .catch((err) => {});
|
|
|
+ }, 1000 * 30);
|
|
|
+};
|
|
|
+getSubscriptCount();
|
|
|
//判断是否是ios系统
|
|
|
const isIos = () => {
|
|
|
const u = navigator.userAgent;
|