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

272 lines
7.8 KiB
Vue
Raw Normal View History

2025-07-04 17:52:10 +08:00
<template>
<div class="page_container">
<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-07-04 17:52:10 +08:00
<el-col :span="14">
<el-row type="flex" justify="end">
<el-button type="primary" icon="el-icon-zoom-in" size="mini" @click="zoomIn">放大</el-button>
<el-button type="primary" icon="el-icon-zoom-out" size="mini" @click="zoomOut">缩小</el-button>
</el-row>
</el-col>
</el-row>
<div class="canvas-container">
<canvas id="canvas" ref="canvas" width="1920" height="1080"></canvas>
</div>
2025-07-15 13:59:05 +08:00
<el-row type="flex" justify="end"><button class="button_control" :disabled="disabled" @click="_stopMapping"><p>结束建图</p></button></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">
<el-form-item label="站点名称" prop="point">
<el-input v-model="dataForm.point" id="point" @focus="show" data-layout="normal"></el-input>
</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>
<vue-touch-keyboard id="keyboard" :options="options" v-if="visible" :layout="layout" :cancel="hide" :accept="accept" :input="input" :next="next" />
</el-dialog>
2025-07-15 13:59:05 +08:00
<div v-if="message" class="message_wrap">
<div class="message">{{ message }}</div>
</div>
2025-07-04 17:52:10 +08:00
</div>
</template>
<script>
2025-07-15 13:59:05 +08:00
import { startMapping, setStation, stopMapping, getLocalMaps, oneClickDeployment } from '@config/getData.js'
2025-07-04 17:52:10 +08:00
export default {
data () {
return {
2025-07-14 17:52:37 +08:00
mapName: '',
2025-07-14 09:28:21 +08:00
dialogVisible: false,
dataForm: {
point: ''
},
keyPoints: [],
2025-07-15 13:59:05 +08:00
disabled: false,
message: '', // 用于显示消息
intervalId: null, // 用于存储定时器ID
startTime: null, // 用于记录开始时间
2025-07-14 09:28:21 +08:00
visible: false,
layout: 'normal',
input: null,
options: {
useKbEvents: false,
preventClickEvent: false
2025-07-15 13:59:05 +08:00
}
2025-07-04 17:52:10 +08:00
}
},
beforeDestroy () {
if (this.intervalId) {
clearInterval(this.intervalId)
}
},
2025-07-14 09:28:21 +08:00
mounted () {
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-14 17:52:37 +08:00
const getTimestamp = new Date().getTime()
this.mapName = `apt_map_${getTimestamp}`
let res = await startMapping(this.mapName)
2025-07-14 09:28:21 +08:00
if (res) {
if (res.code !== 200) {
this.$message.error(res.message)
}
}
} catch (e) {
this.$message.error(e)
}
},
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
this.dataForm.point = 'B' + (this.keyPoints.length + 1)
},
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 {
let res = await setStation(this.dataForm.point)
if (res) {
if (res.code === 200) {
this.$message({
type: 'success',
message: res.message
})
this.keyPoints.push(this.dataForm.point)
} 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-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 {
let res = await stopMapping()
2025-07-14 17:52:37 +08:00
if (res) {
if (res.code === 200) {
this.$message({
type: 'success',
message: res.message
})
2025-07-15 13:59:05 +08:00
this.message = '正在建图,请等待。。。'
this.startTime = Date.now() // 记录开始时间
this.intervalId = setInterval(this._getLocalMaps, 3000) // 每5秒检查一次
2025-07-14 17:52:37 +08:00
} else {
this.$message.error(res.message)
2025-07-15 13:59:05 +08:00
this.disabled = false
}
}
} catch (e) {
this.$message.error(e)
this.disabled = false
}
},
async _getLocalMaps () {
try {
let res = await getLocalMaps()
if (res && res.code === 200) {
let flag = false
res.data.map(el => {
if (el.id === this.mapName) {
flag = true
}
})
if (flag) {
clearInterval(this.intervalId) // 停止定时器
await this._oneClickDeployment()
} else {
const elapsedTime = Date.now() - this.startTime
if (elapsedTime >= 60000) { // 超过1分钟
clearInterval(this.intervalId) // 停止定时器
this.message = ''
this.$message.error('建图失败,请重新建图')
this.disabled = false
}
2025-07-14 17:52:37 +08:00
}
2025-07-15 13:59:05 +08:00
} else {
clearInterval(this.intervalId) // 停止定时器
this.message = ''
this.$message.error('建图失败,请重新建图')
this.disabled = false
2025-07-14 17:52:37 +08:00
}
} catch (e) {
2025-07-15 13:59:05 +08:00
clearInterval(this.intervalId) // 出错时停止定时器
this.message = ''
this.disabled = false
2025-07-14 17:52:37 +08:00
this.$message.error(e)
}
},
async _oneClickDeployment () {
try {
let res = await oneClickDeployment(this.mapName)
2025-07-14 09:28:21 +08:00
if (res) {
if (res.code === 200) {
this.$message({
type: 'success',
message: res.message
})
} else {
this.$message.error(res.message)
}
2025-07-15 13:59:05 +08:00
this.message = ''
this.disabled = false
2025-07-14 09:28:21 +08:00
}
} catch (e) {
this.$message.error(e)
2025-07-15 13:59:05 +08:00
this.message = ''
this.disabled = false
2025-07-04 17:52:10 +08:00
}
},
// 放大
zoomIn () {
2025-07-15 13:59:05 +08:00
// this.scale += 0.1
// this.redrawCanvas()
2025-07-04 17:52:10 +08:00
},
// 缩小
zoomOut () {
2025-07-15 13:59:05 +08:00
// this.scale -= 0.1
// if (this.scale < 0.1) this.scale = 0.1 // 防止缩放到 0 或负值
// this.redrawCanvas()
2025-07-04 17:52:10 +08:00
}
}
}
</script>
<style lang="stylus" scoped>
.canvas-container
height calc(100% - 1rem)
margin .14rem 0
background-color rgba(0, 19, 48, 70%)
box-shadow inset 1px 1px 7px 2px #4d9bcd
overflow hidden
#canvas
width 100%
height 100%
2025-07-15 13:59:05 +08:00
.message_wrap
position fixed
left 0
top 0
width 100%
height 100%
z-index 2025
background center center / 40% auto url(../../images/new/popover.png) no-repeat
display flex
justify-content center
align-items center
.message
width 30%
font-size .18rem
list-height .2rem
color #fff
2025-07-04 17:52:10 +08:00
</style>