diff --git a/app/composables/directus/index.ts b/app/composables/directus/index.ts index d480dd2..96113b0 100644 --- a/app/composables/directus/index.ts +++ b/app/composables/directus/index.ts @@ -7,3 +7,4 @@ export * from './useSolution'; export * from './useQuestionList'; export * from './useDocumentList'; export * from './useContactInfo'; +export * from './useCompanyProfile'; diff --git a/app/composables/directus/useCompanyProfile.ts b/app/composables/directus/useCompanyProfile.ts new file mode 100644 index 0000000..0b26039 --- /dev/null +++ b/app/composables/directus/useCompanyProfile.ts @@ -0,0 +1,29 @@ +import { readSingleton } from '@directus/sdk'; + +export const useCompanyProfile = () => { + const { $directus } = useNuxtApp(); + const { getDirectusLocale } = useLocalizations(); + const locale = getDirectusLocale(); + + return useAsyncData(`company-profile-${locale}`, async () => { + return await $directus.request( + readSingleton('company_profile', { + fields: [ + 'id', + { + translations: ['id', 'content'], + }, + ], + deep: { + translations: { + _filter: { + languages_code: { + _eq: locale, + }, + }, + }, + }, + }) + ); + }); +}; diff --git a/app/models/mappers/companyProfileMapper.ts b/app/models/mappers/companyProfileMapper.ts new file mode 100644 index 0000000..34eda30 --- /dev/null +++ b/app/models/mappers/companyProfileMapper.ts @@ -0,0 +1,17 @@ +/** + * 将 Directus 返回的 CompanyProfile 数据转换为 CompanyProfileView 视图模型 + * + * @param raw: 原始的 CompanyProfile 数据 + * @returns 转换后的 CompanyProfileView 对象 + * + * @example + * const view = toCompanyProfileView(rawCompanyProfile); + */ +export function toCompanyProfileView(raw: CompanyProfile): CompanyProfileView { + const trans = raw.translations?.[0] ?? { content: '' }; + + return { + id: raw.id, + content: trans.content, + }; +} diff --git a/app/models/views/CompanyProfileView.ts b/app/models/views/CompanyProfileView.ts new file mode 100644 index 0000000..cba398c --- /dev/null +++ b/app/models/views/CompanyProfileView.ts @@ -0,0 +1,10 @@ +/** + * 公司简介视图模型 + */ +export interface CompanyProfileView { + /** 唯一标识符 **/ + id: number; + + /** 内容 **/ + content: string; +} diff --git a/app/pages/about/index.vue b/app/pages/about/index.vue index 7545652..70c2b39 100644 --- a/app/pages/about/index.vue +++ b/app/pages/about/index.vue @@ -15,7 +15,7 @@