From 8b65a1745c28d5849551dc9c61e63e94cce20a2b Mon Sep 17 00:00:00 2001 From: Eamon-meng <17516219072@163.com> Date: Thu, 16 Apr 2026 17:46:11 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E7=94=A8=E6=88=B7=E6=9C=AA/?= =?UTF-8?q?=E6=8E=88=E6=9D=83=E8=B4=AD=E4=B9=B0=E5=A5=97=E9=A4=90=E4=BB=B7?= =?UTF-8?q?=E6=A0=BC=E8=AE=A1=E7=AE=97=20&=20=E5=8F=91=E5=B8=83v1.6.0?= =?UTF-8?q?=E7=89=88=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 2 +- src/actions/resource.ts | 8 +++ .../(home)/_components/header/menu-mobile.tsx | 49 +++++++++++++------ src/components/composites/purchase/index.tsx | 15 +++--- .../composites/purchase/long/right.tsx | 32 +++++++----- .../composites/purchase/short/form.tsx | 2 +- .../composites/purchase/short/right.tsx | 36 +++++++++----- 7 files changed, 97 insertions(+), 47 deletions(-) diff --git a/package.json b/package.json index 978f51e..05177f9 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "lanhu-web", - "version": "1.5.0", + "version": "1.6.0", "private": true, "scripts": { "dev": "next dev -H 0.0.0.0 --turbopack", diff --git a/src/actions/resource.ts b/src/actions/resource.ts index 03fbab4..47e74e9 100644 --- a/src/actions/resource.ts +++ b/src/actions/resource.ts @@ -89,6 +89,14 @@ export async function payClose(props: { } export async function getPrice(props: CreateResourceReq) { + return callByUser<{ + price: string + actual?: string + discounted?: string + }>('/api/resource/price', props) +} + +export async function getPriceHome(props: CreateResourceReq) { return callByDevice<{ price: string actual?: string diff --git a/src/app/(home)/_components/header/menu-mobile.tsx b/src/app/(home)/_components/header/menu-mobile.tsx index 2475ddb..1df4984 100644 --- a/src/app/(home)/_components/header/menu-mobile.tsx +++ b/src/app/(home)/_components/header/menu-mobile.tsx @@ -1,6 +1,6 @@ 'use client' -import {useContext, useState} from 'react' +import {useContext, useEffect, useState} from 'react' import {useRouter} from 'next/navigation' import {X} from 'lucide-react' import {HeaderContext} from './common' @@ -21,6 +21,8 @@ import h03 from '@/assets/header/help/03.svg' import {merge} from '@/lib/utils' import Link from 'next/link' import logo from '@/assets/logo.webp' +import {Product} from '@/lib/models/product' +import {listProductHome} from '@/actions/product' export type MobileMenuProps = {} @@ -37,7 +39,18 @@ export default function MobileMenu(props: MobileMenuProps) { ctx.setMenu(false) router.push(href) } - + const [productList, setProductList] = useState([]) + useEffect(() => { + const fetchProducts = async () => { + const res = await listProductHome({}) + if (res.success) { + setProductList(res.data) + } + } + fetchProducts() + }, []) + const shortProduct = productList.find(p => p.name?.includes('短效') || p.code === 'short') + const longProduct = productList.find(p => p.name?.includes('长效') || p.code === 'long') return (
@@ -87,20 +100,24 @@ export default function MobileMenu(props: MobileMenuProps) { {productTab === 'domestic' && (
- - + {shortProduct && ( + + )} + {longProduct && ( + + )} store.profile)) useEffect(() => { const fetchProducts = async () => { - const res = await listProduct({}) + const res = profile + ? await listProduct({}) + : await listProductHome({}) + if (res.success) { setProductList(res.data) } } fetchProducts() - }, []) + }, [profile]) - const currentProduct = productList.find(item => item.code === tab) - const currentSkuList = currentProduct?.skus || [] const componentMap: Record> = { short: ShortForm, long: LongForm, diff --git a/src/components/composites/purchase/long/right.tsx b/src/components/composites/purchase/long/right.tsx index 97538f7..e1d191b 100644 --- a/src/components/composites/purchase/long/right.tsx +++ b/src/components/composites/purchase/long/right.tsx @@ -8,7 +8,7 @@ import {merge} from '@/lib/utils' import {useFormContext, useWatch} from 'react-hook-form' import {Schema} from '@/components/composites/purchase/long/form' import {Card} from '@/components/ui/card' -import {getPrice} from '@/actions/resource' +import {getPrice, getPriceHome} from '@/actions/resource' import {ExtraResp} from '@/lib/api' import {FieldPayment} from '../shared/field-payment' @@ -25,19 +25,29 @@ export default function Right() { actual: '0.00', discounted: '0.00', }) + const profile = use(useProfileStore(store => store.profile)) useEffect(() => { const price = async () => { try { - const resp = await getPrice({ - type: 2, - long: { - live: Number(live), - mode: Number(mode), - quota: mode === '1' ? Number(dailyLimit) : Number(quota), - expire: mode === '1' ? Number(expire) : undefined, - }, - }) + const resp = profile + ? await getPrice({ + type: 2, + long: { + live: Number(live), + mode: Number(mode), + quota: mode === '1' ? Number(dailyLimit) : Number(quota), + expire: mode === '1' ? Number(expire) : undefined, + }, + }) : await getPriceHome({ + type: 1, + short: { + live: Number(live), + mode: Number(mode), + quota: mode === '1' ? Number(dailyLimit) : Number(quota), + expire: mode === '1' ? Number(expire) : undefined, + }, + }) if (!resp.success) { throw new Error('获取价格失败') } @@ -57,7 +67,7 @@ export default function Right() { } } price() - }, [dailyLimit, expire, live, quota, mode]) + }, [dailyLimit, expire, live, quota, mode, profile]) const {price, actual: discountedPrice = ''} = priceData // 计算总折扣价(原价 - 实付价格) diff --git a/src/components/composites/purchase/short/form.tsx b/src/components/composites/purchase/short/form.tsx index 6e75922..9e5892d 100644 --- a/src/components/composites/purchase/short/form.tsx +++ b/src/components/composites/purchase/short/form.tsx @@ -59,7 +59,7 @@ export default function ShortForm({skuList}: {skuList: ProductItem['skus']}) { return (
- + ) } diff --git a/src/components/composites/purchase/short/right.tsx b/src/components/composites/purchase/short/right.tsx index a8ec203..d00b4c6 100644 --- a/src/components/composites/purchase/short/right.tsx +++ b/src/components/composites/purchase/short/right.tsx @@ -8,12 +8,12 @@ import {merge} from '@/lib/utils' import Pay from '@/components/composites/purchase/pay' import {useFormContext, useWatch} from 'react-hook-form' import {Card} from '@/components/ui/card' -import {getPrice} from '@/actions/resource' +import {getPrice, getPriceHome} from '@/actions/resource' import {ExtraResp} from '@/lib/api' import {FieldPayment} from '../shared/field-payment' import {ProductItem} from '@/actions/product' -export default function Right({skuList}: {skuList: ProductItem['skus']}) { +export default function Right() { const {control} = useFormContext() const method = useWatch({control, name: 'pay_type'}) const live = useWatch({control, name: 'live'}) @@ -26,19 +26,31 @@ export default function Right({skuList}: {skuList: ProductItem['skus']}) { actual: '0.00', discounted: '0.00', }) + const profile = use(useProfileStore(store => store.profile)) useEffect(() => { const price = async () => { try { - const priceResponse = await getPrice({ - type: 1, - short: { - live: Number(live), - mode: Number(mode), - quota: mode === '1' ? Number(dailyLimit) : Number(quota), - expire: mode === '1' ? Number(expire) : undefined, - }, - }) + const priceResponse = profile + ? await getPrice({ + type: 1, + short: { + live: Number(live), + mode: Number(mode), + quota: mode === '1' ? Number(dailyLimit) : Number(quota), + expire: mode === '1' ? Number(expire) : undefined, + }, + }) + : await getPriceHome({ + type: 1, + short: { + live: Number(live), + mode: Number(mode), + quota: mode === '1' ? Number(dailyLimit) : Number(quota), + expire: mode === '1' ? Number(expire) : undefined, + }, + }) + if (!priceResponse.success) { throw new Error('获取价格失败') } @@ -60,7 +72,7 @@ export default function Right({skuList}: {skuList: ProductItem['skus']}) { } } price() - }, [expire, live, quota, mode, dailyLimit]) + }, [expire, live, quota, mode, dailyLimit, profile]) const {price, actual: discountedPrice = ''} = priceData