Files
apt15e/src/pages/modules/building.vue

412 lines
12 KiB
Vue
Raw Normal View History

2025-07-04 17:52:10 +08:00
<template>
<div class="page_container">
2025-08-13 18:06:35 +08:00
<gl-map ref="glMap"/>
2025-07-04 17:52:10 +08:00
<el-row type="flex" justify="space-between">
2025-07-15 13:59:05 +08:00
<el-col :span="10"><button class="button_control" :disabled="disabled" @click="addPoint"><p>打点</p></button></el-col>
2025-08-13 18:06:35 +08:00
<el-col :span="14">
<el-row type="flex" justify="end">
<button class="button_control" @click="$router.push('/index/home')"><p>放弃建图</p></button>
<button class="button_control" style="margin-left: 10px" :disabled="disabled" @click="stopMappingConfirm"><p>结束建图</p></button>
</el-row>
</el-col>
2025-07-16 10:49:07 +08:00
</el-row>
2025-07-14 09:28:21 +08:00
<el-dialog
title="设置站点"
:visible.sync="dialogVisible"
width="50%">
<el-form :model="dataForm" ref="dataForm" :label-width="$i18n.locale === 'en-us' ? '' : '1.1rem'" size="mini">
2025-08-08 17:44:36 +08:00
<el-form-item label="站点名称" prop="stationName">
<el-input v-model="dataForm.stationName" id="stationName" @focus="show" data-layout="normal"></el-input>
2025-07-14 09:28:21 +08:00
</el-form-item>
</el-form>
<el-row type="flex" justify="space-around" style="margin-top: .3rem">
<el-col :span="7"><button class="button_control button_control_disabled" @click="dialogVisible = false"><p>{{$t('Cancel')}}</p></button></el-col>
<el-col :span="7"><button class="button_control" @click="_setStation"><p>{{$t('Save')}}</p></button></el-col>
</el-row>
2025-08-11 14:42:41 +08:00
<!-- <vue-touch-keyboard id="keyboard" :options="options" v-if="visible" :layout="layout" :cancel="hide" :accept="accept" :input="input" :next="next" /> -->
2025-07-14 09:28:21 +08:00
</el-dialog>
2025-08-05 16:30:59 +08:00
<transition name="custom-message" >
<div v-if="message" class="message" :style="{'top': isTop ? '.87rem' : '.57rem', 'color': error ? '#F56C6C' : '#67C23A'}">
<i :class="error ? 'el-icon-error' : 'el-icon-success'"></i>
2025-07-16 10:49:07 +08:00
<p>{{ message }}</p>
</div>
</transition>
2025-08-08 17:44:36 +08:00
<div v-if="showProgress" class="progress-mask">
<!-- 进度条内容区 -->
<div class="progress-container">
2025-08-11 13:28:37 +08:00
<div class="progress_tip">{{warnTip ? '正在部署地图中...' : '正在生成地图中...'}}</div>
<el-progress
v-show="!warnTip"
2025-08-08 17:44:36 +08:00
:percentage="percentage"
2025-08-11 13:28:37 +08:00
:stroke-width="10"
2025-08-08 17:44:36 +08:00
style="width: 300px;"
></el-progress>
</div>
</div>
2025-07-04 17:52:10 +08:00
</div>
</template>
<script>
2025-08-08 17:44:36 +08:00
import GlMap from './gl-map.vue'
// import PointCloudMap from './point-cloud-map.vue'
// import { startMapping, stopMapping, getMappingStatus } from '../../config/mork.js'
import { startMapping, stopMapping, getMappingStatus, setStation, oneClickDeployment, abandonMapping } from '../../config/getData.js'
2025-08-05 16:30:59 +08:00
import { mapGetters } from 'vuex'
2025-07-04 17:52:10 +08:00
export default {
2025-08-05 14:20:40 +08:00
name: 'ModuleBuilding',
components: {
2025-08-08 17:44:36 +08:00
GlMap,
// PointCloudMap
2025-08-05 14:20:40 +08:00
},
2025-07-16 10:49:07 +08:00
beforeRouteLeave (to, from, next) {
2025-07-23 20:05:03 +08:00
if (this.needsConfirmation) {
this.$confirm('是否放弃本次建图?', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
2025-07-25 18:43:20 +08:00
}).then(async () => {
try {
// 显示加载中状态
this.loading = this.$loading({
lock: true,
spinner: 'el-icon-loading',
background: 'rgba(0, 0, 0, 0.6)'
})
// 调用放弃建图接口
const res = await abandonMapping()
this.loading.close()
if (res && res.code === 200) {
// 接口成功,允许离开页面
this.needsConfirmation = false // 标记无需再确认
next()
} else {
// 接口返回失败,提示错误并阻止离开
this.$message.error(res.message || '放弃建图失败,请重试')
next(false)
}
} catch (error) {
// 发生异常,提示错误并阻止离开
this.loading.close()
this.$message.error('操作失败:' + error.message)
next(false)
}
2025-07-23 20:05:03 +08:00
}).catch(() => {
next(false) // 阻止离开
})
} else {
next()
}
2025-07-16 10:49:07 +08:00
},
2025-07-04 17:52:10 +08:00
data () {
return {
2025-07-23 20:05:03 +08:00
needsConfirmation: true,
2025-07-14 17:52:37 +08:00
mapName: '',
2025-07-14 09:28:21 +08:00
dialogVisible: false,
dataForm: {
2025-08-08 17:44:36 +08:00
stationCode: '',
stationName: ''
2025-07-14 09:28:21 +08:00
},
keyPoints: [],
2025-07-15 13:59:05 +08:00
disabled: false,
message: '', // 用于显示消息
2025-08-05 16:30:59 +08:00
error: false,
2025-07-14 09:28:21 +08:00
visible: false,
layout: 'normal',
input: null,
options: {
useKbEvents: false,
preventClickEvent: false
2025-08-08 17:44:36 +08:00
},
showProgress: false,
2025-08-11 13:28:37 +08:00
warnTip: false,
2025-08-08 17:44:36 +08:00
percentage: 0,
intervalId: null // 用于存储定时器ID
2025-07-04 17:52:10 +08:00
}
},
2025-08-05 16:30:59 +08:00
computed: {
...mapGetters(['isTop'])
},
2025-07-04 17:52:10 +08:00
beforeDestroy () {
if (this.intervalId) {
2025-08-08 17:44:36 +08:00
clearTimeout(this.intervalId)
2025-07-04 17:52:10 +08:00
}
},
2025-07-16 10:49:07 +08:00
created () {
2025-07-14 09:28:21 +08:00
this._startMapping()
},
2025-07-04 17:52:10 +08:00
methods: {
2025-07-14 09:28:21 +08:00
show (e) {
// 关闭中文keyboard
let arr = document.querySelectorAll('.hg-theme-default')
arr.forEach((ele) => {
ele.style.visibility = 'hidden'
})
this.input = e.target
this.layout = e.target.dataset.layout
if (!this.visible) {
this.visible = true
}
},
hide () {
this.visible = false
},
accept () {
this.hide()
},
next () {
let inputs = document.querySelectorAll('input')
let found = false;
[].forEach.call(inputs, (item, i) => {
if (!found && item === this.input && i < inputs.length - 1 && this.input.dataset.next === '1') {
found = true
this.$nextTick(() => {
inputs[i + 1].focus()
})
}
})
if (!found) {
this.input.blur()
this.hide()
}
},
2025-07-15 13:59:05 +08:00
// 开始建图
2025-07-14 09:28:21 +08:00
async _startMapping () {
try {
2025-07-16 10:49:07 +08:00
this.loading = this.$loading({
lock: true,
spinner: 'el-icon-loading',
background: 'rgba(0, 0, 0, 0.6)'
})
2025-08-08 17:44:36 +08:00
const now = new Date()
const year = now.getFullYear()
const month = String(now.getMonth() + 1).padStart(2, '0') // 月份从0开始补0
const day = String(now.getDate()).padStart(2, '0')
const hours = String(now.getHours()).padStart(2, '0')
const minutes = String(now.getMinutes()).padStart(2, '0')
const seconds = String(now.getSeconds()).padStart(2, '0')
this.mapName = `apt_map_${year}${month}${day}${hours}${minutes}${seconds}`
2025-07-14 17:52:37 +08:00
let res = await startMapping(this.mapName)
2025-07-16 10:49:07 +08:00
if (res && res.code === 200) {
this.message = '小车正在建图中'
2025-08-05 16:30:59 +08:00
this.error = false
2025-08-08 17:44:36 +08:00
this.$nextTick(() => {
this.$refs.glMap.init()
})
2025-07-14 09:28:21 +08:00
}
2025-07-16 10:49:07 +08:00
this.loading.close()
2025-07-14 09:28:21 +08:00
} catch (e) {
2025-08-05 16:30:59 +08:00
this.message = '建图出现错误,需要重新建图'
this.error = true
2025-07-16 10:49:07 +08:00
this.loading.close()
2025-07-14 09:28:21 +08:00
}
},
2025-07-15 13:59:05 +08:00
// 打点
2025-07-04 17:52:10 +08:00
addPoint () {
2025-07-14 09:28:21 +08:00
this.dialogVisible = true
2025-08-08 17:44:36 +08:00
this.dataForm.stationCode = 'B' + (this.keyPoints.length + 1)
2025-08-11 13:28:37 +08:00
this.dataForm.stationName = '工作点' + (this.keyPoints.length + 1)
2025-07-14 09:28:21 +08:00
},
2025-07-15 13:59:05 +08:00
// 打点->保存
2025-07-14 09:28:21 +08:00
async _setStation () {
2025-07-15 13:59:05 +08:00
this.disabled = true
2025-07-14 09:28:21 +08:00
try {
2025-08-08 17:44:36 +08:00
let res = await setStation(this.dataForm.stationName, this.dataForm.stationCode)
2025-07-14 09:28:21 +08:00
if (res) {
if (res.code === 200) {
this.$message({
type: 'success',
message: res.message
})
2025-08-08 17:44:36 +08:00
this.keyPoints.push(this.dataForm.stationCode)
2025-07-14 09:28:21 +08:00
} else {
this.$message.error(res.message)
}
}
2025-07-14 17:52:37 +08:00
this.dialogVisible = false
2025-07-14 09:28:21 +08:00
this.visible = false
2025-07-15 13:59:05 +08:00
this.disabled = false
2025-07-14 09:28:21 +08:00
} catch (e) {
this.$message.error(e)
2025-07-14 17:52:37 +08:00
this.dialogVisible = false
2025-07-14 09:28:21 +08:00
this.visible = false
2025-07-15 13:59:05 +08:00
this.disabled = false
2025-07-14 09:28:21 +08:00
}
},
2025-08-12 19:52:18 +08:00
stopMappingConfirm () {
this.$confirm('确定是否结束建图?', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(() => {
this._stopMapping()
}).catch(() => {
this.$message({
type: 'info',
message: '已取消结束建图'
})
})
},
2025-07-15 13:59:05 +08:00
// 结束建图
2025-07-14 09:28:21 +08:00
async _stopMapping () {
2025-07-15 13:59:05 +08:00
this.disabled = true
2025-07-14 09:28:21 +08:00
try {
2025-07-16 10:49:07 +08:00
this.loading = this.$loading({
lock: true,
spinner: 'el-icon-loading',
background: 'rgba(0, 0, 0, 0.6)'
})
2025-07-14 09:28:21 +08:00
let res = await stopMapping()
2025-07-16 10:49:07 +08:00
if (res && res.code === 200) {
this.message = ''
2025-08-05 16:30:59 +08:00
this.error = false
2025-08-08 17:44:36 +08:00
this.$nextTick(() => {
this.$refs.glMap.closeWebSocket()
})
this._getMappingStatus()
2025-07-15 13:59:05 +08:00
}
2025-08-08 17:44:36 +08:00
this.disabled = false
this.loading.close()
2025-07-15 13:59:05 +08:00
} catch (e) {
2025-08-08 17:44:36 +08:00
this.message = '结束建图出现错误'
this.error = true
2025-07-15 13:59:05 +08:00
this.disabled = false
2025-07-16 10:49:07 +08:00
this.loading.close()
2025-07-15 13:59:05 +08:00
}
},
2025-08-08 17:44:36 +08:00
// 进度条
async _getMappingStatus () {
2025-07-15 13:59:05 +08:00
try {
2025-08-08 17:44:36 +08:00
let res = await getMappingStatus()
2025-08-11 13:28:37 +08:00
this.showProgress = true
this.percentage = Number(res.mapping_percent) || 0
if (res.mapping_return === '0') {
if (this.intervalId) clearTimeout(this.intervalId)
this.intervalId = setTimeout(() => this._getMappingStatus(), 1000)
}
if (res.mapping_return === '1') {
if (this.intervalId) clearTimeout(this.intervalId)
this.warnTip = true
this.percentage = 0
this._oneClickDeployment()
}
if (res.mapping_return === '2') {
if (this.intervalId) clearTimeout(this.intervalId)
this.showProgress = false
this.percentage = 0
this.keyPoints = []
this.$confirm('新建地图失败, 是否重新建图?', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(() => {
this._startMapping()
}).catch(() => {
this.$message({
type: 'info',
message: '已取消建图'
2025-08-08 17:44:36 +08:00
})
2025-08-11 13:28:37 +08:00
})
2025-07-14 17:52:37 +08:00
}
} catch (e) {
2025-07-15 13:59:05 +08:00
this.message = ''
2025-08-05 16:30:59 +08:00
this.error = false
2025-08-08 17:44:36 +08:00
this.keyPoints = []
this.$confirm('新建地图失败, 是否重新建图?', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(() => {
this._startMapping()
}).catch(() => {
this.$message({
type: 'info',
message: '已取消建图'
})
})
2025-07-14 17:52:37 +08:00
}
},
async _oneClickDeployment () {
try {
let res = await oneClickDeployment(this.mapName)
2025-07-16 10:49:07 +08:00
if (res && res.code === 200) {
this.$message({
type: 'success',
message: res.message
})
2025-07-23 20:05:03 +08:00
this.needsConfirmation = false
2025-07-16 10:49:07 +08:00
this.$router.push('/index/home')
} else {
this.$message.error(res.message)
2025-07-14 09:28:21 +08:00
}
2025-08-11 13:28:37 +08:00
this.showProgress = false
this.warnTip = false
2025-07-16 10:49:07 +08:00
this.message = ''
2025-08-05 16:30:59 +08:00
this.error = false
2025-07-16 10:49:07 +08:00
this.disabled = false
this.loading.close()
2025-07-14 09:28:21 +08:00
} catch (e) {
2025-08-11 13:28:37 +08:00
this.showProgress = false
this.warnTip = false
2025-07-14 09:28:21 +08:00
this.$message.error(e)
2025-07-15 13:59:05 +08:00
this.message = ''
2025-08-05 16:30:59 +08:00
this.error = false
2025-07-15 13:59:05 +08:00
this.disabled = false
2025-07-16 10:49:07 +08:00
this.loading.close()
2025-07-04 17:52:10 +08:00
}
}
}
}
</script>
<style lang="stylus" scoped>
2025-07-16 10:49:07 +08:00
.message
min-width 380px
border 1px solid #e1f3d8
border-radius 4px
2025-07-15 13:59:05 +08:00
position fixed
2025-07-16 10:49:07 +08:00
left 50%
transform translateX(-50%)
background-color #f0f9eb
transition opacity .3s,transform .4s
overflow hidden
padding 8px 15px
2025-07-15 13:59:05 +08:00
z-index 2025
display flex
align-items center
2025-07-16 10:49:07 +08:00
font-size .16rem
list-height 1
p
margin-left 10px
.custom-message-enter, .custom-message-leave-to
opacity 0
transform translate(-50%,-100%)
2025-08-08 17:44:36 +08:00
.progress-mask {
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
background-color: rgba(0, 0, 0, 0.6); /* 半透明黑色遮罩 */
z-index: 9999; /* 确保在最上层 */
display: flex;
justify-content: center;
align-items: center;
}
/* 进度条容器 */
.progress-container {
background-color: #fff;
padding: 30px 40px;
border-radius: 8px;
text-align: center;
box-shadow: 0 2px 12px rgba(0, 0, 0, 0.1);
}
2025-08-11 13:28:37 +08:00
.progress_tip {
font-size: .2rem
line-height: .34rem
color: #000
font-weight: 700
}
2025-07-04 17:52:10 +08:00
</style>