更新了购买套餐里的充值和立即支付的传参,增加我的账单模块待支付链接跳转和弹窗

This commit is contained in:
Eamon-meng
2025-06-18 19:05:38 +08:00
parent 36b17f1bf2
commit ba7d22168d
9 changed files with 662 additions and 136 deletions

136
src/lib/models/trade.ts Normal file
View File

@@ -0,0 +1,136 @@
import {StaticImageData} from 'next/image'
import {useEffect, useState} from 'react'
import zod from 'zod'
import wechat from '@/components/composites/purchase/_assets/wechat.svg'
import alipay from '@/components/composites/purchase/_assets/alipay.svg'
// 支付方法枚举
export const PaymentMethod = {
Alipay: 1,
WeChat: 2,
Sft: 3,
SftAlipay: 4,
SftWeChat: 5,
} as const
// 平台枚举
export const Platform = {
Desktop: 1,
Mobile: 2,
} as const
// 定义类型
export type PaymentMethod = typeof PaymentMethod[keyof typeof PaymentMethod]
export type Platform = typeof Platform[keyof typeof Platform]
// 支付方法配置类型
export type PaymentMethodConfig = {
name: string
icon: StaticImageData | null
formValue: string
availablePlatforms: Platform[]
actualMethod: PaymentMethod
}
// 支付方法配置
export const PAYMENT_METHODS: Record<PaymentMethod, PaymentMethodConfig> = {
[PaymentMethod.Alipay]: {
name: '支付宝',
icon: alipay,
formValue: 'alipay',
availablePlatforms: [Platform.Desktop],
actualMethod: PaymentMethod.Sft,
},
[PaymentMethod.WeChat]: {
name: '微信支付',
icon: wechat,
formValue: 'wechat',
availablePlatforms: [Platform.Desktop],
actualMethod: PaymentMethod.Sft,
},
[PaymentMethod.Sft]: {
name: '商福通',
icon: null,
formValue: 'sft',
availablePlatforms: [],
actualMethod: PaymentMethod.Sft,
},
[PaymentMethod.SftAlipay]: {
name: '支付宝',
icon: alipay,
formValue: 'sftAlipay',
availablePlatforms: [Platform.Mobile],
actualMethod: PaymentMethod.SftAlipay,
},
[PaymentMethod.SftWeChat]: {
name: '微信',
icon: wechat,
formValue: 'sftWeChat',
availablePlatforms: [Platform.Mobile],
actualMethod: PaymentMethod.SftWeChat,
},
} as const
// 设备检测Hook
export const usePlatformType = (): Platform => {
const [platform, setPlatform] = useState<Platform>(Platform.Desktop)
useEffect(() => {
const checkPlatform = () => {
const isMobile = window.matchMedia('(max-width: 768px)').matches
setPlatform(isMobile ? Platform.Mobile : Platform.Desktop)
}
checkPlatform()
const mediaQuery = window.matchMedia('(max-width: 768px)')
mediaQuery.addEventListener('change', checkPlatform)
return () => mediaQuery.removeEventListener('change', checkPlatform)
}, [])
return platform
}
// export const usePlatformType = (): Platform => {
// const [platform, setPlatform] = useState<Platform>(Platform.Desktop)
// useEffect(() => {
// // 确保在客户端执行
// if (typeof window === 'undefined') return
// const checkPlatform = () => {
// const isMobile = window.matchMedia('(max-width: 768px)').matches
// setPlatform(isMobile ? Platform.Mobile : Platform.Desktop)
// }
// checkPlatform()
// const mediaQuery = window.matchMedia('(max-width: 768px)')
// mediaQuery.addEventListener('change', checkPlatform)
// return () => mediaQuery.removeEventListener('change', checkPlatform)
// }, [])
// return platform
// }
// 支付表单验证schema
export const paymentSchema = zod.object({
method: zod.enum(['alipay', 'wechat', 'sft', 'sftAlipay', 'sftWeChat']),
amount: zod.number().min(1, '充值金额必须大于 0'),
})
export type PaymentSchema = zod.infer<typeof paymentSchema>
// 支付请求参数类型
export type PaymentRequest = {
amount: string
platform: Platform
method: PaymentMethod
}
export interface Trade {
inner_no: string
method: number
pay_url: string
status?: number
amount?: number
}
export interface OptionalTrade extends Partial<Trade> {}