This commit is contained in:
Mrhongxing committed 2026-11-04 14:22:20 +08:00
commit 4aaaf23d2f
2411 files changed
+1248679

No files matched your search

+109
View File
@@ -0,0 +1,109 @@
<template>
<div class="app">
<h1>Vue 3 拖拽控制器</h1>
<p class="description">通过滑块控制元素位置,也可以直接拖拽元素</p>
<DraggableController
:container-height="500"
:element-width="150"
:element-height="120"
element-color="#409eff"
:initial-x="100"
:initial-y="100"
:min-x="0"
:min-y="0"
:max-x="350"
:max-y="380"
@position-change="handlePositionChange"
@drag-start="handleDragStart"
@drag-end="handleDragEnd"
/>
<div v-if="logs.length" class="log-panel">
<h3>事件日志</h3>
<div class="log-list">
<div v-for="(log, index) in logs.slice(-5)" :key="index" class="log-item">
{{ log }}
</div>
</div>
</div>
</div>
</template>
<script setup lang="ts">
import { ref } from 'vue'
import DraggableController from './components/DraggleController.vue'
const logs = ref<string[]>([])
const handlePositionChange = (x: number, y: number) => {
const timestamp = new Date().toLocaleTimeString()
logs.value.unshift(`[${timestamp}] 位置变化: (${x.toFixed(0)}, ${y.toFixed(0)})`)
}
const handleDragStart = () => {
const timestamp = new Date().toLocaleTimeString()
logs.value.unshift(`[${timestamp}] 开始拖拽`)
}
const handleDragEnd = () => {
const timestamp = new Date().toLocaleTimeString()
logs.value.unshift(`[${timestamp}] 结束拖拽`)
}
</script>
<style scoped>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', sans-serif;
background: #f0f2f5;
padding: 20px;
}
.app {
max-width: 1400px;
margin: 0 auto;
}
h1 {
margin-bottom: 8px;
color: #333;
}
.description {
color: #666;
margin-bottom: 24px;
}
.log-panel {
margin-top: 20px;
padding: 16px;
background: white;
border-radius: 8px;
box-shadow: 0 1px 4px rgba(0,0,0,0.1);
}
.log-panel h3 {
margin-bottom: 12px;
font-size: 16px;
color: #333;
}
.log-list {
max-height: 200px;
overflow-y: auto;
}
.log-item {
padding: 6px 0;
font-size: 12px;
color: #666;
border-bottom: 1px solid #f0f0f0;
font-family: monospace;
}
</style>