This commit is contained in:
xhf 2025-02-22 17:06:20 +08:00
commit 6f0db9c934
5 changed files with 941 additions and 668 deletions

View File

@ -4,7 +4,7 @@ NODE_ENV=development
VITE_DEV=true
# 请求路径
VITE_BASE_URL='http://192.168.0.74:48080'
VITE_BASE_URL='http://192.168.0.172:48080'
# VITE_BASE_URL='http://192.168.0.189:48080'
# 文件上传类型server - 后端上传, client - 前端直连上传,仅支持 S3 服务

View File

@ -229,10 +229,10 @@ const open = (item, list) => {
console.log(item)
form.value = item
form.value.layersNumber = item.dataList.length || ''
form.value.deviceId = item.deviceId || item.dataObj.id || ''
form.value.deviceId = item?.deviceId || item?.dataObj?.id || ''
form.value.positionMapId = props.positionMapId
equipmentList.value = list
if (item.dataObj.deviceType) {
if (item?.dataObj?.deviceType) {
deviceInfo.value.deviceType = item.dataObj.deviceType || ''
getDeviceList()
} else {

View File

@ -2,7 +2,12 @@
<template>
<div :style="wrapperStyle" class="vue-ruler-wrapper" onselectstart="return false;" ref="el">
<section>
<div ref="horizontalRuler" class="vue-ruler-h" @mousedown.stop="horizontalDragRuler">
<div
ref="horizontalRuler"
class="vue-ruler-h"
@mousedown.stop="horizontalDragRuler"
:style="{ width: width + 'px' }"
>
<span
v-for="(item, index) in xScale"
:key="index"
@ -11,7 +16,12 @@
>{{ item.id }}</span
>
</div>
<div ref="verticalRuler" class="vue-ruler-v" @mousedown.stop="verticalDragRuler">
<div
ref="verticalRuler"
class="vue-ruler-v"
@mousedown.stop="verticalDragRuler"
:style="{ height: height + 'px' }"
>
<span
v-for="(item, index) in yScale"
:key="index"
@ -82,6 +92,12 @@ const props = defineProps({
type: Number,
default: 100,
validator: (val) => val % 10 === 0
},
width: {
type: Number
},
height: {
type: Number
}
})
@ -166,12 +182,10 @@ onBeforeUnmount(() => {
off(document, 'mouseup', dottedLineUp)
off(window, 'resize', windowResize)
})
//function
const init = () => {
box()
scaleCalc()
}
const windowResize = () => {
xScale.value = [{ id: 0 }]
yScale.value = [{ id: 0 }]
@ -193,8 +207,10 @@ const box = () => {
getCalcRevise(xScale.value, contentLeft)
getCalcRevise(yScale.value, contentTop)
}
windowWidth.value = document.documentElement.clientWidth - leftSpacing
windowHeight.value = document.documentElement.clientHeight - topSpacing - 80
// windowWidth.value = document.documentElement.clientWidth - leftSpacing
// windowHeight.value = document.documentElement.clientHeight - topSpacing - 80
windowWidth.value = props.width + 18
windowHeight.value = props.height + 18
rulerWidth = verticalRuler.value.clientWidth
rulerHeight = horizontalRuler.value.clientHeight
}
@ -204,8 +220,8 @@ const setSpacing = () => {
}
//
const scaleCalc = () => {
getCalc(xScale.value, windowWidth.value)
getCalc(yScale.value, windowHeight.value)
getCalc(xScale.value, props.width)
getCalc(yScale.value, props.height)
}
//
@ -360,7 +376,7 @@ const dragVerticalLine = (id) => {
}
.vue-ruler-h {
width: calc(100% - 18px);
// width: calc(100% - 18px);
background-color: #333;
height: 18px;
left: 18px;
@ -371,7 +387,7 @@ const dragVerticalLine = (id) => {
.vue-ruler-v {
width: 18px;
height: 85vh;
// height: 85vh;
top: 18px;
opacity: 0.6;
background: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABIAAAAyCAMAAABmvHtTAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAAlQTFRFMzMzAAAA////BqjYlAAAACBJREFUeNpiYGBEBwwMTGiAakI0NX7U9aOuHyGuBwgwAH6bBkAR6jkzAAAAAElFTkSuQmCC)

File diff suppressed because it is too large Load Diff

View File

@ -1,110 +1,190 @@
<template>
<div>
<svg width="800" height="600">
<path
v-for="(curve, index) in curves"
<svg
ref="svgElement"
:width="width"
:height="height"
@mousedown="startDrawing"
@mousemove="drawLine"
@mouseup="stopDrawing"
@mouseleave="stopDrawing"
>
<!-- 渲染所有点 -->
<circle
v-for="(point, index) in points"
:key="index"
:d="getCurvePath(curve)"
:stroke="curve.isSelected ? 'red' : 'blue'"
:cx="point.x"
:cy="point.y"
r="5"
fill="red"
@mousedown="startFromPoint(index, $event)"
/>
<!-- 渲染所有直线 -->
<path
v-for="(line, index) in lines"
:key="'line-' + index"
:d="`M ${line.startPointX} ${line.startPointY} L ${line.endPointX} ${line.endPointY}`"
stroke="black"
stroke-width="2"
fill="none"
@mousedown="selectCurve(index)"
/>
<circle
v-for="(curve, index) in curves"
:key="'start-' + index"
:cx="curve.beginControlX"
:cy="curve.beginControlY"
r="5"
fill="green"
@mousedown="startDrag(index, 'start')"
/>
<circle
v-for="(curve, index) in curves"
:key="'end-' + index"
:cx="curve.endControlX"
:cy="curve.endControlY"
r="5"
fill="green"
@mousedown="startDrag(index, 'end')"
<!-- 实时绘制当前直线 -->
<path
v-if="isDrawing"
:d="`M ${startX} ${startY} L ${currentX} ${currentY}`"
stroke="blue"
stroke-width="2"
fill="none"
/>
</svg>
<!-- 显示直线数据 -->
<div>
<h3>直线数据</h3>
<pre>{{ lines }}</pre>
</div>
</div>
</template>
<script setup>
<script>
import { ref } from 'vue'
//
const curves = ref([
{
startPointX: 100,
startPointY: 100,
endPointX: 300,
endPointY: 100,
beginControlX: 100,
beginControlY: 100,
endControlX: 300,
endControlY: 100,
isSelected: false
},
{
startPointX: 200,
startPointY: 200,
endPointX: 400,
endPointY: 200,
beginControlX: 200,
beginControlY: 200,
endControlX: 400,
endControlY: 200,
isSelected: false
}
])
export default {
setup() {
const svgElement = ref(null) // SVG
const width = 800 // SVG
const height = 600 // SVG
// 线
const dragging = ref({
index: null,
type: null
})
//
const points = ref([
{ x: 10, y: 10 },
{ x: 30, y: 100 },
{ x: 40, y: 40 },
{ x: 230, y: 400 },
{ x: 750, y: 640 }
])
// 线
const getCurvePath = (curve) => {
return `M${curve.startPointX},${curve.startPointY} C${curve.beginControlX},${curve.beginControlY} ${curve.endControlX},${curve.endControlY} ${curve.endPointX},${curve.endPointY}`
}
// 线
const lines = ref([])
// 线
const selectCurve = (index) => {
curves.value.forEach((curve, i) => {
curve.isSelected = i === index
})
console.log('Selected curve:', curves.value[index])
}
// 线
const isDrawing = ref(false)
const startX = ref(0)
const startY = ref(0)
const currentX = ref(0)
const currentY = ref(0)
const startPointIndex = ref(null) //
//
const startDrag = (index, type) => {
dragging.value = { index, type }
window.addEventListener('mousemove', handleDrag)
window.addEventListener('mouseup', endDrag)
}
//
const startFromPoint = (index, event) => {
const point = points.value[index]
startX.value = point.x
startY.value = point.y
startPointIndex.value = index
isDrawing.value = true
event.preventDefault() //
}
//
const handleDrag = (event) => {
if (dragging.value.index !== null) {
const curve = curves.value[dragging.value.index]
if (dragging.value.type === 'start') {
curve.beginControlX = event.offsetX
curve.beginControlY = event.offsetY
} else {
curve.endControlX = event.offsetX
curve.endControlY = event.offsetY
//
const drawLine = (event) => {
if (isDrawing.value) {
const rect = svgElement.value.getBoundingClientRect()
currentX.value = event.clientX - rect.left
currentY.value = event.clientY - rect.top
}
}
//
const stopDrawing = () => {
if (isDrawing.value) {
//
const endPointIndex = findClosestPoint(currentX.value, currentY.value)
if (endPointIndex !== null && endPointIndex !== startPointIndex.value) {
const endPoint = points.value[endPointIndex]
const newLine = {
startPointX: startX.value,
startPointY: startY.value,
endPointX: endPoint.x,
endPointY: endPoint.y
}
// 线
const isDuplicate = lines.value.some(
(line) =>
(line.startPointX === newLine.startPointX &&
line.startPointY === newLine.startPointY &&
line.endPointX === newLine.endPointX &&
line.endPointY === newLine.endPointY) ||
(line.startPointX === newLine.endPointX &&
line.startPointY === newLine.endPointY &&
line.endPointX === newLine.startPointX &&
line.endPointY === newLine.startPointY)
)
if (!isDuplicate) {
// 线
lines.value.push(newLine)
}
}
//
isDrawing.value = false
startX.value = 0
startY.value = 0
currentX.value = 0
currentY.value = 0
startPointIndex.value = null
}
}
//
const findClosestPoint = (x, y) => {
let minDistance = Infinity
let closestIndex = null
points.value.forEach((point, index) => {
const distance = Math.sqrt((point.x - x) ** 2 + (point.y - y) ** 2)
if (distance < minDistance && distance < 10) {
// 10
minDistance = distance
closestIndex = index
}
})
return closestIndex
}
return {
svgElement,
width,
height,
points,
lines,
isDrawing,
startX,
startY,
currentX,
currentY,
startFromPoint,
drawLine,
stopDrawing
}
}
}
//
const endDrag = () => {
dragging.value = { index: null, type: null }
window.removeEventListener('mousemove', handleDrag)
window.removeEventListener('mouseup', endDrag)
}
</script>
<style scoped>
svg {
border: 1px solid #ccc;
background-color: #f9f9f9;
}
pre {
background-color: #f5f5f5;
padding: 10px;
border-radius: 5px;
}
</style>