diff --git a/app/components/shared/FilePreviewer.vue b/app/components/shared/FilePreviewer.vue index e3eaf3a..9dbb177 100644 --- a/app/components/shared/FilePreviewer.vue +++ b/app/components/shared/FilePreviewer.vue @@ -122,6 +122,8 @@ const errorText = computed(() => error.value?.message ?? null); const fileMeta = computed(() => props.file ?? data.value ?? null); + logger.debug('FilePreviewer - fileMeta:', fileMeta.value); + /** 预览源地址:支持在 file.url 上追加额外 query(如临时 token、inline) */ const src = computed(() => { if (!fileMeta.value) return ''; diff --git a/app/composables/directus/useCompanyProfile.ts b/app/composables/directus/useCompanyProfile.ts index af3954b..d98385d 100644 --- a/app/composables/directus/useCompanyProfile.ts +++ b/app/composables/directus/useCompanyProfile.ts @@ -1,16 +1,17 @@ -import GetCompanyProfile from '@/graphql/companyProfile.graphql?raw'; - export const useCompanyProfile = () => { - const { $directus } = useNuxtApp(); const { getDirectusLocale } = useLocalizations(); const locale = getDirectusLocale(); return useAsyncData(`company-profile-${locale}`, async () => { - return await $directus.query<{ company_profile: CompanyProfile }>( - GetCompanyProfile, - { - locale: locale, - } - ); + try { + const data = await $fetch(`/api/cms/companyProfile`, { + headers: { 'x-locale': locale }, + }); + + return data; + } catch (error) { + logger.error('Error fetching company profile: ', error); + throw error; + } }); }; diff --git a/app/composables/directus/useContactInfo.ts b/app/composables/directus/useContactInfo.ts index 3bfbc81..532e118 100644 --- a/app/composables/directus/useContactInfo.ts +++ b/app/composables/directus/useContactInfo.ts @@ -1,16 +1,17 @@ -import GetContactInfo from '@/graphql/contactInfo.graphql?raw'; - export const useContactInfo = () => { - const { $directus } = useNuxtApp(); const { getDirectusLocale } = useLocalizations(); const locale = getDirectusLocale(); return useAsyncData(`contact-info-${locale}`, async () => { - return await $directus.query<{ contact_info: ContactInfo }>( - GetContactInfo, - { - locale: locale, - } - ); + try { + const data = await $fetch('/api/cms/contactInfo', { + headers: { 'x-locale': locale }, + }); + + return data; + } catch (error) { + logger.error('Error fetching contact info: ', error); + throw error; + } }); }; diff --git a/app/composables/directus/useDirectusFiles.ts b/app/composables/directus/useDirectusFiles.ts index 38af82b..69ee3e7 100644 --- a/app/composables/directus/useDirectusFiles.ts +++ b/app/composables/directus/useDirectusFiles.ts @@ -1,19 +1,14 @@ export const useDirectusFiles = () => { - const config = useRuntimeConfig(); - const baseUrl = config.public.directus.url; - const getFileUrl = ( id?: string | null, options?: Record ): string => { if (!id) return ''; - const query = options - ? '?' + - new URLSearchParams( - Object.entries(options).map(([key, value]) => [key, String(value)]) - ).toString() - : ''; - return `${baseUrl}/assets/${id}${query}`; + + const params = new URLSearchParams( + options as Record + ).toString(); + return `/api/assets/${id}${params ? `?${params}` : ''}`; }; return { diff --git a/app/composables/directus/useDirectusImage.ts b/app/composables/directus/useDirectusImage.ts index 08215d6..14b4143 100644 --- a/app/composables/directus/useDirectusImage.ts +++ b/app/composables/directus/useDirectusImage.ts @@ -1,8 +1,4 @@ export const useDirectusImage = () => { - const config = useRuntimeConfig(); - const baseUrl = config.public.directus.url; - const token = config.public.directus.token; - type DirectusAssetParams = { width?: number; height?: number; @@ -13,19 +9,11 @@ export const useDirectusImage = () => { const getImageUrl = (id?: string | null, options?: DirectusAssetParams) => { if (!id) return ''; - const queryToken = token ? 'access_token=' + token : ''; - const queryOptions = options - ? new URLSearchParams( - Object.fromEntries( - Object.entries(options).map(([key, value]) => [key, String(value)]) - ) - ).toString - : ''; - const query = - queryToken || queryOptions - ? `?${[queryToken, queryOptions].filter(Boolean).join('&')}` - : ''; - return `${baseUrl}/assets/${id}${query}`; + + const params = new URLSearchParams( + options as Record + ).toString(); + return `/api/assets/${id}${params ? `?${params}` : ''}`; }; return { getImageUrl }; diff --git a/app/composables/directus/useDocumentList.ts b/app/composables/directus/useDocumentList.ts index 11b0978..d1749a7 100644 --- a/app/composables/directus/useDocumentList.ts +++ b/app/composables/directus/useDocumentList.ts @@ -1,16 +1,17 @@ -import GetDocumentList from '@/graphql/documentList.graphql?raw'; - export const useDocumentList = () => { - const { $directus } = useNuxtApp(); const { getDirectusLocale } = useLocalizations(); const locale = getDirectusLocale(); return useAsyncData(`document-list-${locale}`, async () => { - return await $directus.query<{ product_documents: ProductDocument[] }>( - GetDocumentList, - { - locale: locale, - } - ); + try { + const data = $fetch(`/api/cms/documentList`, { + headers: { 'x-locale': locale }, + }); + + return data; + } catch (error) { + logger.error('Error fetching document list:', error); + throw error; + } }); }; diff --git a/app/composables/directus/useHomepage.ts b/app/composables/directus/useHomepage.ts index af50bfe..89cf811 100644 --- a/app/composables/directus/useHomepage.ts +++ b/app/composables/directus/useHomepage.ts @@ -1,13 +1,17 @@ -import GetHomepage from '@/graphql/homepage.graphql?raw'; - export const useHomepage = () => { - const { $directus } = useNuxtApp(); const { getDirectusLocale } = useLocalizations(); const locale = getDirectusLocale(); return useAsyncData(`homepage-${locale}`, async () => { - return await $directus.query<{ homepage: Homepage }>(GetHomepage, { - locale: locale, - }); + try { + const data = $fetch(`/api/cms/homepage`, { + headers: { 'x-locale': locale }, + }); + + return data; + } catch (error) { + logger.error('Error fetching homepage:', error); + throw error; + } }); }; diff --git a/app/composables/directus/useProduct.ts b/app/composables/directus/useProduct.ts index e264cb0..5e8772a 100644 --- a/app/composables/directus/useProduct.ts +++ b/app/composables/directus/useProduct.ts @@ -1,15 +1,17 @@ -import GetProduct from '@/graphql/product.graphql?raw'; - export const useProduct = (id: string) => { - const { $directus } = useNuxtApp(); - const { getDirectusLocale } = useLocalizations(); const locale = getDirectusLocale(); return useAsyncData(`product-${id}-${locale}`, async () => { - return await $directus.query<{ products_by_id: Product }>(GetProduct, { - id: id, - locale: locale, - }); + try { + const data = await $fetch(`/api/cms/product/${id}`, { + headers: { 'x-locale': locale }, + }); + + return data; + } catch (error) { + logger.error('Error fetching product: ', error); + throw error; + } }); }; diff --git a/app/composables/directus/useProductList.ts b/app/composables/directus/useProductList.ts index 58bac21..61f6191 100644 --- a/app/composables/directus/useProductList.ts +++ b/app/composables/directus/useProductList.ts @@ -1,14 +1,17 @@ -import GetProductList from '@/graphql/productList.graphql?raw'; - export const useProductList = () => { - const { $directus } = useNuxtApp(); - const { getDirectusLocale } = useLocalizations(); const locale = getDirectusLocale(); return useAsyncData(`product-list-${locale}`, async () => { - return await $directus.query<{ products: Product[] }>(GetProductList, { - locale: locale, - }); + try { + const data = await $fetch(`/api/cms/productList`, { + headers: { 'x-locale': locale }, + }); + + return data; + } catch (error) { + logger.error('Error fetching product list: ', error); + throw error; + } }); }; diff --git a/app/composables/directus/useQuestionList.ts b/app/composables/directus/useQuestionList.ts index d9c35b2..6b672cf 100644 --- a/app/composables/directus/useQuestionList.ts +++ b/app/composables/directus/useQuestionList.ts @@ -1,14 +1,17 @@ -import GetQuestionList from '@/graphql/questionList.graphql?raw'; - export const useQuestionList = () => { - const { $directus } = useNuxtApp(); - const { getDirectusLocale } = useLocalizations(); const locale = getDirectusLocale(); return useAsyncData(`question-list-${locale}`, async () => { - return await $directus.query<{ questions: Question[] }>(GetQuestionList, { - locale: locale, - }); + try { + const data = $fetch(`/api/cms/questionList`, { + headers: { 'x-locale': locale }, + }); + + return data; + } catch (error) { + logger.error('Error fetching question list:', error); + throw error; + } }); }; diff --git a/app/composables/directus/useSolution.ts b/app/composables/directus/useSolution.ts index 1ab8f55..e3d4316 100644 --- a/app/composables/directus/useSolution.ts +++ b/app/composables/directus/useSolution.ts @@ -1,14 +1,17 @@ -import GetSolution from '@/graphql/solution.graphql?raw'; - export const useSolution = (id: string) => { - const { $directus } = useNuxtApp(); const { getDirectusLocale } = useLocalizations(); const locale = getDirectusLocale(); return useAsyncData(`solution-${id}-${locale}`, async () => { - return await $directus.query<{ solutions_by_id: Solution }>(GetSolution, { - id: id, - locale: locale, - }); + try { + const data = await $fetch(`/api/cms/solution/${id}`, { + headers: { 'x-locale': locale }, + }); + + return data; + } catch (error) { + logger.error('Error fetching solution: ', error); + throw error; + } }); }; diff --git a/app/composables/directus/useSolutionList.ts b/app/composables/directus/useSolutionList.ts index fcbd25d..3f8a3b0 100644 --- a/app/composables/directus/useSolutionList.ts +++ b/app/composables/directus/useSolutionList.ts @@ -1,13 +1,17 @@ -import GetSolutionList from '@/graphql/solutionList.graphql?raw'; - export const useSolutionList = () => { - const { $directus } = useNuxtApp(); const { getDirectusLocale } = useLocalizations(); const locale = getDirectusLocale(); return useAsyncData(`solution-list-${locale}`, async () => { - return await $directus.query<{ solutions: Solution[] }>(GetSolutionList, { - locale: locale, - }); + try { + const data = $fetch(`/api/cms/solutionList`, { + headers: { 'x-locale': locale }, + }); + + return data; + } catch (error) { + logger.error('Error fetching solution list:', error); + throw error; + } }); }; diff --git a/app/pages/about/index.vue b/app/pages/about/index.vue index 09a775c..64dd05f 100644 --- a/app/pages/about/index.vue +++ b/app/pages/about/index.vue @@ -34,9 +34,7 @@ ]; const { data, pending, error } = await useCompanyProfile(); - const content = computed(() => - toCompanyProfileView(data.value.company_profile) - ); + const content = computed(() => toCompanyProfileView(data.value)); watch(error, (value) => { if (value) { diff --git a/app/pages/index.vue b/app/pages/index.vue index d5d6720..f2eb413 100644 --- a/app/pages/index.vue +++ b/app/pages/index.vue @@ -16,7 +16,7 @@ const { data, pending, error } = await useHomepage(); const homepageData = computed(() => { - return toHomepageView(data.value.homepage); + return toHomepageView(data.value); }); const pageTilte = $t('page-title.homepage'); diff --git a/app/pages/products/[slug].vue b/app/pages/products/[slug].vue index 6eee50a..fb06327 100644 --- a/app/pages/products/[slug].vue +++ b/app/pages/products/[slug].vue @@ -39,7 +39,7 @@ const { data, pending, error } = await useProduct(id); - const rawProduct = computed(() => data.value.products_by_id ?? null); + const rawProduct = computed(() => data.value ?? null); const product = computed(() => { if (rawProduct.value === null) { @@ -61,10 +61,10 @@ }); // SEO - // usePageSeo({ - // title: product.value.name || $t('page-title.products'), - // description: product.value.summary || '', - // }); + usePageSeo({ + title: product.value.name || $t('page-title.products'), + description: product.value.summary || '', + });