topfans/frontend/config/preload.config.js

263 lines
5.7 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// frontend/config/preload.config.js
// API 预加载业务配置
// 声明每个预拉 key 的fetcher / ttl / persistence / 触发时机
import {
getCastloveConfigApi,
getUserProfileApi,
getHotRankingApi,
getAssetLikersApi,
getActivityDetailApi,
getActivityItemsApi,
getInspirationFlowApi,
getActivityListApi,
getMintingActivitiesApi,
dashboardApi,
getStarbookHomeApi,
getMyGalleriesApi,
getMyExhibitedAssetsApi,
getMyLikedAssetsApi,
getStarbookItemsApi,
getUserGalleriesApi,
getUserLikedAssetsApi,
getEarningsSummaryApi,
listActivityMessagesApi,
getActivityTopRankingApi,
getActivityProgressApi,
} from "@/utils/api";
export const preloadConfig = {
// ── 全局默认 ──
defaults: {
ttl: 5 * 60 * 1000,
persistence: "memory",
concurrency: 4,
timeout: 10000,
silent: true,
limits: {
maxEntrySizeKB: 1024,
maxMemoryEntries: 100,
maxFileCacheMB: 50,
},
},
// ── 启动期预热清单App.vue onLaunch 跑)──
startup: [
{
key: "castlove.config",
fetcher: getCastloveConfigApi,
ttl: 60 * 60 * 1000,
persistence: "file",
},
{
key: "me.profile",
fetcher: getUserProfileApi,
ttl: 10 * 60 * 1000,
},
],
// ── idle 预拉清单(首屏渲染完后跑)──
idle: [
{
key: "ranking.hot",
fetcher: () => getHotRankingApi("total", null, 1, 10),
ttl: 10 * 60 * 1000,
},
// banner
{
key: "banner.activities",
fetcher: () =>
getActivityListApi(uni.getStorageSync("star_id") || null, 1, 10),
ttl: 5 * 60 * 1000,
},
{
key: "banner.minting",
fetcher: () => getMintingActivitiesApi(null, 1, 10),
ttl: 5 * 60 * 1000,
},
// square 页面三个 tab 的首屏数据
{
key: "ranking.xinghe",
fetcher: () => getHotRankingApi("displaying", null, 1, 12),
ttl: 5 * 60 * 1000,
},
{
key: "ranking.xingbang",
fetcher: () => getHotRankingApi("displaying", null, 1, 10),
ttl: 5 * 60 * 1000,
},
{
key: "inspiration.flow",
fetcher: () =>
getInspirationFlowApi({ limit: 20, type: "hot", cursor: "" }),
ttl: 3 * 60 * 1000,
},
],
// ── 页面切换预拉映射wrappedNavigateTo 命中时触发)──
pages: {
"/pages/asset-detail/asset-detail": [
{
key: "asset.likers",
fetcher: (params) => getAssetLikersApi(Number(params.asset_id)),
},
],
"/pages/activity-detail/activity-detail": [
{
key: "activity.detail",
fetcher: (params) => getActivityDetailApi(params.id),
},
{
key: "activity.items",
fetcher: (params) => getActivityItemsApi(params.id),
},
],
"/pages/support-activity/index": [
{
key: "activity.detail",
fetcher: (params) => getActivityDetailApi(params.id),
},
{
key: "activity.items",
fetcher: (params) => getActivityItemsApi(params.id),
},
{
key: "activity.earnings",
fetcher: () => getEarningsSummaryApi(),
ttl: 5 * 60 * 1000,
},
{
key: "activity.messages",
fetcher: (params) => listActivityMessagesApi(params.id, 1, 20),
ttl: 30 * 1000,
},
{
key: "activity.topRanking",
fetcher: (params) =>
getActivityTopRankingApi(
params.id,
uni.getStorageSync("star_id") || null,
),
ttl: 3 * 60 * 1000,
},
{
key: "activity.progress",
fetcher: (params) => getActivityProgressApi(params.id),
ttl: 30 * 1000,
},
],
"/pages/support-activity/center": [
{
key: "activity.centerList",
fetcher: () =>
getActivityListApi(uni.getStorageSync("star_id") || null, 1, 50),
ttl: 5 * 60 * 1000,
},
],
"/pages/profile/profile": [
{
key: "me.profile",
fetcher: () => getUserProfileApi(),
ttl: 10 * 60 * 1000,
},
],
"/pages/starbook/index": [
{
key: "starbook.home",
fetcher: () => getStarbookHomeApi(),
ttl: 10 * 60 * 1000,
},
],
"/pages/starbook/items": [
{
key: "starbook.items",
fetcher: (params) =>
getStarbookItemsApi(
params.type || "regular",
params.category || "castlove",
params.grade ? Number(params.grade) : null,
1,
20,
),
ttl: 5 * 60 * 1000,
},
],
"/pages/profile/hisWorks": [
{
key: "hisWorks.galleries",
fetcher: (params) => getUserGalleriesApi(params.userId),
ttl: 5 * 60 * 1000,
},
{
key: "hisWorks.liked",
fetcher: (params) => getUserLikedAssetsApi(params.userId, 1, 20),
ttl: 3 * 60 * 1000,
},
],
"/pages/profile/myWorks": [
{
key: "myWorks.galleries",
fetcher: () => getMyGalleriesApi(),
ttl: 5 * 60 * 1000,
},
{
key: "myWorks.exhibited",
fetcher: () => getMyExhibitedAssetsApi(1, 20),
ttl: 3 * 60 * 1000,
},
{
key: "myWorks.liked",
fetcher: () => getMyLikedAssetsApi(1, 20),
ttl: 3 * 60 * 1000,
},
],
"/pages/dashboard/dashboard": [
{
key: "dashboard.today",
fetcher: () =>
dashboardApi.getTodayOverview(uni.getStorageSync("star_id") || null),
},
{
key: "dashboard.curve",
fetcher: () =>
dashboardApi.get7DayIncomeCurve(
uni.getStorageSync("star_id") || null,
),
},
{
key: "dashboard.exhibition",
fetcher: () =>
dashboardApi.getExhibitionSummary(
uni.getStorageSync("star_id") || null,
),
},
{
key: "dashboard.likeIncome",
fetcher: () =>
dashboardApi.getLikeIncomeByLevel(
uni.getStorageSync("star_id") || null,
),
},
{
key: "dashboard.topAssets",
fetcher: () =>
dashboardApi.getTopAssets(uni.getStorageSync("star_id") || null),
},
{
key: "dashboard.levels",
fetcher: () =>
dashboardApi.getLevelDistribution(
uni.getStorageSync("star_id") || null,
),
},
{
key: "dashboard.upgrades",
fetcher: () =>
dashboardApi.getUpgradeProgress(
uni.getStorageSync("star_id") || null,
),
},
],
},
};