feat: update SocialLinks component styling and functionality
This commit is contained in:
parent
f752449dc4
commit
65f44b146b
@ -1,65 +1,65 @@
|
|||||||
<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: `
|
||||||
@ -67,48 +67,42 @@ const cardTransform = computed(() => {
|
|||||||
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>
|
</TransitionGroup>
|
||||||
</Transition>
|
|
||||||
|
|
||||||
<!-- 社交链接主体 -->
|
<!-- 社交链接主体 -->
|
||||||
<div class="social-grid">
|
<div class="social-grid">
|
||||||
@ -117,7 +111,9 @@ const openLink = (url) => {
|
|||||||
: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
|
||||||
@ -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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user