cuiqian2004
5 天以前 2af5f043b60c1f7ac38ecccc8f5bf44743134325
pages/map/scene.vue
@@ -1,20 +1,22 @@
<template>
   <view class="pages-scene">
      <view class="map-content" v-if="opSceneType =='' ">
         <image v-if="opType != 'extend'" class="img" src="/images/image_25.png" alt=" 图片" mode="aspectFit" />
         <image v-else class="img" :src="extendBase64Img" alt=" 图片" mode="aspectFit" />
         <view v-if="opType != 'extend'" class="space">没有找到符合条件的地图</view>
         <image v-if="opType != 'extend'" class="img" src="/images/image_25.png" alt=" picture" mode="aspectFit" />
         <image v-else class="img" :src="extendBase64Img" alt=" picture" mode="aspectFit" />
         <view v-if="opType != 'extend'" class="space">{{translate("no_map_found")}}</view>
         <!-- <view class="loading-view">{{mapserverIsOk?"构图程序准备就绪":"等待构图程序就绪..."}}
            <view v-if="!mapserverIsOk" class="auto-circle"></view>:disabled="!mapserverIsOk" 
         </view> -->
         <view class="text-button-group">
            <a-button type="primary" class="button" @click="clickStartConstructScene">
               {{opType == 'extend'?"开始扩展":'开始构建'}}
               {{opType == 'extend'?translate("start_extending"):translate("start_building")}}
            </a-button>
            <a-button v-if="opType != 'extend'" type="primary" class="button"
               :disabled="loading && localSceneList.length == 0" @click="clickDownloadScene" disabled>
               下载场景
            </a-button>
            <navigator :url="`/pages/index/backup?ip=${ip}&opType=download`" hover-class="other-navigator-hover">
               <a-button v-if="opType != 'extend'" type="primary" class="button"
                  :disabled="loading && localSceneList.length == 0">
                  {{translate("download_scenes")}}
               </a-button>
            </navigator>
         </view>
      </view>
@@ -26,38 +28,46 @@
      </view>
      <view class="bottom">
         <view class="bottom-content" v-if="opSceneType =='add_name' ">
            <view class="tip">请输入场景名称</view>
            <view class="tip">{{translate('input_scene_name')}}</view>
            <view class="name-input">
               <input ref="refInputName" :focus="true" placeholder="请输入场景名称" :value="sceneName"
                  @input="onInputName" />
               <input ref="refInputName" :focus="true" :placeholder="translate('input_scene_name')"
                  :value="sceneName" @input="onInputName" />
               <uni-icons class="clear" color="#ccc" type="clear" size="20" v-if="showClearName"
                  @click="clickClearName"></uni-icons>
            </view>
            <view class="text-button-group">
               <a-button type="primary" class="button" :disabled="loading || sceneName.trim() == ''"
                  @click="clickNameOK">确认</a-button>
                  @click="clickNameOK">{{translate("confirm")}}</a-button>
               <a-button type="ghost" class="button" :disabled="loading" @click="clickNameCancel">取消</a-button>
            </view>
         </view>
         <view class="bottom-content" v-else-if="opSceneType =='scan'">
            <view class="tip">场景构建中</view>
            <view class="tip">{{translate("scene_construction_in_progress")}}</view>
            <view>
               请操作搬运车扫描地图覆盖的区域
               <!-- 请操作搬运车扫描地图覆盖的区域 -->
               {{mapCreatePhase}}
            </view>
            <view class="text-button-group">
               <a-button type="primary" class="button" :disabled="loading" @click="clickScanFinish">扫描完成</a-button>
               <a-button type="primary" class="button" :disabled="loading"
                  @click="clickScanFinish">{{translate("scan_completed")}}</a-button>
            </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"?translate("scene_extend_completed"):translate("scene_construction_completed")}}
            </view>
            <!--    <view> 已成功构建“{{sceneName}}”</view> -->
            <view class="loading-view">
               {{mapCreatePhase}}
               <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"?translate('re_extend'):translate("rebuild")}}</a-button>
               <a-button type="primary" class="button" v-else :disabled=" mapServerPhase !==5 || loading"
                  @click="clickFinish">{{opType == "extend"?translate("extend_completed"):translate("construction_completed")}}</a-button>
            </view>
         </view>
      </view>
@@ -81,13 +91,15 @@
      createScene,
      addMap,
      stopMap,
      delScene,
      //getAgvState,
      getMapLaserData,
      saveDBData,
      checkMapServerIsStart,
      startOrStopMapServer,
      checkMapServerIsOk,
      checkSaveMapIsOk,
      // checkMapServerIsStart,
      // startOrStopMapServer,
      // checkMapServerIsOk,
      // checkSaveMapIsOk,
      getMapServerPhase,
      getMapUrl
   } from "@/api/vehicle.js"
@@ -110,7 +122,7 @@
            localSceneList: [],
            positioningAgv: true,
            robotPos: {},
            mapserverIsOk: false,
            mapServerPhase: 1,
            extendBase64Img: "",
            saveMapIsOk: false,
            destroyFlag: false,
@@ -118,7 +130,22 @@
         }
      },
      computed: {
         mapCreatePhase() {
            if (this.mapServerPhase == 1) {
               return this.translate("scene_construction_service_not_start")
            } else if (this.mapServerPhase == 2) {
               return this.translate("scene_construction_service_starting")
            } else if (this.mapServerPhase == 3) {
               return this.translate("scene_construction_in_progress")
            } else if (this.mapServerPhase == 4) {
               return this.translate("scene_composition_saving")
            } else if (this.mapServerPhase == 5) {
               return this.translate("scene_composition_save_success")
            } else if (this.mapServerPhase == 6) {
               return this.translate("scene_composition_save_failed")
            } else
               return this.mapServerPhase
         }
      },
      watch: {
@@ -146,7 +173,12 @@
         if (this.opSceneType == "scan") {
            showModal("已构建场景将会被删除", "是否中断场景构建?").then((res) => {
            showModal({
               title: this.translate("ask_interrupt_scene_construction"),
               content: `${this.translate('built_scene_will_be_deleted')}`,
               confirmText: this.translate('yes'),
               cancelText: this.translate("no"),
            }).then((res) => {
               if (res) {
                  this.opSceneType = ""
                  if (this.opType != "") {
@@ -210,7 +242,6 @@
         async loadData() {
            try {
               // this.loadMapServerState()
               if (this.opType == "") {
                  this.localSceneList = await this.loadLocalScene()
               } else {
@@ -218,7 +249,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,12 +267,13 @@
                  // }
               }
               this.refreshMapLaserData()
            } catch (ex) {
               showError(ex)
               showError(ex, this.translate('error'))
            }
         },
         async loadMapInfo(id) {
@@ -251,58 +285,21 @@
               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.opSceneType === "finish") {
                  if (this.mapServerPhase === 5 || this.mapServerPhase === 6) {
                     this.saveMapIsOk = true
                     return
                  }
               }
               setTimeout(this.checkMapServerPhase, 1000);
            } 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) {
                  this.saveMapIsOk = true
               } else {
                  this.saveMapIsOk = false
                  setTimeout(this.checkSaveMapState, 1000);
               }
            } catch (ex) {
               showError(ex).then((res) => {
                  setTimeout(this.checkSaveMapState, 1000);
               })
               showToast(ex)
               setTimeout(this.checkMapServerPhase, 1000);
            }
         },
@@ -345,14 +342,14 @@
                  })
                  const now = new Date()
                  const date = `${now.getHours()}:${now.getMinutes()}:${now.getSeconds()}`
                  showToast("加载底图失败")
                  showToast(this.translate("loading_base_map_failed"))
                  const log = {
                     date,
                     method: `POST`,
                     url: "app/log/load_img",
                     param: param.msg,
                     statusCode: 100,
                     data: "加载底图失败"
                     data: this.translate("loading_base_map_failed")
                  }
                  const listLog = session.getValue("request_log") || []
                  listLog.unshift(log)
@@ -374,39 +371,46 @@
               const list = session.getValue("scene_db") || []
               return list
            } catch (ex) {
               showError(ex)
               showError(ex, this.translate('error'))
               return []
            }
         },
         async clickStartConstructScene() {
            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"
               }
            } catch (ex) {
               showError(ex)
               showError(ex, this.translate('error'))
            }
         },
         async clickDownloadScene() {
            try {
               this.loading = true
               uni.showLoading({
                  title: "下载场景中"
               uni.navigateTo({
                  url: `/pages/index/backup?ip=${this.ip}&opType=download`,
               })
               const data = this.localSceneList[0].data
               await saveDBData(this.ip, data)
               showToast("下载场景成功")
               this.opSceneType = ""
               const eventChannel = this.getOpenerEventChannel();
               eventChannel.emit('create_finish', this.sceneName);
               uni.navigateBack({
                  delta: 1, //返回层数,2则上上页
               })
               // this.loading = true
               // uni.showLoading({
               //    title: this.translate("downloading_scene")
               // })
               // const data = this.localSceneList[0].data
               // await saveDBData(this.ip, data)
               // showToast(this.translate("download_scene_success"))
               // this.opSceneType = ""
               // const eventChannel = this.getOpenerEventChannel();
               // eventChannel.emit('create_finish', this.sceneName);
               // uni.navigateBack({
               //    delta: 1, //返回层数,2则上上页
               // })
            } catch (ex) {
               showError(ex)
               showError(ex, this.translate('error'))
            } finally {
               this.loading = false
               uni.hideLoading()
@@ -424,25 +428,27 @@
            try {
               this.loading = true
               uni.showLoading({
                  title: "开始构建场景"
                  title: this.translate("start_building")
               })
               const name = this.sceneName.trim()
               if (!name) {
                  showToast("站点名称还未输入")
                  showToast(this.translate("input_scene_name"))
                  return
               }
               this.sceneName = name
               await createScene(this.ip, name, 1)
               await addMap(this.ip, name)
               this.checkMapServerPhase()
               uni.showLoading({
                  title: "开始扫描地图"
                  title: this.translate("start_scanning_map")
               })
               this.mapId = ""
               this.opSceneType = 'scan'
            } catch (ex) {
               showError(ex)
               showError(ex, this.translate('error'))
               this.opSceneType = 'add_name'
            } finally {
               this.loading = false
@@ -465,7 +471,7 @@
            try {
               this.loading = true
               uni.showLoading({
                  title: "地图扫描结束"
                  title: this.translate("end_scanning_map")
               })
               this.opSceneType = "finish"
               uni.setNavigationBarTitle({
@@ -473,8 +479,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();
@@ -483,13 +489,17 @@
               //       delta: 1, //返回层数,2则上上页
               //    })
               // }
               setTimeout(() => {this.saveMapIsOk = true}, 5000);
            } catch (ex) {
               console.log(ex)
               showModal("请检查车辆连接,并重新开始构建场景", "场景构建失败", false, "确定").then((res) => {
               showModal({
                  title: this.translate("scene_construction_failed"),
                  content: `${this.translate('check_vehicle_connection_and_restart_building_scene')}`,
                  confirmText: this.translate('ok'),
                  showCancel: false
               }).then((res) => {
                  this.opSceneType = ''
                  // this.loadMapServerState()
               })
            } finally {
               this.loading = false
@@ -502,7 +512,7 @@
               this.loading = true
               uni.showLoading({
                  title: "结束场景构建"
                  title: this.translate("scene_construction_completed")
               })
               this.opSceneType = ""
               const eventChannel = this.getOpenerEventChannel();
@@ -516,9 +526,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)
@@ -556,7 +585,11 @@
                           filedata: mapData
                        }
                     })
                     listCtrData.push({
                        method: "point_trajectory",
                        param: data.base_map.trajectoryPoints ||
                        [] //[ [[2,2],[6,2],[10,2],[14,2],[18,2],[2,6],[2,10],[2,14],[2,18],]
                     })
                  }
@@ -564,6 +597,8 @@
                     method: "point_cloud",
                     param: data.point_cloud
                  })
                  if (data.robot_pose) {
                     listCtrData.push({
                        method: "agv_laser",
@@ -590,6 +625,7 @@
                           })
                        }
                     }
                  }
                  // console.log("ctxDataStr",listCtrData.length)
                  this.ctxDataStr = JSON.stringify(listCtrData)
@@ -600,6 +636,7 @@
                     }
                  }
               }
               setTimeout(this.refreshMapLaserData, 1000);
            } catch (ex) {
               showToast(ex)
@@ -622,7 +659,10 @@
         },
         translate(t) {
            if (typeof this.$t == "function") return this.$t(`page.${t}`)
            else return t;
         },
      }
   }
</script>