From 2af5f043b60c1f7ac38ecccc8f5bf44743134325 Mon Sep 17 00:00:00 2001
From: cuiqian2004 <cuiqian2004@163.com>
Date: 星期五, 12 十二月 2025 18:08:00 +0800
Subject: [PATCH] test

---
 pages/map/scene.vue |  472 +++++++++++++++++++++++++++++++++++++++++++++-------------
 1 files changed, 361 insertions(+), 111 deletions(-)

diff --git a/pages/map/scene.vue b/pages/map/scene.vue
index 4da13fa..c0f2929 100644
--- a/pages/map/scene.vue
+++ b/pages/map/scene.vue
@@ -1,57 +1,73 @@
 <template>
 	<view class="pages-scene">
 		<view class="map-content" v-if="opSceneType =='' ">
-			<image class="img" src="/images/image 25.png" alt=" 鍥剧墖" mode="aspectFit" />
-			<view 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'?translate("start_extending"):translate("start_building")}}
 				</a-button>
-				<a-button 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>
 		<view class="content" v-show="opSceneType =='scan'">
 			<view class="fabric" :message="ctxDataStr" :change:message="ctx.receiveMsg" id="canvasMap"></view>
+			<view class="position" @click="clickVehiclePosition">
+				<text class="ico my-location-rounded"></text>
+			</view>
 		</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>
+					<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">鍦烘櫙鏋勫缓瀹屾垚</view>
-				<view>
-					宸叉垚鍔熸瀯寤衡�{{sceneName}}鈥�+				<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="loading" @click="clickFinish">鏋勫缓瀹屾垚</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>
@@ -64,6 +80,8 @@
 		showToast,
 		showModal,
 		session,
+		showError,
+		showInfo
 	} from "@/comm/utils.js"
 	import {
 		Button
@@ -73,9 +91,16 @@
 		createScene,
 		addMap,
 		stopMap,
+		delScene,
 		//getAgvState,
 		getMapLaserData,
 		saveDBData,
+		// checkMapServerIsStart,
+		// startOrStopMapServer,
+		// checkMapServerIsOk,
+		// checkSaveMapIsOk,
+		getMapServerPhase,
+		getMapUrl
 
 	} from "@/api/vehicle.js"
 	export default {
@@ -94,17 +119,39 @@
 				showClearName: false,
 				mapId: "",
 				ctxDataStr: "[]",
-				localSceneList: []
+				localSceneList: [],
+				positioningAgv: true,
+				robotPos: {},
+				mapServerPhase: 1,
+				extendBase64Img: "",
+				saveMapIsOk: false,
+				destroyFlag: false,
 
 			}
 		},
 		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: {
 
 		},
 		onLoad(option) {
+			console.log("scene load")
 			const _this = this
 			this.ip = option.ip || ""
 			uni.getSystemInfo({
@@ -120,16 +167,22 @@
 
 		},
 		onUnload() {
-
+			console.log("scene unload")
 		},
 		onBackPress() {
 
 			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 != "") {
+
 							uni.navigateBack({
 								delta: 1, //杩斿洖灞傛暟锛�鍒欎笂涓婇〉
 							})
@@ -139,8 +192,28 @@
 				})
 				return true
 
+			} else if (this.opSceneType == "finish") {
+				if (this.destroyFlag) {
+
+					const eventChannel = this.getOpenerEventChannel();
+					eventChannel.emit('create_finish', this.sceneName);
+					return false
+				} else {
+					this.ctxDataStr = JSON.stringify([{
+						method: "destroy",
+					}])
+					return true
+				}
+
 			} else {
-				return false
+				if (this.destroyFlag)
+					return false
+				else {
+					this.ctxDataStr = JSON.stringify([{
+						method: "destroy",
+					}])
+					return true
+				}
 			}
 
 		},
@@ -176,9 +249,23 @@
 							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") {
+						// 	// const infoMap = await this.loadMapInfo(this.sceneName)
+						// 	// if (infoMap.filedata) {
+						// 	// 	var base64Image = infoMap.filedata
+						// 	// 	if (base64Image.indexOf("data:image/png;base64,") < 0) {
+						// 	// 		base64Image = "data:image/png;base64," + infoMap.filedata
+						// 	// 	}
+						// 	// 	this.extendBase64Img = base64Image
+						// 	// }
+
+						// }
+
 					}
 
 					this.refreshMapLaserData()
@@ -186,12 +273,47 @@
 
 				} catch (ex) {
 
-					this.showError(ex)
+					showError(ex, this.translate('error'))
 				}
 			},
+			async loadMapInfo(id) {
+				try {
+					const info = await getMapUrl(this.ip, id)
+					return info
+				} catch (ex) {
+
+					return {}
+				}
+			},
+			async checkMapServerPhase() {
+				try {
+
+					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) {
+					showToast(ex)
+					setTimeout(this.checkMapServerPhase, 1000);
+				}
+			},
+
 			receiveRenderData(param) {
 				console.log('鎺ユ敹鍒拌鍥惧眰鐨勬暟鎹細', param);
-				if (param.method == "set_backgroud_progress") {
+
+				if (param.method === "destroy_complete") {
+					if (param.param) {
+						this.destroyFlag = true
+						uni.navigateBack({
+							delta: 1
+						})
+					}
+				} else if (param.method == "set_backgroud_progress") {
 					if (param.type == "start") {
 						this.setData({
 							bgProgressPercent: 50,
@@ -213,12 +335,34 @@
 						}, 500)
 
 					} else if (param.type == "error") {
+						console.log("set_backgroud_progress error")
 						this.setData({
 							bgProgressPercent: 0,
 							bgLoading: false
 						})
+						const now = new Date()
+						const date = `${now.getHours()}:${now.getMinutes()}:${now.getSeconds()}`
+						showToast(this.translate("loading_base_map_failed"))
+						const log = {
+							date,
+							method: `POST`,
+							url: "app/log/load_img",
+							param: param.msg,
+							statusCode: 100,
+							data: this.translate("loading_base_map_failed")
+						}
+						const listLog = session.getValue("request_log") || []
+						listLog.unshift(log)
+						session.setValue("request_log", listLog)
+
 					}
 
+				} else if (param.method == "cancel_positioning_agv") {
+					//this.positioningAgv = false
+				} else if (param.method == "show_log") {
+					const listLog = session.getValue("request_log") || []
+					listLog.unshift(param.data)
+					session.setValue("request_log", listLog)
 				}
 			},
 
@@ -227,30 +371,46 @@
 					const list = session.getValue("scene_db") || []
 					return list
 				} catch (ex) {
-					this.showError(ex)
+					showError(ex, this.translate('error'))
 					return []
 				}
 			},
-			clickStartConstructScene() {
-				this.opSceneType = "add_name"
+			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, 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, //杩斿洖灞傛暟锛�鍒欎笂涓婇〉
-					})
+					// 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, //杩斿洖灞傛暟锛�鍒欎笂涓婇〉
+					// })
 				} catch (ex) {
-					this.showError(ex)
+					showError(ex, this.translate('error'))
 				} finally {
 					this.loading = false
 					uni.hideLoading()
@@ -268,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) {
-					this.showError(ex)
+					showError(ex, this.translate('error'))
 					this.opSceneType = 'add_name'
 				} finally {
 					this.loading = false
@@ -309,31 +471,35 @@
 				try {
 					this.loading = true
 					uni.showLoading({
-						title: "鍦板浘鎵弿缁撴潫"
+						title: this.translate("end_scanning_map")
 					})
 					this.opSceneType = "finish"
 					uni.setNavigationBarTitle({
 						title: this.sceneName
 					})
+					this.saveMapIsOk = false
 					await stopMap(this.ip, this.sceneName)
-					if (this.opType == "extend") {
-						this.opSceneType = ""
-						const eventChannel = this.getOpenerEventChannel();
-						eventChannel.emit('create_finish', this.sceneName);
-						uni.navigateBack({
-							delta: 1, //杩斿洖灞傛暟锛�鍒欎笂涓婇〉
-						})
-					}
+					//this.mapServerPhase = 4
+					//this.checkMapServerPhase();
+					// if (this.opType == "extend") {
+					// 	this.opSceneType = ""
+					// 	const eventChannel = this.getOpenerEventChannel();
+					// 	eventChannel.emit('create_finish', this.sceneName);
+					// 	uni.navigateBack({
+					// 		delta: 1, //杩斿洖灞傛暟锛�鍒欎笂涓婇〉
+					// 	})
+					// }
 
 				} catch (ex) {
-
-					showModal("璇锋鏌ヨ溅杈嗚繛鎺ワ紝骞堕噸鏂板紑濮嬫瀯寤哄満鏅�, "鍦烘櫙鏋勫缓澶辫触", false, "纭畾").then((res) => {
+					console.log(ex)
+					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 = ''
-						if (this.opType != "") {
-							uni.navigateBack({
-								delta: 1, //杩斿洖灞傛暟锛�鍒欎笂涓婇〉
-							})
-						}
+
 					})
 				} finally {
 					this.loading = false
@@ -346,37 +512,48 @@
 
 					this.loading = true
 					uni.showLoading({
-						title: "缁撴潫鍦烘櫙鏋勫缓"
+						title: this.translate("scene_construction_completed")
 					})
 					this.opSceneType = ""
-					await createScene(this.ip, this.sceneName, 0)
 					const eventChannel = this.getOpenerEventChannel();
 					eventChannel.emit('create_finish', this.sceneName);
 					uni.navigateBack({
 						delta: 1, //杩斿洖灞傛暟锛�鍒欎笂涓婇〉
 					})
 				} catch (ex) {
-					showModal("璇锋鏌ヨ溅杈嗚繛鎺ワ紝骞堕噸鏂板紑濮嬫瀯寤哄満鏅�, "鍦烘櫙鏋勫缓澶辫触", false, "纭畾").then((res) => {
-						this.opSceneType = ''
-						if (this.opType != "") {
-							uni.navigateBack({
-								delta: 1, //杩斿洖灞傛暟锛�鍒欎笂涓婇〉
-							})
-						}
-					})
+					console.log(ex)
 				} finally {
 					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)
 					return info
 				} catch (ex) {
-					this.showError(ex)
+					showToast(ex)
 					return {}
 				}
 			},
@@ -387,69 +564,105 @@
 						const data = await this.loadMapLaserData()
 
 						const listCtrData = []
+						let newMap = false
 						if (data.base_map?.image_base64) {
-
+							this.robotPos = {}
+							newMap = true
+							const mapData = data.base_map.image_base64 //this.mapId ?"terdy": 
 							this.mapId = data.base_map.map_id
+
 							listCtrData.push({
 								method: "background",
 								param: {
 									proportion: 1,
 									img_proportion: 1,
-									max_x: data.base_map.width,
-									max_y: data.base_map.height,
+									max_x: data.base_map.width || 100,
+									max_y: data.base_map.height || 100,
 									min_x: 0,
 									min_y: 0,
-									img_x: data.base_map.width,
-									img_y: data.base_map.height,
-									filedata: data.base_map.image_base64
+									img_x: data.base_map.width || 100,
+									img_y: data.base_map.height || 100,
+									filedata: mapData
 								}
 							})
 							listCtrData.push({
-								method: "agv_laser",
-								param: data.robot_pose
-							})
-							listCtrData.push({
-								method: "point_cloud",
-								param: data.point_cloud
-							})
-							listCtrData.push({
-								method: "move_canvas",
-								param: {
-									x: data.robot_pose.x,
-									y: data.robot_pose.y
-								}
+								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],]
 							})
 
-						} else {
+						}
+
+						listCtrData.push({
+							method: "point_cloud",
+							param: data.point_cloud
+						})
+
+
+						if (data.robot_pose) {
 							listCtrData.push({
 								method: "agv_laser",
 								param: data.robot_pose
 							})
-							listCtrData.push({
-								method: "point_cloud",
-								param: data.point_cloud
-							})
+							if (newMap) {
+								listCtrData.push({
+									method: "move_pt_center",
+									param: {
+										x: data.robot_pose.x,
+										y: data.robot_pose.y,
+									}
+								})
+							} else {
+								if (this.positioningAgv) {
+									listCtrData.push({
+										method: "move_pt_visible",
+										param: {
+											x: data.robot_pose.x,
+											y: data.robot_pose.y,
+											width: 50,
+											height: 50,
+										}
+									})
+								}
+							}
+
 						}
+						// console.log("ctxDataStr",listCtrData.length)
 						this.ctxDataStr = JSON.stringify(listCtrData)
+						if (data.robot_pose) {
+							this.robotPos = {
+								x: data.robot_pose.x,
+								y: data.robot_pose.y
+							}
+						}
 					}
+
+					setTimeout(this.refreshMapLaserData, 1000);
 				} catch (ex) {
-					this.showError(ex)
-				} finally {
-					// 鏃犺鎴愬姛澶辫触锛� 绉掑悗鍐嶆潵
+					showToast(ex)
 					setTimeout(this.refreshMapLaserData, 1000);
 				}
 			},
+			async clickVehiclePosition() {
+				this.positioningAgv = true
 
-			showError(ex) {
-				console.log(ex)
-				let exStr = JSON.stringify(ex)
-				if (exStr == "{}")
-					exStr = ex
-				let tip = typeof ex.msg == "string" ? ex.msg : exStr
-				showModal(tip, "閿欒", false, "纭畾")
+				if (this.robotPos.x) {
+					this.ctxDataStr = JSON.stringify([{
+						method: "move_pt_center",
+						param: {
+							x: this.robotPos.x,
+							y: this.robotPos.y
+						}
+					}])
+				}
+
+
 			},
 
-
+			translate(t) {
+				if (typeof this.$t == "function") return this.$t(`page.${t}`)
+				else return t;
+			},
 		}
 	}
 </script>
@@ -475,6 +688,16 @@
 				background-color: #fff;
 			}
 
+			.position {
+				position: absolute;
+				right: 50rpx;
+				bottom: 500rpx;
+
+				.ico {
+					font-size: 65rpx;
+					color: #1890FF;
+				}
+			}
 
 		}
 
@@ -488,6 +711,7 @@
 			justify-content: center;
 
 
+
 			.text-button-group {
 				display: flex;
 				width: 100%;
@@ -504,6 +728,32 @@
 
 		}
 
+		.loading-view {
+			display: flex;
+			flex-direction: row;
+
+			.auto-circle {
+				margin-left: 20rpx;
+				width: 50rpx;
+				height: 50rpx;
+				border-radius: 50%;
+				border: 10rpx solid #1890FF;
+				border-top-color: transparent;
+				animation: drawCircle 1s infinite linear;
+			}
+
+			@keyframes drawCircle {
+				0% {
+					transform: rotate(0deg);
+				}
+
+				100% {
+					transform: rotate(360deg);
+				}
+			}
+
+		}
+
 
 		.bottom {
 			position: fixed;

--
Gitblit v1.9.1