feat!: 将项目有Strapi迁移至Directus #43

Manually merged
remilia merged 30 commits from feat/directus into master 2025-10-24 17:22:40 +08:00
50 changed files with 2284 additions and 316 deletions
Showing only changes of commit c156d1414c - Show all commits

View File

@ -7,3 +7,4 @@ export * from './useSolution';
export * from './useQuestionList';
export * from './useDocumentList';
export * from './useContactInfo';
export * from './useCompanyProfile';

View 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,
},
},
},
},
})
);
});
};

View 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,
};
}

View File

@ -0,0 +1,10 @@
/**
* 公司简介视图模型
*/
export interface CompanyProfileView {
/** 唯一标识符 **/
id: number;
/** 内容 **/
content: string;
}

View File

@ -15,7 +15,7 @@
</el-breadcrumb>
<div class="content">
<markdown-renderer :content="content || ''" />
<markdown-renderer :content="content.content || ''" />
</div>
<el-divider content-position="left">更多信息</el-divider>
@ -38,17 +38,9 @@
</template>
<script setup lang="ts">
const { findOne } = useStrapi();
const { getStrapiLocale } = useLocalizations();
const strapiLocale = getStrapiLocale();
const { data, pending, error } = await useCompanyProfile();
const { data, pending, error } = useAsyncData('company-profile', () =>
findOne<StrapiCompanyProfile>('company-profile', undefined, {
locale: strapiLocale,
})
);
const content = computed(() => data.value?.data.content);
const content = computed(() => toCompanyProfileView(data.value));
watch(error, (value) => {
if (value) {