topfans/frontend/utils/mock/dashboard.js

152 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.

// 数据看板 mock 数据工厂
// 后端就绪后,将 utils/api.js 顶部 USE_MOCK_API 改为 false 即可
const randomDelay = (min = 200, max = 600) =>
new Promise((resolve) => setTimeout(resolve, Math.random() * (max - min) + min))
// 1. 今日概览
export async function mockTodayOverview({ star_id }) {
await randomDelay()
return {
code: 200,
data: {
crystal_balance: 2713,
today_income: 213,
week_rank: 12,
},
}
}
// 2. 七日收益曲线
export async function mock7DayIncomeCurve({ star_id }) {
await randomDelay()
const today = new Date()
const points = []
const incomes = [180, 245, 198, 312, 276, 221, 189] // 最后一个是今天
for (let i = 6; i >= 0; i--) {
const d = new Date(today)
d.setDate(d.getDate() - i)
const income = incomes[6 - i]
points.push({
date: `${d.getFullYear()}.${String(d.getMonth() + 1).padStart(2, '0')}.${String(d.getDate()).padStart(2, '0')}`,
income,
is_today: i === 0,
is_peak: income === 312,
})
}
return {
code: 200,
data: {
points,
total_income: incomes.reduce((a, b) => a + b, 0),
avg_income: Math.round(incomes.reduce((a, b) => a + b, 0) / 7),
},
}
}
// 3. 展出收益中心
export async function mockExhibitionSummary({ star_id }) {
await randomDelay()
return {
code: 200,
data: {
exhibiting_count: 21,
starbook_count: 33,
total_duration: '712:13:56',
total_earnings: 39721,
top5: [
{ asset_id: 1, asset_name: '璀璨星河', asset_thumb: '/static/sucai/image-07.png', duration_7d: '144:13:56', earnings_7d: 2173, avg_earnings: 15 },
{ asset_id: 2, asset_name: '夏日微风', asset_thumb: '/static/sucai/image-19.png', duration_7d: '77:13:56', earnings_7d: 1332, avg_earnings: 15 },
{ asset_id: 3, asset_name: '夜色霓虹', asset_thumb: '/static/sucai/image-23.png', duration_7d: '64:15:37', earnings_7d: 1201, avg_earnings: 12 },
{ asset_id: 4, asset_name: '黎明序曲', asset_thumb: '/static/sucai/image-38.png', duration_7d: '51:22:12', earnings_7d: 783, avg_earnings: 12 },
{ asset_id: 5, asset_name: '深海回响', asset_thumb: '/static/sucai/image-46.png', duration_7d: '51:22:12', earnings_7d: 783, avg_earnings: 12 },
],
},
}
}
// 4. 点赞收益按等级
export async function mockLikeIncomeByLevel({ star_id }) {
await randomDelay()
return {
code: 200,
data: {
total_like_count: 231,
total_income: 12719,
levels: [
{ level: 'UR', asset_count: 1, total_income: 723, thumb: '/static/sucai/image-03.png' },
{ level: 'SSR', asset_count: 2, total_income: 381, thumb: '/static/sucai/image-14.png' },
{ level: 'SR', asset_count: 5, total_income: 233, thumb: '/static/sucai/image-27.png' },
{ level: 'SR', asset_count: 4, total_income: 169, thumb: '/static/sucai/image-35.png' },
{ level: 'R', asset_count: 6, total_income: 57, thumb: '/static/sucai/image-49.png' },
],
},
}
}
// 5. 藏品 TOP5
export async function mockTopAssets({ star_id }) {
await randomDelay()
return {
code: 200,
data: {
items: [
{ asset_id: 1, asset_name: '璀璨星河', asset_thumb: '/static/sucai/image-04.png', total_earnings: 8420, rank: 1 },
{ asset_id: 2, asset_name: '夏日微风', asset_thumb: '/static/sucai/image-11.png', total_earnings: 6230, rank: 2 },
{ asset_id: 3, asset_name: '夜色霓虹', asset_thumb: '/static/sucai/image-26.png', total_earnings: 5180, rank: 3 },
{ asset_id: 4, asset_name: '黎明序曲', asset_thumb: '/static/sucai/image-39.png', total_earnings: 4320, rank: 4 },
{ asset_id: 5, asset_name: '深海回响', asset_thumb: '/static/sucai/image-50.png', total_earnings: 3980, rank: 5 },
],
},
}
}
// 6. 藏品等级分布
export async function mockLevelDistribution({ star_id }) {
await randomDelay()
const total = 33
return {
code: 200,
data: {
items: [
{ level: 'UR', count: 1, total },
{ level: 'SSR', count: 2, total },
{ level: 'SR', count: 5, total },
{ level: 'R', count: 6, total },
{ level: 'N', count: 0, total },
],
},
}
}
// 7. 升级进度
export async function mockUpgradeProgress({ star_id }) {
await randomDelay()
return {
code: 200,
data: {
upcoming: [
{ asset_id: 1, asset_name: '璀璨星河', asset_thumb: '/static/sucai/image-02.png', like_progress: 73, duration_progress: 92 },
{ asset_id: 2, asset_name: '夏日微风', asset_thumb: '/static/sucai/image-16.png', like_progress: 75, duration_progress: 96 },
{ asset_id: 3, asset_name: '夜色霓虹', asset_thumb: '/static/sucai/image-28.png', like_progress: 97, duration_progress: 71 },
],
recent: [
{ asset_id: 4, asset_name: '黎明序曲', asset_thumb: '/static/sucai/image-02.png', new_level: 'SSR', upgrade_time: Date.now() - 3600000 },
{ asset_id: 5, asset_name: '深海回响', asset_thumb: '/static/sucai/image-16.png', new_level: 'SR', upgrade_time: Date.now() - 86400000 },
{ asset_id: 6, asset_name: '晨曦微光', asset_thumb: '/static/sucai/image-28.png', new_level: 'SR', upgrade_time: Date.now() - 172800000 },
],
},
}
}
// 路由表endpoints 字符串 → mock 工厂
export const mockRouter = {
'/api/v1/dashboard/today-overview': mockTodayOverview,
'/api/v1/dashboard/income-curve': mock7DayIncomeCurve,
'/api/v1/dashboard/exhibition-summary': mockExhibitionSummary,
'/api/v1/dashboard/like-income-by-level': mockLikeIncomeByLevel,
'/api/v1/dashboard/top-assets': mockTopAssets,
'/api/v1/dashboard/level-distribution': mockLevelDistribution,
'/api/v1/dashboard/upgrade-progress': mockUpgradeProgress,
}