From 4dd7b834f3bf2f405b5b6e8712a52659287a3549 Mon Sep 17 00:00:00 2001 From: luorijun Date: Thu, 20 Nov 2025 18:01:54 +0800 Subject: [PATCH] =?UTF-8?q?/admin/profile=20=E9=A1=B5=E9=9D=A2=E4=BB=8E?= =?UTF-8?q?=E6=9C=8D=E5=8A=A1=E7=AB=AF=E8=8E=B7=E5=8F=96=E7=94=A8=E6=88=B7?= =?UTF-8?q?=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/app/admin/profile/clients.tsx | 189 +++++++++++++++++++++++++ src/app/admin/profile/page.tsx | 226 +++--------------------------- 2 files changed, 205 insertions(+), 210 deletions(-) create mode 100644 src/app/admin/profile/clients.tsx diff --git a/src/app/admin/profile/clients.tsx b/src/app/admin/profile/clients.tsx new file mode 100644 index 0000000..7200f9d --- /dev/null +++ b/src/app/admin/profile/clients.tsx @@ -0,0 +1,189 @@ +'use client' +import {update} from '@/actions/user' +import {useProfileStore} from '@/components/stores-provider' +import {Button} from '@/components/ui/button' +import {Form, FormField} from '@/components/ui/form' +import {Input} from '@/components/ui/input' +import {User} from '@/lib/models' +import {merge} from '@/lib/utils' +import {zodResolver} from '@hookform/resolvers/zod' +import {useEffect, useRef} from 'react' +import {useForm} from 'react-hook-form' +import {toast} from 'sonner' +import z from 'zod' +import * as qrcode from 'qrcode' +import {Card, CardHeader, CardTitle, CardContent} from '@/components/ui/card' +import {QrCodeIcon} from 'lucide-react' + +export function Aftersale(props: { + profile: User +}) { + const admin = props.profile.admin_id + const canvasRef = useRef(null) + + useEffect(() => { + if (admin && canvasRef.current) { + qrcode.toCanvas(canvasRef.current, String(admin), { + width: 180, + margin: 0, + }).catch((err) => { + console.error(err) + }) + } + }, [admin]) + + return ( + + + + + 关于售后 + + + + +
+

+ 1.全国100万+动态IP代理资源免费测试,先测后买让您安心使用。 +

+ +

+ 2.注册即享新人福利,专业的客户经理,多维度为您提供在线代理相关答疑 +

+ +

+ 3.1V1专属售后答疑,技术团队7*24小时在线支持提供专属解决方案 +

+
+ +
+

您的专属客服经理

+
+ +
+

+ 扫描上方二维码添加客服经理微信 +
+ 获取更多帮助与支持 +

+
+
+
+ ) +} + +export function BasicForm(props: { + profile: User +}) { + const schema = z.object({ + username: z.string(), + email: z.string().email('请输入正确的邮箱'), + contact_qq: z.string(), + contact_wechat: z.string(), + }) + type Schema = z.infer + const form = useForm({ + resolver: zodResolver(schema), + defaultValues: { + username: props.profile.username || '', + email: props.profile.email || '', + contact_qq: props.profile.contact_qq || '', + contact_wechat: props.profile.contact_wechat || '', + }, + }) + const handler = form.handleSubmit(async (value) => { + try { + const resp = await update(value) + if (!resp.success) { + throw new Error(resp.message) + } + + await refreshProfile() + toast.success(`保存成功`) + } + catch (e) { + console.error(e) + toast.error(`保存失败`, { + description: e instanceof Error ? e.message : String(e), + }) + } + }) + + const refreshProfile = useProfileStore(store => store.refreshProfile) + + return ( +
+

基本信息

+
+ + name="username" + label={用户名} + className="grid grid-cols-[48px_1fr] grid-rows-[auto_auto] gap-x-4" + classNames={{ + message: `col-start-2`, + }} + > + {({field}) => ( + + )} + + + name="email" + label={邮箱} + className="grid grid-cols-[48px_1fr] grid-rows-[auto_auto] gap-x-4" + classNames={{ + message: `col-start-2`, + }} + > + {({field}) => ( + + )} + + + name="contact_qq" + label={QQ} + className="grid grid-cols-[48px_1fr] grid-rows-[auto_auto] gap-x-4" + classNames={{ + message: `col-start-2`, + }} + > + {({field}) => ( + + )} + + + name="contact_wechat" + label={微信} + className="grid grid-cols-[48px_1fr] grid-rows-[auto_auto] gap-x-4" + classNames={{ + message: `col-start-2`, + }} + > + {({field}) => ( + + )} + +
+ + +
+ +
+ ) +} diff --git a/src/app/admin/profile/page.tsx b/src/app/admin/profile/page.tsx index 33765eb..dcfc078 100644 --- a/src/app/admin/profile/page.tsx +++ b/src/app/admin/profile/page.tsx @@ -1,48 +1,27 @@ -'use client' -import {useEffect, useRef} from 'react' import Page from '@/components/page' import {Card, CardContent, CardHeader, CardTitle} from '@/components/ui/card' -import {Form, FormField} from '@/components/ui/form' -import {Button} from '@/components/ui/button' -import {useForm} from 'react-hook-form' -import {zodResolver} from '@hookform/resolvers/zod' -import * as z from 'zod' -import {useProfileStore} from '@/components/stores-provider' -import {toast} from 'sonner' -import {CheckCircle, QrCodeIcon} from 'lucide-react' -import * as qrcode from 'qrcode' +import {CheckCircle} from 'lucide-react' import Image from 'next/image' import banner from '@/app/admin/identify/_assets/banner.webp' -import {Input} from '@/components/ui/input' -import {merge} from '@/lib/utils' -import {User} from '@/lib/models' -import {update} from '@/actions/user' import RechargeModal from '@/components/composites/recharge' -import {useRouter} from 'next/navigation' import {RealnameAuthDialog} from '@/components/composites/dialogs/realname-auth-dialog' import {ChangePasswordDialog} from '@/components/composites/dialogs/change-password-dialog' +import {getProfile} from '@/actions/auth' +import {Aftersale, BasicForm} from './clients' export type ProfilePageProps = {} -export default function ProfilePage(props: ProfilePageProps) { - const router = useRouter() - const profile = useProfileStore(store => store.profile) - - // ====================== - // render - // ====================== - - if (!profile) { +export default async function ProfilePage(props: ProfilePageProps) { + const profile = await getProfile() + if (!profile.success) { return ( -
-

加载中...

-

请稍等片刻

-
+ 获取用户信息失败
) } + const user = profile.data return (
@@ -61,7 +40,7 @@ export default function ProfilePage(props: ProfilePageProps) { 帐号余额(元) -

{profile?.balance}

+

{user.balance}

@@ -73,12 +52,12 @@ export default function ProfilePage(props: ProfilePageProps) { 实名认证 - {!profile?.id_token + {!user.id_token ? ( <>

为了保障您的账户安全和正常使用服务,请您尽快完成实名认证

@@ -86,8 +65,8 @@ export default function ProfilePage(props: ProfilePageProps) { : ( <>

- {profile.name} - {profile.id_no} + {user.name} + {user.id_no}

@@ -105,192 +84,19 @@ export default function ProfilePage(props: ProfilePageProps) {

安全信息

-

{profile.phone}

+

{user.phone}

{/* 基本信息 */} - +
{/* 侧边栏:客服经理信息 */} - +
) } - -function Aftersale(props: { - profile: User -}) { - const admin = props.profile.admin_id - const canvasRef = useRef(null) - - useEffect(() => { - if (admin && canvasRef.current) { - qrcode.toCanvas(canvasRef.current, String(admin), { - width: 180, - margin: 0, - }).catch((err) => { - console.error(err) - }) - } - }, [admin]) - - return ( - - - - - 关于售后 - - - - -
-

- 1.全国100万+动态IP代理资源免费测试,先测后买让您安心使用。 -

- -

- 2.注册即享新人福利,专业的客户经理,多维度为您提供在线代理相关答疑 -

- -

- 3.1V1专属售后答疑,技术团队7*24小时在线支持提供专属解决方案 -

-
- -
-

您的专属客服经理

-
- -
-

- 扫描上方二维码添加客服经理微信 -
- 获取更多帮助与支持 -

-
-
-
- ) -} - -function BasicForm(props: { - profile: User -}) { - const schema = z.object({ - username: z.string(), - email: z.string().email('请输入正确的邮箱'), - contact_qq: z.string(), - contact_wechat: z.string(), - }) - type Schema = z.infer - const form = useForm({ - resolver: zodResolver(schema), - defaultValues: { - username: props.profile.username || '', - email: props.profile.email || '', - contact_qq: props.profile.contact_qq || '', - contact_wechat: props.profile.contact_wechat || '', - }, - }) - const handler = form.handleSubmit(async (value) => { - try { - const resp = await update(value) - if (!resp.success) { - throw new Error(resp.message) - } - - await refreshProfile() - toast.success(`保存成功`) - } - catch (e) { - console.error(e) - toast.error(`保存失败`, { - description: e instanceof Error ? e.message : String(e), - }) - } - }) - - const refreshProfile = useProfileStore(store => store.refreshProfile) - - return ( -
-

基本信息

-
- - name="username" - label={用户名} - className="grid grid-cols-[48px_1fr] grid-rows-[auto_auto] gap-x-4" - classNames={{ - message: `col-start-2`, - }} - > - {({field}) => ( - - )} - - - name="email" - label={邮箱} - className="grid grid-cols-[48px_1fr] grid-rows-[auto_auto] gap-x-4" - classNames={{ - message: `col-start-2`, - }} - > - {({field}) => ( - - )} - - - name="contact_qq" - label={QQ} - className="grid grid-cols-[48px_1fr] grid-rows-[auto_auto] gap-x-4" - classNames={{ - message: `col-start-2`, - }} - > - {({field}) => ( - - )} - - - name="contact_wechat" - label={微信} - className="grid grid-cols-[48px_1fr] grid-rows-[auto_auto] gap-x-4" - classNames={{ - message: `col-start-2`, - }} - > - {({field}) => ( - - )} - -
- - -
- -
- ) -}