refactor: 将数据获取从app端移至server端

- 调整数据获取位置以提升安全性
- 对于后端状态为Archived的数据,通过server控制不进行获取
This commit is contained in:
2025-11-12 17:54:43 +08:00
parent 58223734a2
commit a5f3895794
37 changed files with 302 additions and 85 deletions

View File

@ -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;
}
});
};