使用服务端渲染实现购买页面跳转
This commit is contained in:
@@ -1,8 +1,12 @@
|
|||||||
import BreadCrumb from '@/components/bread-crumb'
|
import BreadCrumb from '@/components/bread-crumb'
|
||||||
import Wrap from '@/components/wrap'
|
import Wrap from '@/components/wrap'
|
||||||
import Purchase from '@/components/composites/purchase'
|
import Purchase, {TabType} from '@/components/composites/purchase'
|
||||||
|
|
||||||
export type ProductPageProps = {}
|
export type ProductPageProps = {
|
||||||
|
searchParams?: {
|
||||||
|
type?: TabType
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export default function ProductPage(props: ProductPageProps) {
|
export default function ProductPage(props: ProductPageProps) {
|
||||||
return (
|
return (
|
||||||
@@ -11,7 +15,7 @@ export default function ProductPage(props: ProductPageProps) {
|
|||||||
<BreadCrumb items={[
|
<BreadCrumb items={[
|
||||||
{label: '产品中心', href: '/product'},
|
{label: '产品中心', href: '/product'},
|
||||||
]}/>
|
]}/>
|
||||||
<Purchase/>
|
<Purchase defaultType={props.searchParams?.type ?? 'short'}/>
|
||||||
</Wrap>
|
</Wrap>
|
||||||
</main>
|
</main>
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -1,12 +1,16 @@
|
|||||||
import Purchase from '@/components/composites/purchase'
|
import Purchase, {TabType} from '@/components/composites/purchase'
|
||||||
import Page from '@/components/page'
|
import Page from '@/components/page'
|
||||||
|
|
||||||
export type PurchasePageProps = {}
|
export type PurchasePageProps = {
|
||||||
|
searchParams?: {
|
||||||
|
type?: TabType
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export default async function PurchasePage(props: PurchasePageProps) {
|
export default async function PurchasePage(props: PurchasePageProps) {
|
||||||
return (
|
return (
|
||||||
<Page className="flex-col">
|
<Page className="flex-col">
|
||||||
<Purchase/>
|
<Purchase defaultType={props.searchParams?.type ?? 'short'}/>
|
||||||
</Page>
|
</Page>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,23 +1,19 @@
|
|||||||
'use client'
|
import {ReactNode} from 'react'
|
||||||
import {ReactNode, useContext} from 'react'
|
|
||||||
import {merge} from '@/lib/utils'
|
import {merge} from '@/lib/utils'
|
||||||
import {Tabs, TabsContent, TabsList, TabsTrigger} from '@/components/ui/tabs'
|
import {Tabs, TabsContent, TabsList, TabsTrigger} from '@/components/ui/tabs'
|
||||||
import LongForm from '@/components/composites/purchase/long/form'
|
import LongForm from '@/components/composites/purchase/long/form'
|
||||||
import ShortForm from '@/components/composites/purchase/short/form'
|
import ShortForm from '@/components/composites/purchase/short/form'
|
||||||
import Link from 'next/link'
|
|
||||||
import {useSearchParams} from 'next/navigation'
|
|
||||||
import {HeaderContext} from '@/app/(home)/@header/_client/provider'
|
|
||||||
import {useRouter} from 'next/navigation'
|
|
||||||
|
|
||||||
export type TabType = 'short' | 'long' | 'fixed' | 'custom'
|
export type TabType = 'short' | 'long' | 'fixed' | 'custom'
|
||||||
|
|
||||||
export default function Purchase() {
|
type PurchaseProps = {
|
||||||
const searchParams = useSearchParams()
|
defaultType: TabType
|
||||||
const defaultTab = searchParams?.get('type') as TabType || 'short'
|
}
|
||||||
|
|
||||||
|
export default async function Purchase(props: PurchaseProps) {
|
||||||
return (
|
return (
|
||||||
<>
|
|
||||||
<div className="flex flex-col gap-4">
|
<div className="flex flex-col gap-4">
|
||||||
<Tabs value={defaultTab} className="gap-4">
|
<Tabs defaultValue={props.defaultType} className="gap-4">
|
||||||
<TabsList className="w-full p-2 bg-white rounded-lg justify-start md:justify-center overflow-auto">
|
<TabsList className="w-full p-2 bg-white rounded-lg justify-start md:justify-center overflow-auto">
|
||||||
<Tab value="short">短效动态</Tab>
|
<Tab value="short">短效动态</Tab>
|
||||||
<Tab value="long">长效静态</Tab>
|
<Tab value="long">长效静态</Tab>
|
||||||
@@ -32,7 +28,6 @@ export default function Purchase() {
|
|||||||
</TabsContent>
|
</TabsContent>
|
||||||
</Tabs>
|
</Tabs>
|
||||||
</div>
|
</div>
|
||||||
</>
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -40,33 +35,15 @@ function Tab(props: {
|
|||||||
value: string
|
value: string
|
||||||
children: ReactNode
|
children: ReactNode
|
||||||
}) {
|
}) {
|
||||||
const ctx = useContext(HeaderContext)
|
|
||||||
const router = useRouter()
|
|
||||||
const handleClick = (e: React.MouseEvent) => {
|
|
||||||
e.preventDefault()
|
|
||||||
e.stopPropagation()
|
|
||||||
if (ctx) {
|
|
||||||
ctx.setMenu(false)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return (
|
return (
|
||||||
<Link
|
|
||||||
href={{
|
|
||||||
pathname: '/product',
|
|
||||||
query: {type: props.value},
|
|
||||||
}}
|
|
||||||
passHref
|
|
||||||
legacyBehavior // 如果需要兼容旧版行为
|
|
||||||
>
|
|
||||||
<TabsTrigger
|
<TabsTrigger
|
||||||
className={merge(
|
className={merge(
|
||||||
`w-36 h-12 text-base font-normal flex-none`,
|
`w-36 h-12 text-base font-normal flex-none`,
|
||||||
`data-[state=active]:text-primary data-[state=active]:bg-primary-muted`,
|
`data-[state=active]:text-primary data-[state=active]:bg-primary-muted`,
|
||||||
)}
|
)}
|
||||||
value={props.value}
|
value={props.value}
|
||||||
onClick={handleClick}>
|
>
|
||||||
{props.children}
|
{props.children}
|
||||||
</TabsTrigger>
|
</TabsTrigger>
|
||||||
</Link>
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user