重构认证逻辑,优化登录和用户信息获取流程,新增全局缓存支持
This commit is contained in:
@@ -6,7 +6,7 @@ import wechat from '../_assets/wechat.svg'
|
||||
import balance from '../_assets/balance.svg'
|
||||
import Image from 'next/image'
|
||||
import {useContext, useRef, useState} from 'react'
|
||||
import {AuthContext} from '@/components/providers/AuthProvider'
|
||||
import {StoreContext, useProfileStore} from '@/components/providers/StoreProvider'
|
||||
import {Alert, AlertDescription} from '@/components/ui/alert'
|
||||
import {
|
||||
prepareResourceByAlipay,
|
||||
@@ -32,7 +32,9 @@ export type PayProps = {
|
||||
|
||||
export default function Pay(props: PayProps) {
|
||||
|
||||
const ctx = useContext(AuthContext)
|
||||
const profile = useProfileStore(store=>store.profile)
|
||||
const refreshProfile = useProfileStore(store=>store.refreshProfile)
|
||||
|
||||
const [open, setOpen] = useState(false)
|
||||
const [payInfo, setPayInfo] = useState<CreateResourceResp | undefined>()
|
||||
const canvas = useRef<HTMLCanvasElement>(null)
|
||||
@@ -97,7 +99,7 @@ export default function Pay(props: PayProps) {
|
||||
})
|
||||
|
||||
setOpen(false)
|
||||
await ctx.refreshProfile()
|
||||
await refreshProfile()
|
||||
}
|
||||
catch (e) {
|
||||
console.log(e)
|
||||
@@ -133,12 +135,12 @@ export default function Pay(props: PayProps) {
|
||||
</DialogHeader>
|
||||
|
||||
{props.method === 'balance' ? (
|
||||
ctx.profile && (
|
||||
profile && (
|
||||
<div className="flex flex-col gap-4">
|
||||
<div className="flex flex-col gap-1">
|
||||
<div className="flex justify-between items-center">
|
||||
<span className="text-weak text-sm">账户余额</span>
|
||||
<span className={`text-lg`}>{ctx.profile.balance}元</span>
|
||||
<span className={`text-lg`}>{profile.balance}元</span>
|
||||
</div>
|
||||
<div className="flex justify-between items-center">
|
||||
<span className="text-weak text-sm">支付金额</span>
|
||||
@@ -147,13 +149,13 @@ export default function Pay(props: PayProps) {
|
||||
<hr className="my-2"/>
|
||||
<div className="flex justify-between items-center">
|
||||
<span className="text-weak text-sm">支付后余额</span>
|
||||
<span className={`text-lg ${ctx.profile.balance > props.amount ? 'text-done' : `text-fail`}`}>
|
||||
{ctx.profile.balance - props.amount}元
|
||||
<span className={`text-lg ${profile.balance > props.amount ? 'text-done' : `text-fail`}`}>
|
||||
{profile.balance - props.amount}元
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{ctx.profile.balance < props.amount && (
|
||||
{profile.balance < props.amount && (
|
||||
<Alert variant="fail">
|
||||
<AlertDescription>
|
||||
余额不足,请先充值或选择其他支付方式
|
||||
@@ -161,7 +163,7 @@ export default function Pay(props: PayProps) {
|
||||
</Alert>
|
||||
)}
|
||||
|
||||
{ctx.profile.balance >= props.amount && (
|
||||
{profile.balance >= props.amount && (
|
||||
<Alert>
|
||||
<AlertDescription>
|
||||
检查无误后,点击确认支付按钮完成支付
|
||||
@@ -200,7 +202,7 @@ export default function Pay(props: PayProps) {
|
||||
<DialogFooter>
|
||||
<Button
|
||||
type="button"
|
||||
disabled={props.method === 'balance' && !!ctx.profile && ctx.profile.balance < props.amount}
|
||||
disabled={props.method === 'balance' && !!profile && profile.balance < props.amount}
|
||||
onClick={onSubmit}
|
||||
>
|
||||
{props.method === 'balance' ? '确认支付' : '已完成支付'}
|
||||
|
||||
Reference in New Issue
Block a user