Compare commits
11 Commits
5f7756199a
...
v1.10.0
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
165151b9d2 | ||
|
|
1e76275f04 | ||
|
|
d9cd5eb41b | ||
|
|
7ff42861f1 | ||
|
|
eb4c2d2d5f | ||
| a0b0956677 | |||
|
|
27e694ee0d | ||
|
|
74d53c619d | ||
| 8f8def3a87 | |||
|
|
ed73d8579f | ||
|
|
e3c61a77e6 |
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "lanhu-web",
|
||||
"version": "1.6.0",
|
||||
"version": "1.10.0",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"dev": "next dev -H 0.0.0.0 --turbopack",
|
||||
|
||||
@@ -9,8 +9,8 @@ if ($confrim -ne "y") {
|
||||
exit 0
|
||||
}
|
||||
|
||||
docker build -t repo.lanhuip.com:8554/lanhu/web:latest .
|
||||
docker build -t repo.lanhuip.com:8554/lanhu/web:$($args[0]) .
|
||||
docker build -t repo.lanhuip.com/lanhu/web:latest .
|
||||
docker build -t repo.lanhuip.com/lanhu/web:$($args[0]) .
|
||||
|
||||
docker push repo.lanhuip.com:8554/lanhu/web:latest
|
||||
docker push repo.lanhuip.com:8554/lanhu/web:$($args[0])
|
||||
docker push repo.lanhuip.com/lanhu/web:latest
|
||||
docker push repo.lanhuip.com/lanhu/web:$($args[0])
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
import {API_BASE_URL, ApiResponse, CLIENT_ID, CLIENT_SECRET} from '@/lib/api'
|
||||
import {add, isBefore} from 'date-fns'
|
||||
import {cookies, headers} from 'next/headers'
|
||||
import {redirect} from 'next/navigation'
|
||||
import {cache} from 'react'
|
||||
|
||||
export type TokenResp = {
|
||||
@@ -106,7 +107,6 @@ const _callByUser = cache(async <R = undefined>(
|
||||
// ======================
|
||||
|
||||
async function call<R = undefined>(url: string, body: RequestInit['body'], auth?: string): Promise<ApiResponse<R>> {
|
||||
let response: Response
|
||||
try {
|
||||
const reqHeaders = await headers()
|
||||
const reqIP = reqHeaders.get('x-forwarded-for')
|
||||
@@ -118,55 +118,59 @@ async function call<R = undefined>(url: string, body: RequestInit['body'], auth?
|
||||
if (reqIP) callHeaders['X-Forwarded-For'] = reqIP
|
||||
if (reqUA) callHeaders['User-Agent'] = reqUA
|
||||
|
||||
response = await fetch(url, {
|
||||
const response = await fetch(url, {
|
||||
method: 'POST',
|
||||
headers: callHeaders,
|
||||
body,
|
||||
})
|
||||
|
||||
if (response.status === 401) {
|
||||
return redirect('/login?redirect=' + encodeURIComponent(url.replace(API_BASE_URL, '')))
|
||||
}
|
||||
|
||||
const type = response.headers.get('Content-Type') ?? 'text/plain'
|
||||
if (type.indexOf('text/plain') !== -1) {
|
||||
const text = await response.text()
|
||||
if (!response.ok) {
|
||||
console.log('后端请求失败', url, `status=${response.status}`, text)
|
||||
return {
|
||||
success: false,
|
||||
status: response.status,
|
||||
message: text || '请求失败',
|
||||
}
|
||||
}
|
||||
|
||||
if (!!text?.trim()?.length) {
|
||||
console.log('未处理的响应成功', `type=text`, `text=${text}`)
|
||||
}
|
||||
return {
|
||||
success: true,
|
||||
data: undefined as R, // 强转类型,考虑优化
|
||||
}
|
||||
}
|
||||
else if (type.indexOf('application/json') !== -1) {
|
||||
const json = await response.json()
|
||||
if (!response.ok) {
|
||||
console.log('后端请求失败', url, `status=${response.status}`, json)
|
||||
|
||||
return {
|
||||
success: false,
|
||||
status: response.status,
|
||||
message: json.message || json.error_description || '请求失败', // 业务错误(message)或者 oauth 错误(error_description)
|
||||
}
|
||||
}
|
||||
return {
|
||||
success: true,
|
||||
data: json,
|
||||
}
|
||||
}
|
||||
|
||||
throw new Error(`无法解析响应数据,未处理的 Content-Type: ${type}`)
|
||||
}
|
||||
catch (e) {
|
||||
console.error('后端请求失败', url, (e as Error).message)
|
||||
throw new Error(`请求失败,网络错误`)
|
||||
}
|
||||
|
||||
const type = response.headers.get('Content-Type') ?? 'text/plain'
|
||||
if (type.indexOf('text/plain') !== -1) {
|
||||
const text = await response.text()
|
||||
if (!response.ok) {
|
||||
console.log('后端请求失败', url, `status=${response.status}`, text)
|
||||
return {
|
||||
success: false,
|
||||
status: response.status,
|
||||
message: text || '请求失败',
|
||||
}
|
||||
}
|
||||
|
||||
if (!!text?.trim()?.length) {
|
||||
console.log('未处理的响应成功', `type=text`, `text=${text}`)
|
||||
}
|
||||
return {
|
||||
success: true,
|
||||
data: undefined as R, // 强转类型,考虑优化
|
||||
}
|
||||
}
|
||||
else if (type.indexOf('application/json') !== -1) {
|
||||
const json = await response.json()
|
||||
if (!response.ok) {
|
||||
console.log('后端请求失败', url, `status=${response.status}`, json)
|
||||
|
||||
return {
|
||||
success: false,
|
||||
status: response.status,
|
||||
message: json.message || json.error_description || '请求失败', // 业务错误(message)或者 oauth 错误(error_description)
|
||||
}
|
||||
}
|
||||
return {
|
||||
success: true,
|
||||
data: json,
|
||||
}
|
||||
}
|
||||
|
||||
throw new Error(`无法解析响应数据,未处理的 Content-Type: ${type}`)
|
||||
}
|
||||
|
||||
// 导出
|
||||
|
||||
@@ -103,3 +103,10 @@ export async function getPriceHome(props: CreateResourceReq) {
|
||||
discounted?: string
|
||||
}>('/api/resource/price', props)
|
||||
}
|
||||
|
||||
export async function updateCheckip(props: {
|
||||
id: number
|
||||
checkip: boolean
|
||||
}) {
|
||||
return callByUser('/api/resource/update/checkip', props)
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ import {Card, CardContent} from '@/components/ui/card'
|
||||
import {Form, FormField} from '@/components/ui/form'
|
||||
import {Label} from '@/components/ui/label'
|
||||
import {Tabs, TabsList, TabsTrigger} from '@/components/ui/tabs'
|
||||
import {EyeClosedIcon, EyeIcon} from 'lucide-react'
|
||||
import {EyeClosedIcon, EyeIcon, HomeIcon} from 'lucide-react'
|
||||
import {useState, ReactNode, useEffect, Suspense} from 'react'
|
||||
import zod from 'zod'
|
||||
import {useForm, useFormContext, useWatch} from 'react-hook-form'
|
||||
@@ -16,6 +16,7 @@ import {useRouter} from 'next/navigation'
|
||||
import {login, LoginMode} from '@/actions/auth'
|
||||
import {useProfileStore} from '@/components/stores/profile'
|
||||
import dynamic from 'next/dynamic'
|
||||
import Link from 'next/link'
|
||||
|
||||
const smsSchema = zod.object({
|
||||
username: zod.string().length(11, '请输入正确的手机号码'),
|
||||
@@ -88,111 +89,122 @@ export default function LoginCard() {
|
||||
const [showPwd, setShowPwd] = useState(false)
|
||||
|
||||
return (
|
||||
<Card className="w-96 mx-4 shadow-lg relative z-20 py-8">
|
||||
<CardContent className="px-8">
|
||||
{/* 登录方式切换 */}
|
||||
<Tabs
|
||||
value={mode}
|
||||
onValueChange={(val) => {
|
||||
setMode(val as LoginMode)
|
||||
form.reset({username: '', password: '', remember: false})
|
||||
form.clearErrors()
|
||||
}}
|
||||
className="mb-6">
|
||||
<TabsList className="w-full p-0 bg-white">
|
||||
<Tab value="password">密码登录</Tab>
|
||||
<Tab value="phone_code">验证码登录/注册</Tab>
|
||||
</TabsList>
|
||||
</Tabs>
|
||||
<Form<LoginSchema> className="space-y-6" form={form} handler={handler}>
|
||||
<FormField name="username" label={mode === 'phone_code' ? '手机号' : '用户名'}>
|
||||
{({id, field}) => (
|
||||
<Input
|
||||
{...field}
|
||||
id={id}
|
||||
type="tel"
|
||||
placeholder={mode === 'phone_code' ? '请输入手机号' : '请输入用户名/手机号/邮箱'}
|
||||
autoComplete="tel-national"
|
||||
/>
|
||||
)}
|
||||
</FormField>
|
||||
<FormField name="password" label={mode === 'phone_code' ? '验证码' : '密码'}>
|
||||
{({id, field}) =>
|
||||
mode === 'phone_code' ? (
|
||||
<div className="flex space-x-4">
|
||||
<Input
|
||||
{...field}
|
||||
id={id}
|
||||
className="h-10"
|
||||
placeholder="请输入验证码"
|
||||
autoComplete="one-time-code"
|
||||
disabled={submitting}
|
||||
/>
|
||||
<SendMsgByUsername/>
|
||||
</div>
|
||||
) : (
|
||||
<div className="relative">
|
||||
<Input
|
||||
{...field}
|
||||
id={id}
|
||||
type={showPwd ? 'text' : 'password'}
|
||||
className="h-10 pr-10"
|
||||
placeholder="至少6位密码,需包含字母和数字"
|
||||
autoComplete="current-password"
|
||||
minLength={6}
|
||||
disabled={submitting}
|
||||
/>
|
||||
<button
|
||||
type="button"
|
||||
tabIndex={-1}
|
||||
className="absolute right-2 top-1/2 -translate-y-1/2 text-gray-400 hover:text-gray-600 cursor-pointer"
|
||||
onClick={() => setShowPwd(v => !v)}
|
||||
aria-label={showPwd ? '隐藏密码' : '显示密码'}
|
||||
>
|
||||
{showPwd ? (
|
||||
<EyeIcon size={20}/>
|
||||
) : (
|
||||
<EyeClosedIcon size={20}/>
|
||||
)}
|
||||
</button>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
</FormField>
|
||||
<FormField name="remember">
|
||||
{({id, field}) => (
|
||||
<div className="flex flex-row items-start space-x-2 space-y-0">
|
||||
<Checkbox
|
||||
<div className="relative flex flex-col items-center">
|
||||
<div className="relative w-96 mx-4">
|
||||
<Link
|
||||
href="/"
|
||||
className="absolute -top-8 right-0 inline-flex items-center text-sm transition-colors px-10"
|
||||
>
|
||||
<HomeIcon size={18} className="mr-1"/>
|
||||
返回首页
|
||||
</Link>
|
||||
</div>
|
||||
<Card className="w-96 mx-4 shadow-lg relative z-20 py-8">
|
||||
<CardContent className="px-8">
|
||||
{/* 登录方式切换 */}
|
||||
<Tabs
|
||||
value={mode}
|
||||
onValueChange={(val) => {
|
||||
setMode(val as LoginMode)
|
||||
form.reset({username: '', password: '', remember: false})
|
||||
form.clearErrors()
|
||||
}}
|
||||
className="mb-6">
|
||||
<TabsList className="w-full p-0 bg-white">
|
||||
<Tab value="password">密码登录</Tab>
|
||||
<Tab value="phone_code">验证码登录/注册</Tab>
|
||||
</TabsList>
|
||||
</Tabs>
|
||||
<Form<LoginSchema> className="space-y-6" form={form} handler={handler}>
|
||||
<FormField name="username" label={mode === 'phone_code' ? '手机号' : '用户名'}>
|
||||
{({id, field}) => (
|
||||
<Input
|
||||
{...field}
|
||||
id={id}
|
||||
checked={field.value}
|
||||
onCheckedChange={field.onChange}
|
||||
disabled={submitting}
|
||||
type="tel"
|
||||
placeholder={mode === 'phone_code' ? '请输入手机号' : '请输入用户名/手机号/邮箱'}
|
||||
autoComplete="tel-national"
|
||||
/>
|
||||
<div className="space-y-1 leading-none">
|
||||
<Label>保持登录</Label>
|
||||
)}
|
||||
</FormField>
|
||||
<FormField name="password" label={mode === 'phone_code' ? '验证码' : '密码'}>
|
||||
{({id, field}) =>
|
||||
mode === 'phone_code' ? (
|
||||
<div className="flex space-x-4">
|
||||
<Input
|
||||
{...field}
|
||||
id={id}
|
||||
className="h-10"
|
||||
placeholder="请输入验证码"
|
||||
autoComplete="one-time-code"
|
||||
disabled={submitting}
|
||||
/>
|
||||
<SendMsgByUsername/>
|
||||
</div>
|
||||
) : (
|
||||
<div className="relative">
|
||||
<Input
|
||||
{...field}
|
||||
id={id}
|
||||
type={showPwd ? 'text' : 'password'}
|
||||
className="h-10 pr-10"
|
||||
placeholder="至少6位密码,需包含字母和数字"
|
||||
autoComplete="current-password"
|
||||
minLength={6}
|
||||
disabled={submitting}
|
||||
/>
|
||||
<button
|
||||
type="button"
|
||||
tabIndex={-1}
|
||||
className="absolute right-2 top-1/2 -translate-y-1/2 text-gray-400 hover:text-gray-600 cursor-pointer"
|
||||
onClick={() => setShowPwd(v => !v)}
|
||||
aria-label={showPwd ? '隐藏密码' : '显示密码'}
|
||||
>
|
||||
{showPwd ? (
|
||||
<EyeIcon size={20}/>
|
||||
) : (
|
||||
<EyeClosedIcon size={20}/>
|
||||
)}
|
||||
</button>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
</FormField>
|
||||
<FormField name="remember">
|
||||
{({id, field}) => (
|
||||
<div className="flex flex-row items-start space-x-2 space-y-0">
|
||||
<Checkbox
|
||||
id={id}
|
||||
checked={field.value}
|
||||
onCheckedChange={field.onChange}
|
||||
disabled={submitting}
|
||||
/>
|
||||
<div className="space-y-1 leading-none">
|
||||
<Label>保持登录</Label>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</FormField>
|
||||
<div className="flex flex-col gap-3">
|
||||
<Button
|
||||
className="w-full h-12 text-lg"
|
||||
type="submit"
|
||||
theme="gradient"
|
||||
disabled={submitting}
|
||||
>
|
||||
{submitting ? '登录中...' : (mode === 'phone_code' ? '首次登录即注册' : '立即登录')}
|
||||
</Button>
|
||||
<p className="text-xs text-center text-gray-500">
|
||||
登录即表示您同意
|
||||
<a href="/userAgreement" className="text-blue-600 hover:text-blue-500">《用户协议》</a>
|
||||
和
|
||||
<a href="/privacyPolicy" className="text-blue-600 hover:text-blue-500">《隐私政策》</a>
|
||||
</p>
|
||||
</div>
|
||||
</Form>
|
||||
</CardContent>
|
||||
</Card>
|
||||
)}
|
||||
</FormField>
|
||||
<div className="flex flex-col gap-3">
|
||||
<Button
|
||||
className="w-full h-12 text-lg"
|
||||
type="submit"
|
||||
theme="gradient"
|
||||
disabled={submitting}
|
||||
>
|
||||
{submitting ? '登录中...' : (mode === 'phone_code' ? '首次登录即注册' : '立即登录')}
|
||||
</Button>
|
||||
<p className="text-xs text-center text-gray-500">
|
||||
登录即表示您同意
|
||||
<a href="/userAgreement" className="text-blue-600 hover:text-blue-500">《用户协议》</a>
|
||||
和
|
||||
<a href="/privacyPolicy" className="text-blue-600 hover:text-blue-500">《隐私政策》</a>
|
||||
</p>
|
||||
</div>
|
||||
</Form>
|
||||
</CardContent>
|
||||
</Card>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -237,7 +237,7 @@ export default function CustomPage() {
|
||||
<section className="relative rounded-lg overflow-hidden h-48 lg:h-56">
|
||||
<Image
|
||||
src={group}
|
||||
alt="免费试用背景"
|
||||
alt="立即试用背景"
|
||||
fill
|
||||
className="object-cover"
|
||||
priority
|
||||
@@ -251,9 +251,9 @@ export default function CustomPage() {
|
||||
className={merge(
|
||||
'bg-blue-600 hover:bg-blue-700 text-white px-8 py-3 rounded-md whitespace-nowrap',
|
||||
)}
|
||||
onClick={() => router.push('/login')}
|
||||
onClick={() => router.push('/product')}
|
||||
>
|
||||
免费试用
|
||||
立即试用
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -10,13 +10,13 @@ export default function Addr({channel}: {
|
||||
const expired = isBefore(channel.expired_at, new Date())
|
||||
|
||||
return (
|
||||
<div className={`${expired ? 'text-weak' : ''}`}>
|
||||
<>
|
||||
<span>{ip}:{port}</span>
|
||||
{expired && (
|
||||
<Badge variant="secondary">
|
||||
<Badge className="ml-2 bg-orange-100 text-orange-700 hover:bg-orange-100 dark:bg-orange-900/30 dark:text-orange-400">
|
||||
已过期
|
||||
</Badge>
|
||||
)}
|
||||
</div>
|
||||
</>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -192,7 +192,7 @@ export default function ChannelsPage(props: ChannelsPageProps) {
|
||||
<span >白名单</span>
|
||||
<div className="flex flex-wrap gap-1 max-w-[200px]">
|
||||
{channel.whitelists.split(',').map((ip, index) => (
|
||||
<Badge key={index} variant="secondary">
|
||||
<Badge key={index} className="bg-green-100 text-green-700 hover:bg-green-100 dark:bg-green-900/30 dark:text-green-400">
|
||||
{ip.trim()}
|
||||
</Badge >
|
||||
))}
|
||||
@@ -201,7 +201,7 @@ export default function ChannelsPage(props: ChannelsPageProps) {
|
||||
) : hasAuth ? (
|
||||
<div className="flex flex-col">
|
||||
<span>账号密码</span>
|
||||
<Badge variant="secondary">
|
||||
<Badge className="bg-blue-100 text-blue-700 hover:bg-blue-100 dark:bg-blue-900/30 dark:text-blue-400">
|
||||
{channel.username}:{channel.password}
|
||||
</Badge >
|
||||
</div>
|
||||
|
||||
@@ -6,7 +6,7 @@ import {RealnameAuthDialog} from '@/components/composites/dialogs/realname-auth-
|
||||
import UserCenter from '@/components/composites/user-center'
|
||||
import {Button} from '@/components/ui/button'
|
||||
import {Tooltip, TooltipContent, TooltipProvider, TooltipTrigger} from '@/components/ui/tooltip'
|
||||
import {Archive, ArchiveRestore, Eye, HardDriveUpload, IdCard, LockKeyhole, Package, PanelLeftCloseIcon, PanelLeftOpenIcon, ShoppingCart, UserRound, UserRoundPen, Wallet} from 'lucide-react'
|
||||
import {Archive, ArchiveRestore, Eye, HardDriveUpload, IdCard, LockKeyhole, MessageCircleMoreIcon, Package, PanelLeftCloseIcon, PanelLeftOpenIcon, ShoppingCart, UserRound, UserRoundPen, Wallet} from 'lucide-react'
|
||||
import {merge} from '@/lib/utils'
|
||||
import logoAvatar from '@/assets/logo-avatar.svg'
|
||||
import logoText from '@/assets/logo-text.svg'
|
||||
@@ -93,7 +93,8 @@ function ContentResolved() {
|
||||
export function Header() {
|
||||
const navbar = useLayoutStore(store => store.navbar)
|
||||
const toggleNavbar = useLayoutStore(store => store.toggleNavbar)
|
||||
|
||||
const profile = use(useProfileStore(store => store.profile))
|
||||
const showRealnameAuth = profile?.id_type === 0
|
||||
return (
|
||||
<header className={merge(
|
||||
`flex-none h-16 overflow-hidden`,
|
||||
@@ -103,25 +104,53 @@ export function Header() {
|
||||
<div className="flex-auto flex items-center gap-2">
|
||||
<Button
|
||||
theme="ghost"
|
||||
className="w-9 h-9 ml-4 md:ml-0"
|
||||
className="h-9 ml-4 md:ml-0"
|
||||
onClick={toggleNavbar}>
|
||||
{navbar
|
||||
? <PanelLeftCloseIcon/>
|
||||
: <PanelLeftOpenIcon/>
|
||||
}
|
||||
{navbar ? (
|
||||
<>
|
||||
<PanelLeftCloseIcon/>
|
||||
<span className="text-foreground/90">关闭菜单</span>
|
||||
</>
|
||||
) : (
|
||||
<>
|
||||
<PanelLeftOpenIcon/>
|
||||
<span className="text-foreground/90">打开菜单</span>
|
||||
</>
|
||||
)}
|
||||
</Button>
|
||||
<span className="max-md:hidden">
|
||||
欢迎来到,蓝狐代理
|
||||
</span>
|
||||
<span className="max-md:hidden">欢迎来到,蓝狐代理</span>
|
||||
<div className="max-md:hidden h-5 w-px bg-gray-300 mx-2"/>
|
||||
{showRealnameAuth ? (
|
||||
<Link
|
||||
href="/admin/identify"
|
||||
className="max-md:hidden flex items-center gap-1.5 text-sm text-blue-600 hover:text-blue-800 transition-colors"
|
||||
>
|
||||
<IdCard size={16}/>
|
||||
<span>实名认证</span>
|
||||
</Link>
|
||||
) : (
|
||||
<Link
|
||||
href=""
|
||||
className="max-md:hidden flex items-center gap-1.5 text-sm text-green-400 hover:text-green-400 transition-colors"
|
||||
>
|
||||
<IdCard size={16}/>
|
||||
<span>已实名</span>
|
||||
</Link>
|
||||
)}
|
||||
<div className="max-md:hidden h-5 w-px bg-gray-300 mx-2"/>
|
||||
<a
|
||||
href="https://wpa1.qq.com/K0s0cvwf?_type=wpa&qidian=true"
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
className="max-md:hidden flex items-center gap-1.5 text-sm text-blue-600 hover:text-blue-800 transition-colors mr-2"
|
||||
>
|
||||
<MessageCircleMoreIcon size={16}/>
|
||||
<span>联系专属客服</span>
|
||||
</a>
|
||||
</div>
|
||||
|
||||
{/* right */}
|
||||
<div className="flex-none flex items-center justify-end pr-4 max-md:hidden gap-2">
|
||||
<Link
|
||||
href="/"
|
||||
className={merge(
|
||||
`flex-none h-16 flex items-center justify-center`,
|
||||
)}>
|
||||
<div className="flex-none flex items-center justify-end pr-4 max-md:hidden gap-3">
|
||||
<Link href="/" className="flex-none h-16 flex items-center justify-center text-sm">
|
||||
返回首页
|
||||
</Link>
|
||||
<Suspense>
|
||||
@@ -176,7 +205,7 @@ export function Navbar() {
|
||||
<TooltipProvider>
|
||||
<NavItem href="/admin" icon={<UserRound size={20}/>} label="账户总览" expand={navbar}/>
|
||||
<NavTitle label="快速开始"/>
|
||||
<NavItem href="/admin/identify" icon={<IdCard size={20}/>} label="实名认证" expand={navbar}/>
|
||||
{/* <NavItem href="/admin/identify" icon={<IdCard size={20}/>} label="实名认证" expand={navbar}/> */}
|
||||
<NavItem href="/admin/whitelist" icon={<LockKeyhole size={20}/>} label="白名单" expand={navbar}/>
|
||||
<NavItem href="/admin/purchase" icon={<ShoppingCart size={20}/>} label="购买套餐" expand={navbar}/>
|
||||
<NavItem href="/admin/extract" icon={<HardDriveUpload size={20}/>} label="提取 IP" expand={navbar}/>
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import {ReactNode} from 'react'
|
||||
import {ReactNode, Suspense} from 'react'
|
||||
import {Shell, Content, Header, Navbar, Mask} from './clients'
|
||||
|
||||
export default function Template(props: {
|
||||
@@ -13,7 +13,9 @@ export default function Template(props: {
|
||||
</div>
|
||||
|
||||
<div className="col-start-2 row-start-1 bg-card overflow-hidden relative z-20">
|
||||
<Header/>
|
||||
<Suspense>
|
||||
<Header/>
|
||||
</Suspense>
|
||||
</div>
|
||||
|
||||
<svg className="col-start-2 row-start-2 w-full h-full z-20 pointer-events-none" preserveAspectRatio="none">
|
||||
|
||||
@@ -8,7 +8,7 @@ import zod from 'zod'
|
||||
import {toast} from 'sonner'
|
||||
import {useStatus} from '@/lib/states'
|
||||
import {ExtraResp} from '@/lib/api'
|
||||
import {listResourceLong, listResourceShort} from '@/actions/resource'
|
||||
import {listResourceLong, listResourceShort, updateCheckip} from '@/actions/resource'
|
||||
import DataTable from '@/components/data-table'
|
||||
import {ColumnDef} from '@tanstack/react-table'
|
||||
import {Resource} from '@/lib/models/resource'
|
||||
@@ -21,6 +21,7 @@ import {
|
||||
isValidResourceType,
|
||||
ResourceTypeBadge,
|
||||
} from './utils'
|
||||
import {Button} from '@/components/ui/button'
|
||||
|
||||
const filterSchema = zod.object({
|
||||
resource_no: zod.string().optional().default(''),
|
||||
@@ -130,11 +131,32 @@ export default function ResourceList({resourceType}: ResourceListProps) {
|
||||
})
|
||||
}
|
||||
|
||||
const handleCheckipChange = async (id: number, currentCheckip: boolean) => {
|
||||
try {
|
||||
const result = await updateCheckip({
|
||||
id: id,
|
||||
checkip: !currentCheckip,
|
||||
})
|
||||
|
||||
if (result.success) {
|
||||
toast.success(`IP检查已${!currentCheckip ? '启用' : '停用'}`)
|
||||
await refresh(data.page, data.size)
|
||||
}
|
||||
else {
|
||||
throw new Error(result.message || '操作失败')
|
||||
}
|
||||
}
|
||||
catch (e) {
|
||||
toast.error(e instanceof Error ? e.message : '更新IP检查状态失败')
|
||||
}
|
||||
}
|
||||
console.log(data.list, 'data.list')
|
||||
|
||||
// 表格列定义
|
||||
const columns = useMemo<ColumnDef<Resource<1> | Resource<2>>[]>(() => {
|
||||
const resourceKey = isLong ? 'long' : 'short'
|
||||
|
||||
const baseColumns: ColumnDef<Resource<1> | Resource<2>>[] = [
|
||||
const baseColumns = ([
|
||||
{
|
||||
header: '套餐编号',
|
||||
cell: ({row}) => {
|
||||
@@ -218,7 +240,11 @@ export default function ResourceList({resourceType}: ResourceListProps) {
|
||||
{
|
||||
header: '开通时间',
|
||||
cell: ({row}) => formatDateTime(row.original.created_at),
|
||||
},
|
||||
}, // 短效资源增加到期时间列
|
||||
!isLong ? {
|
||||
header: '到期时间',
|
||||
cell: ({row}) => formatDateTime((row.original as Resource<1>).short.expire_at),
|
||||
} : undefined,
|
||||
{
|
||||
header: '状态',
|
||||
cell: ({row}) => {
|
||||
@@ -230,15 +256,22 @@ export default function ResourceList({resourceType}: ResourceListProps) {
|
||||
)
|
||||
},
|
||||
},
|
||||
]
|
||||
|
||||
// 短效资源增加到期时间列
|
||||
if (!isLong) {
|
||||
baseColumns.push({
|
||||
header: '到期时间',
|
||||
cell: ({row}) => formatDateTime((row.original as Resource<1>).short.expire_at),
|
||||
})
|
||||
}
|
||||
{
|
||||
header: '操作',
|
||||
cell: ({row}) => {
|
||||
const checkip = row.original.checkip
|
||||
return (
|
||||
<Button
|
||||
theme="default"
|
||||
className="h-7 px-3 text-sm"
|
||||
onClick={() => handleCheckipChange(row.original.id, row.original.checkip)}
|
||||
>
|
||||
{checkip ? '停用IP检查' : '启用IP检查'}
|
||||
</Button>
|
||||
)
|
||||
},
|
||||
},
|
||||
] satisfies ((ColumnDef<Resource<1> | Resource<2>> | undefined)[])).filter(Boolean) as ColumnDef<Resource<1> | Resource<2>>[]
|
||||
|
||||
return baseColumns
|
||||
}, [isLong])
|
||||
|
||||
@@ -34,7 +34,7 @@ type SchemaType = z.infer<typeof schema>
|
||||
|
||||
export type WhitelistPageProps = {}
|
||||
|
||||
const MAX_WHITELIST_COUNT = 5
|
||||
const MAX_WHITELIST_COUNT = 10
|
||||
|
||||
export default function WhitelistPage(props: WhitelistPageProps) {
|
||||
const [wait, setWait] = useState(false)
|
||||
|
||||
@@ -9,7 +9,7 @@ import {Button} from '@/components/ui/button'
|
||||
import {useForm, useFormContext, useWatch} from 'react-hook-form'
|
||||
import {Alert, AlertTitle} from '@/components/ui/alert'
|
||||
import {ArrowRight, Box, CircleAlert, CopyIcon, ExternalLinkIcon, LinkIcon, Loader, Plus, Timer} from 'lucide-react'
|
||||
import {memo, ReactNode, useEffect, useRef, useState} from 'react'
|
||||
import {memo, ReactNode, Suspense, use, useEffect, useRef, useState} from 'react'
|
||||
import {useStatus} from '@/lib/states'
|
||||
import {allResource} from '@/actions/resource'
|
||||
import {Resource} from '@/lib/models'
|
||||
@@ -113,7 +113,9 @@ const FormFields = memo(() => {
|
||||
return (
|
||||
<div className="flex flex-col gap-6 items-stretch max-w-[calc(160px*4+1rem*3)]">
|
||||
{/* 选择套餐 */}
|
||||
<SelectResource/>
|
||||
<Suspense>
|
||||
<SelectResource/>
|
||||
</Suspense>
|
||||
|
||||
{/* 地区筛选 */}
|
||||
<SelectRegion/>
|
||||
@@ -332,8 +334,13 @@ FormFields.displayName = 'FormFields'
|
||||
function SelectResource() {
|
||||
const [resources, setResources] = useState<Resource[]>([])
|
||||
const [status, setStatus] = useStatus()
|
||||
const profile = useProfileStore(state => state.profile)
|
||||
const profile = use(useProfileStore(store => store.profile))
|
||||
const getResources = async () => {
|
||||
if (!profile) {
|
||||
setStatus('done')
|
||||
setResources([])
|
||||
return
|
||||
}
|
||||
setStatus('load')
|
||||
try {
|
||||
const resp = await allResource()
|
||||
@@ -352,7 +359,7 @@ function SelectResource() {
|
||||
useEffect(() => {
|
||||
getResources().then()
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [])
|
||||
}, [profile])
|
||||
|
||||
return (
|
||||
<FormField name="resource" className="md:max-w-[calc(160px*2+1rem)]" label="选择套餐" classNames={{label: 'max-md:text-sm'}}>
|
||||
@@ -372,12 +379,10 @@ function SelectResource() {
|
||||
</div>
|
||||
) : !profile ? (
|
||||
<div className="p-4 flex gap-1 items-center">
|
||||
<Loader className="animate-spin" size={20}/>
|
||||
<span>请先登录账号,<Link href="/login" className="text-blue-600 hover:underline">去登录</Link></span>
|
||||
<span className="text-gray-600">请先登录账号,<Link href="/login" className="text-blue-600 hover:text-blue-700 font-medium">去登录</Link></span>
|
||||
</div>
|
||||
) : resources.length === 0 ? (
|
||||
<div className="p-4 flex gap-1 items-center">
|
||||
<Loader className="animate-spin" size={20}/>
|
||||
<span>暂无可用套餐</span>
|
||||
</div>
|
||||
) : (
|
||||
|
||||
@@ -17,21 +17,21 @@ export type PaymentModalProps = {
|
||||
export function PaymentModal(props: PaymentModalProps) {
|
||||
// 手动关闭时的处理
|
||||
const handleClose = async () => {
|
||||
try {
|
||||
const res = await payClose({
|
||||
trade_no: props.inner_no,
|
||||
method: props.method,
|
||||
})
|
||||
if (!res.success) {
|
||||
throw new Error(res.message)
|
||||
}
|
||||
}
|
||||
catch (error) {
|
||||
console.error('关闭订单失败:', error)
|
||||
}
|
||||
finally {
|
||||
props.onClose?.()
|
||||
}
|
||||
// try {
|
||||
// const res = await payClose({
|
||||
// trade_no: props.inner_no,
|
||||
// method: props.method,
|
||||
// })
|
||||
// if (!res.success) {
|
||||
// throw new Error(res.message)
|
||||
// }
|
||||
// }
|
||||
// catch (error) {
|
||||
// console.error('关闭订单失败:', error)
|
||||
// }
|
||||
// finally {
|
||||
props.onClose?.()
|
||||
// }
|
||||
}
|
||||
|
||||
// SSE处理方式检查支付状态
|
||||
|
||||
@@ -3,18 +3,18 @@ import {FormField} from '@/components/ui/form'
|
||||
import {RadioGroup} from '@/components/ui/radio-group'
|
||||
import FormOption from '@/components/composites/purchase/option'
|
||||
import {Schema} from '@/components/composites/purchase/long/form'
|
||||
import {useEffect} from 'react'
|
||||
import {useEffect, useMemo} from 'react'
|
||||
import {useFormContext, useWatch} from 'react-hook-form'
|
||||
import {Card} from '@/components/ui/card'
|
||||
import {BillingMethodField} from '../shared/billing-method-field'
|
||||
import {FeatureList} from '../shared/feature-list'
|
||||
import {NumberStepperField} from '../shared/number-stepper-field'
|
||||
import {getAvailablePurchaseExpires, getAvailablePurchaseLives, getPurchaseSkuPrice, hasPurchaseSku, PurchaseSkuData} from '../shared/sku'
|
||||
import {getAvailablePurchaseExpires, getAvailablePurchaseLives, getPurchaseSkuCountMin, getPurchaseSkuPrice, hasPurchaseSku, PurchaseSkuData} from '../shared/sku'
|
||||
|
||||
export default function Center({skuData}: {
|
||||
skuData: PurchaseSkuData
|
||||
}) {
|
||||
const {setValue} = useFormContext<Schema>()
|
||||
const {setValue, getValues} = useFormContext<Schema>()
|
||||
const type = useWatch<Schema>({name: 'type'}) as Schema['type']
|
||||
const live = useWatch<Schema>({name: 'live'}) as Schema['live']
|
||||
const expire = useWatch<Schema>({name: 'expire'}) as Schema['expire']
|
||||
@@ -26,18 +26,35 @@ export default function Center({skuData}: {
|
||||
? getAvailablePurchaseExpires(skuData, {mode: type, live})
|
||||
: []
|
||||
|
||||
const currentCountMin = useMemo(() => {
|
||||
if (!type || !live) return 0
|
||||
const expireValue = type === '1' ? expire : '0'
|
||||
const countMin = getPurchaseSkuCountMin(skuData, {
|
||||
mode: type,
|
||||
live,
|
||||
expire: expireValue,
|
||||
})
|
||||
return countMin
|
||||
}, [type, live, expire, skuData])
|
||||
|
||||
useEffect(() => {
|
||||
if (currentCountMin <= 0) return
|
||||
const targetField = type === '1' ? 'daily_limit' : 'quota'
|
||||
const currentValue = getValues(targetField)
|
||||
if (currentValue !== currentCountMin) {
|
||||
setValue(targetField, currentCountMin, {shouldValidate: true})
|
||||
}
|
||||
}, [currentCountMin, type, setValue, getValues])
|
||||
|
||||
useEffect(() => {
|
||||
const nextType = modeList.includes(type) ? type : modeList[0]
|
||||
|
||||
if (!nextType) {
|
||||
return
|
||||
}
|
||||
|
||||
if (nextType !== type) {
|
||||
setValue('type', nextType)
|
||||
return
|
||||
}
|
||||
|
||||
const nextLiveList = nextType === '1'
|
||||
? getAvailablePurchaseLives(skuData, {mode: nextType, expire})
|
||||
: getAvailablePurchaseLives(skuData, {mode: nextType})
|
||||
@@ -146,14 +163,14 @@ export default function Center({skuData}: {
|
||||
<NumberStepperField
|
||||
name="daily_limit"
|
||||
label="每日提取上限"
|
||||
min={100}
|
||||
min={currentCountMin}
|
||||
step={100}
|
||||
/>
|
||||
) : (
|
||||
<NumberStepperField
|
||||
name="quota"
|
||||
label="IP 购买数量"
|
||||
min={500}
|
||||
min={currentCountMin}
|
||||
step={100}
|
||||
/>
|
||||
)}
|
||||
|
||||
@@ -5,15 +5,15 @@ import {Form} from '@/components/ui/form'
|
||||
import * as z from 'zod'
|
||||
import {zodResolver} from '@hookform/resolvers/zod'
|
||||
import {ProductItem} from '@/actions/product'
|
||||
import {getAvailablePurchaseExpires, getAvailablePurchaseLives, parsePurchaseSkuList} from '../shared/sku'
|
||||
import {getAvailablePurchaseExpires, getAvailablePurchaseLives, getPurchaseSkuCountMin, parsePurchaseSkuList} from '../shared/sku'
|
||||
import {PurchaseSidePanel} from '../shared/side-panel'
|
||||
|
||||
const schema = z.object({
|
||||
type: z.enum(['1', '2']).default('2'),
|
||||
live: z.string(),
|
||||
quota: z.number().min(500, '购买数量不能少于 500 个'),
|
||||
quota: z.number().min(1, '购买数量不能少于 1 个'),
|
||||
expire: z.string(),
|
||||
daily_limit: z.number().min(100, '每日限额不能少于 100 个'),
|
||||
daily_limit: z.number().min(1, '每日限额不能少于 1 个'),
|
||||
pay_type: z.enum(['wechat', 'alipay', 'balance']),
|
||||
})
|
||||
export type Schema = z.infer<typeof schema>
|
||||
@@ -25,6 +25,11 @@ export default function LongForm({skuList}: {skuList: ProductItem['skus']}) {
|
||||
const defaultExpire = defaultMode === '1'
|
||||
? getAvailablePurchaseExpires(skuData, {mode: defaultMode, live: defaultLive})[0] || '0'
|
||||
: '0'
|
||||
const defaultCountMin = getPurchaseSkuCountMin(skuData, {
|
||||
mode: defaultMode,
|
||||
live: defaultLive,
|
||||
expire: defaultExpire,
|
||||
})
|
||||
|
||||
const form = useForm<Schema>({
|
||||
resolver: zodResolver(schema),
|
||||
@@ -32,8 +37,8 @@ export default function LongForm({skuList}: {skuList: ProductItem['skus']}) {
|
||||
type: defaultMode,
|
||||
live: defaultLive,
|
||||
expire: defaultExpire,
|
||||
quota: 500,
|
||||
daily_limit: 100,
|
||||
quota: defaultCountMin,
|
||||
daily_limit: defaultCountMin,
|
||||
pay_type: 'balance', // 余额支付
|
||||
},
|
||||
})
|
||||
|
||||
@@ -11,7 +11,7 @@ export function BillingMethodField(props: {
|
||||
modeList: PurchaseMode[]
|
||||
timeDailyLimit: number
|
||||
}) {
|
||||
const {setValue} = useFormContext<PurchaseFormValues>()
|
||||
const {setValue, getValues} = useFormContext<PurchaseFormValues>()
|
||||
|
||||
return (
|
||||
<FormField<PurchaseFormValues, 'type'>
|
||||
@@ -30,8 +30,7 @@ export function BillingMethodField(props: {
|
||||
setValue('expire', '0')
|
||||
return
|
||||
}
|
||||
|
||||
setValue('daily_limit', props.timeDailyLimit)
|
||||
setValue('expire', getValues('expire') || '0')
|
||||
}}
|
||||
className="flex gap-4 max-md:flex-col"
|
||||
>
|
||||
|
||||
@@ -49,6 +49,9 @@ export function NumberStepperField(props: NumberStepperFieldProps) {
|
||||
className="w-40 h-10 border border-gray-200 rounded-sm text-center"
|
||||
min={props.min}
|
||||
step={props.step}
|
||||
onInvalid={(e) => {
|
||||
e.preventDefault()
|
||||
}}
|
||||
onBlur={(event) => {
|
||||
field.onBlur()
|
||||
const nextValue = Number(event.target.value)
|
||||
|
||||
@@ -14,6 +14,7 @@ import {ExtraResp} from '@/lib/api'
|
||||
import {formatPurchaseLiveLabel} from './sku'
|
||||
import {User} from '@/lib/models'
|
||||
import {PurchaseFormValues} from './form-values'
|
||||
import {IdCard} from 'lucide-react'
|
||||
|
||||
const emptyPrice: ExtraResp<typeof getPrice> = {
|
||||
price: '0.00',
|
||||
@@ -107,15 +108,30 @@ export function PurchaseSidePanel(props: PurchaseSidePanelProps) {
|
||||
<span className="text-xl text-orange-500">¥{discountedPrice}</span>
|
||||
</p>
|
||||
{profile ? (
|
||||
<>
|
||||
<FieldPayment balance={profile.balance}/>
|
||||
<Pay
|
||||
method={method}
|
||||
balance={profile.balance}
|
||||
amount={discountedPrice}
|
||||
resource={resource}
|
||||
/>
|
||||
</>
|
||||
profile.id_type !== 0 ? (
|
||||
<>
|
||||
<FieldPayment balance={profile.balance}/>
|
||||
<Pay
|
||||
method={method}
|
||||
balance={profile.balance}
|
||||
amount={discountedPrice}
|
||||
resource={resource}
|
||||
/>
|
||||
</>
|
||||
) : (
|
||||
<div className="flex flex-col gap-3">
|
||||
<p className="text-sm text-gray-500">
|
||||
根据监管要求,您需要完成实名认证后才能支付。
|
||||
</p>
|
||||
<Link
|
||||
href="/admin/identify"
|
||||
className={buttonVariants()}
|
||||
>
|
||||
<IdCard size={16} className="mr-1"/>
|
||||
去实名认证
|
||||
</Link>
|
||||
</div>
|
||||
)
|
||||
) : (
|
||||
<Link href="/login" className={buttonVariants()}>
|
||||
登录后支付
|
||||
|
||||
@@ -7,11 +7,13 @@ export type PurchaseSkuItem = {
|
||||
live: string
|
||||
expire: string
|
||||
price: string
|
||||
count_min: number
|
||||
}
|
||||
|
||||
export type PurchaseSkuData = {
|
||||
items: PurchaseSkuItem[]
|
||||
priceMap: Map<string, string>
|
||||
countMinMap: Map<string, number>
|
||||
modeList: PurchaseMode[]
|
||||
liveList: string[]
|
||||
expireList: string[]
|
||||
@@ -24,6 +26,7 @@ export function parsePurchaseSkuList(kind: PurchaseKind, skuList: ProductItem['s
|
||||
|
||||
const items: PurchaseSkuItem[] = []
|
||||
const priceMap = new Map<string, string>()
|
||||
const countMinMap = new Map<string, number>()
|
||||
const modeSet = new Set<PurchaseMode>()
|
||||
const liveSet = new Set<number>()
|
||||
const expireSet = new Set<number>()
|
||||
@@ -45,6 +48,8 @@ export function parsePurchaseSkuList(kind: PurchaseKind, skuList: ProductItem['s
|
||||
live: liveValue,
|
||||
expire: expireValue,
|
||||
})
|
||||
const countMin = typeof sku.count_min === 'number' ? sku.count_min : Number(sku.count_min) || 0
|
||||
countMinMap.set(code, countMin)
|
||||
|
||||
items.push({
|
||||
code,
|
||||
@@ -52,6 +57,7 @@ export function parsePurchaseSkuList(kind: PurchaseKind, skuList: ProductItem['s
|
||||
live: liveValue,
|
||||
expire: expireValue,
|
||||
price: sku.price,
|
||||
count_min: countMin,
|
||||
})
|
||||
priceMap.set(code, sku.price)
|
||||
modeSet.add(mode)
|
||||
@@ -75,6 +81,7 @@ export function parsePurchaseSkuList(kind: PurchaseKind, skuList: ProductItem['s
|
||||
return {
|
||||
items,
|
||||
priceMap,
|
||||
countMinMap,
|
||||
modeList: (['2', '1'] as const).filter(mode => modeSet.has(mode)),
|
||||
liveList: sortNumericValues(liveSet),
|
||||
expireList: sortNumericValues(expireSet),
|
||||
@@ -163,3 +170,11 @@ export function formatPurchaseLiveLabel(live: string, kind: PurchaseKind) {
|
||||
|
||||
return `${minutes} 分钟`
|
||||
}
|
||||
|
||||
export function getPurchaseSkuCountMin(
|
||||
skuData: PurchaseSkuData,
|
||||
props: {mode: PurchaseMode, live: string, expire: string},
|
||||
): number {
|
||||
const key = getPurchaseSkuKey(props)
|
||||
return skuData.countMinMap.get(key) ?? 0
|
||||
}
|
||||
|
||||
@@ -2,21 +2,21 @@
|
||||
import {FormField} from '@/components/ui/form'
|
||||
import {RadioGroup} from '@/components/ui/radio-group'
|
||||
import FormOption from '@/components/composites/purchase/option'
|
||||
import {useEffect} from 'react'
|
||||
import {useEffect, useMemo} from 'react'
|
||||
import {useFormContext, useWatch} from 'react-hook-form'
|
||||
import {Schema} from '@/components/composites/purchase/short/form'
|
||||
import {Card} from '@/components/ui/card'
|
||||
import {BillingMethodField} from '../shared/billing-method-field'
|
||||
import {FeatureList} from '../shared/feature-list'
|
||||
import {NumberStepperField} from '../shared/number-stepper-field'
|
||||
import {getAvailablePurchaseExpires, getAvailablePurchaseLives, getPurchaseSkuPrice, hasPurchaseSku, PurchaseSkuData} from '../shared/sku'
|
||||
import {getAvailablePurchaseExpires, getAvailablePurchaseLives, getPurchaseSkuCountMin, getPurchaseSkuPrice, hasPurchaseSku, PurchaseSkuData} from '../shared/sku'
|
||||
|
||||
export default function Center({
|
||||
skuData,
|
||||
}: {
|
||||
skuData: PurchaseSkuData
|
||||
}) {
|
||||
const {setValue} = useFormContext<Schema>()
|
||||
const {setValue, getValues} = useFormContext<Schema>()
|
||||
const type = useWatch<Schema>({name: 'type'}) as Schema['type']
|
||||
const live = useWatch<Schema>({name: 'live'}) as Schema['live']
|
||||
const expire = useWatch<Schema>({name: 'expire'}) as Schema['expire']
|
||||
@@ -28,6 +28,22 @@ export default function Center({
|
||||
? getAvailablePurchaseExpires(skuData, {mode: type, live})
|
||||
: []
|
||||
|
||||
const currentCountMin = useMemo(() => {
|
||||
if (!type || !live) return 0
|
||||
const expireValue = type === '1' ? expire : '0'
|
||||
return getPurchaseSkuCountMin(skuData, {mode: type, live, expire: expireValue})
|
||||
}, [type, live, expire, skuData])
|
||||
|
||||
useEffect(() => {
|
||||
if (currentCountMin <= 0) return
|
||||
|
||||
const targetField = type === '1' ? 'daily_limit' : 'quota'
|
||||
const currentValue = getValues(targetField)
|
||||
|
||||
if (currentValue !== currentCountMin) {
|
||||
setValue(targetField, currentCountMin, {shouldValidate: true})
|
||||
}
|
||||
}, [currentCountMin, type, setValue, getValues])
|
||||
useEffect(() => {
|
||||
const nextType = modeList.includes(type) ? type : modeList[0]
|
||||
|
||||
@@ -151,14 +167,14 @@ export default function Center({
|
||||
<NumberStepperField
|
||||
name="daily_limit"
|
||||
label="每日提取上限"
|
||||
min={2000}
|
||||
min={currentCountMin}
|
||||
step={1000}
|
||||
/>
|
||||
) : (
|
||||
<NumberStepperField
|
||||
name="quota"
|
||||
label="IP 购买数量"
|
||||
min={10000}
|
||||
min={currentCountMin}
|
||||
step={5000}
|
||||
/>
|
||||
)}
|
||||
|
||||
@@ -5,15 +5,15 @@ import {Form} from '@/components/ui/form'
|
||||
import * as z from 'zod'
|
||||
import {zodResolver} from '@hookform/resolvers/zod'
|
||||
import {ProductItem} from '@/actions/product'
|
||||
import {getAvailablePurchaseExpires, getAvailablePurchaseLives, parsePurchaseSkuList} from '../shared/sku'
|
||||
import {getAvailablePurchaseExpires, getAvailablePurchaseLives, getPurchaseSkuCountMin, parsePurchaseSkuList} from '../shared/sku'
|
||||
import {PurchaseSidePanel} from '../shared/side-panel'
|
||||
|
||||
const schema = z.object({
|
||||
type: z.enum(['1', '2']).default('2'),
|
||||
live: z.string(),
|
||||
quota: z.number().min(10000, '购买数量不能少于 10000 个'),
|
||||
quota: z.number(),
|
||||
expire: z.string(),
|
||||
daily_limit: z.number().min(2000, '每日限额不能少于 2000 个'),
|
||||
daily_limit: z.number(),
|
||||
pay_type: z.enum(['wechat', 'alipay', 'balance']).default('balance'),
|
||||
})
|
||||
export type Schema = z.infer<typeof schema>
|
||||
@@ -25,6 +25,11 @@ export default function ShortForm({skuList}: {skuList: ProductItem['skus']}) {
|
||||
const defaultExpire = defaultMode === '1'
|
||||
? getAvailablePurchaseExpires(skuData, {mode: defaultMode, live: defaultLive})[0] || '0'
|
||||
: '0'
|
||||
const defaultCountMin = getPurchaseSkuCountMin(skuData, {
|
||||
mode: defaultMode,
|
||||
live: defaultLive,
|
||||
expire: defaultExpire,
|
||||
})
|
||||
|
||||
const form = useForm<Schema>({
|
||||
resolver: zodResolver(schema),
|
||||
@@ -32,8 +37,8 @@ export default function ShortForm({skuList}: {skuList: ProductItem['skus']}) {
|
||||
type: defaultMode,
|
||||
live: defaultLive,
|
||||
expire: defaultExpire,
|
||||
quota: 10_000, // >= 10000,
|
||||
daily_limit: 2_000, // >= 2000
|
||||
quota: defaultCountMin,
|
||||
daily_limit: defaultCountMin,
|
||||
pay_type: 'balance', // 余额支付
|
||||
},
|
||||
})
|
||||
|
||||
@@ -26,7 +26,7 @@ function Resolved(props: {
|
||||
router.push(profile ? '/admin/purchase' : '/product')
|
||||
}}
|
||||
>
|
||||
免费试用
|
||||
立即试用
|
||||
</button>
|
||||
)
|
||||
}
|
||||
@@ -42,7 +42,7 @@ function Pending(props: {
|
||||
router.push('/product')
|
||||
}}
|
||||
>
|
||||
免费试用
|
||||
立即试用
|
||||
</button>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
export type ProductSku = {
|
||||
id: number
|
||||
code: string
|
||||
count_min: number
|
||||
name: string
|
||||
price: string
|
||||
price_min: string
|
||||
|
||||
@@ -29,6 +29,7 @@ export type Resource<T extends 1 | 2 = 1 | 2> = {
|
||||
active: boolean
|
||||
created_at: Date
|
||||
updated_at: Date
|
||||
checkip: boolean
|
||||
} & (
|
||||
T extends 1 ? {
|
||||
type: 1
|
||||
|
||||
Reference in New Issue
Block a user