feat: update SocialLinks component styling and functionality

This commit is contained in:
Cat Tom 2025-03-26 01:35:51 +08:00
parent f752449dc4
commit 65f44b146b

View File

@ -1,133 +1,129 @@
<script setup> <script setup>
import { computed } from 'vue' import { 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 cardRef = ref(null);
const { elementX, elementY } = useMouseInElement(cardRef) const { elementX, elementY } = useMouseInElement(cardRef);
// //
const socialPlatforms = [ const socialPlatforms = [
{ {
name: 'GitHub', name: "GitHub",
icon: 'ri-github-fill', icon: "ri-github-fill",
url: 'https://github.com/cattom', url: "https://github.com/cattom",
color: '#181717', color: "#181717",
hoverColor: '#6e5494', hoverColor: "#6e5494",
ariaLabel: '访问我的GitHub主页' ariaLabel: "访问我的GitHub主页",
}, },
{ {
name: 'Twitter', name: "Twitter",
icon: 'ri-twitter-x-fill', icon: "ri-twitter-x-fill",
url: 'https://twitter.com/cattom', url: "https://twitter.com/cattom",
color: '#000000', color: "#000000",
hoverColor: '#1DA1F2', hoverColor: "#1DA1F2",
ariaLabel: '在Twitter上关注我' ariaLabel: "在Twitter上关注我",
}, },
{ {
name: 'LinkedIn', name: "LinkedIn",
icon: 'ri-linkedin-fill', icon: "ri-linkedin-fill",
url: 'https://linkedin.com/in/cattom', url: "https://linkedin.com/in/cattom",
color: '#0A66C2', color: "#0A66C2",
hoverColor: '#0077B5', hoverColor: "#0077B5",
ariaLabel: '查看我的LinkedIn资料' ariaLabel: "查看我的LinkedIn资料",
}, },
{ {
name: 'Email', name: "Email",
icon: 'ri-mail-fill', icon: "ri-mail-fill",
url: 'mailto:hi@cattom.me', url: "mailto:hi@cattom.me",
color: '#D44638', color: "#D44638",
hoverColor: '#EA4335', hoverColor: "#EA4335",
ariaLabel: '发送电子邮件给我' ariaLabel: "发送电子邮件给我",
}, },
{ {
name: 'WeChat', name: "WeChat",
icon: 'ri-wechat-fill', icon: "ri-wechat-fill",
color: '#07C160', color: "#07C160",
hoverColor: '#2DC100', hoverColor: "#2DC100",
ariaLabel: '扫描我的微信二维码', ariaLabel: "扫描我的微信二维码",
qrCode: '/assets/qr-wechat.png', qrCode: "/assets/qr-wechat.png",
showQr: ref(false) showQr: ref(false),
} },
] ];
// //
const cardTransform = computed(() => { const cardTransform = computed(() => {
const MAX_TILT = 8 const MAX_TILT = 8;
const x = (elementX.value - (cardRef.value?.offsetWidth / 2 || 0)) / 20 const x = (elementX.value - (cardRef.value?.offsetWidth / 2 || 0)) / 20;
const y = ((cardRef.value?.offsetHeight / 2 || 0) - elementY.value) / 20 const y = ((cardRef.value?.offsetHeight / 2 || 0) - elementY.value) / 20;
return { return {
transform: ` transform: `
perspective(1000px) perspective(1000px)
rotateX(${Math.min(Math.max(-y, -MAX_TILT), MAX_TILT)}deg) rotateX(${Math.min(Math.max(-y, -MAX_TILT), MAX_TILT)}deg)
rotateY(${Math.min(Math.max(x, -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)' transition: "transform 0.5s cubic-bezier(0.03, 0.98, 0.52, 0.99)",
} };
}) });
// //
const toggleQrCode = (platform) => { const props = defineProps({
if (!platform.qrCode) return socialPlatforms: {
platform.showQr.value = !platform.showQr.value type: Array,
} required: true
}
})
const platformsWithQr = computed(() =>
props.socialPlatforms.filter(p => p.qrCode)
)
// //
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>
<div <div ref="cardRef" class="social-links-card" :style="cardTransform">
ref="cardRef"
class="social-links-card"
:style="cardTransform"
>
<!-- 微信二维码弹窗 --> <!-- 微信二维码弹窗 -->
<Transition name="fade"> <TransitionGroup name="fade" tag="div" class="qr-container">
<div <div
v-for="platform in socialPlatforms.filter(p => p.qrCode)" v-for="platform in platformsWithQr"
v-show="platform.showQr?.value" v-show="platform.showQr?.value"
:key="`qr-${platform.name}`" :key="`qr-${platform.name}`"
class="qr-overlay" class="qr-code"
@click.self="platform.showQr.value = false"
> >
<div class="qr-container"> <img :src="platform.qrCode" :alt="`${platform.name}二维码`" />
<img
:src="platform.qrCode"
:alt="`${platform.name}二维码`"
class="qr-image"
>
<p class="qr-hint">扫码添加{{ platform.name }}</p>
</div>
</div> </div>
</Transition> </TransitionGroup>
<!-- 社交链接主体 --> <!-- 社交链接主体 -->
<div class="social-grid"> <div class="social-grid">
<div <div
v-for="(platform, index) in socialPlatforms" v-for="(platform, index) in socialPlatforms"
:key="index" :key="index"
class="social-item" class="social-item"
:style="{ '--hover-color': platform.hoverColor }" :style="{ '--hover-color': platform.hoverColor }"
@click="platform.qrCode ? toggleQrCode(platform) : openLink(platform.url)" @click="
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" :aria-label="platform.ariaLabel"
/> />
</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>
@ -142,21 +138,17 @@ 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: box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1),
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: transition: background 0.3s ease, box-shadow 0.3s ease;
background 0.3s ease,
box-shadow 0.3s ease;
} }
/* 暗黑模式适配 */ /* 暗黑模式适配 */
[data-theme="dark"] .social-links-card { [data-theme="dark"] .social-links-card {
background: rgba(var(--v-theme-surface), 0.6); background: rgba(var(--v-theme-surface), 0.6);
box-shadow: box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3),
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);
} }
@ -293,12 +285,12 @@ const openLink = (url) => {
grid-template-columns: repeat(auto-fit, minmax(70px, 1fr)); grid-template-columns: repeat(auto-fit, minmax(70px, 1fr));
gap: 1rem; gap: 1rem;
} }
.social-icon-wrapper { .social-icon-wrapper {
width: 3rem; width: 3rem;
height: 3rem; height: 3rem;
} }
.social-icon { .social-icon {
font-size: 1.4rem; font-size: 1.4rem;
} }