更新底部服务保障跳转链接 & 购买套餐添加折扣字段 & 用户总览添加长效动态图表

This commit is contained in:
Eamon-meng
2025-12-18 17:11:19 +08:00
parent 375a6f30c0
commit fa942d4b99
5 changed files with 163 additions and 48 deletions

View File

@@ -17,6 +17,13 @@ import Pay from '@/components/composites/purchase/pay'
import {useFormContext, useWatch} from 'react-hook-form'
import {Card} from '@/components/ui/card'
import {CreateResourceReq, getPrice} from '@/actions/resource'
interface PriceData {
price: string
discounted_price?: string
discounted?: number
}
export default function Right() {
const {control} = useFormContext<Schema>()
const method = useWatch({control, name: 'pay_type'})
@@ -25,7 +32,11 @@ export default function Right() {
const expire = useWatch({control, name: 'expire'})
const quota = useWatch({control, name: 'quota'})
const dailyLimit = useWatch({control, name: 'daily_limit'})
const [price, setPrice] = useState<string>('')
const [priceData, setPriceData] = useState<PriceData>({
price: '0.00',
discounted_price: '0.00',
discounted: 0,
})
useEffect(() => {
const price = async () => {
@@ -40,18 +51,31 @@ export default function Right() {
}
try {
const priceResponse = await getPrice(params)
if (priceResponse.success && priceResponse.data?.price) {
setPrice(priceResponse.data.price)
console.log(priceResponse, 'priceResponse')
if (priceResponse.success && priceResponse.data) {
const data: PriceData = priceResponse.data
setPriceData({
price: data.price,
discounted_price: data.discounted_price ?? data.price ?? '',
discounted: data.discounted,
})
}
}
catch (error) {
console.error('获取价格失败:', error)
setPrice('0.00')
setPriceData({
price: '0.00',
discounted_price: '0.00',
discounted: 0,
})
}
}
price()
}, [expire, live, quota, mode, dailyLimit])
const {price, discounted_price: discountedPrice = '', discounted} = priceData
return (
<Card className={merge(
`flex-none basis-90 p-6 flex flex-col gap-6 relative`,
@@ -73,13 +97,21 @@ export default function Right() {
</span>
</li>
{mode === '2' ? (
<li className="flex justify-between items-center">
<span className="text-sm text-gray-500"> IP </span>
<span className="text-sm">
{quota}
</span>
</li>
<>
<li className="flex justify-between items-center">
<span className="text-sm text-gray-500"> IP </span>
<span className="text-sm">
{quota}
</span>
</li>
<li className="flex justify-between items-center">
<span className="text-sm text-gray-500"></span>
<span className="text-sm">
{price}
</span>
</li>
</>
) : (
<>
<li className="flex justify-between items-center">
@@ -96,19 +128,32 @@ export default function Right() {
</span>
</li>
<li className="flex justify-between items-center">
<span className="text-sm text-gray-500"></span>
<span className="text-sm">
{price}
</span>
</li>
{discounted === 1 ? '' : (
<li className="flex justify-between items-center">
<span className="text-sm text-gray-500"></span>
<span className="text-sm">
-{discounted === 1 ? '' : discounted}
</span>
</li>
)}
</>
)}
</ul>
<div className="border-b border-gray-200"></div>
<p className="flex justify-between items-center">
<span></span>
<span></span>
<span className="text-xl text-orange-500">
{price}
{discountedPrice}
</span>
</p>
<Suspense>
<BalanceOrLogin {...{method, price, mode, live, quota, expire, dailyLimit}}/>
<BalanceOrLogin {...{method, discountedPrice, mode, live, quota, expire, dailyLimit}}/>
</Suspense>
</Card>
)
@@ -116,7 +161,7 @@ export default function Right() {
function BalanceOrLogin(props: {
method: 'wechat' | 'alipay' | 'balance'
price: string
discountedPrice: string
mode: string
live: string
quota: number
@@ -175,7 +220,7 @@ function BalanceOrLogin(props: {
<Pay
method={props.method}
balance={profile.balance}
amount={props.price}
amount={props.discountedPrice}
resource={{
type: 1,
short: {