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 verified: boolean | null loading: boolean error: string | null } type DashboardActions = { refresh: () => Promise refreshAgreement: () => Promise } export type DashboardStore = DashboardState & DashboardActions export const useDashboardStore = create()(set => ({ data: null, agreementSigned: null, verified: null, loading: false, error: null, refresh: async () => { set({ loading: true }) const res = await fetchApiIndex() if (res.success) { set({ data: res.data, verified: res.data ? res.data.UserModel?.is_verify === 1 : null, error: null, loading: false, }) } else { set({ error: res.message, loading: false }) } }, refreshAgreement: async () => { const res = await fetchAgreementStatus() if (res.success) set({ agreementSigned: res.data }) }, }))