'use client' import { useState, useEffect, useCallback } from 'react' import { useRouter } from 'next/navigation' import { useToast } from '@/components/ui/Toast' import { USE_MOCK } from '@/contexts/AuthContext' import { api } from '@/lib/api' import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/Card' import { Button } from '@/components/ui/Button' import { Input } from '@/components/ui/Input' import { ArrowLeft, CircleUser, Camera, Copy, Check } from 'lucide-react' // 模拟用户数据 const mockUserData = { avatar: '星', name: '张经理', agencyId: 'AG789012', phone: '138****8888', email: 'zhang@starmedia.com', position: '运营总监', department: '内容审核部', } export default function AgencyProfileEditPage() { const router = useRouter() const toast = useToast() const [formData, setFormData] = useState(mockUserData) const [isSaving, setIsSaving] = useState(false) const [copied, setCopied] = useState(false) const loadData = useCallback(async () => { if (USE_MOCK) return try { const profile = await api.getProfile() setFormData({ avatar: profile.name?.[0] || '?', name: profile.name || '', agencyId: profile.agency?.id || '--', phone: profile.phone || '', email: profile.email || '', position: profile.agency?.contact_name || '', department: '', }) } catch {} }, []) useEffect(() => { loadData() }, [loadData]) const handleCopyId = async () => { try { await navigator.clipboard.writeText(formData.agencyId) setCopied(true) setTimeout(() => setCopied(false), 2000) } catch { toast.error('复制失败,请重试') } } const handleSave = async () => { setIsSaving(true) if (USE_MOCK) { await new Promise(resolve => setTimeout(resolve, 1000)) } else { try { await api.updateProfile({ name: formData.name, phone: formData.phone, contact_name: formData.position, }) } catch (err: any) { toast.error(err.message || '保存失败') setIsSaving(false) return } } setIsSaving(false) toast.success('个人信息已保存') router.back() } return (
编辑您的个人资料
点击相机图标更换头像
支持 JPG、PNG,最大 2MB
代理商ID不可修改,用于邀请达人时使用