Kaynağa Gözat

🚧 优化nuxt请求缓存

快乐的梦鱼 2 hafta önce
ebeveyn
işleme
9b5951ada4

+ 1 - 1
components/parts/IndexStats.vue

@@ -37,7 +37,7 @@ import IndexContent from '~/api/introduction/IndexContent';
 import { useSSrSimpleDataLoader } from '~/composeable/SimpleDataLoader';
 
 const router = useRouter();
-const statsData = await useSSrSimpleDataLoader('stats', async () => {
+const statsData = await useSSrSimpleDataLoader('index-stats', async () => {
   const data = (await IndexContent.getStats());
   const semiCount = (await SeminarContent.getContentList(new GetContentListParams(), 1, 1)).total;
   const unmoveableCount = (await UnmoveableContent.getContentList(new GetContentListParams(), 1, 1)).total;

+ 4 - 2
composeable/SimpleDataLoader.ts

@@ -61,6 +61,7 @@ export async function useSSrSimpleDataLoader<T, P = any>(
   loader: (params?: P) => Promise<T>,
   params : P|undefined = undefined,
   emptyIfArrayEmpty = true,
+  timeout = 60000,
 )  : Promise<ISimpleDataLoader<T, P>>
  {
   const route = useRoute();
@@ -68,8 +69,9 @@ export async function useSSrSimpleDataLoader<T, P = any>(
   let lastParams: P | undefined = params;
   const loadStatus = ref<LoaderLoadType>('finished');
   const loadError = ref('');
-  const { data: content, error } = (await useAsyncData(route.fullPath + '/' + name, () => loader(lastParams)))
-
+  const { data: content, error } = (await useAsyncData(name, () => loader(lastParams), {
+    timeout
+  }));
 
   async function loadData(params?: P, refresh: boolean = false) {
     if (!import.meta.client)

+ 2 - 2
pages/about/index.vue

@@ -179,7 +179,7 @@ function handleTabClick(value: number) {
   mainTabActive.value = value; 
 }
 
-const introdLoader = await useSSrSimpleDataLoader('introd', async () => {
+const introdLoader = await useSSrSimpleDataLoader('about-introd', async () => {
   const res = await CommonContent.getContentList(new GetContentListParams()
         .setModelId(17)
         .setMainBodyColumnId([ 256, 283, 284 ])
@@ -226,7 +226,7 @@ const newsLoader = await useSSrSimplePagerDataLoader('news', Number(route.query.
     total: res.total,
   };
 });
-const lawsData = await useSSrSimpleDataLoader('laws', async () => 
+const lawsData = await useSSrSimpleDataLoader('about-laws', async () => 
   (await PolicyContent.getContentList(new GetContentListParams(), 1, 8))
     .list?.map(item => ({
       id: item.id,

+ 1 - 1
pages/communicate/index.vue

@@ -67,7 +67,7 @@ const carouselConfig = {
   autoPlay: 5000,
 }
 
-const overviewsLoader = await useSSrSimpleDataLoader('overviews', async () => {
+const overviewsLoader = await useSSrSimpleDataLoader('communicate-overviews', async () => {
   return [
     (await CommunicateContent.getColumList(
       new GetColumListParams().setMainBodyColumnId(260)

+ 5 - 1
pages/details/TabDetailView.vue

@@ -150,6 +150,10 @@ const props = defineProps({
   load: {
     type: Function as PropType<(id: number) => Promise<GetContentDetailItem>>,
     default: null,
+  },
+  name: {
+    type: String,
+    default: '',
   }
 })
 
@@ -165,7 +169,7 @@ function handleShowImage(url: string) {
   imagePreviewSrc.value = url;
 }
 
-const loader = await useSSrSimpleDataLoader('details' + route.query.id, async () => {
+const loader = await useSSrSimpleDataLoader(props.name, async () => {
   if (!props.load)
     throw new Error("!props.load");
   return (await props.load(Number(route.query.id))).toJSON();

+ 1 - 0
pages/details/artifact.vue

@@ -2,6 +2,7 @@
   <!-- 文物详情页 -->
   <TabDetailView 
     :load="loadData"
+    name="artifact"
   >
     <template #extraInfo="{ content }">
       <IntroBlock

+ 1 - 0
pages/details/intangible.vue

@@ -2,6 +2,7 @@
   <!-- 非遗详情页 -->
   <TabDetailView 
     :load="loadData"
+    name="intangible"
   >
     <template #extraInfo="{ content }">
       <IntroBlock

+ 7 - 7
pages/index.vue

@@ -229,33 +229,33 @@ const carousel2Config = {
 }
 const carousel6Ref = ref<any>(null);
 
-const bannerData = await useSSrSimpleDataLoader('banner', async () => {
+const bannerData = await useSSrSimpleDataLoader('index-banner', async () => {
   return (await IndexContent.getBanner()).map(p => p.toJSON());
 });
-const overviewData = await useSSrSimpleDataLoader('overview', async () => {
+const overviewData = await useSSrSimpleDataLoader('index-overview', async () => {
   return (await IndexContent.getColumList(new GetColumListParams().setSelfValues({
     modelId: 17,
     mainBodyColumnId: 234,
   }))).list[0]?.overview || NO_CONTENT_STRING
 });
-const recommend1Data = await useSSrSimpleDataLoader('recommend1', async () => {
+const recommend1Data = await useSSrSimpleDataLoader('index-recommend1', async () => {
   return (await UnmoveableContent.getContentList(new GetContentListParams(), 1, 9)).list.map(p => p.toJSON());
 });
-const recommend2Data = await useSSrSimpleDataLoader('recommend2', async () => {
+const recommend2Data = await useSSrSimpleDataLoader('index-recommend2', async () => {
   return (await ProjectsContent.getContentList(new GetContentListParams().setMainBodyColumnId([]), 1, 9)).list.map(p => p.toJSON());
 });
-const recommend3Data = await useSSrSimpleDataLoader('recommend3', async () => {
+const recommend3Data = await useSSrSimpleDataLoader('index-recommend3', async () => {
   return (await CommonContent.getContentList(new GetContentListParams()
     .setModelId(17)
     .setMainBodyColumnId(273)
   , 1, 8)).list.map(p => p.toJSON());
 });
-const newsData = await useSSrSimpleDataLoader('news', async () => {
+const newsData = await useSSrSimpleDataLoader('index-news', async () => {
   return (await NewsIndexContent.getContentList(new GetContentListParams()
     .setMainBodyColumnId([ 228/* , 298, 299 */ ])
   , 1, 9)).list.map(p => p.toJSON());
 });
-const recordData = await useSSrSimpleDataLoader('record', async () => {
+const recordData = await useSSrSimpleDataLoader('index-record', async () => {
   return (await CommonContent.getContentList(new GetContentListParams()
     .setSelfValues({
       order: 'publish_at',

+ 5 - 5
pages/inheritor/index.vue

@@ -180,31 +180,31 @@ const list2 = [
   },
 ]
 
-const areaData = await useSSrSimpleDataLoader('area', async () => 
+const areaData = await useSSrSimpleDataLoader('inheritor-area', async () => 
  (await CommonContent.getContentList(new GetContentListParams()
     .setModelId(17)
     .setMainBodyColumnId(286)
   , 1, 6)).list.map(p => p.toJSON())
 )
-const heritageData = await useSSrSimpleDataLoader('heritage', async () => 
+const heritageData = await useSSrSimpleDataLoader('inheritor-heritage', async () => 
  (await CommonContent.getContentList(new GetContentListParams()
     .setModelId(17)
     .setMainBodyColumnId(310)
   , 1, 6)).list.map(p => p.toJSON())
 )
-const blockData = await useSSrSimpleDataLoader('block', async () => 
+const blockData = await useSSrSimpleDataLoader('inheritor-block', async () => 
  (await CommonContent.getContentList(new GetContentListParams()
     .setModelId(17)
     .setMainBodyColumnId(286)
   , 1, 6)).list.map(p => p.toJSON())
 )
-const minnanyuLoader = await useSSrSimpleDataLoader('minnanyu', async () => 
+const minnanyuLoader = await useSSrSimpleDataLoader('inheritor-minnanyu', async () => 
  (await CommonContent.getContentList(new GetContentListParams()
     .setModelId(18)
     .setMainBodyColumnId(318)
   , 1, 6)).list.map(p => p.toJSON())
 )
-const overviewsLoader = await useSSrSimpleDataLoader('overviews', async () => {
+const overviewsLoader = await useSSrSimpleDataLoader('inheritor-overviews', async () => {
   return [
     (await IndexContent.getColumList(
       new GetColumListParams()

+ 3 - 3
pages/introduction/index.vue

@@ -133,7 +133,7 @@ const list = [
   }
 ]
 
-const historyData = await useSSrSimpleDataLoader('history', async () => 
+const historyData = await useSSrSimpleDataLoader('inroduction-history', async () => 
  (await HistoryContent.getContentList(new GetContentListParams().setMainBodyColumnId([ 233, 250, 251 ]), 1, 6)).list.map(p => ({
     id: p.id,
     title: p.title,
@@ -142,7 +142,7 @@ const historyData = await useSSrSimpleDataLoader('history', async () =>
     link: router.resolve({ path: '/news/detail', query: { id: p.id } }).href,
  }))
 )
-const languageData = await useSSrSimpleDataLoader('language', async () => 
+const languageData = await useSSrSimpleDataLoader('inroduction-language', async () => 
  (await LanguageContent.getContentList(new GetContentListParams(), 1, 6)).list.map(p => ({
     id: p.id,
     title: p.title,
@@ -151,7 +151,7 @@ const languageData = await useSSrSimpleDataLoader('language', async () =>
     link: router.resolve({ path: '/news/detail', query: { id: p.id } }).href,
  }))
 )
-const overviewsLoader = await useSSrSimpleDataLoader('overviews', async () => {
+const overviewsLoader = await useSSrSimpleDataLoader('inroduction-overviews', async () => {
   return [
     (await IndexContent.getColumList(
       new GetColumListParams()

+ 1 - 1
pages/news/detail.vue

@@ -115,7 +115,7 @@ import ContentNode from '@/components/content/ContentNode.vue';
 
 const route = useRoute();
 const router = useRouter();
-const newsLoader = await useSSrSimpleDataLoader('detail', async () => {
+const newsLoader = await useSSrSimpleDataLoader('new-detail', async () => {
   const id = Number(route.query.id);
   const modelId = route.query.modelId ? Number(route.query.modelId) : undefined;
   if (!id)