v0.2
This commit is contained in:
1 parent
4aaaf23d2f
commit
d1ee8edbbd
14 files changed
+1678
-104
No files matched your search
+216
-87
@@ -1,109 +1,238 @@
|
||||
<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'
|
||||
import { computed } from 'vue';
|
||||
import { useRoute } from 'vue-router';
|
||||
const router = useRoute();
|
||||
const isLoginPage = computed(() => router.path === '/login');
|
||||
const isActiveNav = (path: string) => router.path === path;
|
||||
|
||||
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>
|
||||
|
||||
<template>
|
||||
<header v-if="!isLoginPage" class="topbar">
|
||||
<a class="brand" href="#">
|
||||
<span class="brand-mark">
|
||||
<svg viewBox="0 0 24 24" aria-hidden="true">
|
||||
<path
|
||||
d="M21 7.5a6.6 6.6 0 0 1-8.8 6.2L6.2 19.7a2.1 2.1 0 0 1-3-3l6-6A6.6 6.6 0 0 1 15.5 3l-2.7 2.7 1.5 1.5L17 4.5A6.6 6.6 0 0 1 21 7.5Z" />
|
||||
</svg>
|
||||
</span>
|
||||
<span>天泽汽修</span>
|
||||
</a>
|
||||
<nav class="nav-links" aria-label="主导航">
|
||||
<a :class="{ active: isActiveNav('/main') }" href="/main">首页</a>
|
||||
<a :class="{ active: isActiveNav('/maintenance') }" href="/maintenance">车辆保养</a>
|
||||
<a :class="{ active: isActiveNav('/bill') }" href="/bill">维修服务</a>
|
||||
<a :class="{ active: isActiveNav('/contact') }" href="/contact">联系我们</a>
|
||||
</nav>
|
||||
<div class="topbar-actions">
|
||||
<button class="icon-button" aria-label="搜索服务">
|
||||
<svg viewBox="0 0 24 24" aria-hidden="true">
|
||||
<circle cx="10.8" cy="10.8" r="6.8" />
|
||||
<path d="m16 16 5 5" />
|
||||
</svg>
|
||||
</button>
|
||||
<button class="icon-button notification" aria-label="在线咨询">
|
||||
<svg viewBox="0 0 24 24" aria-hidden="true">
|
||||
<path
|
||||
d="M20 11.5a7.5 7.5 0 0 1-8 7.5 8.5 8.5 0 0 1-3.5-.8L4 20l1.5-3.5A7.3 7.3 0 0 1 4.5 12 7.5 7.5 0 0 1 12 4.5a7.5 7.5 0 0 1 8 7Z" />
|
||||
<path d="M8 12h.01M12 12h.01M16 12h.01" />
|
||||
</svg>
|
||||
</button>
|
||||
<div class="user-avatar">泽</div>
|
||||
<span class="user-name">在线客服</span>
|
||||
</div>
|
||||
</header>
|
||||
<router-view />
|
||||
<!-- <HelloWorld /> -->
|
||||
</template>
|
||||
<style scoped>
|
||||
* {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
box-sizing: border-box;
|
||||
.topbar {
|
||||
position: relative;
|
||||
height: 74px;
|
||||
padding: 0 clamp(24px, 5vw, 76px);
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 58px;
|
||||
background: #fff;
|
||||
border-bottom: 1px solid #e8edf5;
|
||||
animation: nav-slide-down 0.55s cubic-bezier(.22, 1, .36, 1) both;
|
||||
}
|
||||
|
||||
body {
|
||||
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', sans-serif;
|
||||
background: #f0f2f5;
|
||||
padding: 20px;
|
||||
.topbar::after {
|
||||
content: "";
|
||||
position: absolute;
|
||||
right: 0;
|
||||
bottom: -1px;
|
||||
left: 0;
|
||||
height: 1px;
|
||||
transform: scaleX(0);
|
||||
transform-origin: left;
|
||||
background: #1769e0;
|
||||
animation: nav-border-reveal 0.8s .2s ease-out both;
|
||||
}
|
||||
|
||||
.app {
|
||||
max-width: 1400px;
|
||||
margin: 0 auto;
|
||||
.brand {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 10px;
|
||||
color: #13213b;
|
||||
font-size: 19px;
|
||||
font-weight: 800;
|
||||
text-decoration: none;
|
||||
white-space: nowrap;
|
||||
transition: color .25s ease, transform .25s ease;
|
||||
}
|
||||
|
||||
h1 {
|
||||
margin-bottom: 8px;
|
||||
color: #333;
|
||||
.brand:hover {
|
||||
color: #1769e0;
|
||||
transform: translateY(-2px);
|
||||
}
|
||||
|
||||
.description {
|
||||
color: #666;
|
||||
margin-bottom: 24px;
|
||||
.brand-mark {
|
||||
width: 36px;
|
||||
height: 36px;
|
||||
display: grid;
|
||||
place-items: center;
|
||||
color: #fff;
|
||||
background: #1769e0;
|
||||
border-radius: 10px;
|
||||
transition: transform .35s cubic-bezier(.22, 1, .36, 1), box-shadow .35s ease;
|
||||
}
|
||||
|
||||
.log-panel {
|
||||
margin-top: 20px;
|
||||
padding: 16px;
|
||||
background: white;
|
||||
border-radius: 8px;
|
||||
box-shadow: 0 1px 4px rgba(0,0,0,0.1);
|
||||
.brand:hover .brand-mark {
|
||||
transform: rotate(-8deg) scale(1.08);
|
||||
box-shadow: 0 7px 15px #1769e14d;
|
||||
}
|
||||
|
||||
.log-panel h3 {
|
||||
margin-bottom: 12px;
|
||||
font-size: 16px;
|
||||
color: #333;
|
||||
.brand-mark svg {
|
||||
width: 22px;
|
||||
fill: currentColor;
|
||||
}
|
||||
.nav-links {
|
||||
display: flex;
|
||||
align-self: stretch;
|
||||
gap: 34px;
|
||||
}
|
||||
|
||||
.log-list {
|
||||
max-height: 200px;
|
||||
overflow-y: auto;
|
||||
.nav-links a {
|
||||
position: relative;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
color: #78849a;
|
||||
font-size: 14px;
|
||||
text-decoration: none;
|
||||
opacity: 0;
|
||||
animation: nav-item-in .45s cubic-bezier(.22, 1, .36, 1) both;
|
||||
transition: color .25s ease, transform .25s ease;
|
||||
}
|
||||
|
||||
.log-item {
|
||||
padding: 6px 0;
|
||||
font-size: 12px;
|
||||
color: #666;
|
||||
border-bottom: 1px solid #f0f0f0;
|
||||
font-family: monospace;
|
||||
.nav-links a:nth-child(1) {
|
||||
animation-delay: .18s;
|
||||
}
|
||||
|
||||
.nav-links a:nth-child(2) {
|
||||
animation-delay: .25s;
|
||||
}
|
||||
|
||||
.nav-links a:nth-child(3) {
|
||||
animation-delay: .32s;
|
||||
}
|
||||
|
||||
.nav-links a:nth-child(4) {
|
||||
animation-delay: .39s;
|
||||
}
|
||||
|
||||
.nav-links a:hover {
|
||||
color: #1769e0;
|
||||
transform: translateY(-2px);
|
||||
}
|
||||
|
||||
.nav-links a.active {
|
||||
color: #1769e0;
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
.nav-links a.active::after {
|
||||
content: "";
|
||||
position: absolute;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
left: 0;
|
||||
height: 3px;
|
||||
transform: scaleX(1);
|
||||
transform-origin: center;
|
||||
background: #1769e0;
|
||||
border-radius: 3px 3px 0 0;
|
||||
animation: nav-underline-in .35s .35s cubic-bezier(.22, 1, .36, 1) both;
|
||||
}
|
||||
|
||||
.nav-links a:not(.active)::after {
|
||||
content: "";
|
||||
position: absolute;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
left: 0;
|
||||
height: 3px;
|
||||
transform: scaleX(0);
|
||||
transform-origin: center;
|
||||
background: #1769e0;
|
||||
border-radius: 3px 3px 0 0;
|
||||
transition: transform .25s cubic-bezier(.22, 1, .36, 1);
|
||||
}
|
||||
|
||||
.nav-links a:not(.active):hover::after {
|
||||
transform: scaleX(1);
|
||||
}
|
||||
|
||||
@keyframes nav-slide-down {
|
||||
from {
|
||||
opacity: 0;
|
||||
transform: translateY(-18px);
|
||||
}
|
||||
to {
|
||||
opacity: 1;
|
||||
transform: translateY(0);
|
||||
}
|
||||
}
|
||||
|
||||
@keyframes nav-border-reveal {
|
||||
from {
|
||||
transform: scaleX(0);
|
||||
}
|
||||
to {
|
||||
transform: scaleX(1);
|
||||
}
|
||||
}
|
||||
|
||||
@keyframes nav-item-in {
|
||||
from {
|
||||
opacity: 0;
|
||||
transform: translateY(-8px);
|
||||
}
|
||||
to {
|
||||
opacity: 1;
|
||||
transform: translateY(0);
|
||||
}
|
||||
}
|
||||
|
||||
@keyframes nav-underline-in {
|
||||
from {
|
||||
transform: scaleX(0);
|
||||
}
|
||||
to {
|
||||
transform: scaleX(1);
|
||||
}
|
||||
}
|
||||
|
||||
@media (prefers-reduced-motion: reduce) {
|
||||
.topbar,
|
||||
.topbar::after,
|
||||
.nav-links a,
|
||||
.nav-links a.active::after {
|
||||
animation: none;
|
||||
}
|
||||
|
||||
.nav-links a {
|
||||
opacity: 1;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
Reference in new issue
Block a user