refactor(pages): migrate app data reads to api adapters

This commit is contained in:
zetaloop
2026-02-22 08:30:21 +08:00
parent 43a0cf7a73
commit 4beb610f23
13 changed files with 97 additions and 66 deletions
+5 -5
View File
@@ -6,17 +6,17 @@ import { Badge } from "@/components/ui/badge"
import { Button } from "@/components/ui/button"
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"
import { Progress } from "@/components/ui/progress"
import { listOrders, listPlayers, listServices, listShops } from "@/lib/api"
import { statusLabels } from "@/lib/constants"
import { mockOrders, mockPlayers, mockServices, mockShops } from "@/lib/mock"
import { useAuthStore } from "@/store/auth"
export default function DashboardPage() {
const { currentRole } = useAuthStore()
const isOwner = currentRole === "owner"
const player = mockPlayers[0]
const shop = mockShops[0]
const recentOrders = mockOrders.slice(0, 3)
const player = listPlayers()[0]
const shop = listShops()[0]
const recentOrders = listOrders().slice(0, 3)
return (
<div className="space-y-6">
@@ -76,7 +76,7 @@ export default function DashboardPage() {
</CardHeader>
<CardContent>
<div className="text-2xl font-bold">
{isOwner ? "¥12,800" : mockServices.filter((s) => s.playerId === player.id).length}
{isOwner ? "¥12,800" : listServices().filter((s) => s.playerId === player.id).length}
</div>
</CardContent>
</Card>
@@ -19,8 +19,8 @@ import {
SelectValue,
} from "@/components/ui/select"
import { Textarea } from "@/components/ui/textarea"
import { getGameById, listGames } from "@/lib/api"
import { GameIcon } from "@/lib/game-icons"
import { mockGames } from "@/lib/mock"
import type { PlayerService } from "@/lib/types"
import { useAuthStore } from "@/store/auth"
import { useServiceStore } from "@/store/services"
@@ -76,9 +76,10 @@ export default function NewServicePage() {
const selectedGameId = watch("gameId")
const selectedUnit = watch("unit")
const games = listGames()
const onSubmit = async (data: z.infer<typeof serviceSchema>) => {
const game = mockGames.find((item) => item.id === data.gameId)
const game = getGameById(data.gameId)
if (!game) return
const payload: Omit<PlayerService, "id"> = {
@@ -128,7 +129,7 @@ export default function NewServicePage() {
<SelectValue placeholder="选择游戏" />
</SelectTrigger>
<SelectContent>
{mockGames.map((game) => (
{games.map((game) => (
<SelectItem key={game.id} value={game.id}>
<div className="flex items-center gap-2">
<GameIcon name={game.icon} className="h-4 w-4" />
@@ -11,7 +11,7 @@ import {
TableHeader,
TableRow,
} from "@/components/ui/table"
import { mockTransactions } from "@/lib/mock"
import { listTransactions } from "@/lib/api"
import { useAuthStore } from "@/store/auth"
import { useOrderStore } from "@/store/orders"
import { useShopStore } from "@/store/shops"
@@ -35,7 +35,7 @@ export default function ShopIncomePage() {
.reduce((acc, order) => acc + order.totalPrice, 0)
const shopOrderIds = new Set(shopOrders.map((order) => order.id))
const relatedTransactions = mockTransactions.filter((transaction) => {
const relatedTransactions = listTransactions().filter((transaction) => {
if (transaction.type === "withdrawal") return true
if (transaction.type !== "income") return false
const match = transaction.description.match(/ord\d+/)