refactor: 调整components目录
- 将components根据作用范围/可复用性进行分类
This commit is contained in:
75
app/components/shared/DocumentList.vue
Normal file
75
app/components/shared/DocumentList.vue
Normal file
@ -0,0 +1,75 @@
|
||||
<template>
|
||||
<div class="document-list">
|
||||
<el-card
|
||||
v-for="(doc, index) in documents"
|
||||
:key="index"
|
||||
class="document-card"
|
||||
@click="handleClick(doc.fileId)"
|
||||
>
|
||||
<div class="document-info">
|
||||
<h3>{{ doc.title }}</h3>
|
||||
<div class="document-content">
|
||||
<span v-if="doc.size" class="document-meta"
|
||||
>大小: {{ formatFileSize(doc.size) }}
|
||||
</span>
|
||||
<span v-if="doc.filename" class="document-meta"
|
||||
>格式:
|
||||
{{ formatFileExtension(getFileExtension(doc.filename)) }}</span
|
||||
>
|
||||
</div>
|
||||
</div>
|
||||
</el-card>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
defineProps({
|
||||
documents: {
|
||||
type: Array as () => Array<ProductDocumentView>,
|
||||
default: () => [],
|
||||
},
|
||||
});
|
||||
|
||||
const localePath = useLocalePath();
|
||||
|
||||
const handleClick = (id: string) => {
|
||||
// 获取路由参数
|
||||
if (id) {
|
||||
navigateTo(localePath(`/download/${id}`));
|
||||
}
|
||||
};
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.document-list {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 1rem;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.document-card {
|
||||
cursor: pointer;
|
||||
transition: all 0.3s ease;
|
||||
}
|
||||
|
||||
.document-card:hover {
|
||||
transform: translateY(-1px);
|
||||
box-shadow: 0 8px 25px rgba(0, 0, 0, 0.15);
|
||||
}
|
||||
|
||||
.document-meta {
|
||||
font-size: 0.8rem;
|
||||
color: var(--el-text-color-secondary);
|
||||
}
|
||||
|
||||
.download-button {
|
||||
margin-left: auto;
|
||||
}
|
||||
|
||||
.document-content {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 1rem;
|
||||
}
|
||||
</style>
|
||||
177
app/components/shared/FilePreviewer.vue
Normal file
177
app/components/shared/FilePreviewer.vue
Normal file
@ -0,0 +1,177 @@
|
||||
<template>
|
||||
<section class="h-screen flex flex-col">
|
||||
<!-- 头部工具栏 -->
|
||||
<header
|
||||
v-if="showToolbar && fileMeta"
|
||||
class="p-3 border-b flex items-center justify-between"
|
||||
>
|
||||
<div class="min-w-0">
|
||||
<h2 class="truncate font-medium" :title="fileMeta.filename_download">
|
||||
{{ fileMeta.filename_download }}
|
||||
</h2>
|
||||
<p class="text-xs text-gray-500">
|
||||
{{ fileMeta.type }} · {{ formatedSize }} · {{ formatedDate }}
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div class="shrink-0 flex items-center gap-2">
|
||||
<button
|
||||
class="px-3 py-1.5 rounded border hover:bg-gray-50"
|
||||
type="button"
|
||||
:disabled="!fileMeta"
|
||||
@click="openInNewTab"
|
||||
>
|
||||
在新标签打开
|
||||
</button>
|
||||
<button
|
||||
class="px-3 py-1.5 rounded bg-blue-600 text-white hover:bg-blue-700 disabled:opacity-50"
|
||||
type="button"
|
||||
:disabled="!fileMeta"
|
||||
@click="download"
|
||||
>
|
||||
下载
|
||||
</button>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<div class="flex-1 overflow-hidden">
|
||||
<!-- 加载状态 -->
|
||||
<div v-if="pending" class="h-48 grid place-items-center border rounded">
|
||||
正在加载...
|
||||
</div>
|
||||
<div
|
||||
v-else-if="errorText"
|
||||
class="h-48 grid place-items-center border rounded text-red-600"
|
||||
>
|
||||
{{ errorText }}
|
||||
</div>
|
||||
<!-- 文件预览 -->
|
||||
<ClientOnly v-else>
|
||||
<div
|
||||
v-if="fileMeta && previewable"
|
||||
class="h-full w-full flex justify-center bg-gray-50"
|
||||
>
|
||||
<!-- 图片 -->
|
||||
<el-image
|
||||
v-if="isImage"
|
||||
fit="contain"
|
||||
class="max-w-full max-h-full select-none"
|
||||
:src="src"
|
||||
:alt="fileMeta.title || fileMeta.filename_download"
|
||||
/>
|
||||
|
||||
<!-- PDF -->
|
||||
<iframe
|
||||
v-else-if="isPdf"
|
||||
:src="src"
|
||||
title="PDF 预览"
|
||||
class="w-full h-full border-0"
|
||||
/>
|
||||
|
||||
<!-- 视频 -->
|
||||
<video
|
||||
v-else-if="isVideo"
|
||||
:src="src"
|
||||
controls
|
||||
class="w-full bg-black"
|
||||
/>
|
||||
|
||||
<!-- 文本(简单方式用 iframe;如需代码高亮可改为拉取文本并渲染 <pre>) -->
|
||||
<iframe
|
||||
v-else-if="isText"
|
||||
:src="src"
|
||||
title="文本预览"
|
||||
class="w-full h-full border-0"
|
||||
/>
|
||||
</div>
|
||||
</ClientOnly>
|
||||
</div>
|
||||
</section>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
const props = withDefaults(
|
||||
defineProps<{
|
||||
/** 预览的文件 ID */
|
||||
fileId?: string;
|
||||
file?: FileMeta;
|
||||
|
||||
/** 是否显示上方工具栏(文件名、大小、按钮) */
|
||||
showToolbar?: boolean;
|
||||
|
||||
/** 下载 API 基础路径(你的后端流接口),用于“下载”按钮 */
|
||||
downloadApiBase?: string;
|
||||
|
||||
/** 追加到 file.url 的查询(如临时 token),形如 { token: 'xxx' } */
|
||||
extraQuery?: Record<string, string | number | boolean>;
|
||||
}>(),
|
||||
{
|
||||
fileId: undefined,
|
||||
file: undefined,
|
||||
showToolbar: true,
|
||||
downloadApiBase: '/api/download',
|
||||
extraQuery: undefined,
|
||||
}
|
||||
);
|
||||
|
||||
const { data, pending, error } = await useFetch<FileMeta>(
|
||||
() => (props.file ? null : `/api/file/${props.fileId}`),
|
||||
{ server: true }
|
||||
);
|
||||
|
||||
const errorText = computed(() => error.value?.message ?? null);
|
||||
const fileMeta = computed(() => props.file ?? data.value ?? null);
|
||||
|
||||
/** 预览源地址:支持在 file.url 上追加额外 query(如临时 token、inline) */
|
||||
const src = computed<string>(() => {
|
||||
if (!fileMeta.value) return '';
|
||||
const url = new URL(fileMeta.value.url, window?.location?.origin);
|
||||
if (props.extraQuery) {
|
||||
Object.entries(props.extraQuery).forEach(([k, v]) =>
|
||||
url.searchParams.set(k, String(v))
|
||||
);
|
||||
}
|
||||
return url.toString();
|
||||
});
|
||||
|
||||
/** 类型判定 */
|
||||
const isImage = computed(
|
||||
() => fileMeta.value?.type.startsWith('image/') === true
|
||||
);
|
||||
const isPdf = computed(() => fileMeta.value?.type === 'application/pdf');
|
||||
const isVideo = computed(
|
||||
() => fileMeta.value?.type.startsWith('video/') === true
|
||||
);
|
||||
const isText = computed(
|
||||
() => fileMeta.value?.type.startsWith('text/') === true
|
||||
);
|
||||
const previewable = computed(() => fileMeta.value?.previewable === true);
|
||||
|
||||
const formatedSize = computed(() => {
|
||||
const size = fileMeta.value?.filesize ?? 0;
|
||||
return formatFileSize(size);
|
||||
});
|
||||
|
||||
const formatedDate = computed(() => {
|
||||
if (!fileMeta.value?.uploaded_on) return '';
|
||||
return new Date(fileMeta.value.uploaded_on).toLocaleDateString();
|
||||
});
|
||||
|
||||
/** 下载动作:走你自己的流式后端,避免直链暴露(便于权限与统计) */
|
||||
function download(): void {
|
||||
if (!fileMeta.value) return;
|
||||
const id = fileMeta.value.id;
|
||||
const a = document.createElement('a');
|
||||
a.href = `${props.downloadApiBase}/${encodeURIComponent(id)}`;
|
||||
a.download = fileMeta.value.filename_download;
|
||||
document.body.appendChild(a);
|
||||
a.click();
|
||||
document.body.removeChild(a);
|
||||
}
|
||||
|
||||
/** 新标签打开(直接访问直链,适合预览失败时的兜底体验) */
|
||||
function openInNewTab(): void {
|
||||
if (!src.value) return;
|
||||
window.open(src.value, '_blank', 'noopener,noreferrer');
|
||||
}
|
||||
</script>
|
||||
280
app/components/shared/JinshenFooter.vue
Normal file
280
app/components/shared/JinshenFooter.vue
Normal file
@ -0,0 +1,280 @@
|
||||
<template>
|
||||
<footer class="jinshen-footer">
|
||||
<div class="footer-container">
|
||||
<!-- Logo 和公司信息 -->
|
||||
<div class="footer-section">
|
||||
<div class="footer-logo">
|
||||
<img src="/jinshen-logo.png" alt="Jinshen Logo" class="logo-image" />
|
||||
<h3>{{ $t('company-name') }}</h3>
|
||||
</div>
|
||||
<p class="company-description">
|
||||
{{ $t('company-description') }}
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<!-- 快速链接 -->
|
||||
<div class="footer-section">
|
||||
<h4>{{ $t('quick-links') }}</h4>
|
||||
<ul class="footer-links">
|
||||
<li>
|
||||
<NuxtLinkLocale to="/">{{ $t('navigation.home') }}</NuxtLinkLocale>
|
||||
</li>
|
||||
<li>
|
||||
<NuxtLink :to="$localePath('/products')">{{
|
||||
$t('navigation.products')
|
||||
}}</NuxtLink>
|
||||
</li>
|
||||
<li>
|
||||
<NuxtLink :to="$localePath('/solutions')">{{
|
||||
$t('navigation.solutions')
|
||||
}}</NuxtLink>
|
||||
</li>
|
||||
<li>
|
||||
<NuxtLink :to="$localePath('/support')">{{
|
||||
$t('navigation.support')
|
||||
}}</NuxtLink>
|
||||
</li>
|
||||
<li>
|
||||
<NuxtLink :to="$localePath('/about')">{{
|
||||
$t('navigation.about-us')
|
||||
}}</NuxtLink>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<!-- 实用工具 -->
|
||||
<div class="footer-section">
|
||||
<h4>{{ $t('utilities') }}</h4>
|
||||
<ul class="footer-links">
|
||||
<li>
|
||||
<a
|
||||
href="http://cal.jinshen.cn"
|
||||
target="_blank"
|
||||
rel="noopener noreferer"
|
||||
>
|
||||
{{ $t('navigation.calculator') }}
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<!-- 联系信息 -->
|
||||
<div class="footer-section">
|
||||
<h4>{{ $t('contact-info') }}</h4>
|
||||
<div class="contact-item">
|
||||
<el-icon><Phone /></el-icon>
|
||||
<span>{{ $t('telephone') }}: 0573-88187988</span>
|
||||
</div>
|
||||
<div class="contact-item">
|
||||
<el-icon><Message /></el-icon>
|
||||
<span>{{ $t('email') }}: jinshen@wzjinshen.com</span>
|
||||
</div>
|
||||
<div class="contact-item">
|
||||
<el-icon><Location /></el-icon>
|
||||
<span>{{ $t('address') }}: {{ $t('company-address') }}</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 版权信息 -->
|
||||
<div class="footer-bottom">
|
||||
<div class="footer-container">
|
||||
<div class="copyright">
|
||||
<p>
|
||||
© {{ currentYear }} {{ $t('company-name') }}.
|
||||
{{ $t('all-rights-reserved') }}
|
||||
</p>
|
||||
<p>备案号: 浙ICP备12003709号-5</p>
|
||||
</div>
|
||||
<div class="footer-links-bottom">
|
||||
<NuxtLink :to="$localePath('/privacy')">{{
|
||||
$t('privacy-policy')
|
||||
}}</NuxtLink>
|
||||
<span class="separator">|</span>
|
||||
<NuxtLink :to="$localePath('/terms')">{{
|
||||
$t('terms-of-service')
|
||||
}}</NuxtLink>
|
||||
<span class="separator">|</span>
|
||||
<NuxtLink :to="$localePath('/sitemap')">{{ $t('sitemap') }}</NuxtLink>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</footer>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { Phone, Message, Location } from '@element-plus/icons-vue';
|
||||
|
||||
const currentYear = new Date().getFullYear();
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.jinshen-footer {
|
||||
background: var(--el-bg-color-page);
|
||||
border-top: 1px solid var(--el-border-color);
|
||||
margin-top: auto;
|
||||
}
|
||||
|
||||
.footer-container {
|
||||
max-width: 1200px;
|
||||
margin: 0 auto;
|
||||
padding: 2rem 1rem;
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
|
||||
gap: 2rem;
|
||||
}
|
||||
|
||||
.footer-section h3,
|
||||
.footer-section h4 {
|
||||
color: var(--el-text-color-primary);
|
||||
margin-bottom: 1rem;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.footer-logo {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.75rem;
|
||||
margin-bottom: 1rem;
|
||||
}
|
||||
|
||||
.logo-image {
|
||||
width: 40px;
|
||||
height: 40px;
|
||||
object-fit: contain;
|
||||
}
|
||||
|
||||
.company-description {
|
||||
color: var(--el-text-color-regular);
|
||||
line-height: 1.6;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.footer-links {
|
||||
list-style: none;
|
||||
padding: 0;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.footer-links li {
|
||||
margin-bottom: 0.5rem;
|
||||
}
|
||||
|
||||
.footer-links a {
|
||||
color: var(--el-text-color-regular);
|
||||
text-decoration: none;
|
||||
transition: color 0.3s ease;
|
||||
}
|
||||
|
||||
.footer-links a:hover {
|
||||
color: var(--el-color-primary);
|
||||
}
|
||||
|
||||
.contact-item {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.5rem;
|
||||
margin-bottom: 0.75rem;
|
||||
color: var(--el-text-color-regular);
|
||||
}
|
||||
|
||||
.contact-item .el-icon {
|
||||
color: var(--el-color-primary);
|
||||
}
|
||||
|
||||
.social-links {
|
||||
display: flex;
|
||||
gap: 1rem;
|
||||
}
|
||||
|
||||
.social-link {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 40px;
|
||||
height: 40px;
|
||||
background: var(--el-fill-color-light);
|
||||
border-radius: 50%;
|
||||
color: var(--el-text-color-regular);
|
||||
text-decoration: none;
|
||||
transition: all 0.3s ease;
|
||||
}
|
||||
|
||||
.social-link:hover {
|
||||
background: var(--el-color-primary);
|
||||
color: white;
|
||||
transform: translateY(-2px);
|
||||
}
|
||||
|
||||
.footer-bottom {
|
||||
background: var(--el-fill-color-light);
|
||||
border-top: 1px solid var(--el-border-color-lighter);
|
||||
padding: 1rem 0;
|
||||
}
|
||||
|
||||
.footer-bottom .footer-container {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
padding: 0 1rem;
|
||||
grid-template-columns: none;
|
||||
gap: 1rem;
|
||||
}
|
||||
|
||||
.copyright p {
|
||||
margin: 0;
|
||||
color: var(--el-text-color-regular);
|
||||
font-size: 0.875rem;
|
||||
}
|
||||
|
||||
.footer-links-bottom {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.5rem;
|
||||
}
|
||||
|
||||
.footer-links-bottom a {
|
||||
color: var(--el-text-color-regular);
|
||||
text-decoration: none;
|
||||
font-size: 0.875rem;
|
||||
transition: color 0.3s ease;
|
||||
}
|
||||
|
||||
.footer-links-bottom a:hover {
|
||||
color: var(--el-color-primary);
|
||||
}
|
||||
|
||||
.separator {
|
||||
color: var(--el-text-color-placeholder);
|
||||
}
|
||||
|
||||
/* 响应式设计 */
|
||||
@media (max-width: 768px) {
|
||||
.footer-container {
|
||||
grid-template-columns: 1fr;
|
||||
padding: 1.5rem 1rem;
|
||||
}
|
||||
|
||||
.footer-bottom .footer-container {
|
||||
flex-direction: column;
|
||||
text-align: center;
|
||||
gap: 1rem;
|
||||
}
|
||||
|
||||
.footer-links-bottom {
|
||||
flex-wrap: wrap;
|
||||
justify-content: center;
|
||||
}
|
||||
}
|
||||
|
||||
/* 暗色模式适配 */
|
||||
@media (prefers-color-scheme: dark) {
|
||||
.jinshen-footer {
|
||||
background: var(--el-bg-color-page);
|
||||
}
|
||||
|
||||
.footer-bottom {
|
||||
background: var(--el-fill-color-darker);
|
||||
}
|
||||
}
|
||||
</style>
|
||||
170
app/components/shared/JinshenHeader.vue
Normal file
170
app/components/shared/JinshenHeader.vue
Normal file
@ -0,0 +1,170 @@
|
||||
<template>
|
||||
<header class="header-container">
|
||||
<div class="logo-section">
|
||||
<NuxtLink :to="$localePath('/')" class="logo-link">
|
||||
<el-image
|
||||
class="website-logo"
|
||||
src="/jinshen-logo.png"
|
||||
alt="Jinshen Logo"
|
||||
fit="contain"
|
||||
/>
|
||||
</NuxtLink>
|
||||
</div>
|
||||
|
||||
<div class="header-menu-section">
|
||||
<!-- 导航菜单 -->
|
||||
<el-menu
|
||||
:default-active="activeName"
|
||||
class="header-menu"
|
||||
mode="horizontal"
|
||||
:ellipsis="false"
|
||||
:persistent="false"
|
||||
router
|
||||
>
|
||||
<el-menu-item index="products" :route="$localePath('/products')">
|
||||
<span class="title">{{ $t('navigation.products') }}</span>
|
||||
</el-menu-item>
|
||||
<el-menu-item index="solutions" :route="$localePath('/solutions')">
|
||||
<span class="title">{{ $t('navigation.solutions') }}</span>
|
||||
</el-menu-item>
|
||||
<el-menu-item index="support" :route="$localePath('/support')">
|
||||
<span class="title">{{ $t('navigation.support') }}</span>
|
||||
</el-menu-item>
|
||||
<el-menu-item index="about" :route="$localePath('/about')">
|
||||
<span class="title">{{ $t('navigation.about-us') }}</span>
|
||||
</el-menu-item>
|
||||
</el-menu>
|
||||
</div>
|
||||
|
||||
<!-- 右侧功能区 -->
|
||||
<div class="header-actions">
|
||||
<el-link
|
||||
class="search-link"
|
||||
:underline="false"
|
||||
type="info"
|
||||
@click="navigateTo(localePath('/search'))"
|
||||
>
|
||||
<el-icon class="mdi mdi-magnify action-icon" />
|
||||
</el-link>
|
||||
|
||||
<el-link
|
||||
type="info"
|
||||
:underline="false"
|
||||
href="http://cal.jinshen.cn"
|
||||
target="_blank"
|
||||
>
|
||||
<el-icon class="mdi mdi-calculator action-icon" />
|
||||
</el-link>
|
||||
|
||||
<el-dropdown @command="setLocale">
|
||||
<el-link type="info" :underline="false">
|
||||
<el-icon class="mdi mdi-translate action-icon" />
|
||||
</el-link>
|
||||
<template #dropdown>
|
||||
<el-dropdown-menu>
|
||||
<el-dropdown-item command="zh">简体中文</el-dropdown-item>
|
||||
<el-dropdown-item command="en">English</el-dropdown-item>
|
||||
</el-dropdown-menu>
|
||||
</template>
|
||||
</el-dropdown>
|
||||
</div>
|
||||
</header>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
const router = useRouter();
|
||||
const localePath = useLocalePath();
|
||||
|
||||
const { setLocale } = useI18n();
|
||||
|
||||
const activeName = ref<string | undefined>(undefined);
|
||||
|
||||
const refreshMenu = () => {
|
||||
const path = router.currentRoute.value.path;
|
||||
if (path.startsWith('/products')) {
|
||||
activeName.value = 'products';
|
||||
} else if (path.startsWith('/solutions')) {
|
||||
activeName.value = 'solutions';
|
||||
} else if (path.startsWith('/support')) {
|
||||
activeName.value = 'support';
|
||||
} else if (path.startsWith('/about')) {
|
||||
activeName.value = 'about';
|
||||
} else {
|
||||
activeName.value = undefined; // 默认不激活任何菜单项
|
||||
}
|
||||
};
|
||||
|
||||
onMounted(() => {
|
||||
refreshMenu();
|
||||
// 监听路由变化以更新激活状态
|
||||
router.afterEach(() => {
|
||||
refreshMenu();
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.header-container {
|
||||
padding: 0 10px;
|
||||
display: flex;
|
||||
height: 80px;
|
||||
align-items: center;
|
||||
border-bottom: 1px solid #e0e0e0;
|
||||
}
|
||||
|
||||
.logo-section {
|
||||
display: flex;
|
||||
flex: 1;
|
||||
margin-left: 20px;
|
||||
}
|
||||
|
||||
.logo-link {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
.website-logo {
|
||||
height: 64px;
|
||||
width: auto;
|
||||
}
|
||||
|
||||
.header-menu-section {
|
||||
flex: 2;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
.header-menu {
|
||||
margin-right: 40px;
|
||||
border-bottom: none !important;
|
||||
width: auto;
|
||||
--el-menu-horizontal-height: 100%;
|
||||
}
|
||||
|
||||
.header-menu .el-menu-item {
|
||||
font-size: 16px;
|
||||
background-color: transparent !important;
|
||||
}
|
||||
|
||||
.header-menu .el-menu-item.is-active {
|
||||
border-bottom: 2.5px solid var(--el-color-primary-dark-2);
|
||||
color: var(--el-color-primary);
|
||||
}
|
||||
|
||||
.header-menu .el-menu-item:hover {
|
||||
border-bottom: 2.5px solid var(--el-color-primary);
|
||||
}
|
||||
|
||||
.header-actions {
|
||||
flex: 1;
|
||||
justify-content: flex-end;
|
||||
display: flex;
|
||||
gap: 16px;
|
||||
}
|
||||
|
||||
.action-icon {
|
||||
font-size: 24px;
|
||||
}
|
||||
</style>
|
||||
111
app/components/shared/MarkdownRenderer.vue
Normal file
111
app/components/shared/MarkdownRenderer.vue
Normal file
@ -0,0 +1,111 @@
|
||||
<!-- eslint-disable vue/no-v-html -->
|
||||
<template>
|
||||
<!-- 用 v-html 渲染解析后的 HTML -->
|
||||
<div ref="container" class="markdown-body" v-html="safeHtml" />
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { createApp } from 'vue';
|
||||
import MarkdownTable from './MarkdownTable.vue';
|
||||
interface Props {
|
||||
content: string;
|
||||
}
|
||||
|
||||
const props = defineProps<Props>();
|
||||
|
||||
const contentWithAbsoluteUrls = convertMedia(props.content);
|
||||
|
||||
// 将 Markdown 转换成 HTML
|
||||
const safeHtml = computed(() => renderMarkdown(contentWithAbsoluteUrls));
|
||||
// const safeHtml = computed(() => renderMarkdown(props.content))
|
||||
|
||||
const container = ref<HTMLElement | null>(null);
|
||||
|
||||
onMounted(async () => {
|
||||
await nextTick();
|
||||
if (!safeHtml.value) return;
|
||||
console.log(safeHtml.value);
|
||||
|
||||
// 查找所有 table
|
||||
const tables = container.value.querySelectorAll('table');
|
||||
console.log(tables);
|
||||
tables.forEach((table) => {
|
||||
// 1. 提取表头
|
||||
const headers = Array.from(table.querySelectorAll('thead th')).map(
|
||||
(th) => th.textContent?.trim() ?? ''
|
||||
);
|
||||
|
||||
// 2. 提取行数据
|
||||
const rows = Array.from(table.querySelectorAll('tbody tr')).map((tr) => {
|
||||
const cells = Array.from(tr.querySelectorAll('td')).map(
|
||||
(td) => td.textContent?.trim() ?? ''
|
||||
);
|
||||
const obj: Record<string, string> = {};
|
||||
headers.forEach((h, i) => {
|
||||
obj[h] = cells[i];
|
||||
});
|
||||
return obj;
|
||||
});
|
||||
|
||||
// 3. 创建 Vue 子应用,把原生 table 替换成 <md-table>
|
||||
const mountPoint = document.createElement('div');
|
||||
table.replaceWith(mountPoint);
|
||||
|
||||
const app = createApp(MarkdownTable, { headers, rows });
|
||||
app.mount(mountPoint);
|
||||
});
|
||||
});
|
||||
|
||||
// console.log('Rendered HTML:', safeHtml.value);
|
||||
</script>
|
||||
|
||||
<style>
|
||||
.markdown-body {
|
||||
padding: 10px;
|
||||
line-height: 1.6;
|
||||
}
|
||||
|
||||
.markdown-body h1 {
|
||||
color: var(--el-color-primary);
|
||||
font-size: 1.5em;
|
||||
margin-bottom: 0.5em;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.markdown-body h2 {
|
||||
color: var(--el-color-primary);
|
||||
font-size: 1.5em;
|
||||
margin-bottom: 0.5em;
|
||||
}
|
||||
|
||||
.markdown-body h3 {
|
||||
color: var(--el-color-primary);
|
||||
font-size: 1.2em;
|
||||
margin-bottom: 0.5em;
|
||||
}
|
||||
|
||||
.markdown-body p {
|
||||
text-indent: 2em;
|
||||
text-align: justify;
|
||||
margin: 0.5em 0;
|
||||
margin-bottom: 1em;
|
||||
}
|
||||
|
||||
.markdown-body ol {
|
||||
list-style-type: decimal;
|
||||
padding-left: 2em;
|
||||
margin-bottom: 1em;
|
||||
}
|
||||
|
||||
.markdown-body ul {
|
||||
list-style-type: disc;
|
||||
padding-left: 2em;
|
||||
margin-bottom: 1em;
|
||||
}
|
||||
|
||||
.markdown-body hr {
|
||||
border: none;
|
||||
border-top: 1px solid var(--el-border-color);
|
||||
margin: 20px 0;
|
||||
}
|
||||
</style>
|
||||
12
app/components/shared/MarkdownTable.vue
Normal file
12
app/components/shared/MarkdownTable.vue
Normal file
@ -0,0 +1,12 @@
|
||||
<template>
|
||||
<el-table :data="rows" border>
|
||||
<el-table-column v-for="h in headers" :key="h" :prop="h" :label="h" />
|
||||
</el-table>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
defineProps<{
|
||||
headers: string[];
|
||||
rows: Record<string, string>[];
|
||||
}>();
|
||||
</script>
|
||||
86
app/components/shared/ProductCard.vue
Normal file
86
app/components/shared/ProductCard.vue
Normal file
@ -0,0 +1,86 @@
|
||||
<template>
|
||||
<el-card class="product-card" @click="handleClick">
|
||||
<template #header>
|
||||
<!-- Image -->
|
||||
<el-image class="product-image" :src="imageUrl" fit="contain" />
|
||||
</template>
|
||||
|
||||
<div class="card-body">
|
||||
<!-- Name -->
|
||||
<div class="text-center">
|
||||
<span class="product-name">{{ name }}</span>
|
||||
</div>
|
||||
<!-- Description -->
|
||||
<div class="card-description text-left opacity-25">{{ description }}</div>
|
||||
</div>
|
||||
</el-card>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
interface Props {
|
||||
name: string;
|
||||
description: string;
|
||||
imageUrl: string;
|
||||
id?: string | number;
|
||||
slug?: string;
|
||||
}
|
||||
|
||||
const props = defineProps<Props>();
|
||||
const localePath = useLocalePath();
|
||||
|
||||
const handleClick = () => {
|
||||
// 优先使用 slug,如果没有则使用 id
|
||||
const routeParam = props.slug || props.id;
|
||||
if (routeParam) {
|
||||
navigateTo(localePath(`/products/${routeParam}`));
|
||||
}
|
||||
};
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.product-card {
|
||||
width: 30%;
|
||||
cursor: pointer;
|
||||
transition: all 0.3s ease;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.product-card:hover {
|
||||
transform: translateY(-4px);
|
||||
box-shadow: 0 8px 25px rgba(0, 0, 0, 0.15);
|
||||
}
|
||||
|
||||
.product-name {
|
||||
font-size: 1rem;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.card-description {
|
||||
font-size: 0.8rem;
|
||||
margin-top: 5px;
|
||||
}
|
||||
|
||||
.product-card .el-image {
|
||||
height: 150px;
|
||||
border-radius: 4px;
|
||||
}
|
||||
|
||||
.card-body {
|
||||
margin: 10px auto;
|
||||
padding: 0px auto;
|
||||
height: 100px;
|
||||
}
|
||||
|
||||
/* 响应式设计 */
|
||||
@media (max-width: 1200px) {
|
||||
.product-card {
|
||||
width: 45%;
|
||||
}
|
||||
}
|
||||
|
||||
@media (max-width: 768px) {
|
||||
.product-card {
|
||||
width: 90%;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
61
app/components/shared/QuestionList.vue
Normal file
61
app/components/shared/QuestionList.vue
Normal file
@ -0,0 +1,61 @@
|
||||
<template>
|
||||
<div class="question-list">
|
||||
<el-collapse class="question-collapse" accordion>
|
||||
<el-collapse-item
|
||||
v-for="question in questions"
|
||||
:key="question.id"
|
||||
:title="question.title"
|
||||
:name="question.id"
|
||||
>
|
||||
<markdown-renderer :content="question.content || ''" />
|
||||
</el-collapse-item>
|
||||
</el-collapse>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
defineProps({
|
||||
questions: {
|
||||
type: Array as PropType<ProductQuestionView[]>,
|
||||
default: () => [],
|
||||
},
|
||||
});
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.question-list {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.question-collapse {
|
||||
border: none;
|
||||
}
|
||||
|
||||
.question-collapse :deep(.el-collapse-item) {
|
||||
margin-bottom: 1rem;
|
||||
border-radius: 8px;
|
||||
}
|
||||
|
||||
.question-collapse :deep(.el-collapse-item__header) {
|
||||
font-size: 1rem;
|
||||
padding: 1rem;
|
||||
border-radius: 8px;
|
||||
background-color: #f5f7fa;
|
||||
|
||||
transition: all 0.3s ease;
|
||||
|
||||
&.is-active {
|
||||
background-color: #e1e6eb;
|
||||
color: var(--el-color-primary);
|
||||
}
|
||||
}
|
||||
|
||||
.question-collapse :deep(.el-collapse-item__wrap) {
|
||||
border: none;
|
||||
}
|
||||
|
||||
.question-collapse :deep(.el-collapse-item__content) {
|
||||
padding: 1rem;
|
||||
font-size: 0.9rem;
|
||||
}
|
||||
</style>
|
||||
85
app/components/shared/SolutionCard.vue
Normal file
85
app/components/shared/SolutionCard.vue
Normal file
@ -0,0 +1,85 @@
|
||||
<template>
|
||||
<el-card
|
||||
class="solution-card"
|
||||
body-class="card-body"
|
||||
header-class="card-header"
|
||||
@click="handleClick"
|
||||
>
|
||||
<template #header>
|
||||
<!-- Cover Image -->
|
||||
<el-image class="solution-cover" :src="coverUrl" fit="cover" />
|
||||
</template>
|
||||
<!-- Title -->
|
||||
<template #default>
|
||||
<div class="text-center mx-auto text-md">
|
||||
<span class="solution-title">{{ title }}</span>
|
||||
</div>
|
||||
<!-- Summary -->
|
||||
<div class="mx-auto mt-5 text-left text-sm opacity-25">{{ summary }}</div>
|
||||
</template>
|
||||
</el-card>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
interface Props {
|
||||
title: string;
|
||||
summary: string;
|
||||
coverUrl: string;
|
||||
documentId?: string;
|
||||
}
|
||||
|
||||
const props = defineProps<Props>();
|
||||
const localePath = useLocalePath();
|
||||
|
||||
const handleClick = () => {
|
||||
const routeParam = props.documentId;
|
||||
if (routeParam) {
|
||||
navigateTo(localePath(`/solutions/${routeParam}`));
|
||||
}
|
||||
};
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.solution-card {
|
||||
width: 30%;
|
||||
cursor: pointer;
|
||||
transition: all 0.3s ease;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.solution-card:hover {
|
||||
transform: translateY(-4px);
|
||||
box-shadow: 0 8px 25px rgba(0, 0, 0, 0.15);
|
||||
}
|
||||
|
||||
.solution-title {
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
:deep(.card-header) {
|
||||
padding: 0;
|
||||
border-bottom: none !important;
|
||||
}
|
||||
|
||||
:deep(.card-body) {
|
||||
margin: 10px auto;
|
||||
padding: 1px auto;
|
||||
}
|
||||
|
||||
.solution-card .el-image {
|
||||
height: 250px;
|
||||
}
|
||||
|
||||
@media (max-width: 1200px) {
|
||||
.solution-card {
|
||||
width: 45%;
|
||||
}
|
||||
}
|
||||
|
||||
@media (max-width: 768px) {
|
||||
.solution-card {
|
||||
width: 90%;
|
||||
margin: 10px auto;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
Reference in New Issue
Block a user