完善个人中心页面
This commit is contained in:
41
src/components/stores/dashboard.ts
Normal file
41
src/components/stores/dashboard.ts
Normal file
@@ -0,0 +1,41 @@
|
||||
import { create } from "zustand"
|
||||
import { fetchAgreementStatus } from "@/api/agreement"
|
||||
import { fetchApiIndex } from "@/api/dashboard"
|
||||
import type { ApiIndexItem } from "@/lib/models/dashboard"
|
||||
|
||||
// ==================== 个人中心账户总览 ====================
|
||||
// 数据源:.NET /user/ApiIndex;协议签署状态:php-api /tencent/index/get_is_upload
|
||||
|
||||
export type DashboardState = {
|
||||
data: ApiIndexItem | null
|
||||
agreementSigned: boolean | null
|
||||
loading: boolean
|
||||
error: string | null
|
||||
}
|
||||
|
||||
type DashboardActions = {
|
||||
refresh: () => Promise<void>
|
||||
refreshAgreement: () => Promise<void>
|
||||
}
|
||||
|
||||
export type DashboardStore = DashboardState & DashboardActions
|
||||
|
||||
export const useDashboardStore = create<DashboardStore>()(set => ({
|
||||
data: null,
|
||||
agreementSigned: null,
|
||||
loading: false,
|
||||
error: null,
|
||||
refresh: async () => {
|
||||
set({ loading: true })
|
||||
const res = await fetchApiIndex()
|
||||
if (res.success) {
|
||||
set({ data: res.data, error: null, loading: false })
|
||||
} else {
|
||||
set({ error: res.message, loading: false })
|
||||
}
|
||||
},
|
||||
refreshAgreement: async () => {
|
||||
const res = await fetchAgreementStatus()
|
||||
if (res.success) set({ agreementSigned: res.data })
|
||||
},
|
||||
}))
|
||||
Reference in New Issue
Block a user