完善支付页面与路由的交互实现
This commit is contained in:
@@ -15,7 +15,7 @@ export default async function ProductPage(props: ProductPageProps) {
|
||||
<BreadCrumb items={[
|
||||
{label: '产品中心', href: '/product'},
|
||||
]}/>
|
||||
<Purchase defaultTab={(await props.searchParams)?.type ?? 'short'}/>
|
||||
<Purchase/>
|
||||
</Wrap>
|
||||
</main>
|
||||
)
|
||||
|
||||
@@ -10,7 +10,7 @@ export type PurchasePageProps = {
|
||||
export default async function PurchasePage(props: PurchasePageProps) {
|
||||
return (
|
||||
<Page className="flex-col">
|
||||
<Purchase defaultTab={(await props.searchParams)?.type ?? 'short'}/>
|
||||
<Purchase/>
|
||||
</Page>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -1,25 +1,23 @@
|
||||
'use client'
|
||||
import {ReactNode, useState} from 'react'
|
||||
import {ReactNode} from 'react'
|
||||
import {merge} from '@/lib/utils'
|
||||
import {Tabs, TabsContent, TabsList, TabsTrigger} from '@/components/ui/tabs'
|
||||
import LongForm from '@/components/composites/purchase/long/form'
|
||||
import ShortForm from '@/components/composites/purchase/short/form'
|
||||
import {useSearchParams} from 'next/navigation'
|
||||
import {usePathname, useRouter, useSearchParams} from 'next/navigation'
|
||||
export type TabType = 'short' | 'long' | 'fixed' | 'custom'
|
||||
|
||||
type PurchaseProps = {
|
||||
defaultTab: TabType
|
||||
}
|
||||
|
||||
export default function Purchase(props: PurchaseProps) {
|
||||
const [tab, setTab] = useState(props.defaultTab)
|
||||
|
||||
export default function Purchase() {
|
||||
const router = useRouter()
|
||||
const path = usePathname()
|
||||
const params = useSearchParams()
|
||||
|
||||
const tab = params.get('type') as TabType || 'short'
|
||||
|
||||
const updateTab = async (tab: string) => {
|
||||
setTab(tab as TabType)
|
||||
const newParams = new URLSearchParams(params)
|
||||
newParams.set('type', tab)
|
||||
window.history.pushState({}, '', `?${newParams.toString()}`)
|
||||
router.push(`${path}?${newParams.toString()}`)
|
||||
}
|
||||
|
||||
return (
|
||||
|
||||
18
src/proxy.ts
18
src/proxy.ts
@@ -29,20 +29,10 @@ export async function proxy(request: NextRequest) {
|
||||
}
|
||||
|
||||
// 验证访问令牌
|
||||
if (request.cookies.get('auth_token')) {
|
||||
// 如果刷新访问令牌成功,则继续访问之前的页面
|
||||
const isLogin = request.nextUrl.pathname === '/login'
|
||||
const hasRedirect = request.nextUrl.searchParams.get('redirect')
|
||||
if (isLogin && hasRedirect) {
|
||||
return NextResponse.redirect(`${request.nextUrl.origin}${hasRedirect}`)
|
||||
}
|
||||
}
|
||||
else {
|
||||
// 没有访问令牌不允许访问 admin 页面
|
||||
const isAdmin = request.nextUrl.pathname.startsWith('/admin')
|
||||
if (isAdmin) {
|
||||
return NextResponse.redirect(`${request.nextUrl.origin}/login?redirect=${request.nextUrl.pathname}`)
|
||||
}
|
||||
const hasToken = !!request.cookies.get('auth_token')
|
||||
const isToAdmin = request.nextUrl.pathname.startsWith('/admin')
|
||||
if (!hasToken && isToAdmin) {
|
||||
return NextResponse.redirect(`${request.nextUrl.origin}/login?redirect=${request.nextUrl.pathname}`)
|
||||
}
|
||||
|
||||
return NextResponse.next({request})
|
||||
|
||||
Reference in New Issue
Block a user