无人机管理后台前端(已迁走)
linwe
2024-10-12 d6fd9c838e208c4c3dc2507de0f175115fb5fa87
新增设备代码优化
1 files modified
141 ■■■■■ changed files
src/views/device/addDevice.vue 141 ●●●●● patch | view | raw | blame | history
src/views/device/addDevice.vue
@@ -64,9 +64,9 @@
                menuWidth: 300,
                lazy: true,
                tree: true,
                height: '460',
                calcHeight: 32,
                dialogWidth: 1050,
                // height: '460',
                // calcHeight: 32,
                // dialogWidth: 1050,
                tip: false,
                searchShow: true,
                searchMenuSpan: 6,
@@ -171,18 +171,7 @@
                ],
            },
            data: [],
            DeviceFirmwareTypeEnum: {
                // 普通升级
                ToUpgraded: 3,
                // 一致性升级
                ConsistencyUpgrade: 2,
            },
            DeviceFirmwareStatusEnum: {
                None: 1, // 无需升级
                ToUpgraded: 2, // 待升级
                ConsistencyUpgrade: 3, // 一致性升级
                DuringUpgrade: 4, // 升级中
            },
        };
    },
    computed: {
@@ -224,72 +213,8 @@
                this.$message.error("复制失败");
            });
        },
        // 关闭所有的webscoket
        closeAllWebsoket() {
            this.websocketMap.forEach((k, v) => {
                if (null != v) {
                    v.close()
                    this.websocketMap.delete(k)
                    this.webSocketIdSet.delete(k)
                }
            });
        },
        // 连接webSocket
        connectWebSocket(data) {
            const webSocketId = data.workspace_id
            if (!this.webSocketIdSet.has(webSocketId)) {
                // 防止重复连接
                this.webSocketIdSet.add(webSocketId);
                const webSorketUrl = getWebsocketUrl() + '&workspace-id=' + data.workspace_id;
                // 监听ws 消息
                this.useConnectWebSocket(webSocketId, webSorketUrl);
            }
        },
        useConnectWebSocket(webSocketId, url) {
            const websocket = new ConnectWebSocket(url);
            // 加入 webscoket map
            this.websocketMap.set(webSocketId, websocket)
            websocket?.registerMessageHandler(this.messageHandler);
            websocket?.initSocket();
        },
        async messageHandler(payload) {
            console.log(payload, 7777);
            if (!payload) {
                return;
            }
            if (payload.biz_code != "ota_progress") {
                return;
            }
            var data = payload.data;
            this.data.forEach(e => {
                if (e.device_sn == data.sn && data.output.status == 'in_progress') {
                    e.firmware_progress = data.output.progress.percent;
                }
                if (e.device_sn == data.sn && data.output.status == 'ok') {
                    // 升级完成修改状态
                    e.firmware_status = 1
                    const webscoket = this.websocketMap.get(e.workspace_id);
                    // 关闭
                    webscoket?.close();
                    //删除对应的webscoket
                    this.websocketMap.delete(e.workspace_id);
                    this.webSocketIdSet.delete(e.workspace_id);
                }
            });
        },
        init() {
            this.onLoad(this.page);
        },
        // 打开权限分享页面
        handleOpenDevicePerShare(row) {
            var that = this;
            this.devicePerShareVisible = true;
            this.$nextTick(() => {
                that.$refs.devicePerShare.init(row);
            });
        },
        handleOpenRemoteDebugging(row) {
@@ -297,63 +222,6 @@
            this.remoteDebuggingShow = true;
        },
        // 打开固件管理页面
        handleOpenFirmwarm(row) {
            var that = this;
            this.firmwareManageVisible = true;
            this.$nextTick(() => {
                that.$refs.firmwareManage.init(row);
            });
        },
        // 升级固件按钮事件
        updateFirmware(row) {
            if (row.status == 0) {
                this.$message({
                    type: 'warning',
                    message: '设备不在线!',
                });
                return;
            }
            var that = this;
            this.firmwareBox = true;
            const param = {
                device_name: row.device_name,
            };
            // 获取固件最新版本信息
            getDeviceUpgradeInfo(param).then(res => {
                const data = res.data.data;
                if (data.length === 0) {
                    return;
                }
                that.firmwareVersion = data[0].product_version;
                that.firmwareInfo['device_name'] = row.device_name;
                that.firmwareInfo['sn'] = row.device_sn;
                that.firmwareInfo['product_version'] = data[0].product_version;
                // 1-普通升级,2-一致性升级;
                that.firmwareInfo['firmware_upgrade_type'] =
                    row.firmware_status === that.DeviceFirmwareStatusEnum.ToUpgraded
                        ? that.DeviceFirmwareTypeEnum.ToUpgraded
                        : that.DeviceFirmwareTypeEnum.ConsistencyUpgrade;
                that.firmwareInfo['workspaceId'] = row.workspace_id;
            });
        },
        // 确定升级固件版本
        updateFirmwareConfirm() {
            var that = this;
            var arr = [];
            arr.push(that.firmwareInfo);
            ota(that.firmwareInfo.workspaceId, arr).then(res => {
                that.firmwareVersion = '';
                that.firmwareInfo = {};
                that.firmwareBox = false;
                this.$message({
                    type: 'success',
                    message: '操作成功!',
                });
                this.onLoad(this.page);
                done();
            });
        },
        rowSave(row, done, loading) {
            add(row).then(
                () => {
@@ -460,7 +328,6 @@
            this.onLoad(this.page, this.query);
        },
        onLoad(page, params = {}) {
            this.closeAllWebsoket()
            const { releaseTimeRange } = this.query;
            let values = {
                ...params,