Compare commits

...

2 Commits

Author SHA1 Message Date
631146eeb8 Fix: 修正面包屑导航的跳转逻辑 2025-08-16 17:16:31 +08:00
c3964b8e35 Fix: 小修小补 & 优化代码结构 2025-08-16 17:13:51 +08:00
7 changed files with 85 additions and 74 deletions

View File

@ -13,7 +13,6 @@ const props = defineProps<Props>()
// 将 Markdown 转换成 HTML
const safeHtml = computed(() => renderMarkdown(props.content))
console.log('Markdown content:', safeHtml.value)
</script>
<style>

View File

@ -3,9 +3,9 @@
<div v-if="production">
<!-- 面包屑导航 -->
<el-breadcrumb class="breadcrumb" separator="/">
<el-breadcrumb-item class="text-sm opacity-50" :to="{ path: '/' }">{{ $t('navigation.home')
<el-breadcrumb-item class="text-sm opacity-50" :to="{ path: $localePath('/') }">{{ $t('navigation.home')
}}</el-breadcrumb-item>
<el-breadcrumb-item class="text-sm opacity-50" :to="{ path: '/productions' }">{{ $t('productions')
<el-breadcrumb-item class="text-sm opacity-50" :to="{ path: $localePath('/productions') }">{{ $t('productions')
}}</el-breadcrumb-item>
<el-breadcrumb-item class="text-sm opactiy-50">{{ production.title }}</el-breadcrumb-item>
</el-breadcrumb>
@ -13,7 +13,7 @@
<!-- 产品详情内容 -->
<div class="production-header">
<div class="production-image">
<el-image :src="production.production_image.url" :alt="production.title" fit="contain" />
<el-image :src="useStrapiMedia(production?.production_image?.url || '')" :alt="production.title" fit="contain" />
</div>
<div class="production-info">
<h1>{{ production.title }}</h1>
@ -59,32 +59,19 @@
</template>
<script setup lang="ts">
interface ProductionDetails {
id: number
title: string
summary: string
production_type?: string
production_image: {
url: string
}
production_details?: string
production_specs?: string | object
documentId?: string
}
const route = useRoute()
const { findOne } = useStrapi()
const { getStrapiLocale } = useLocalizations()
const strapiLocale = getStrapiLocale()
const production = ref<ProductionDetails | null>(null)
const production = ref<Production | null>(null)
const pending = ref(true)
const activeName = ref('details') // 默认选中概览标签
// 获取路由参数slug 或 id
const productionParam = computed(() => route.params.slug as string)
const documentId = computed(() => route.params.slug as string)
const parsedSpecs = computed(() => {
if (!production.value?.production_specs) return JSON.parse('{}')
@ -106,7 +93,7 @@ const parsedSpecs = computed(() => {
onMounted(async () => {
try {
const response = await findOne<ProductionDetails>('productions', productionParam.value, {
const response = await findOne<Production>('productions', documentId.value, {
populate: '*',
locale: strapiLocale,
})
@ -114,21 +101,14 @@ onMounted(async () => {
if (response.data) {
const item = response.data
production.value = {
id: item.id,
title: item.title,
summary: item.summary,
production_details: item.production_details || '',
production_specs: item.production_specs || '',
production_image: {
url: item.production_image?.url
? `http://192.168.86.5:1337${item.production_image.url}`
: ''
},
documentId: item.documentId || '',
production_type: item.production_type,
production_details: item.production_details,
production_specs: item.production_specs,
production_image: item.production_image,
documentId: item.documentId,
}
console.log('Fetched production:', production.value)
console.log('Raw specs:', production.value.production_specs)
}
} catch (error) {
console.error('Failed to fetch production:', error)

View File

@ -4,10 +4,10 @@
v-for="production in productions"
:id="production.id"
:key="production.id"
:slug="production.slug"
:image-url="production.image_url"
:slug="production.documentId"
:image-url="useStrapiMedia(production?.production_image?.url || '')"
:name="production.title"
:description="production.summary"
:description="production.summary || ''"
/>
</div>
</template>
@ -20,35 +20,7 @@ const { getStrapiLocale } = useLocalizations()
const strapiLocale = getStrapiLocale()
const baseUrl = 'http://192.168.86.5:1337';
interface Production {
id: number;
title: string;
summary: string;
production_image?: {
url: string;
};
documentId?: string;
}
class ProductionInfo {
id: number;
title: string;
summary: string;
image_url: string;
slug?: string;
constructor(id: number, title: string, summary: string, image_url: string, slug?: string) {
this.id = id;
this.title = title;
this.summary = summary;
this.image_url = baseUrl + image_url;
this.slug = slug;
}
}
const productions = ref<ProductionInfo[]>();
const productions = ref<Production[]>();
onMounted(async () => {
try {
@ -56,16 +28,15 @@ onMounted(async () => {
populate: '*',
locale: strapiLocale, // 使用简体中文
})
productions.value = response.data.map((item: Production) => {
return new ProductionInfo(
item.id,
item.title,
item.summary,
item.production_image?.url || '',
item.documentId ? item.documentId : undefined
);
});
productions.value = response.data.map((item: Production) => ({
title: item.title,
summary: item.summary,
production_type: item.production_type,
production_image: item.production_image,
production_details: item.production_details,
production_specs: item.production_specs,
documentId: item.documentId
}))
} catch (error) {
console.error('Failed to fetch productions:', error)
}

View File

@ -0,0 +1,41 @@
export interface StrapiEntity {
id?: number;
documentId?: string;
createdAt?: string;
updatedAt?: string;
publishedAt?: string;
locale?: string;
}
export interface StrapiImage {
id: number;
url: string;
alternativeText?: string;
caption?: string;
width?: number;
height?: number;
formats?: {
small?: StrapiImageFormat;
medium?: StrapiImageFormat;
thumbnail?: StrapiImageFormat;
}
}
export interface StrapiImageFormat {
url: string;
width: number;
height: number;
size: number;
}
export interface StrapiResponse<T> {
data: T;
meta?: {
pagination?: {
page: number;
pageSize: number;
pageCount: number;
total: number;
}
}
}

View File

@ -0,0 +1,2 @@
export * from './common';
export * from './production';

View File

@ -0,0 +1,14 @@
import type { StrapiEntity, StrapiImage } from './common';
export interface ProductionType extends StrapiEntity {
type: string;
}
export interface Production extends StrapiEntity {
title: string;
summary?: string;
production_type?: ProductionType;
production_image?: StrapiImage;
production_details?: string;
production_specs?: string | object;
}

View File

@ -80,6 +80,10 @@ export default defineNuxtConfig({
cookieName: "strapi_jwt",
},
imports: {
dirs: ['types/**']
},
modules: [
"@nuxt/eslint",