2026-05-26 05:15:10 +00:00
|
|
|
|
import React, { useState, useEffect } from 'react';
|
|
|
|
|
|
import { useNavigate } from 'react-router-dom';
|
|
|
|
|
|
import { useAuth } from '../../contexts/AuthContext';
|
|
|
|
|
|
import { supabase } from '../../supabase/client';
|
|
|
|
|
|
import { motion } from 'framer-motion';
|
2026-05-28 05:54:23 +00:00
|
|
|
|
import { FileText, Plus, Warehouse, Factory, ArrowLeft, Users, TrendingUp, Package, Clock, Building2, CheckCircle2, DollarSign, Droplets, LogOut, HelpCircle, X, BookOpen, MessageSquare, Info, Camera } from 'lucide-react';
|
2026-05-26 05:15:10 +00:00
|
|
|
|
import { useResponsive } from '../../hooks/useResponsive';
|
2026-05-27 03:17:46 +00:00
|
|
|
|
import { OnboardingGuide, shouldShowOnboarding } from '../../components/OnboardingGuide';
|
2026-05-26 05:15:10 +00:00
|
|
|
|
import { NotificationCenter } from '../../components/NotificationCenter';
|
2026-05-27 03:17:46 +00:00
|
|
|
|
import { HelpCenter, HelpButton } from '../../components/HelpCenter';
|
|
|
|
|
|
import { VersionUpdate, useVersionCheck, AboutModal } from '../../components/VersionUpdate';
|
|
|
|
|
|
import { FeedbackModal } from '../../components/FeedbackModal';
|
|
|
|
|
|
import { UserManual } from '../../components/UserManual';
|
2026-05-26 05:15:10 +00:00
|
|
|
|
import type { ProductionPlan } from '../../types';
|
|
|
|
|
|
|
|
|
|
|
|
const statusMap: Record<string, { label: string; color: string; bgColor: string; icon: any }> = {
|
2026-05-28 05:54:23 +00:00
|
|
|
|
pending: { label: '待确定', color: 'text-amber-500', bgColor: 'bg-amber-50', icon: Clock },
|
|
|
|
|
|
producing: { label: '生产中', color: 'text-amber-500', bgColor: 'bg-amber-50', icon: TrendingUp },
|
|
|
|
|
|
completed: { label: '已完成', color: 'text-emerald-500', bgColor: 'bg-emerald-50', icon: Package }
|
2026-05-26 05:15:10 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
2026-05-28 05:54:23 +00:00
|
|
|
|
const getQuickActions = () => {
|
|
|
|
|
|
return [
|
|
|
|
|
|
{ id: 'plans', icon: FileText, label: '计划总览', path: '/purchaser/plans', gradient: 'from-amber-400 to-orange-400', description: '查看所有计划' },
|
|
|
|
|
|
{ id: 'new', icon: Plus, label: '新建纺织计划', path: '/purchaser/plans/new', gradient: 'from-orange-400 to-amber-400', description: '创建新纺织计划' },
|
|
|
|
|
|
{ id: 'washing', icon: Droplets, label: '新建水洗', path: '/purchaser/washing-plans/new', gradient: 'from-cyan-400 to-blue-400', description: '创建水洗计划' },
|
|
|
|
|
|
{ id: 'warehouse', icon: Warehouse, label: '产品信息', path: '/purchaser/warehouse', gradient: 'from-amber-400 to-yellow-400', description: '管理产品库存' },
|
|
|
|
|
|
{ id: 'finished', icon: Package, label: '水洗仓库', path: '/purchaser/finished-warehouse', gradient: 'from-yellow-400 to-amber-400', description: '管理水洗厂内坯布库存' },
|
|
|
|
|
|
{ id: 'factories', icon: Factory, label: '工厂管理', path: '/purchaser/factories', gradient: 'from-orange-400 to-rose-400', description: '管理合作工厂' },
|
|
|
|
|
|
{ id: 'accounts-payable', icon: DollarSign, label: '应付账款', path: '/purchaser/accounts-payable', gradient: 'from-rose-400 to-pink-400', description: '查看应付账款' }
|
2026-05-26 05:15:10 +00:00
|
|
|
|
];
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
const containerVariants = {
|
|
|
|
|
|
hidden: { opacity: 0 },
|
|
|
|
|
|
visible: { opacity: 1, transition: { staggerChildren: 0.1 } }
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
const itemVariants = {
|
|
|
|
|
|
hidden: { opacity: 0, y: 20 },
|
|
|
|
|
|
visible: { opacity: 1, y: 0, transition: { duration: 0.4 } }
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
export function PurchaserDashboard() {
|
|
|
|
|
|
const navigate = useNavigate();
|
|
|
|
|
|
const { auth, logout } = useAuth();
|
|
|
|
|
|
const { isMobile } = useResponsive();
|
|
|
|
|
|
const [plans, setPlans] = useState<ProductionPlan[]>([]);
|
|
|
|
|
|
const [loading, setLoading] = useState(true);
|
|
|
|
|
|
|
2026-05-27 03:17:46 +00:00
|
|
|
|
// 帮助中心状态
|
|
|
|
|
|
const [showHelp, setShowHelp] = useState(false);
|
|
|
|
|
|
const [showOnboarding, setShowOnboarding] = useState(false);
|
|
|
|
|
|
const [showUserManual, setShowUserManual] = useState(false);
|
|
|
|
|
|
const [showFeedback, setShowFeedback] = useState(false);
|
|
|
|
|
|
const [showAbout, setShowAbout] = useState(false);
|
|
|
|
|
|
|
2026-05-28 05:54:23 +00:00
|
|
|
|
// 账户卡片弹窗状态
|
|
|
|
|
|
const [showAccountCard, setShowAccountCard] = useState(false);
|
|
|
|
|
|
|
2026-05-27 03:17:46 +00:00
|
|
|
|
// 版本更新检查
|
|
|
|
|
|
const { showUpdate, setShowUpdate } = useVersionCheck();
|
|
|
|
|
|
|
|
|
|
|
|
// 检查是否显示新手引导
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
|
if (shouldShowOnboarding('purchaser')) {
|
|
|
|
|
|
setShowOnboarding(true);
|
|
|
|
|
|
}
|
|
|
|
|
|
}, []);
|
|
|
|
|
|
|
2026-05-26 05:15:10 +00:00
|
|
|
|
useEffect(() => {
|
|
|
|
|
|
if (!auth.company) return;
|
|
|
|
|
|
fetchPlans();
|
|
|
|
|
|
}, [auth.company]);
|
|
|
|
|
|
|
|
|
|
|
|
const fetchPlans = async () => {
|
2026-05-27 03:17:46 +00:00
|
|
|
|
const { data: planData } = await supabase
|
2026-05-26 05:15:10 +00:00
|
|
|
|
.from('production_plans')
|
|
|
|
|
|
.select('*')
|
|
|
|
|
|
.eq('purchaser_id', auth.company!.id)
|
|
|
|
|
|
.order('created_at', { ascending: false });
|
2026-05-27 03:17:46 +00:00
|
|
|
|
|
|
|
|
|
|
// 获取流程步骤,检测 rejected 状态
|
|
|
|
|
|
const planIds = (planData || []).map(p => p.id);
|
|
|
|
|
|
const { data: stepsData } = await supabase
|
|
|
|
|
|
.from('plan_process_steps')
|
|
|
|
|
|
.select('plan_id, status')
|
|
|
|
|
|
.in('plan_id', planIds);
|
|
|
|
|
|
|
|
|
|
|
|
// 过滤掉有 rejected 步骤的计划
|
|
|
|
|
|
const rejectedPlanIds = new Set<string>();
|
|
|
|
|
|
(stepsData || []).forEach(step => {
|
|
|
|
|
|
if (step.status === 'rejected') {
|
|
|
|
|
|
rejectedPlanIds.add(step.plan_id);
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
const filteredPlans = (planData || []).filter(p => !rejectedPlanIds.has(p.id));
|
|
|
|
|
|
setPlans(filteredPlans);
|
2026-05-26 05:15:10 +00:00
|
|
|
|
setLoading(false);
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
const stats = {
|
|
|
|
|
|
all: plans.length,
|
|
|
|
|
|
producing: plans.filter(p => p.status === 'producing').length,
|
|
|
|
|
|
completed: plans.filter(p => p.status === 'completed').length
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2026-05-28 05:54:23 +00:00
|
|
|
|
// 获取5条进行中的计划,用于滑动展示
|
|
|
|
|
|
const producingPlans = plans.filter(p => p.status === 'producing').slice(0, 5);
|
|
|
|
|
|
const [currentPlanIndex, setCurrentPlanIndex] = useState(0);
|
2026-05-26 05:15:10 +00:00
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
|
<div className="min-h-screen bg-gradient-to-br from-slate-50 via-blue-50/30 to-indigo-50/30">
|
2026-05-27 03:17:46 +00:00
|
|
|
|
{/* 新用户引导动画 - 已集成到下方弹窗 */}
|
2026-05-26 05:15:10 +00:00
|
|
|
|
{/* Header - 移动端优化 */}
|
|
|
|
|
|
<header className="bg-white/80 backdrop-blur-xl border-b border-gray-200/50 sticky top-0 z-10">
|
|
|
|
|
|
<div className="max-w-7xl mx-auto px-3 sm:px-4 md:px-8 py-3 sm:py-4 flex justify-between items-center">
|
|
|
|
|
|
<div className="flex items-center gap-2 sm:gap-3">
|
2026-05-28 05:54:23 +00:00
|
|
|
|
<motion.button
|
|
|
|
|
|
whileHover={{ scale: 1.05 }}
|
|
|
|
|
|
whileTap={{ scale: 0.95 }}
|
|
|
|
|
|
onClick={() => setShowAccountCard(true)}
|
|
|
|
|
|
className="w-8 h-8 sm:w-10 sm:h-10 bg-gradient-to-br from-blue-500 to-indigo-600 rounded-xl flex items-center justify-center shadow-lg shadow-blue-500/20 cursor-pointer overflow-hidden"
|
|
|
|
|
|
>
|
|
|
|
|
|
{(auth.user as any)?.image_url ? (
|
|
|
|
|
|
<img
|
|
|
|
|
|
src={(auth.user as any).image_url}
|
|
|
|
|
|
alt="头像"
|
|
|
|
|
|
className="w-full h-full object-cover"
|
|
|
|
|
|
onError={(e) => {
|
|
|
|
|
|
(e.target as HTMLImageElement).style.display = 'none';
|
|
|
|
|
|
}}
|
|
|
|
|
|
/>
|
|
|
|
|
|
) : (
|
|
|
|
|
|
<Building2 className="w-4 h-4 sm:w-5 sm:h-5 text-white" />
|
|
|
|
|
|
)}
|
|
|
|
|
|
</motion.button>
|
2026-05-26 05:15:10 +00:00
|
|
|
|
<div>
|
2026-05-27 03:17:46 +00:00
|
|
|
|
<h1 className="text-sm sm:text-lg font-bold text-gray-900 flex items-center gap-2 whitespace-nowrap">
|
2026-05-28 05:54:23 +00:00
|
|
|
|
<span className="sm:hidden truncate max-w-[80px]">{(auth.user as any)?.display_name || auth.user?.username || '用户'}</span>
|
|
|
|
|
|
<span className="hidden sm:inline">{auth.company?.name || '采购商'}工作台</span>
|
2026-05-27 03:17:46 +00:00
|
|
|
|
<span className="text-[10px] sm:text-xs bg-gradient-to-r from-amber-500 to-orange-500 text-white px-1.5 sm:px-2 py-0.5 rounded-full font-medium whitespace-nowrap">限时免费</span>
|
2026-05-26 05:15:10 +00:00
|
|
|
|
</h1>
|
2026-05-28 05:54:23 +00:00
|
|
|
|
<p className="text-xs text-gray-500 hidden sm:block truncate max-w-[150px]">{(auth.user as any)?.display_name || auth.user?.username || '用户'},欢迎回来</p>
|
2026-05-26 05:15:10 +00:00
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<div className="flex items-center gap-2">
|
2026-05-27 03:17:46 +00:00
|
|
|
|
<HelpButton onClick={() => setShowHelp(true)} />
|
2026-05-26 05:15:10 +00:00
|
|
|
|
<NotificationCenter />
|
|
|
|
|
|
<button
|
|
|
|
|
|
onClick={async () => { await logout(); navigate('/login'); }}
|
2026-05-27 03:17:46 +00:00
|
|
|
|
className="p-2 sm:px-3 sm:py-1.5 text-gray-600 hover:text-gray-900 hover:bg-gray-100 rounded-lg transition-colors"
|
|
|
|
|
|
title="退出登录"
|
2026-05-26 05:15:10 +00:00
|
|
|
|
>
|
2026-05-27 03:17:46 +00:00
|
|
|
|
<LogOut className="w-5 h-5 sm:hidden" />
|
|
|
|
|
|
<span className="hidden sm:inline text-xs sm:text-sm">退出</span>
|
2026-05-26 05:15:10 +00:00
|
|
|
|
</button>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</header>
|
|
|
|
|
|
|
|
|
|
|
|
<div className="p-3 sm:p-4 md:p-8 max-w-7xl mx-auto">
|
|
|
|
|
|
{loading ? (
|
|
|
|
|
|
<div className="flex items-center justify-center py-20">
|
|
|
|
|
|
<div className="w-8 h-8 border-2 border-blue-500 border-t-transparent rounded-full animate-spin" />
|
|
|
|
|
|
</div>
|
|
|
|
|
|
) : (
|
|
|
|
|
|
<motion.div variants={containerVariants} initial="hidden" animate="visible" className="space-y-4 sm:space-y-6">
|
|
|
|
|
|
{/* 统计卡片 - 移动端优化 */}
|
|
|
|
|
|
<div className="grid grid-cols-3 gap-2 sm:gap-4">
|
|
|
|
|
|
<motion.div
|
|
|
|
|
|
variants={itemVariants}
|
|
|
|
|
|
whileHover={isMobile ? {} : { scale: 1.02, y: -2 }}
|
|
|
|
|
|
onClick={() => navigate('/purchaser/plans')}
|
|
|
|
|
|
className="bg-white rounded-xl sm:rounded-2xl p-3 sm:p-5 shadow-sm border border-gray-100 cursor-pointer hover:border-blue-300 hover:shadow-md transition-all"
|
|
|
|
|
|
>
|
|
|
|
|
|
<div className="flex items-center justify-between mb-2 sm:mb-3">
|
|
|
|
|
|
<p className="text-xs sm:text-sm text-gray-500">所有计划</p>
|
|
|
|
|
|
<div className="w-6 h-6 sm:w-8 sm:h-8 bg-blue-50 rounded-lg flex items-center justify-center">
|
|
|
|
|
|
<FileText className="w-3 h-3 sm:w-4 sm:h-4 text-blue-600" />
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<p className="text-xl sm:text-3xl font-bold text-gray-900">{stats.all}</p>
|
|
|
|
|
|
<p className="text-xs text-gray-400 mt-0.5 sm:mt-1">累计创建</p>
|
|
|
|
|
|
</motion.div>
|
|
|
|
|
|
|
|
|
|
|
|
<motion.div
|
|
|
|
|
|
variants={itemVariants}
|
|
|
|
|
|
whileHover={isMobile ? {} : { scale: 1.02, y: -2 }}
|
|
|
|
|
|
onClick={() => navigate('/purchaser/plans?filter=producing')}
|
|
|
|
|
|
className="bg-white rounded-xl sm:rounded-2xl p-3 sm:p-5 shadow-sm border border-gray-100 cursor-pointer hover:border-emerald-300 hover:shadow-md transition-all"
|
|
|
|
|
|
>
|
|
|
|
|
|
<div className="flex items-center justify-between mb-2 sm:mb-3">
|
|
|
|
|
|
<p className="text-xs sm:text-sm text-gray-500">进行中</p>
|
|
|
|
|
|
<div className="w-6 h-6 sm:w-8 sm:h-8 bg-emerald-50 rounded-lg flex items-center justify-center">
|
|
|
|
|
|
<TrendingUp className="w-3 h-3 sm:w-4 sm:h-4 text-emerald-600" />
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<p className="text-xl sm:text-3xl font-bold text-gray-900">{stats.producing}</p>
|
|
|
|
|
|
<p className="text-xs text-gray-400 mt-0.5 sm:mt-1">正在生产</p>
|
|
|
|
|
|
</motion.div>
|
|
|
|
|
|
|
|
|
|
|
|
<motion.div
|
|
|
|
|
|
variants={itemVariants}
|
|
|
|
|
|
whileHover={isMobile ? {} : { scale: 1.02, y: -2 }}
|
|
|
|
|
|
onClick={() => navigate('/purchaser/plans?filter=completed')}
|
|
|
|
|
|
className="bg-white rounded-xl sm:rounded-2xl p-3 sm:p-5 shadow-sm border border-gray-100 cursor-pointer hover:border-amber-300 hover:shadow-md transition-all"
|
|
|
|
|
|
>
|
|
|
|
|
|
<div className="flex items-center justify-between mb-2 sm:mb-3">
|
|
|
|
|
|
<p className="text-xs sm:text-sm text-gray-500">已完成</p>
|
|
|
|
|
|
<div className="w-6 h-6 sm:w-8 sm:h-8 bg-amber-50 rounded-lg flex items-center justify-center">
|
|
|
|
|
|
<Package className="w-3 h-3 sm:w-4 sm:h-4 text-amber-600" />
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<p className="text-xl sm:text-3xl font-bold text-gray-900">{stats.completed}</p>
|
|
|
|
|
|
<p className="text-xs text-gray-400 mt-0.5 sm:mt-1">已入库</p>
|
|
|
|
|
|
</motion.div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
2026-05-28 05:54:23 +00:00
|
|
|
|
{/* 最近计划 - 左右滑动展示 */}
|
2026-05-27 03:17:46 +00:00
|
|
|
|
<motion.div variants={itemVariants} className="bg-white rounded-xl sm:rounded-2xl shadow-sm border border-gray-100 p-3 sm:p-4 md:p-6">
|
2026-05-26 05:15:10 +00:00
|
|
|
|
<div className="flex justify-between items-center mb-3 sm:mb-4">
|
2026-05-27 03:17:46 +00:00
|
|
|
|
<h2 className="text-sm sm:text-base font-semibold text-gray-900 whitespace-nowrap">最近计划</h2>
|
2026-05-26 05:15:10 +00:00
|
|
|
|
<button
|
|
|
|
|
|
onClick={() => navigate('/purchaser/plans')}
|
2026-05-27 03:17:46 +00:00
|
|
|
|
className="text-xs sm:text-sm text-blue-600 hover:text-blue-700 font-medium flex items-center gap-1 whitespace-nowrap"
|
2026-05-26 05:15:10 +00:00
|
|
|
|
>
|
|
|
|
|
|
查看全部
|
|
|
|
|
|
<ArrowLeft className="w-3 h-3 sm:w-4 sm:h-4 rotate-180" />
|
|
|
|
|
|
</button>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
2026-05-28 05:54:23 +00:00
|
|
|
|
{producingPlans.length === 0 ? (
|
2026-05-26 05:15:10 +00:00
|
|
|
|
<div className="text-center py-8 sm:py-12 text-gray-400">
|
|
|
|
|
|
<Package className="w-10 h-10 sm:w-12 sm:h-12 mx-auto mb-3 text-gray-300" />
|
2026-05-28 05:54:23 +00:00
|
|
|
|
<p className="text-sm">暂无进行中的计划</p>
|
2026-05-26 05:15:10 +00:00
|
|
|
|
<button
|
|
|
|
|
|
onClick={() => navigate('/purchaser/plans/new')}
|
|
|
|
|
|
className="mt-3 px-4 py-2 bg-blue-600 text-white rounded-lg text-sm hover:bg-blue-700 transition-colors"
|
|
|
|
|
|
>
|
|
|
|
|
|
创建计划
|
|
|
|
|
|
</button>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
) : (
|
2026-05-28 05:54:23 +00:00
|
|
|
|
<div className="relative">
|
|
|
|
|
|
{/* 滑动容器 */}
|
|
|
|
|
|
<div className="overflow-hidden">
|
|
|
|
|
|
<motion.div
|
|
|
|
|
|
className="flex"
|
|
|
|
|
|
animate={{ x: -currentPlanIndex * 100 + '%' }}
|
|
|
|
|
|
transition={{ type: 'spring', stiffness: 300, damping: 30 }}
|
|
|
|
|
|
>
|
|
|
|
|
|
{producingPlans.map((plan, i) => {
|
|
|
|
|
|
const progress = plan.target_quantity > 0
|
|
|
|
|
|
? Math.round((plan.completed_quantity / plan.target_quantity) * 100)
|
|
|
|
|
|
: 0;
|
|
|
|
|
|
const status = statusMap[plan.status] || statusMap.pending;
|
|
|
|
|
|
const StatusIcon = status.icon;
|
|
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
|
<div
|
|
|
|
|
|
key={plan.id}
|
|
|
|
|
|
className="w-full flex-shrink-0 px-1"
|
|
|
|
|
|
onClick={() => navigate(`/purchaser/plans?id=${plan.id}`)}
|
|
|
|
|
|
>
|
|
|
|
|
|
<div className="group p-3 sm:p-4 rounded-xl border border-gray-100 hover:border-blue-200 hover:bg-blue-50/30 cursor-pointer transition-all">
|
|
|
|
|
|
{/* 计划标题行 */}
|
|
|
|
|
|
<div className="flex items-center gap-2 sm:gap-3">
|
|
|
|
|
|
<div className={`w-8 h-8 sm:w-10 sm:h-10 rounded-lg flex items-center justify-center ${status.bgColor}`}>
|
|
|
|
|
|
<StatusIcon className={`w-4 h-4 sm:w-5 sm:h-5 ${status.color}`} />
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<div className="flex-1 min-w-0">
|
|
|
|
|
|
<div className="flex items-center gap-1.5 sm:gap-2">
|
|
|
|
|
|
<h3 className="font-medium text-gray-900 text-sm sm:text-base truncate">{plan.product_name}-{plan.color}</h3>
|
|
|
|
|
|
<span className={`px-1.5 py-0.5 text-xs rounded-full whitespace-nowrap ${status.bgColor} ${status.color}`}>
|
|
|
|
|
|
{status.label}
|
|
|
|
|
|
</span>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<p className="text-xs text-gray-500">{plan.fabric_code}-{plan.color_code}</p>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
2026-05-26 05:15:10 +00:00
|
|
|
|
</div>
|
2026-05-28 05:54:23 +00:00
|
|
|
|
);
|
|
|
|
|
|
})}
|
|
|
|
|
|
</motion.div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
{/* 左右滑动按钮 */}
|
|
|
|
|
|
{producingPlans.length > 1 && (
|
|
|
|
|
|
<>
|
|
|
|
|
|
<button
|
|
|
|
|
|
onClick={() => setCurrentPlanIndex(prev => Math.max(0, prev - 1))}
|
|
|
|
|
|
disabled={currentPlanIndex === 0}
|
|
|
|
|
|
className="absolute left-0 top-1/2 -translate-y-1/2 -translate-x-2 w-8 h-8 bg-white shadow-lg rounded-full flex items-center justify-center disabled:opacity-30 disabled:cursor-not-allowed hover:bg-gray-50 transition-colors z-10"
|
|
|
|
|
|
>
|
|
|
|
|
|
<ArrowLeft className="w-4 h-4 text-gray-600" />
|
|
|
|
|
|
</button>
|
|
|
|
|
|
<button
|
|
|
|
|
|
onClick={() => setCurrentPlanIndex(prev => Math.min(producingPlans.length - 1, prev + 1))}
|
|
|
|
|
|
disabled={currentPlanIndex === producingPlans.length - 1}
|
|
|
|
|
|
className="absolute right-0 top-1/2 -translate-y-1/2 translate-x-2 w-8 h-8 bg-white shadow-lg rounded-full flex items-center justify-center disabled:opacity-30 disabled:cursor-not-allowed hover:bg-gray-50 transition-colors z-10"
|
|
|
|
|
|
>
|
|
|
|
|
|
<ArrowLeft className="w-4 h-4 text-gray-600 rotate-180" />
|
|
|
|
|
|
</button>
|
|
|
|
|
|
</>
|
|
|
|
|
|
)}
|
|
|
|
|
|
|
|
|
|
|
|
{/* 指示器 */}
|
|
|
|
|
|
{producingPlans.length > 1 && (
|
|
|
|
|
|
<div className="flex items-center justify-center gap-1.5 mt-4">
|
|
|
|
|
|
{producingPlans.map((_, i) => (
|
|
|
|
|
|
<button
|
|
|
|
|
|
key={i}
|
|
|
|
|
|
onClick={() => setCurrentPlanIndex(i)}
|
|
|
|
|
|
className={`w-2 h-2 rounded-full transition-all ${
|
|
|
|
|
|
i === currentPlanIndex ? 'bg-blue-500 w-4' : 'bg-gray-300 hover:bg-gray-400'
|
|
|
|
|
|
}`}
|
|
|
|
|
|
/>
|
|
|
|
|
|
))}
|
|
|
|
|
|
</div>
|
|
|
|
|
|
)}
|
2026-05-26 05:15:10 +00:00
|
|
|
|
</div>
|
|
|
|
|
|
)}
|
|
|
|
|
|
</motion.div>
|
2026-05-28 05:54:23 +00:00
|
|
|
|
|
|
|
|
|
|
{/* 快捷操作 - 移动端优化 */}
|
|
|
|
|
|
<motion.div variants={itemVariants} className="bg-white rounded-xl sm:rounded-2xl shadow-sm border border-gray-100 p-3 sm:p-4 md:p-6">
|
|
|
|
|
|
<h2 className="text-sm sm:text-base font-semibold text-gray-900 mb-3 sm:mb-4 whitespace-nowrap">快捷操作</h2>
|
|
|
|
|
|
<div className="grid grid-cols-3 sm:grid-cols-4 gap-2 sm:gap-3">
|
|
|
|
|
|
{getQuickActions().map((action, index) => (
|
|
|
|
|
|
<motion.button
|
|
|
|
|
|
key={action.id}
|
|
|
|
|
|
whileHover={isMobile ? {} : { scale: 1.03, y: -2 }}
|
|
|
|
|
|
whileTap={{ scale: 0.97 }}
|
|
|
|
|
|
onClick={() => navigate(action.path)}
|
|
|
|
|
|
className="group flex flex-col items-center p-2 sm:p-3 rounded-lg sm:rounded-xl border border-gray-100 hover:border-transparent hover:shadow-md transition-all bg-gray-50/50 hover:bg-white"
|
|
|
|
|
|
>
|
|
|
|
|
|
<div className={`w-8 h-8 sm:w-10 sm:h-10 rounded-lg sm:rounded-xl flex items-center justify-center mb-1 sm:mb-2 bg-gradient-to-br ${action.gradient} shadow-sm group-hover:shadow-md transition-shadow`}>
|
|
|
|
|
|
<action.icon className="w-4 h-4 sm:w-5 sm:h-5 text-white" />
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<span className="text-[10px] sm:text-xs font-medium text-gray-700 group-hover:text-gray-900 text-center whitespace-nowrap">{action.label}</span>
|
|
|
|
|
|
</motion.button>
|
|
|
|
|
|
))}
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</motion.div>
|
2026-05-26 05:15:10 +00:00
|
|
|
|
</motion.div>
|
|
|
|
|
|
)}
|
|
|
|
|
|
</div>
|
2026-05-27 03:17:46 +00:00
|
|
|
|
|
|
|
|
|
|
{/* 帮助中心弹窗 */}
|
|
|
|
|
|
<HelpCenter isOpen={showHelp} onClose={() => setShowHelp(false)} />
|
|
|
|
|
|
|
|
|
|
|
|
{/* 新手引导 */}
|
|
|
|
|
|
<OnboardingGuide
|
|
|
|
|
|
role="purchaser"
|
|
|
|
|
|
isOpen={showOnboarding}
|
|
|
|
|
|
onClose={() => setShowOnboarding(false)}
|
|
|
|
|
|
/>
|
|
|
|
|
|
|
|
|
|
|
|
{/* 用户手册 */}
|
|
|
|
|
|
<UserManual isOpen={showUserManual} onClose={() => setShowUserManual(false)} />
|
|
|
|
|
|
|
|
|
|
|
|
{/* 反馈弹窗 */}
|
|
|
|
|
|
<FeedbackModal isOpen={showFeedback} onClose={() => setShowFeedback(false)} />
|
|
|
|
|
|
|
|
|
|
|
|
{/* 关于窗口 */}
|
|
|
|
|
|
<AboutModal isOpen={showAbout} onClose={() => setShowAbout(false)} />
|
|
|
|
|
|
|
|
|
|
|
|
{/* 版本更新弹窗 */}
|
|
|
|
|
|
<VersionUpdate
|
|
|
|
|
|
isOpen={showUpdate}
|
|
|
|
|
|
onClose={() => setShowUpdate(false)}
|
|
|
|
|
|
/>
|
2026-05-28 05:54:23 +00:00
|
|
|
|
|
|
|
|
|
|
{/* 账户卡片弹窗 */}
|
|
|
|
|
|
{showAccountCard && (
|
|
|
|
|
|
<div className="fixed inset-0 bg-black/50 backdrop-blur-sm flex items-center justify-center z-50 p-4" onClick={() => setShowAccountCard(false)}>
|
|
|
|
|
|
<motion.div
|
|
|
|
|
|
initial={{ opacity: 0, scale: 0.95 }}
|
|
|
|
|
|
animate={{ opacity: 1, scale: 1 }}
|
|
|
|
|
|
exit={{ opacity: 0, scale: 0.95 }}
|
|
|
|
|
|
className="bg-white rounded-2xl w-full max-w-sm shadow-2xl overflow-hidden"
|
|
|
|
|
|
onClick={e => e.stopPropagation()}
|
|
|
|
|
|
>
|
|
|
|
|
|
{/* 头部 */}
|
|
|
|
|
|
<div className="bg-gradient-to-r from-blue-500 to-indigo-600 p-6 text-white">
|
|
|
|
|
|
<div className="flex items-center justify-between">
|
|
|
|
|
|
<h2 className="text-xl font-bold">账户信息</h2>
|
|
|
|
|
|
<button onClick={() => setShowAccountCard(false)} className="p-2 hover:bg-white/20 rounded-lg transition-colors">
|
|
|
|
|
|
<X className="w-5 h-5" />
|
|
|
|
|
|
</button>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
{/* 账户详情 */}
|
|
|
|
|
|
<div className="p-6 space-y-4">
|
|
|
|
|
|
{/* 用户信息 */}
|
|
|
|
|
|
<div className="flex items-center gap-4">
|
|
|
|
|
|
<label className="w-16 h-16 bg-gradient-to-br from-blue-500 to-indigo-600 rounded-xl flex items-center justify-center shadow-lg cursor-pointer hover:opacity-90 transition-opacity overflow-hidden relative group">
|
|
|
|
|
|
{(auth.user as any)?.image_url ? (
|
|
|
|
|
|
<img src={(auth.user as any).image_url} alt="头像" className="w-full h-full object-cover relative z-10" />
|
|
|
|
|
|
) : (
|
|
|
|
|
|
<Building2 className="w-8 h-8 text-white relative z-10" />
|
|
|
|
|
|
)}
|
|
|
|
|
|
<div className="absolute inset-0 bg-black/30 flex items-center justify-center opacity-0 group-hover:opacity-100 transition-opacity z-20">
|
|
|
|
|
|
<Camera className="w-5 h-5 text-white" />
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<input
|
|
|
|
|
|
type="file"
|
|
|
|
|
|
accept="image/*"
|
|
|
|
|
|
className="hidden"
|
|
|
|
|
|
onChange={async (e) => {
|
|
|
|
|
|
const file = e.target.files?.[0];
|
|
|
|
|
|
if (!file) return;
|
|
|
|
|
|
|
|
|
|
|
|
// 上传头像到 Supabase Storage
|
|
|
|
|
|
const { data: { user } } = await supabase.auth.getUser();
|
|
|
|
|
|
if (!user) return;
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
const fileExt = file.name.split('.').pop();
|
|
|
|
|
|
const fileName = `${user.id}-${Date.now()}.${fileExt}`;
|
|
|
|
|
|
|
|
|
|
|
|
// 读取文件为 ArrayBuffer
|
|
|
|
|
|
const arrayBuffer = await file.arrayBuffer();
|
|
|
|
|
|
|
|
|
|
|
|
const { error: uploadError } = await supabase.storage
|
|
|
|
|
|
.from('avatars')
|
|
|
|
|
|
.upload(fileName, arrayBuffer, {
|
|
|
|
|
|
contentType: file.type,
|
|
|
|
|
|
upsert: true
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
if (uploadError) {
|
|
|
|
|
|
console.error('头像上传失败:', uploadError);
|
|
|
|
|
|
alert('头像上传失败: ' + uploadError.message);
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 获取头像 URL
|
|
|
|
|
|
const { data: { publicUrl } } = supabase.storage
|
|
|
|
|
|
.from('avatars')
|
|
|
|
|
|
.getPublicUrl(fileName);
|
|
|
|
|
|
|
|
|
|
|
|
// 更新用户头像
|
|
|
|
|
|
const { error: updateError } = await supabase
|
|
|
|
|
|
.from('profiles')
|
|
|
|
|
|
.update({ image_url: publicUrl } as any)
|
|
|
|
|
|
.eq('id', user.id);
|
|
|
|
|
|
|
|
|
|
|
|
if (updateError) {
|
|
|
|
|
|
console.error('头像更新失败:', updateError);
|
|
|
|
|
|
alert('头像更新失败: ' + updateError.message);
|
|
|
|
|
|
} else {
|
|
|
|
|
|
// 刷新页面以显示新头像
|
|
|
|
|
|
window.location.reload();
|
|
|
|
|
|
}
|
|
|
|
|
|
} catch (err) {
|
|
|
|
|
|
console.error('头像上传出错:', err);
|
|
|
|
|
|
alert('头像上传出错,请重试');
|
|
|
|
|
|
}
|
|
|
|
|
|
}}
|
|
|
|
|
|
/>
|
|
|
|
|
|
</label>
|
|
|
|
|
|
<div>
|
|
|
|
|
|
<p className="font-semibold text-gray-900 text-lg truncate max-w-[200px]">{(auth.user as any)?.display_name || auth.user?.username || '用户'}</p>
|
|
|
|
|
|
<p className="text-sm text-gray-500">{auth.company?.name || '采购商'}</p>
|
|
|
|
|
|
<span className="inline-flex items-center gap-1 text-xs bg-amber-100 text-amber-700 px-2 py-0.5 rounded-full mt-1">
|
|
|
|
|
|
{auth.user?.is_master ? '主账号' : '子账号'}
|
|
|
|
|
|
</span>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
{/* 功能菜单 */}
|
|
|
|
|
|
<div className="space-y-2 pt-4 border-t border-gray-100">
|
|
|
|
|
|
<button
|
|
|
|
|
|
onClick={() => { setShowAccountCard(false); navigate('/members'); }}
|
|
|
|
|
|
className="w-full flex items-center gap-3 p-3 rounded-xl hover:bg-gray-50 transition-colors text-left"
|
|
|
|
|
|
>
|
|
|
|
|
|
<div className="w-10 h-10 bg-blue-100 rounded-lg flex items-center justify-center">
|
|
|
|
|
|
<Users className="w-5 h-5 text-blue-600" />
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<div>
|
|
|
|
|
|
<p className="font-medium text-gray-900">账号管理</p>
|
|
|
|
|
|
<p className="text-xs text-gray-500">管理团队成员和账户设置</p>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</button>
|
|
|
|
|
|
|
|
|
|
|
|
<button
|
|
|
|
|
|
onClick={() => { setShowAccountCard(false); setShowUserManual(true); }}
|
|
|
|
|
|
className="w-full flex items-center gap-3 p-3 rounded-xl hover:bg-gray-50 transition-colors text-left"
|
|
|
|
|
|
>
|
|
|
|
|
|
<div className="w-10 h-10 bg-emerald-100 rounded-lg flex items-center justify-center">
|
|
|
|
|
|
<BookOpen className="w-5 h-5 text-emerald-600" />
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<div>
|
|
|
|
|
|
<p className="font-medium text-gray-900">用户手册</p>
|
|
|
|
|
|
<p className="text-xs text-gray-500">查看详细使用指南</p>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</button>
|
|
|
|
|
|
|
|
|
|
|
|
<button
|
|
|
|
|
|
onClick={() => { setShowAccountCard(false); setShowFeedback(true); }}
|
|
|
|
|
|
className="w-full flex items-center gap-3 p-3 rounded-xl hover:bg-gray-50 transition-colors text-left"
|
|
|
|
|
|
>
|
|
|
|
|
|
<div className="w-10 h-10 bg-purple-100 rounded-lg flex items-center justify-center">
|
|
|
|
|
|
<MessageSquare className="w-5 h-5 text-purple-600" />
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<div>
|
|
|
|
|
|
<p className="font-medium text-gray-900">用户反馈</p>
|
|
|
|
|
|
<p className="text-xs text-gray-500">提交问题或建议</p>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</button>
|
|
|
|
|
|
|
|
|
|
|
|
<button
|
|
|
|
|
|
onClick={() => { setShowAccountCard(false); setShowAbout(true); }}
|
|
|
|
|
|
className="w-full flex items-center gap-3 p-3 rounded-xl hover:bg-gray-50 transition-colors text-left"
|
|
|
|
|
|
>
|
|
|
|
|
|
<div className="w-10 h-10 bg-gray-100 rounded-lg flex items-center justify-center">
|
|
|
|
|
|
<Info className="w-5 h-5 text-gray-600" />
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<div>
|
|
|
|
|
|
<p className="font-medium text-gray-900">关于</p>
|
|
|
|
|
|
<p className="text-xs text-gray-500">版本信息与版权</p>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</button>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
{/* 退出登录 */}
|
|
|
|
|
|
<button
|
|
|
|
|
|
onClick={async () => { await logout(); navigate('/login'); }}
|
|
|
|
|
|
className="w-full py-3 bg-red-50 hover:bg-red-100 text-red-600 rounded-xl transition-colors flex items-center justify-center gap-2 font-medium"
|
|
|
|
|
|
>
|
|
|
|
|
|
<LogOut className="w-5 h-5" />
|
|
|
|
|
|
退出登录
|
|
|
|
|
|
</button>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</motion.div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
)}
|
2026-05-26 05:15:10 +00:00
|
|
|
|
</div>
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
|