Files
jinshen-website/app/components/pages/about/LearnMoreCard.vue
R2m1liA 67629ed518
All checks were successful
deploy to server / build-and-deploy (push) Successful in 3m21s
feat: about页面添加公司地址跳转功能
- 外部链接跳转:点击公司地址时,跳转带外部地图服务商链接
- 智能跳转: 根据用户的连接情况,自动选择google地图或者高德地图
2025-11-18 14:11:43 +08:00

94 lines
1.8 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<template>
<component
:is="wrapperTag"
v-bind="wrapperProps"
class="learn-more-wrapper"
@click="handleAsyncClick"
>
<el-card class="learn-more-card">
<el-icon class="icon" size="80">
<component :is="icon" />
</el-icon>
<br />
{{ title }}
</el-card>
</component>
</template>
<script setup lang="ts">
const props = defineProps({
title: {
type: String,
default: '',
},
icon: {
type: Object,
default: null,
},
to: {
type: String,
default: null,
},
href: {
type: [String, Function],
default: null,
},
});
// 包裹器标签
const wrapperTag = computed(() => {
if (props.to) return resolveComponent('NuxtLink');
if (props.href) return 'a';
return 'div';
});
// 包裹器属性
const wrapperProps = computed(() => {
// Nuxt 内部跳转
if (props.to) {
return { to: props.to };
}
// 外部跳转(字符串)
if (typeof props.href === 'string') {
return {
href: props.href,
target: '_blank',
rel: 'noopener noreferrer',
};
}
// 其他情况href 是异步函数 → 不在这里处理
return { href: '#' };
});
async function handleAsyncClick(event: Event) {
if (typeof props.href === 'function') {
event.preventDefault();
const url = await props.href();
window.open(url, '_blank', 'noopener,noreferrer');
}
}
</script>
<style scoped>
.learn-more-card {
width: 20%;
min-width: 200px;
padding: 20px;
margin: 0 auto;
cursor: pointer;
text-align: center;
font-size: 1.5em;
}
.learn-more-card:hover {
transform: translateY(-4px);
box-shadow: 0 8px 25px rgba(0, 0, 0, 0.15);
}
.icon {
padding: 10px;
}
</style>