提交 43958000 作者: “kai”

refactor(MMCFlightControlCenter):

- webscoket 推送的设备数据 关联项目id
上级 8d19e538
......@@ -91,10 +91,10 @@ export default {
},
data() {
return {
time:null,
time: null,
bus: new Vue(),
ws: null,
uavWs: null
uavWs: null,
};
},
provide() {
......@@ -189,11 +189,9 @@ export default {
});
},
},
},
beforeCreate() {
clearInterval(this.time)
clearInterval(this.time);
crashMonitor({
alert: this.$alert,
});
......@@ -222,23 +220,20 @@ export default {
window.$mmc_stl.viewer = this.cesiumViewer;
}
// 连接ws监听接管请求数据
let url = this.url.wsUrl
let token = this.$store.state.MMCFlightControlCenter.token
let url = this.url.wsUrl;
let token = this.$store.state.MMCFlightControlCenter.token;
const socket = new WebSocket(`${url}/infra/ws?token=${token}`);
const uavSocket = new WebSocket(`${url}/uas/ws?token=${token}`);
this.ws = socket;
this.uavWs = uavSocket;
socket.onopen = function () {
};
socket.onopen = function () {};
socket.onmessage = (event) => {
let data = JSON.parse(event.data || "{}");
const type = data.type;
const content = JSON.parse(data.content || "{}");
const msg = content.message;
switch (type) {
// 接管申请
case "uas-device-take-message":
//接管消息
......@@ -262,7 +257,7 @@ export default {
} else {
this.$message.warning("操作失败");
}
} catch (e) { }
} catch (e) {}
})
.catch(async () => {
await Control_API.updateControlUav({
......@@ -280,7 +275,7 @@ export default {
// 接管申请同意
case "uas-device-take-agree-message":
console.log('同意接管')
console.log("同意接管");
break;
// 接管申请拒绝
......@@ -298,7 +293,7 @@ export default {
title: "接管消息",
message: msg,
duration: 30000,
offset: 40
offset: 40,
});
break;
......@@ -308,35 +303,37 @@ export default {
title: "接管消息",
message: msg,
duration: 30000,
offset: 40
offset: 40,
});
break;
}
};
uavSocket.onopen = () => {
let user = JSON.parse(localStorage.getItem('tmj'))
let user = JSON.parse(localStorage.getItem("tmj"));
let { projectId } = this.$store.state.MMCFlightControlCenter;
if(user){
clearInterval(this.time)
this.time= setInterval(() => {
const scene = this.getQueryParam('scene');
uavSocket.send(JSON.stringify({
if (user) {
clearInterval(this.time);
this.time = setInterval(() => {
const scene = this.getQueryParam("scene");
uavSocket.send(
JSON.stringify({
type: "uas-device-getTree-message",
content:JSON.stringify( {
text:JSON.stringify({
deviceType:scene,
projectId:projectId,
content: JSON.stringify({
text: JSON.stringify({
deviceType: scene,
projectId: projectId,
serchKey: this.getCurrentSearchKey(),
}),
toUserId:user.user.userId,
},)
}));
toUserId: user.user.userId,
}),
})
);
}, 6000);
}
};
let { projectId } = this.$store.state.MMCFlightControlCenter;
uavSocket.onmessage = (event) => {
let data = JSON.parse(event.data || "{}");
const type = data.type;
......@@ -347,8 +344,9 @@ export default {
break;
// 刷新无人机列表
case "uas-device-getTree-message":
let res = JSON.parse(data.content)
const scene = this.getQueryParam('scene');
let res = JSON.parse(data.content);
if (projectId == res.projectId) {
const scene = this.getQueryParam("scene");
// 根据scene值决定更新哪个组件的数据
if (scene == 1) {
// scene为1时,更新uavList组件的数据
......@@ -359,7 +357,7 @@ export default {
}
break;
}
}
};
},
......@@ -370,24 +368,36 @@ export default {
methods: {
// 获取当前搜索关键字
getCurrentSearchKey() {
const scene = this.getQueryParam('scene');
const scene = this.getQueryParam("scene");
if (scene == 1) {
// 无人机场景,获取 uavList 组件的搜索内容
const uavListComponent = this.$children.find(child => child.$options.name === 'UavApplications');
const uavListComponent = this.$children.find(
(child) => child.$options.name === "UavApplications"
);
if (uavListComponent) {
const uavList = uavListComponent.$children.find(child => child.$options.name === 'UavList' || child.uavSearchContent !== undefined);
return uavList ? uavList.uavSearchContent || '' : '';
const uavList = uavListComponent.$children.find(
(child) =>
child.$options.name === "UavList" ||
child.uavSearchContent !== undefined
);
return uavList ? uavList.uavSearchContent || "" : "";
}
} else if (scene == 2) {
// 机库场景,获取 hangar 组件的搜索内容
const hangarComponent = this.$children.find(child => child.$options.name === 'Hangar');
const hangarComponent = this.$children.find(
(child) => child.$options.name === "Hangar"
);
if (hangarComponent) {
const hangarList = hangarComponent.$children.find(child => child.$options.name === 'List' || child.searchContent !== undefined);
return hangarList ? hangarList.searchContent || '' : '';
const hangarList = hangarComponent.$children.find(
(child) =>
child.$options.name === "List" ||
child.searchContent !== undefined
);
return hangarList ? hangarList.searchContent || "" : "";
}
}
return '';
return "";
},
// 处理搜索变化事件
......@@ -396,11 +406,11 @@ export default {
const url = window.location.href;
// 检查 URL 中是否包含 hash 部分
const hashIndex = url.indexOf('#');
const hashIndex = url.indexOf("#");
if (hashIndex !== -1) {
// 如果有 hash 部分,提取 hash 部分
const hash = url.substring(hashIndex + 1); // 去掉 '#' 符号
const hashParams = new URLSearchParams(hash.split('?')[1]); // 提取 hash 中的查询参数部分
const hashParams = new URLSearchParams(hash.split("?")[1]); // 提取 hash 中的查询参数部分
const value = hashParams.get(paramName);
if (value !== null) {
return value; // 如果在 hash 中找到参数,直接返回
......@@ -410,12 +420,12 @@ export default {
// 如果在 hash 中没有找到,检查普通的查询参数
const searchParams = new URLSearchParams(window.location.search);
return searchParams.get(paramName); // 返回普通查询参数中的值
},
},
reset() {
let cesiumEl = document.querySelector(".cesium-viewer");
// 判断cesium的父元素是否是layer-container来确定当前是否已经切换, 未切换就退出
if (cesiumEl.parentElement.id === 'layer-container') {
if (cesiumEl.parentElement.id === "layer-container") {
return;
}
let cesiumParentEl = document.querySelector("#layer-container");
......@@ -496,7 +506,6 @@ export default {
}
* {
/* 滚动条整体样式 */
&::-webkit-scrollbar {
width: 4px;
......@@ -571,12 +580,14 @@ export default {
align-items: center;
font-size: 20px;
font-family: YouSheBiaoTiHei;
background-image: -webkit-linear-gradient(right,
background-image: -webkit-linear-gradient(
right,
#e3aa77,
#f5cda9,
#f9ecd3,
#fcdbb1,
#edb07a);
#edb07a
);
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
letter-spacing: 0;
......@@ -676,7 +687,6 @@ export default {
}
.el-input-number {
.el-input-number__decrease,
.el-input-number__increase {
bottom: 1px;
......@@ -717,10 +727,12 @@ export default {
.option.hover,
.option:hover {
background-image: linear-gradient(90deg,
background-image: linear-gradient(
90deg,
rgba(44, 135, 176, 0.7) 0%,
rgba(26, 100, 139, 0.37) 51%,
rgba(7, 61, 98, 0.7) 100%);
rgba(7, 61, 98, 0.7) 100%
);
font-family: MicrosoftYaHei;
font-size: 12px;
color: #00f5ff;
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论