Files
juip-web/src/components/stores/dashboard.ts
2026-09-11 17:06:29 +08:00

49 lines
1.3 KiB
TypeScript
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.
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<void>
refreshAgreement: () => Promise<void>
}
export type DashboardStore = DashboardState & DashboardActions
export const useDashboardStore = create<DashboardStore>()(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 })
},
}))