Compare commits
2 Commits
eaf7d3be38
...
631146eeb8
| Author | SHA1 | Date | |
|---|---|---|---|
| 631146eeb8 | |||
| c3964b8e35 |
@ -13,7 +13,6 @@ const props = defineProps<Props>()
|
|||||||
|
|
||||||
// 将 Markdown 转换成 HTML
|
// 将 Markdown 转换成 HTML
|
||||||
const safeHtml = computed(() => renderMarkdown(props.content))
|
const safeHtml = computed(() => renderMarkdown(props.content))
|
||||||
console.log('Markdown content:', safeHtml.value)
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
|
|||||||
@ -3,9 +3,9 @@
|
|||||||
<div v-if="production">
|
<div v-if="production">
|
||||||
<!-- 面包屑导航 -->
|
<!-- 面包屑导航 -->
|
||||||
<el-breadcrumb class="breadcrumb" separator="/">
|
<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>
|
||||||
<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>
|
||||||
<el-breadcrumb-item class="text-sm opactiy-50">{{ production.title }}</el-breadcrumb-item>
|
<el-breadcrumb-item class="text-sm opactiy-50">{{ production.title }}</el-breadcrumb-item>
|
||||||
</el-breadcrumb>
|
</el-breadcrumb>
|
||||||
@ -13,7 +13,7 @@
|
|||||||
<!-- 产品详情内容 -->
|
<!-- 产品详情内容 -->
|
||||||
<div class="production-header">
|
<div class="production-header">
|
||||||
<div class="production-image">
|
<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>
|
||||||
<div class="production-info">
|
<div class="production-info">
|
||||||
<h1>{{ production.title }}</h1>
|
<h1>{{ production.title }}</h1>
|
||||||
@ -59,32 +59,19 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<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 route = useRoute()
|
||||||
const { findOne } = useStrapi()
|
const { findOne } = useStrapi()
|
||||||
const { getStrapiLocale } = useLocalizations()
|
const { getStrapiLocale } = useLocalizations()
|
||||||
|
|
||||||
const strapiLocale = getStrapiLocale()
|
const strapiLocale = getStrapiLocale()
|
||||||
|
|
||||||
const production = ref<ProductionDetails | null>(null)
|
const production = ref<Production | null>(null)
|
||||||
const pending = ref(true)
|
const pending = ref(true)
|
||||||
|
|
||||||
const activeName = ref('details') // 默认选中概览标签
|
const activeName = ref('details') // 默认选中概览标签
|
||||||
|
|
||||||
// 获取路由参数(slug 或 id)
|
// 获取路由参数(slug 或 id)
|
||||||
const productionParam = computed(() => route.params.slug as string)
|
const documentId = computed(() => route.params.slug as string)
|
||||||
|
|
||||||
const parsedSpecs = computed(() => {
|
const parsedSpecs = computed(() => {
|
||||||
if (!production.value?.production_specs) return JSON.parse('{}')
|
if (!production.value?.production_specs) return JSON.parse('{}')
|
||||||
@ -106,7 +93,7 @@ const parsedSpecs = computed(() => {
|
|||||||
onMounted(async () => {
|
onMounted(async () => {
|
||||||
try {
|
try {
|
||||||
|
|
||||||
const response = await findOne<ProductionDetails>('productions', productionParam.value, {
|
const response = await findOne<Production>('productions', documentId.value, {
|
||||||
populate: '*',
|
populate: '*',
|
||||||
locale: strapiLocale,
|
locale: strapiLocale,
|
||||||
})
|
})
|
||||||
@ -114,21 +101,14 @@ onMounted(async () => {
|
|||||||
if (response.data) {
|
if (response.data) {
|
||||||
const item = response.data
|
const item = response.data
|
||||||
production.value = {
|
production.value = {
|
||||||
id: item.id,
|
|
||||||
title: item.title,
|
title: item.title,
|
||||||
summary: item.summary,
|
summary: item.summary,
|
||||||
production_details: item.production_details || '',
|
production_type: item.production_type,
|
||||||
production_specs: item.production_specs || '',
|
production_details: item.production_details,
|
||||||
production_image: {
|
production_specs: item.production_specs,
|
||||||
url: item.production_image?.url
|
production_image: item.production_image,
|
||||||
? `http://192.168.86.5:1337${item.production_image.url}`
|
documentId: item.documentId,
|
||||||
: ''
|
|
||||||
},
|
|
||||||
documentId: item.documentId || '',
|
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log('Fetched production:', production.value)
|
|
||||||
console.log('Raw specs:', production.value.production_specs)
|
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Failed to fetch production:', error)
|
console.error('Failed to fetch production:', error)
|
||||||
|
|||||||
@ -4,10 +4,10 @@
|
|||||||
v-for="production in productions"
|
v-for="production in productions"
|
||||||
:id="production.id"
|
:id="production.id"
|
||||||
:key="production.id"
|
:key="production.id"
|
||||||
:slug="production.slug"
|
:slug="production.documentId"
|
||||||
:image-url="production.image_url"
|
:image-url="useStrapiMedia(production?.production_image?.url || '')"
|
||||||
:name="production.title"
|
:name="production.title"
|
||||||
:description="production.summary"
|
:description="production.summary || ''"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
@ -20,35 +20,7 @@ const { getStrapiLocale } = useLocalizations()
|
|||||||
|
|
||||||
const strapiLocale = getStrapiLocale()
|
const strapiLocale = getStrapiLocale()
|
||||||
|
|
||||||
const baseUrl = 'http://192.168.86.5:1337';
|
const productions = ref<Production[]>();
|
||||||
|
|
||||||
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[]>();
|
|
||||||
|
|
||||||
onMounted(async () => {
|
onMounted(async () => {
|
||||||
try {
|
try {
|
||||||
@ -56,16 +28,15 @@ onMounted(async () => {
|
|||||||
populate: '*',
|
populate: '*',
|
||||||
locale: strapiLocale, // 使用简体中文
|
locale: strapiLocale, // 使用简体中文
|
||||||
})
|
})
|
||||||
|
productions.value = response.data.map((item: Production) => ({
|
||||||
productions.value = response.data.map((item: Production) => {
|
title: item.title,
|
||||||
return new ProductionInfo(
|
summary: item.summary,
|
||||||
item.id,
|
production_type: item.production_type,
|
||||||
item.title,
|
production_image: item.production_image,
|
||||||
item.summary,
|
production_details: item.production_details,
|
||||||
item.production_image?.url || '',
|
production_specs: item.production_specs,
|
||||||
item.documentId ? item.documentId : undefined
|
documentId: item.documentId
|
||||||
);
|
}))
|
||||||
});
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Failed to fetch productions:', error)
|
console.error('Failed to fetch productions:', error)
|
||||||
}
|
}
|
||||||
|
|||||||
41
app/types/strapi/common.ts
Normal file
41
app/types/strapi/common.ts
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
2
app/types/strapi/index.ts
Normal file
2
app/types/strapi/index.ts
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
export * from './common';
|
||||||
|
export * from './production';
|
||||||
14
app/types/strapi/production.ts
Normal file
14
app/types/strapi/production.ts
Normal 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;
|
||||||
|
}
|
||||||
@ -80,6 +80,10 @@ export default defineNuxtConfig({
|
|||||||
cookieName: "strapi_jwt",
|
cookieName: "strapi_jwt",
|
||||||
},
|
},
|
||||||
|
|
||||||
|
imports: {
|
||||||
|
dirs: ['types/**']
|
||||||
|
},
|
||||||
|
|
||||||
|
|
||||||
modules: [
|
modules: [
|
||||||
"@nuxt/eslint",
|
"@nuxt/eslint",
|
||||||
|
|||||||
Reference in New Issue
Block a user