Commit 8e6c3d96 by liuguorong93

Merge branch 'dev_gabjq_dev2' into dev_gabjq

parents 3ed0824a 0cbfde5b
export default {
listen(url, messageCallback, openCallback, closeCallback, errorCallback) {
if (typeof WebSocket === "undefined") {
console.log("您的浏览器不支持WebSocket");
return;
} else {
let protocol = "ws";
let newUrl = "";
if (window.location.protocol == "https:") {
protocol = "wss";
}
let env = process.env.NODE_ENV;
switch (env) {
case 'development':
newUrl = `${protocol}://47.92.48.137:4002/${url}`;
break;
case 'production':
newUrl = `${protocol}://${window.location.host}/${url}`;
break;
}
const ws = new WebSocket(newUrl);
ws.onopen = () => {
if (openCallback) openCallback();
};
ws.onclose = () => {
if (closeCallback) closeCallback();
};
ws.onerror = () => {
if (errorCallback) errorCallback();
};
ws.onmessage = (event) => {
try {
if (event?.data) {
const data = JSON.parse(event.data);
messageCallback(data);
}
} catch (e) {
console.log(e);
}
};
return ws;
}
},
};
......@@ -64,7 +64,7 @@ import dogMajor from "./dogMajor.vue";
// 中间内容
import mapCount from "./mapCount.vue";
// 地图
// import mapBox from "./mapBox.vue";
import mapBox from "./mapBox.vue";
import mapBoxForBingTu from "./mapBoxForBingTu.vue";
import { postRequest } from "@/api/dogView.js";
export default {
......@@ -76,7 +76,7 @@ export default {
qgPhTop,
dogMajor,
mapCount,
// mapBox,
mapBox,
mapBoxForBingTu,
},
data() {
......
......@@ -208,7 +208,7 @@ export default {
z: 4,
animationDuration: 0,
radius: 25,
center: [itemArr.value[0], itemArr.value[1]],
center: itemArr.value,
data: [
{
name: "一级工作犬",
......@@ -262,6 +262,7 @@ export default {
this.$message.error("该区域没有数据,不支持地图下钻!");
this.loading = false;
}
break;
}
}
});
......
......@@ -53,26 +53,47 @@
</template>
<script>
import websocket from "@/utils/websocket.js";
export default {
data() {
return {};
return {
ws: null,
};
},
beforeDestroy() {
this.closeWebSocket();
},
mounted() {
// this.getLists();
// this.wsFn();
},
methods: {
getLists() {
this.$nextTick(() => {
jQuery(".messageClass").slide({
mainCell: ".infoListUl",
autoPage: true,
effect: "top",
autoPlay: true,
scroll: 6,
vis: 6,
});
});
closeWebSocket() {
if (this.ws && this.ws.readyState <= 1) this.ws.close();
},
wsFn() {
let url = "ws/asset";
this.ws = websocket.listen(url, this.websocketCB, this.websocketErrCB);
},
websocketCB(data) {
// console.log("data", data);
},
websocketErrCB(err) {
// console.log("err", err);
},
// getLists() {
// this.$nextTick(() => {
// jQuery(".messageClass").slide({
// mainCell: ".infoListUl",
// autoPage: true,
// effect: "top",
// autoPlay: true,
// scroll: 6,
// vis: 6,
// });
// });
// },
},
};
</script>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment