|
@@ -120,6 +120,7 @@ export default {
|
|
|
data() {
|
|
|
return {
|
|
|
situation: [],
|
|
|
+ websocket: null,
|
|
|
unit: [],
|
|
|
satellite: [],
|
|
|
center: [],
|
|
@@ -144,21 +145,65 @@ export default {
|
|
|
},
|
|
|
mounted() {
|
|
|
this.cesiumInit();
|
|
|
+ this.startWebSocket();
|
|
|
+ },
|
|
|
+ beforeDestroy() {
|
|
|
+ // 在组件销毁前,关闭WebSocket连接
|
|
|
+ if (this.websocket && this.websocket.readyState === WebSocket.OPEN) {
|
|
|
+ this.websocket.close();
|
|
|
+ }
|
|
|
},
|
|
|
|
|
|
methods: {
|
|
|
+ startWebSocket(){
|
|
|
+ this.websocket = new WebSocket('ws://localhost:8765');
|
|
|
+
|
|
|
+this.websocket.onopen = () => {
|
|
|
+ console.log('WebSocket连接已建立!');
|
|
|
+
|
|
|
+};
|
|
|
+
|
|
|
+this.websocket.onmessage = (event) => {
|
|
|
+ // 处理从WebSocket服务器接收到的消息
|
|
|
+ const data = JSON.parse(event.data);
|
|
|
+ console.log('收到消息:', data);
|
|
|
+
|
|
|
+ // 在这里处理接收到的数据,更新Vue组件的数据等操作
|
|
|
+};
|
|
|
+
|
|
|
+this.websocket.onerror = (error) => {
|
|
|
+ console.error('WebSocket错误:', error);
|
|
|
+};
|
|
|
+
|
|
|
+this.websocket.onclose = () => {
|
|
|
+ console.log('WebSocket连接已关闭!');
|
|
|
+};
|
|
|
+ },
|
|
|
async saveJson(row) {
|
|
|
- await axios
|
|
|
- .post("http://localhost:8084/admin/online/onlineOperation/updateDatasource/main", {
|
|
|
- params: {
|
|
|
- datasourceId: "1656243335922192384",
|
|
|
- masterData: row,
|
|
|
- slaveData: {}
|
|
|
- }
|
|
|
- })
|
|
|
- .then((res) => {
|
|
|
- console.log("update successfully ");
|
|
|
- });
|
|
|
+ // await axios
|
|
|
+ // .post("http://localhost:8084/admin/online/onlineOperation/updateDatasource/main", {
|
|
|
+ // params: {
|
|
|
+ // datasourceId: "1656243335922192384",
|
|
|
+ // masterData: row,
|
|
|
+ // slaveData: {}
|
|
|
+ // }
|
|
|
+ // })
|
|
|
+ // .then((res) => {
|
|
|
+ // console.log("update successfully ");
|
|
|
+ // });
|
|
|
+ const requestData = row
|
|
|
+ console.log('this.websocket :>> ', this.websocket);
|
|
|
+ if(this.websocket && this.websocket.readyState === WebSocket.OPEN){
|
|
|
+ this.websocket.send(JSON.stringify(requestData));
|
|
|
+ }
|
|
|
+ else{
|
|
|
+ this.startWebSocket();
|
|
|
+ setTimeout(() => {
|
|
|
+ this.websocket.send(JSON.stringify(requestData));
|
|
|
+ }, 2000); // 这里使用 setTimeout 来模拟耗时操作,2秒后执行回调
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
},
|
|
|
async getJson(row) {
|
|
|
let redunit = [];
|