修改显示
parent
52a8d2598e
commit
d1babb697d
@ -0,0 +1,248 @@
|
||||
<template>
|
||||
<div ref="wrapperRef" class="map-wrapper">
|
||||
<div class="left">
|
||||
|
||||
<div class="baseline">
|
||||
<div
|
||||
v-for="(t, index) in leftTicks"
|
||||
:key="index"
|
||||
class="tick-wrapper"
|
||||
:style="{ bottom: t.percent + '%' }"
|
||||
>
|
||||
<div v-if="t.major || (zoomType === 1 && !t.major)" class="tick-label">{{ t.value }}</div>
|
||||
<div v-if="!(zoomType === 2 && !t.major)" :class="t.major ? 'tick major' : 'tick minor'"/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="bottom">
|
||||
<div class="baseline">
|
||||
<div
|
||||
v-for="t in ticks"
|
||||
:key="t.value"
|
||||
class="tick-wrapper"
|
||||
:style="{ left: t.percent + '%' }"
|
||||
>
|
||||
<div v-if="t.major" class="tick-label">{{ t.value }}</div>
|
||||
<div :class="t.major ? 'tick major' : 'tick minor'"/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="content"></div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
|
||||
import {ref, computed, onMounted, onBeforeUnmount} from 'vue'
|
||||
|
||||
const props = defineProps({
|
||||
num: {type: Number, required: true, default: 600},
|
||||
height: {type: Number, required: true, default: 1000},
|
||||
})
|
||||
|
||||
|
||||
const centerValue = ref(100)
|
||||
const zoomType = ref(1)
|
||||
|
||||
function zoomScale(value, type) {
|
||||
centerValue.value = value
|
||||
zoomType.value = type
|
||||
}
|
||||
|
||||
function getAxisRange() {
|
||||
if (!leftTicks.value || leftTicks.value.length === 0) return {min: 0, max: 0}
|
||||
const values = leftTicks.value.map(t => t.value)
|
||||
return {min: Math.min(...values), max: Math.max(...values)}
|
||||
}
|
||||
|
||||
const leftTicks = computed(() => {
|
||||
const arr = []
|
||||
|
||||
if (centerValue.value === 0 || zoomType.value === 0) {
|
||||
const step = 10
|
||||
const steps = Math.floor(props.height / step)
|
||||
for (let i = 0; i <= steps; i++) {
|
||||
const value = i * step
|
||||
const isMajor = value % 100 === 0
|
||||
const percent = Math.floor((value / props.height) * 100)
|
||||
arr.push({value, major: isMajor, percent})
|
||||
}
|
||||
if (arr[arr.length - 1].value < props.height) {
|
||||
arr.push({value: props.height, major: props.height % 100 === 0, percent: 100})
|
||||
}
|
||||
return arr
|
||||
}
|
||||
|
||||
// 基于默认步长计算放大倍数
|
||||
const defaultStep = 10
|
||||
let factor = 1
|
||||
if (zoomType.value === 1) factor = 10
|
||||
else if (zoomType.value === 2) factor = 100
|
||||
|
||||
const step = defaultStep / factor
|
||||
const halfRange = Math.floor((props.height / factor) / 2)
|
||||
console.log(step)
|
||||
console.log(halfRange)
|
||||
|
||||
let startValue = centerValue.value - halfRange
|
||||
let endValue = centerValue.value + halfRange
|
||||
|
||||
if (startValue < 0) {
|
||||
endValue += -startValue
|
||||
startValue = 0
|
||||
}
|
||||
if (endValue > props.height) {
|
||||
startValue -= endValue - props.height
|
||||
endValue = props.height
|
||||
if (startValue < 0) startValue = 0
|
||||
}
|
||||
|
||||
// 生成刻度
|
||||
for (let value = startValue; value <= endValue; value += step) {
|
||||
const intValue = Math.floor(value)
|
||||
let isMajor = false
|
||||
|
||||
if (zoomType.value === 1) {
|
||||
isMajor = intValue % 10 === 0
|
||||
} else if (zoomType.value === 2) {
|
||||
isMajor = true
|
||||
} else {
|
||||
isMajor = intValue % 100 === 0
|
||||
}
|
||||
|
||||
const percent = Math.floor(((intValue - startValue) / (endValue - startValue)) * 100)
|
||||
arr.push({value: intValue, major: isMajor, percent})
|
||||
}
|
||||
|
||||
return arr
|
||||
})
|
||||
const ticks = computed(() => {
|
||||
const arr = []
|
||||
const step = 10
|
||||
const steps = Math.ceil(props.num / step) // 使用ceil保证覆盖整个范围
|
||||
|
||||
for (let i = 0; i <= steps; i++) {
|
||||
let value = i * step
|
||||
if (value > props.num) value = props.num // 防止超过最大值
|
||||
const isMajor = value % 100 === 0
|
||||
const percent = (value / props.num) * 100
|
||||
arr.push({value, major: isMajor, percent})
|
||||
}
|
||||
|
||||
return arr
|
||||
})
|
||||
</script>
|
||||
|
||||
<style scoped lang="less">
|
||||
.map-wrapper {
|
||||
position: relative;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
background-color: #000;
|
||||
|
||||
.left {
|
||||
position: absolute;
|
||||
width: 40px;
|
||||
height: calc(100% - 40px);
|
||||
background-color: #000;
|
||||
top: 0;
|
||||
left: 0;
|
||||
|
||||
|
||||
.baseline {
|
||||
position: relative;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
border-right: 1px solid #fff;
|
||||
}
|
||||
|
||||
.tick-wrapper {
|
||||
position: absolute;
|
||||
right: 0;
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
align-items: center;
|
||||
transform: translateY(50%);
|
||||
}
|
||||
|
||||
.tick {
|
||||
height: 1px;
|
||||
background-color: #fff;
|
||||
}
|
||||
|
||||
.tick.minor {
|
||||
width: 12px;
|
||||
opacity: 0.6;
|
||||
}
|
||||
|
||||
.tick.major {
|
||||
width: 18px;
|
||||
background-color: #fff;
|
||||
}
|
||||
|
||||
.tick-label {
|
||||
font-size: 12px;
|
||||
color: #fff;
|
||||
writing-mode: vertical-rl;
|
||||
margin-left: 4px;
|
||||
}
|
||||
}
|
||||
|
||||
.bottom {
|
||||
position: absolute;
|
||||
width: calc(100% - 40px);
|
||||
height: 40px;
|
||||
background-color: #000;
|
||||
bottom: 0;
|
||||
left: 40px;
|
||||
|
||||
|
||||
.baseline {
|
||||
position: relative;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
border-bottom: 1px solid #fff3;
|
||||
}
|
||||
|
||||
.tick-wrapper {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.tick {
|
||||
width: 1px;
|
||||
background-color: #fff;
|
||||
}
|
||||
|
||||
.tick.minor {
|
||||
height: 12px;
|
||||
opacity: 0.6;
|
||||
}
|
||||
|
||||
.tick.major {
|
||||
height: 18px;
|
||||
background-color: #fff;
|
||||
}
|
||||
|
||||
|
||||
.tick-label {
|
||||
position: absolute;
|
||||
font-size: 12px;
|
||||
color: #fff;
|
||||
top: 100%;
|
||||
}
|
||||
}
|
||||
|
||||
.content {
|
||||
position: absolute;
|
||||
width: calc(100% - 40px);
|
||||
height: calc(100% - 40px);
|
||||
background-color: #666;
|
||||
top: 0;
|
||||
left: 40px
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@ -0,0 +1,325 @@
|
||||
<template>
|
||||
<div class="table-container">
|
||||
<!-- 主表格 -->
|
||||
<el-card class="main-card">
|
||||
<template #header>
|
||||
<div class="card-header">
|
||||
<div class="operation-buttons">
|
||||
<el-button type="primary" @click="openAddDialog">添加</el-button>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<el-table :data="tableData" @selection-change="handleSelectionChange" style="width: 100%">
|
||||
<el-table-column type="selection" width="55" />
|
||||
<el-table-column prop="name" label="名称" />
|
||||
<el-table-column label="操作" width=" 300">
|
||||
<template #default="scope">
|
||||
<el-button type="primary" size="small" @click="openAreaDialog(scope.row)">
|
||||
设置区域
|
||||
</el-button>
|
||||
<el-button type="danger" size="small" @click="handleDelete(scope.row)">
|
||||
删除
|
||||
</el-button>
|
||||
<el-button type="warning" size="small" @click="handleEdit(scope.row)">
|
||||
修改
|
||||
</el-button>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
</el-card>
|
||||
|
||||
<!-- 添加/修改对话框 -->
|
||||
<el-dialog v-model="dialogVisible" :title="dialogTitle" width="400px">
|
||||
<el-form :model="form" label-width="80px">
|
||||
<el-form-item label="名称">
|
||||
<el-input v-model="form.name" placeholder="请输入名称" />
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
<template #footer>
|
||||
<el-button @click="dialogVisible = false">取消</el-button>
|
||||
<el-button type="primary" @click="handleSubmit">确定</el-button>
|
||||
</template>
|
||||
</el-dialog>
|
||||
|
||||
<!-- 添加区域对话框 -->
|
||||
<el-dialog v-model="areaDialogVisible" title="添加区域" width="800px">
|
||||
<el-card>
|
||||
<template #header>
|
||||
<div class="card-header">
|
||||
<span>区域管理</span>
|
||||
<div class="operation-buttons">
|
||||
<el-button type="primary" @click="openAreaAddDialog">添加</el-button>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<el-table :data="areaTableData" @selection-change="handleAreaSelectionChange" style="width: 100%">
|
||||
<el-table-column type="selection" width="55" />
|
||||
<el-table-column prop="name" label="名称" />
|
||||
<el-table-column label="操作" width="200">
|
||||
<template #default="scope">
|
||||
<el-button type="danger" size="small" @click="handleAreaDelete(scope.row)">
|
||||
删除
|
||||
</el-button>
|
||||
<el-button type="warning" size="small" @click="handleAreaEdit(scope.row)">
|
||||
修改
|
||||
</el-button>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
</el-card>
|
||||
|
||||
<template #footer>
|
||||
<el-button @click="areaDialogVisible = false">关闭</el-button>
|
||||
</template>
|
||||
</el-dialog>
|
||||
|
||||
<!-- 区域添加/修改对话框 -->
|
||||
<el-dialog v-model="areaFormDialogVisible" :title="areaDialogTitle" width="400px">
|
||||
<el-form :model="areaForm" label-width="80px">
|
||||
<el-form-item label="名称">
|
||||
<el-input v-model="areaForm.name" placeholder="请输入名称" />
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
<template #footer>
|
||||
<el-button @click="areaFormDialogVisible = false">取消</el-button>
|
||||
<el-button type="primary" @click="handleAreaSubmit">确定</el-button>
|
||||
</template>
|
||||
</el-dialog>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { ref, reactive, computed, onMounted } from 'vue'
|
||||
import { ElMessage, ElMessageBox } from 'element-plus'
|
||||
import { getAllAirPort, addAirPort, updateAirPort, delAirPort, getArea, addArea, updateArea, delArea } from '@/api/api'
|
||||
|
||||
// 主表格数据
|
||||
const tableData = ref([])
|
||||
|
||||
// 选中的行
|
||||
const selectedRows = ref([])
|
||||
|
||||
// 对话框控制
|
||||
const dialogVisible = ref(false)
|
||||
const areaDialogVisible = ref(false)
|
||||
const areaFormDialogVisible = ref(false)
|
||||
|
||||
// 表单数据
|
||||
const form = reactive({
|
||||
id: null,
|
||||
name: ''
|
||||
})
|
||||
|
||||
const areaForm = reactive({
|
||||
id: null,
|
||||
name: ''
|
||||
})
|
||||
|
||||
// 区域表格数据
|
||||
const areaTableData = ref([])
|
||||
|
||||
// 选中的区域行
|
||||
const selectedAreaRows = ref([])
|
||||
|
||||
// 当前编辑的行
|
||||
const currentRow = ref(null)
|
||||
const currentAreaRow = ref(null)
|
||||
|
||||
// 对话框标题
|
||||
const dialogTitle = computed(() => {
|
||||
return form.id ? '修改' : '添加'
|
||||
})
|
||||
|
||||
const areaDialogTitle = computed(() => {
|
||||
return areaForm.id ? '修改' : '添加'
|
||||
})
|
||||
|
||||
// 选择变化处理
|
||||
const handleSelectionChange = (selection) => {
|
||||
selectedRows.value = selection
|
||||
}
|
||||
|
||||
const handleAreaSelectionChange = (selection) => {
|
||||
selectedAreaRows.value = selection
|
||||
}
|
||||
|
||||
// 打开添加对话框
|
||||
const openAddDialog = () => {
|
||||
form.id = null
|
||||
form.name = ''
|
||||
dialogVisible.value = true
|
||||
}
|
||||
|
||||
// 打开区域对话框
|
||||
const openAreaDialog = (row) => {
|
||||
currentRow.value = row
|
||||
getArea({ airId: row.id }).then(e => {
|
||||
areaTableData.value = e.data
|
||||
areaDialogVisible.value = true
|
||||
})
|
||||
}
|
||||
|
||||
// 打开区域添加对话框
|
||||
const openAreaAddDialog = (row = null) => {
|
||||
areaForm.id = null
|
||||
areaForm.name = ''
|
||||
currentAreaRow.value = row
|
||||
areaFormDialogVisible.value = true
|
||||
}
|
||||
|
||||
// 删除单行
|
||||
const handleDelete = async (row) => {
|
||||
try {
|
||||
await ElMessageBox.confirm('确定要删除这条记录吗?', '提示', {
|
||||
confirmButtonText: '确定',
|
||||
cancelButtonText: '取消',
|
||||
type: 'warning'
|
||||
})
|
||||
|
||||
|
||||
delAirPort({ id: row.id }).then(e => {
|
||||
getTableData()
|
||||
ElMessage.success('删除成功')
|
||||
})
|
||||
} catch {
|
||||
ElMessage.info('已取消删除')
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
// 编辑单行
|
||||
const handleEdit = (row) => {
|
||||
form.id = row.id
|
||||
form.name = row.name
|
||||
dialogVisible.value = true
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
// 区域相关操作
|
||||
const handleAreaDelete = async (row) => {
|
||||
try {
|
||||
await ElMessageBox.confirm('确定要删除这条记录吗?', '提示', {
|
||||
confirmButtonText: '确定',
|
||||
cancelButtonText: '取消',
|
||||
type: 'warning'
|
||||
})
|
||||
delArea({ id: row.id, fodAirId: currentRow.value.id }).then(async e => {
|
||||
await getArea({ airId: currentRow.value.id }).then(e => {
|
||||
areaTableData.value = e.data
|
||||
ElMessage.success('删除成功')
|
||||
})
|
||||
})
|
||||
} catch {
|
||||
ElMessage.info('已取消删除')
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
const handleAreaEdit = (row) => {
|
||||
areaForm.id = row.id
|
||||
areaForm.name = row.name
|
||||
areaFormDialogVisible.value = true
|
||||
}
|
||||
|
||||
|
||||
const handleAreaSubmit = () => {
|
||||
if (!areaForm.name.trim()) {
|
||||
ElMessage.warning('请输入名称')
|
||||
return
|
||||
}
|
||||
|
||||
if (areaForm.id) {
|
||||
updateArea({ name: areaForm.name, id: areaForm.id, fodAirId: currentRow.value.id }).then(async e => {
|
||||
await getArea({ airId: currentRow.value.id }).then(e => {
|
||||
areaTableData.value = e.data
|
||||
ElMessage.success('修改成功')
|
||||
areaFormDialogVisible.value = false
|
||||
})
|
||||
})
|
||||
} else {
|
||||
// 添加
|
||||
addArea({ name: areaForm.name, fodAirId: currentRow.value.id }).then(async e => {
|
||||
await getArea({ airId: currentRow.value.id }).then(e => {
|
||||
areaTableData.value = e.data
|
||||
ElMessage.success('添加成功')
|
||||
areaFormDialogVisible.value = false
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
getTableData()
|
||||
})
|
||||
|
||||
const getTableData = async () => {
|
||||
await getAllAirPort().then(e => {
|
||||
tableData.value = e.data
|
||||
})
|
||||
}
|
||||
|
||||
// 提交表单
|
||||
const handleSubmit = () => {
|
||||
if (!form.name.trim()) {
|
||||
ElMessage.warning('请输入名称')
|
||||
return
|
||||
}
|
||||
|
||||
if (form.id) {
|
||||
updateAirPort(form).then(e => {
|
||||
ElMessage.success('修改成功')
|
||||
getTableData()
|
||||
dialogVisible.value = false
|
||||
})
|
||||
} else {
|
||||
// 添加
|
||||
addAirPort({ name: form.name }).then(async e => {
|
||||
await getTableData()
|
||||
ElMessage.success('添加成功')
|
||||
dialogVisible.value = false
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.table-container {
|
||||
padding: 20px;
|
||||
}
|
||||
|
||||
.main-card {
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.card-header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.operation-buttons {
|
||||
display: flex;
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
.el-table {
|
||||
margin-top: 10px;
|
||||
}
|
||||
|
||||
.el-button {
|
||||
margin-right: 5px;
|
||||
}
|
||||
|
||||
.el-button:last-child {
|
||||
margin-right: 0;
|
||||
}
|
||||
</style>
|
||||
Loading…
Reference in New Issue