cuiqian2004
2025-10-11 bcfb05f5e7782ef23e4deb1b38a1ca4b4085181a
pages/map/scene.vue
@@ -43,7 +43,8 @@
         <view class="bottom-content" v-else-if="opSceneType =='scan'">
            <view class="tip">场景构建中</view>
            <view>
               请操作搬运车扫描地图覆盖的区域
               <!-- 请操作搬运车扫描地图覆盖的区域 -->
               {{mapServerPhase=== 1  ?"场景构建服务:未启动":mapServerPhase===2 ?"场景构建服务:启动中":mapServerPhase===3  ?"场景构建中":mapServerPhase}}
            </view>
            <view class="text-button-group">
@@ -51,13 +52,17 @@
            </view>
         </view>
         <view class="bottom-content" v-else-if="opSceneType =='finish'">
            <view class="tip"> “{{sceneName}}”{{opType == "extend"?"场景扩展完成"+"":"场景构建完成"}}</view>
         <!--    <view> 已成功构建“{{sceneName}}”</view> -->
            <view class="loading-view">{{saveMapIsOk?"构图保存完成":"等待构图保存完成..."}}
               <view v-if="!saveMapIsOk" class="auto-circle"></view>
            <view class="tip"> “{{sceneName}}”{{opType == "extend"?"场景扩展结束"+"":"场景构建结束"}}</view>
            <!--    <view> 已成功构建“{{sceneName}}”</view> -->
            <view class="loading-view">
               构图状态:{{mapServerPhase===5?"保存成功":mapServerPhase===4?"保存中":mapServerPhase===6?"保存失败":mapServerPhase}}
               <view v-if="mapServerPhase === 4" class="auto-circle"></view>
            </view>
            <view class="text-button-group">
               <a-button type="primary" class="button" :disabled=" !saveMapIsOk || loading" @click="clickFinish">{{opType == "extend"?"扩展完成":"构建完成"}}</a-button>
               <a-button type="primary" class="button" v-if="mapServerPhase === 6"
                  @click="clickRecreate">{{opType == "extend"?"重现扩展":"重现构建"}}</a-button>
               <a-button type="primary" class="button" v-else :disabled=" mapServerPhase !==5 || loading"
                  @click="clickFinish">{{opType == "extend"?"扩展完成":"构建完成"}}</a-button>
            </view>
         </view>
      </view>
@@ -81,13 +86,15 @@
      createScene,
      addMap,
      stopMap,
      delScene,
      //getAgvState,
      getMapLaserData,
      saveDBData,
      checkMapServerIsStart,
      startOrStopMapServer,
      checkMapServerIsOk,
      checkSaveMapIsOk,
      // checkMapServerIsStart,
      // startOrStopMapServer,
      // checkMapServerIsOk,
      // checkSaveMapIsOk,
      getMapServerPhase,
      getMapUrl
   } from "@/api/vehicle.js"
@@ -110,7 +117,7 @@
            localSceneList: [],
            positioningAgv: true,
            robotPos: {},
            mapserverIsOk: false,
            mapServerPhase: 1,
            extendBase64Img: "",
            saveMapIsOk: false,
            destroyFlag: false,
@@ -210,7 +217,6 @@
         async loadData() {
            try {
               // this.loadMapServerState()
               if (this.opType == "") {
                  this.localSceneList = await this.loadLocalScene()
               } else {
@@ -218,7 +224,9 @@
                     this.opSceneType = "add_name"
                  }
                  if (this.opType == "extend") {
                     this.mapServerPhase = 1
                     await addMap(this.ip, this.sceneName, "extend")
                     this.checkMapServerPhase()
                     this.opSceneType = 'scan'
                  }
                  // if (this.opType == "extend") {
@@ -234,7 +242,7 @@
                  // }
               }
               this.refreshMapLaserData()
@@ -252,58 +260,22 @@
               return {}
            }
         },
         async loadMapServerState() {
         async checkMapServerPhase() {
            try {
               this.mapserverIsOk = false
               const res = await checkMapServerIsStart(this.ip)
               if (res) {
                  this.mapserverIsOk = true
               } else {
                  this.mapserverIsOk = false
                  const res = await startOrStopMapServer(this.ip, 1)
                  if (res) {
                     this.checkMapServerState()
                  }
               const res = await getMapServerPhase(this.ip)
               this.mapServerPhase = res || 1
               if (this.mapServerPhase === 3) {
                  return
               }
            } catch (ex) {
               showError(ex)
            }
         },
         async checkMapServerState() {
            try {
               const res = await checkMapServerIsOk(this.ip)
               if (res) {
                  this.mapserverIsOk = true
               } else {
                  this.mapserverIsOk = false
                  setTimeout(this.checkMapServerState, 1000);
               }
            } catch (ex) {
               showError(ex).then((res) => {
                  setTimeout(this.checkMapServerState, 1000);
               })
            }
         },
         async checkSaveMapState() {
            try {
               const res = await checkSaveMapIsOk(this.ip)
               if (res) {
               if (this.mapServerPhase === 5 || this.mapServerPhase === 6) {
                  this.saveMapIsOk = true
               } else {
                  this.saveMapIsOk = false
                  setTimeout(this.checkSaveMapState, 1000);
                  return
               }
               setTimeout(this.checkMapServerPhase, 1000);
            } catch (ex) {
               showError(ex).then((res) => {
                  setTimeout(this.checkSaveMapState, 1000);
               })
               showToast(ex)
               setTimeout(this.checkMapServerPhase, 1000);
            }
         },
@@ -383,7 +355,9 @@
            try {
               this.mapId = ""
               if (this.opType == "extend") {
                  this.mapServerPhase = 1
                  await addMap(this.ip, this.sceneName, "extend")
                  this.checkMapServerPhase()
                  this.opSceneType = 'scan'
               } else {
                  this.opSceneType = "add_name"
@@ -437,6 +411,7 @@
               this.sceneName = name
               await createScene(this.ip, name, 1)
               await addMap(this.ip, name)
               this.checkMapServerPhase()
               uni.showLoading({
                  title: "开始扫描地图"
               })
@@ -476,8 +451,8 @@
               })
               this.saveMapIsOk = false
               await stopMap(this.ip, this.sceneName)
               // await startOrStopMapServer(this.ip, 2)
               // this.checkSaveMapState();
               this.mapServerPhase = 4
               this.checkMapServerPhase();
               // if (this.opType == "extend") {
               //    this.opSceneType = ""
               //    const eventChannel = this.getOpenerEventChannel();
@@ -486,13 +461,12 @@
               //       delta: 1, //返回层数,2则上上页
               //    })
               // }
               setTimeout(() => {this.saveMapIsOk = true}, 5000);
            } catch (ex) {
               console.log(ex)
               showModal("请检查车辆连接,并重新开始构建场景", "场景构建失败", false, "确定").then((res) => {
                  this.opSceneType = ''
                  // this.loadMapServerState()
               })
            } finally {
               this.loading = false
@@ -519,9 +493,28 @@
               this.loading = false
               uni.hideLoading()
            }
         },
         async clickRecreate() {
            try {
               if (this.opType == "extend") {
                  this.mapServerPhase = 1
                  await addMap(this.ip, this.sceneName, "extend")
                  this.checkMapServerPhase()
                  this.opSceneType = 'scan'
               } else {
                  this.mapServerPhase = 1
                  await delScene(this.ip, this.sceneName)
                  await createScene(this.ip, this.sceneName, 1)
                  await addMap(this.ip, this.sceneName)
                  this.checkMapServerPhase()
                  this.opSceneType = 'scan'
               }
            } catch (ex) {
               console.log(ex)
            }
         },
         async loadMapLaserData() {
            try {
               const info = await getMapLaserData(this.ip, this.mapId)
@@ -603,7 +596,7 @@
                     }
                  }
               }
               setTimeout(this.refreshMapLaserData, 1000);
            } catch (ex) {
               showToast(ex)