feat: 将/about界面由Strapi迁移至Directus
- 修改相关路由界面 - 增添相应的视图模型与转换方法
This commit is contained in:
@ -7,3 +7,4 @@ export * from './useSolution';
|
|||||||
export * from './useQuestionList';
|
export * from './useQuestionList';
|
||||||
export * from './useDocumentList';
|
export * from './useDocumentList';
|
||||||
export * from './useContactInfo';
|
export * from './useContactInfo';
|
||||||
|
export * from './useCompanyProfile';
|
||||||
|
|||||||
29
app/composables/directus/useCompanyProfile.ts
Normal file
29
app/composables/directus/useCompanyProfile.ts
Normal file
@ -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,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
);
|
||||||
|
});
|
||||||
|
};
|
||||||
17
app/models/mappers/companyProfileMapper.ts
Normal file
17
app/models/mappers/companyProfileMapper.ts
Normal file
@ -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,
|
||||||
|
};
|
||||||
|
}
|
||||||
10
app/models/views/CompanyProfileView.ts
Normal file
10
app/models/views/CompanyProfileView.ts
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
/**
|
||||||
|
* 公司简介视图模型
|
||||||
|
*/
|
||||||
|
export interface CompanyProfileView {
|
||||||
|
/** 唯一标识符 **/
|
||||||
|
id: number;
|
||||||
|
|
||||||
|
/** 内容 **/
|
||||||
|
content: string;
|
||||||
|
}
|
||||||
@ -15,7 +15,7 @@
|
|||||||
</el-breadcrumb>
|
</el-breadcrumb>
|
||||||
|
|
||||||
<div class="content">
|
<div class="content">
|
||||||
<markdown-renderer :content="content || ''" />
|
<markdown-renderer :content="content.content || ''" />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<el-divider content-position="left">更多信息</el-divider>
|
<el-divider content-position="left">更多信息</el-divider>
|
||||||
@ -38,17 +38,9 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
const { findOne } = useStrapi();
|
const { data, pending, error } = await useCompanyProfile();
|
||||||
const { getStrapiLocale } = useLocalizations();
|
|
||||||
const strapiLocale = getStrapiLocale();
|
|
||||||
|
|
||||||
const { data, pending, error } = useAsyncData('company-profile', () =>
|
const content = computed(() => toCompanyProfileView(data.value));
|
||||||
findOne<StrapiCompanyProfile>('company-profile', undefined, {
|
|
||||||
locale: strapiLocale,
|
|
||||||
})
|
|
||||||
);
|
|
||||||
|
|
||||||
const content = computed(() => data.value?.data.content);
|
|
||||||
|
|
||||||
watch(error, (value) => {
|
watch(error, (value) => {
|
||||||
if (value) {
|
if (value) {
|
||||||
|
|||||||
Reference in New Issue
Block a user