feat: improve SocialLinks component accessibility and layout
This commit is contained in:
parent
f1e3d4b698
commit
7c19281020
@ -1,93 +1,106 @@
|
|||||||
<script setup>
|
<script setup>
|
||||||
import { computed } from "vue";
|
import { ref, computed } from "vue"
|
||||||
import { useMouseInElement } from "@vueuse/core";
|
import { useMouseInElement } from "@vueuse/core"
|
||||||
import { useTheme } from "vuetify";
|
import { useTheme } from "vuetify"
|
||||||
|
|
||||||
// 主题控制
|
const theme = useTheme()
|
||||||
const theme = useTheme();
|
const cardRef = ref(null)
|
||||||
|
const { elementX, elementY } = useMouseInElement(cardRef)
|
||||||
|
|
||||||
// 鼠标悬停效果
|
// 定义props并设置默认值
|
||||||
const cardRef = ref(null);
|
|
||||||
const { elementX, elementY } = useMouseInElement(cardRef);
|
|
||||||
|
|
||||||
// 社交平台数据配置
|
|
||||||
const socialPlatforms = [
|
|
||||||
{
|
|
||||||
name: "GitHub",
|
|
||||||
icon: "ri-github-fill",
|
|
||||||
url: "https://github.com/cattom",
|
|
||||||
color: "#181717",
|
|
||||||
hoverColor: "#6e5494",
|
|
||||||
ariaLabel: "访问我的GitHub主页",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "Twitter",
|
|
||||||
icon: "ri-twitter-x-fill",
|
|
||||||
url: "https://twitter.com/cattom",
|
|
||||||
color: "#000000",
|
|
||||||
hoverColor: "#1DA1F2",
|
|
||||||
ariaLabel: "在Twitter上关注我",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "LinkedIn",
|
|
||||||
icon: "ri-linkedin-fill",
|
|
||||||
url: "https://linkedin.com/in/cattom",
|
|
||||||
color: "#0A66C2",
|
|
||||||
hoverColor: "#0077B5",
|
|
||||||
ariaLabel: "查看我的LinkedIn资料",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "Email",
|
|
||||||
icon: "ri-mail-fill",
|
|
||||||
url: "mailto:hi@cattom.me",
|
|
||||||
color: "#D44638",
|
|
||||||
hoverColor: "#EA4335",
|
|
||||||
ariaLabel: "发送电子邮件给我",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "WeChat",
|
|
||||||
icon: "ri-wechat-fill",
|
|
||||||
color: "#07C160",
|
|
||||||
hoverColor: "#2DC100",
|
|
||||||
ariaLabel: "扫描我的微信二维码",
|
|
||||||
qrCode: "/assets/qr-wechat.png",
|
|
||||||
showQr: ref(false),
|
|
||||||
},
|
|
||||||
];
|
|
||||||
|
|
||||||
// 计算卡片倾斜效果
|
|
||||||
const cardTransform = computed(() => {
|
|
||||||
const MAX_TILT = 8;
|
|
||||||
const x = (elementX.value - (cardRef.value?.offsetWidth / 2 || 0)) / 20;
|
|
||||||
const y = ((cardRef.value?.offsetHeight / 2 || 0) - elementY.value) / 20;
|
|
||||||
|
|
||||||
return {
|
|
||||||
transform: `
|
|
||||||
perspective(1000px)
|
|
||||||
rotateX(${Math.min(Math.max(-y, -MAX_TILT), MAX_TILT)}deg)
|
|
||||||
rotateY(${Math.min(Math.max(x, -MAX_TILT), MAX_TILT)}deg)
|
|
||||||
`,
|
|
||||||
transition: "transform 0.5s cubic-bezier(0.03, 0.98, 0.52, 0.99)",
|
|
||||||
};
|
|
||||||
});
|
|
||||||
|
|
||||||
// 处理二维码显示
|
|
||||||
const props = defineProps({
|
const props = defineProps({
|
||||||
socialPlatforms: {
|
socialPlatforms: {
|
||||||
type: Array,
|
type: Array,
|
||||||
required: true
|
required: false,
|
||||||
|
default: () => [
|
||||||
|
{
|
||||||
|
name: "GitHub",
|
||||||
|
icon: "ri-github-fill",
|
||||||
|
url: "https://github.com/cattom",
|
||||||
|
color: "#181717",
|
||||||
|
hoverColor: "#6e5494",
|
||||||
|
ariaLabel: "访问我的GitHub主页"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Twitter",
|
||||||
|
icon: "ri-twitter-x-fill",
|
||||||
|
url: "https://twitter.com/cattom",
|
||||||
|
color: "#000000",
|
||||||
|
hoverColor: "#1DA1F2",
|
||||||
|
ariaLabel: "在Twitter上关注我"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "LinkedIn",
|
||||||
|
icon: "ri-linkedin-fill",
|
||||||
|
url: "https://linkedin.com/in/cattom",
|
||||||
|
color: "#0A66C2",
|
||||||
|
hoverColor: "#0077B5",
|
||||||
|
ariaLabel: "查看我的LinkedIn资料"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Email",
|
||||||
|
icon: "ri-mail-fill",
|
||||||
|
url: "mailto:hi@cattom.me",
|
||||||
|
color: "#D44638",
|
||||||
|
hoverColor: "#EA4335",
|
||||||
|
ariaLabel: "发送电子邮件给我"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "WeChat",
|
||||||
|
icon: "ri-wechat-fill",
|
||||||
|
color: "#07C160",
|
||||||
|
hoverColor: "#2DC100",
|
||||||
|
ariaLabel: "扫描我的微信二维码",
|
||||||
|
qrCode: "/assets/qr-wechat.png",
|
||||||
|
showQr: false
|
||||||
|
}
|
||||||
|
],
|
||||||
|
validator: platforms =>
|
||||||
|
Array.isArray(platforms) &&
|
||||||
|
platforms.every(p =>
|
||||||
|
typeof p === 'object' &&
|
||||||
|
p !== null &&
|
||||||
|
p.name &&
|
||||||
|
typeof p.name === 'string'
|
||||||
|
)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// 微信二维码显示状态管理
|
||||||
|
const qrStates = ref({})
|
||||||
|
const toggleQrCode = (platform) => {
|
||||||
|
if (platform.qrCode) {
|
||||||
|
qrStates.value[platform.name] = !qrStates.value[platform.name]
|
||||||
|
emit('showWechat', qrStates.value[platform.name])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const emit = defineEmits(['showWechat'])
|
||||||
|
|
||||||
|
// 计算属性
|
||||||
const platformsWithQr = computed(() =>
|
const platformsWithQr = computed(() =>
|
||||||
props.socialPlatforms.filter(p => p.qrCode)
|
props.socialPlatforms.filter(p => p.qrCode)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const cardTransform = computed(() => {
|
||||||
|
const MAX_TILT = 8
|
||||||
|
const x = (elementX.value - (cardRef.value?.offsetWidth / 2 || 0)) / 20
|
||||||
|
const y = ((cardRef.value?.offsetHeight / 2 || 0) - elementY.value) / 20
|
||||||
|
|
||||||
|
return {
|
||||||
|
transform: `
|
||||||
|
perspective(1000px)
|
||||||
|
rotateX(${Math.min(Math.max(-y, -MAX_TILT), MAX_TILT)}deg)
|
||||||
|
rotateY(${Math.min(Math.max(x, -MAX_TILT), MAX_TILT)}deg)
|
||||||
|
`,
|
||||||
|
transition: "transform 0.5s cubic-bezier(0.03, 0.98, 0.52, 0.99)"
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
// 打开外部链接
|
|
||||||
const openLink = (url) => {
|
const openLink = (url) => {
|
||||||
if (!url) return;
|
if (!url) return
|
||||||
window.open(url, "_blank", "noopener,noreferrer");
|
window.open(url, "_blank", "noopener,noreferrer")
|
||||||
};
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
@ -96,35 +109,46 @@ const openLink = (url) => {
|
|||||||
<TransitionGroup name="fade" tag="div" class="qr-container">
|
<TransitionGroup name="fade" tag="div" class="qr-container">
|
||||||
<div
|
<div
|
||||||
v-for="platform in platformsWithQr"
|
v-for="platform in platformsWithQr"
|
||||||
v-show="platform.showQr?.value"
|
v-show="qrStates[platform.name]"
|
||||||
:key="`qr-${platform.name}`"
|
:key="`qr-${platform.name}`"
|
||||||
class="qr-code"
|
class="qr-code"
|
||||||
>
|
>
|
||||||
<img :src="platform.qrCode" :alt="`${platform.name}二维码`" />
|
<img
|
||||||
|
:src="platform.qrCode"
|
||||||
|
:alt="`${platform.name}二维码`"
|
||||||
|
@click.stop
|
||||||
|
/>
|
||||||
|
<button
|
||||||
|
class="qr-close"
|
||||||
|
@click="toggleQrCode(platform)"
|
||||||
|
aria-label="关闭二维码"
|
||||||
|
>
|
||||||
|
×
|
||||||
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</TransitionGroup>
|
</TransitionGroup>
|
||||||
|
|
||||||
<!-- 社交链接主体 -->
|
<!-- 社交链接主体 -->
|
||||||
<div class="social-grid">
|
<div class="social-grid">
|
||||||
<div
|
<div
|
||||||
v-for="(platform, index) in socialPlatforms"
|
v-for="(platform, index) in props.socialPlatforms"
|
||||||
:key="index"
|
:key="index"
|
||||||
class="social-item"
|
class="social-item"
|
||||||
:style="{ '--hover-color': platform.hoverColor }"
|
:style="{ '--hover-color': platform.hoverColor || platform.color }"
|
||||||
@click="
|
@click="platform.qrCode ? toggleQrCode(platform) : openLink(platform.url)"
|
||||||
platform.qrCode ? toggleQrCode(platform) : openLink(platform.url)
|
role="button"
|
||||||
"
|
:aria-label="platform.ariaLabel || `${platform.name}链接`"
|
||||||
|
tabindex="0"
|
||||||
|
@keydown.enter="platform.qrCode ? toggleQrCode(platform) : openLink(platform.url)"
|
||||||
>
|
>
|
||||||
<div class="social-icon-wrapper">
|
<div class="social-icon-wrapper">
|
||||||
<i
|
<i
|
||||||
:class="platform.icon"
|
:class="platform.icon"
|
||||||
class="social-icon"
|
class="social-icon"
|
||||||
:aria-label="platform.ariaLabel"
|
:style="{ color: platform.color }"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<span class="social-name">{{ platform.name }}</span>
|
<span class="social-name">{{ platform.name }}</span>
|
||||||
|
|
||||||
<!-- 悬停光效 -->
|
|
||||||
<div class="hover-light" />
|
<div class="hover-light" />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -138,17 +162,22 @@ const openLink = (url) => {
|
|||||||
background: rgba(var(--v-theme-surface), 0.8);
|
background: rgba(var(--v-theme-surface), 0.8);
|
||||||
backdrop-filter: blur(12px);
|
backdrop-filter: blur(12px);
|
||||||
border-radius: 1.5rem;
|
border-radius: 1.5rem;
|
||||||
box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1),
|
box-shadow:
|
||||||
|
0 10px 30px rgba(0, 0, 0, 0.1),
|
||||||
inset 0 0 0 1px rgba(255, 255, 255, 0.1);
|
inset 0 0 0 1px rgba(255, 255, 255, 0.1);
|
||||||
will-change: transform;
|
will-change: transform;
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
transition: background 0.3s ease, box-shadow 0.3s ease;
|
transition:
|
||||||
|
background 0.3s ease,
|
||||||
|
box-shadow 0.3s ease;
|
||||||
|
border: 1px solid rgba(255, 255, 255, 0.05);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 暗黑模式适配 */
|
/* 暗黑模式适配 */
|
||||||
[data-theme="dark"] .social-links-card {
|
:global([data-theme="dark"]) .social-links-card {
|
||||||
background: rgba(var(--v-theme-surface), 0.6);
|
background: rgba(var(--v-theme-surface), 0.6);
|
||||||
box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3),
|
box-shadow:
|
||||||
|
0 10px 30px rgba(0, 0, 0, 0.3),
|
||||||
inset 0 0 0 1px rgba(255, 255, 255, 0.05);
|
inset 0 0 0 1px rgba(255, 255, 255, 0.05);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -169,6 +198,11 @@ const openLink = (url) => {
|
|||||||
padding: 0.8rem 0;
|
padding: 0.8rem 0;
|
||||||
border-radius: 0.8rem;
|
border-radius: 0.8rem;
|
||||||
transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
|
transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
|
||||||
|
outline: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.social-item:focus-visible {
|
||||||
|
box-shadow: 0 0 0 2px var(--hover-color);
|
||||||
}
|
}
|
||||||
|
|
||||||
.social-item:hover {
|
.social-item:hover {
|
||||||
@ -191,7 +225,6 @@ const openLink = (url) => {
|
|||||||
|
|
||||||
.social-icon {
|
.social-icon {
|
||||||
font-size: 1.6rem;
|
font-size: 1.6rem;
|
||||||
color: var(--text-primary);
|
|
||||||
transition: all 0.3s ease;
|
transition: all 0.3s ease;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -234,49 +267,69 @@ const openLink = (url) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* 二维码样式 */
|
/* 二维码样式 */
|
||||||
.qr-overlay {
|
.qr-container {
|
||||||
position: fixed;
|
position: fixed;
|
||||||
top: 0;
|
top: 0;
|
||||||
left: 0;
|
left: 0;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
height: 100%;
|
height: 100%;
|
||||||
background: rgba(0, 0, 0, 0.7);
|
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
z-index: 100;
|
z-index: 100;
|
||||||
backdrop-filter: blur(5px);
|
pointer-events: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
.qr-container {
|
.qr-code {
|
||||||
background: white;
|
background: white;
|
||||||
padding: 1.5rem;
|
padding: 1.5rem;
|
||||||
border-radius: 1rem;
|
border-radius: 1rem;
|
||||||
text-align: center;
|
text-align: center;
|
||||||
box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
|
box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
|
||||||
|
position: relative;
|
||||||
|
pointer-events: auto;
|
||||||
}
|
}
|
||||||
|
|
||||||
.qr-image {
|
.qr-code img {
|
||||||
width: 180px;
|
width: 180px;
|
||||||
height: 180px;
|
height: 180px;
|
||||||
margin-bottom: 0.5rem;
|
display: block;
|
||||||
|
margin: 0 auto;
|
||||||
}
|
}
|
||||||
|
|
||||||
.qr-hint {
|
.qr-close {
|
||||||
color: var(--text-primary);
|
position: absolute;
|
||||||
font-weight: 500;
|
top: 0.5rem;
|
||||||
margin-top: 0.5rem;
|
right: 0.5rem;
|
||||||
|
background: transparent;
|
||||||
|
border: none;
|
||||||
|
font-size: 1.5rem;
|
||||||
|
cursor: pointer;
|
||||||
|
color: #666;
|
||||||
|
width: 2rem;
|
||||||
|
height: 2rem;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
border-radius: 50%;
|
||||||
|
transition: all 0.2s ease;
|
||||||
|
}
|
||||||
|
|
||||||
|
.qr-close:hover {
|
||||||
|
background: #f0f0f0;
|
||||||
|
color: #333;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 过渡动画 */
|
/* 过渡动画 */
|
||||||
.fade-enter-active,
|
.fade-enter-active,
|
||||||
.fade-leave-active {
|
.fade-leave-active {
|
||||||
transition: opacity 0.3s ease;
|
transition: all 0.3s ease;
|
||||||
}
|
}
|
||||||
|
|
||||||
.fade-enter-from,
|
.fade-enter-from,
|
||||||
.fade-leave-to {
|
.fade-leave-to {
|
||||||
opacity: 0;
|
opacity: 0;
|
||||||
|
transform: scale(0.95);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 响应式调整 */
|
/* 响应式调整 */
|
||||||
@ -294,5 +347,14 @@ const openLink = (url) => {
|
|||||||
.social-icon {
|
.social-icon {
|
||||||
font-size: 1.4rem;
|
font-size: 1.4rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.qr-code {
|
||||||
|
padding: 1rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.qr-code img {
|
||||||
|
width: 150px;
|
||||||
|
height: 150px;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
Loading…
x
Reference in New Issue
Block a user