feat: implement user balance management with hooks and store

This commit is contained in:
imeepos
2026-01-26 12:57:21 +08:00
parent 2757b68756
commit 3fd445bb6e
7 changed files with 489 additions and 215 deletions

27
hooks/use-user-balance.ts Normal file
View File

@@ -0,0 +1,27 @@
import { useEffect } from 'react'
import { useUserBalanceStore } from '@/stores/userBalanceStore'
/**
* 用户积分余额 Hook
* 提供积分余额的获取和管理功能
*/
export const useUserBalance = () => {
const { balance, loading, error, load, startPolling, stopPolling, deductBalance } = useUserBalanceStore()
// 组件挂载时开始轮询,卸载时停止
useEffect(() => {
startPolling()
return () => {
stopPolling()
}
}, [startPolling, stopPolling])
return {
balance,
loading,
error,
load,
deductBalance,
}
}