| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874 |
- import 'package:flutter/material.dart';
- import 'package:go_router/go_router.dart';
- import 'package:provider/provider.dart';
- import 'package:flutter_lucide/flutter_lucide.dart';
- import '../widgets/layout/app_layout.dart';
- import '../widgets/common/app_button.dart';
- import '../providers/document_provider.dart';
- import '../models/document.dart';
- import '../utils/constants.dart';
- import '../theme/app_colors.dart';
- /// 首页/仪表盘
- class DashboardPage extends StatefulWidget {
- const DashboardPage({Key? key}) : super(key: key);
- @override
- State<DashboardPage> createState() => _DashboardPageState();
- }
- class _DashboardPageState extends State<DashboardPage>
- with SingleTickerProviderStateMixin {
- late AnimationController _animationController;
- late Animation<double> _fadeAnimation;
- @override
- void initState() {
- super.initState();
- _animationController = AnimationController(
- vsync: this,
- duration: const Duration(milliseconds: 800),
- );
- _fadeAnimation = Tween<double>(begin: 0.0, end: 1.0).animate(
- CurvedAnimation(
- parent: _animationController,
- curve: Curves.easeInOut,
- ),
- );
- _animationController.forward();
- }
- @override
- void dispose() {
- _animationController.dispose();
- super.dispose();
- }
- @override
- Widget build(BuildContext context) {
- return AppLayout(
- child: FadeTransition(
- opacity: _fadeAnimation,
- child: SingleChildScrollView(
- child: Column(
- mainAxisSize: MainAxisSize.min,
- crossAxisAlignment: CrossAxisAlignment.start,
- children: [
- const SizedBox(height: 24),
- // 欢迎区域 - 带渐变背景
- _buildWelcomeSection(context),
- const SizedBox(height: 40),
- // 统计卡片 - 更现代的设计
- _buildStatsSection(context),
- const SizedBox(height: 40),
- // 快速操作 - 网格布局
- _buildQuickActions(context),
- const SizedBox(height: 40),
- // 最近文档 - 改进的列表设计
- _buildRecentDocuments(context),
- const SizedBox(height: 40),
- ],
- ),
- ),
- ),
- );
- }
- Widget _buildWelcomeSection(BuildContext context) {
- return Container(
- padding: const EdgeInsets.all(32),
- decoration: BoxDecoration(
- gradient: LinearGradient(
- begin: Alignment.topLeft,
- end: Alignment.bottomRight,
- colors: [
- AppColors.primary.withOpacity(0.1),
- AppColors.primary.withOpacity(0.05),
- ],
- ),
- borderRadius: BorderRadius.circular(16),
- border: Border.all(
- color: AppColors.primary.withOpacity(0.2),
- width: 1,
- ),
- ),
- child: Row(
- children: [
- Expanded(
- child: Column(
- crossAxisAlignment: CrossAxisAlignment.start,
- children: [
- Row(
- children: [
- Container(
- padding: const EdgeInsets.all(12),
- decoration: BoxDecoration(
- gradient: LinearGradient(
- colors: [AppColors.primary, AppColors.primaryDark],
- ),
- borderRadius: BorderRadius.circular(12),
- boxShadow: [
- BoxShadow(
- color: AppColors.primary.withOpacity(0.3),
- blurRadius: 8,
- offset: const Offset(0, 4),
- ),
- ],
- ),
- child: const Icon(
- LucideIcons.sparkles,
- color: Colors.white,
- size: 28,
- ),
- ),
- const SizedBox(width: 16),
- const Expanded(
- child: Column(
- crossAxisAlignment: CrossAxisAlignment.start,
- children: [
- Text(
- '欢迎使用灵越智报',
- style: TextStyle(
- fontSize: 32,
- fontWeight: FontWeight.bold,
- color: AppColors.textPrimary,
- letterSpacing: -0.5,
- ),
- ),
- SizedBox(height: 8),
- Text(
- '智能文档处理平台 · AI驱动的文档理解与处理',
- style: TextStyle(
- fontSize: 16,
- color: AppColors.textSecondary,
- height: 1.5,
- ),
- ),
- ],
- ),
- ),
- ],
- ),
- const SizedBox(height: 24),
- Row(
- children: [
- AppButton(
- text: '立即上传',
- type: ButtonType.primary,
- icon: LucideIcons.upload,
- onPressed: () => context.push(AppRoutes.upload),
- ),
- const SizedBox(width: 12),
- AppButton(
- text: '查看文档',
- type: ButtonType.secondary,
- icon: LucideIcons.folder_open,
- onPressed: () {},
- ),
- ],
- ),
- ],
- ),
- ),
- ],
- ),
- );
- }
- Widget _buildStatsSection(BuildContext context) {
- return Consumer<DocumentProvider>(
- builder: (context, provider, child) {
- final total = provider.documents.length;
- final completed = provider.documents
- .where((d) => d.status == DocumentStatus.completed)
- .length;
- final processing = provider.documents
- .where(
- (d) =>
- d.status == DocumentStatus.processing ||
- d.status == DocumentStatus.parsing,
- )
- .length;
- final pending = provider.documents
- .where((d) => d.status == DocumentStatus.pending)
- .length;
- return LayoutBuilder(
- builder: (context, constraints) {
- final isWide = constraints.maxWidth > 600;
- return isWide
- ? Row(
- children: [
- Expanded(
- child: _buildStatCard(
- context,
- title: '总文档数',
- value: total.toString(),
- icon: LucideIcons.file_text,
- color: AppColors.primary,
- gradient: [AppColors.primary, AppColors.primaryLight],
- )),
- const SizedBox(width: 16),
- Expanded(
- child: _buildStatCard(
- context,
- title: '处理中',
- value: processing.toString(),
- icon: LucideIcons.loader,
- color: AppColors.warning,
- gradient: [AppColors.warning, Colors.orange.shade300],
- )),
- const SizedBox(width: 16),
- Expanded(
- child: _buildStatCard(
- context,
- title: '已完成',
- value: completed.toString(),
- icon: LucideIcons.circle_check,
- color: AppColors.success,
- gradient: [AppColors.success, Colors.green.shade300],
- )),
- const SizedBox(width: 16),
- Expanded(
- child: _buildStatCard(
- context,
- title: '待处理',
- value: pending.toString(),
- icon: LucideIcons.clock,
- color: AppColors.info,
- gradient: [AppColors.info, Colors.blue.shade300],
- )),
- ],
- )
- : Column(
- children: [
- Row(
- children: [
- Expanded(
- child: _buildStatCard(
- context,
- title: '总文档数',
- value: total.toString(),
- icon: LucideIcons.file_text,
- color: AppColors.primary,
- gradient: [
- AppColors.primary,
- AppColors.primaryLight
- ],
- )),
- const SizedBox(width: 12),
- Expanded(
- child: _buildStatCard(
- context,
- title: '处理中',
- value: processing.toString(),
- icon: LucideIcons.loader,
- color: AppColors.warning,
- gradient: [
- AppColors.warning,
- Colors.orange.shade300
- ],
- )),
- ],
- ),
- const SizedBox(height: 12),
- Row(
- children: [
- Expanded(
- child: _buildStatCard(
- context,
- title: '已完成',
- value: completed.toString(),
- icon: LucideIcons.circle_check,
- color: AppColors.success,
- gradient: [
- AppColors.success,
- Colors.green.shade300
- ],
- )),
- const SizedBox(width: 12),
- Expanded(
- child: _buildStatCard(
- context,
- title: '待处理',
- value: pending.toString(),
- icon: LucideIcons.clock,
- color: AppColors.info,
- gradient: [AppColors.info, Colors.blue.shade300],
- )),
- ],
- ),
- ],
- );
- },
- );
- },
- );
- }
- Widget _buildStatCard(
- BuildContext context, {
- required String title,
- required String value,
- required IconData icon,
- required Color color,
- required List<Color> gradient,
- }) {
- return Container(
- decoration: BoxDecoration(
- gradient: LinearGradient(
- begin: Alignment.topLeft,
- end: Alignment.bottomRight,
- colors: [
- ...gradient.map((c) => c.withOpacity(0.1)),
- Colors.white,
- ],
- ),
- borderRadius: BorderRadius.circular(16),
- border: Border.all(
- color: color.withOpacity(0.2),
- width: 1,
- ),
- boxShadow: [
- BoxShadow(
- color: color.withOpacity(0.1),
- blurRadius: 12,
- offset: const Offset(0, 4),
- ),
- ],
- ),
- child: Padding(
- padding: const EdgeInsets.all(20),
- child: Column(
- crossAxisAlignment: CrossAxisAlignment.start,
- children: [
- Row(
- mainAxisAlignment: MainAxisAlignment.spaceBetween,
- children: [
- Container(
- padding: const EdgeInsets.all(10),
- decoration: BoxDecoration(
- gradient: LinearGradient(colors: gradient),
- borderRadius: BorderRadius.circular(12),
- boxShadow: [
- BoxShadow(
- color: color.withOpacity(0.3),
- blurRadius: 8,
- offset: const Offset(0, 2),
- ),
- ],
- ),
- child: Icon(icon, color: Colors.white, size: 24),
- ),
- Container(
- padding:
- const EdgeInsets.symmetric(horizontal: 8, vertical: 4),
- decoration: BoxDecoration(
- color: color.withOpacity(0.1),
- borderRadius: BorderRadius.circular(12),
- ),
- child: Text(
- '+12%',
- style: TextStyle(
- fontSize: 12,
- fontWeight: FontWeight.w600,
- color: color,
- ),
- ),
- ),
- ],
- ),
- const SizedBox(height: 16),
- Text(
- value,
- style: TextStyle(
- fontSize: 32,
- fontWeight: FontWeight.bold,
- color: color,
- height: 1.2,
- ),
- ),
- const SizedBox(height: 4),
- Text(
- title,
- style: TextStyle(
- fontSize: 14,
- color: AppColors.textSecondary,
- fontWeight: FontWeight.w500,
- ),
- ),
- ],
- ),
- ),
- );
- }
- Widget _buildQuickActions(BuildContext context) {
- final isWide = MediaQuery.of(context).size.width > 600;
- return Column(
- crossAxisAlignment: CrossAxisAlignment.start,
- children: [
- Row(
- mainAxisAlignment: MainAxisAlignment.spaceBetween,
- children: [
- const Text(
- '快速操作',
- style: TextStyle(
- fontSize: 24,
- fontWeight: FontWeight.bold,
- color: AppColors.textPrimary,
- ),
- ),
- TextButton.icon(
- onPressed: () {},
- icon: const Icon(LucideIcons.arrow_right, size: 16),
- label: const Text('查看全部'),
- style: TextButton.styleFrom(
- foregroundColor: AppColors.primary,
- ),
- ),
- ],
- ),
- const SizedBox(height: 20),
- isWide
- ? Row(
- children: [
- Expanded(
- child: _buildActionCard(
- context,
- icon: LucideIcons.upload,
- title: '上传文档',
- subtitle: '支持PDF、Word、图片等多种格式',
- color: AppColors.primary,
- gradient: [AppColors.primary, AppColors.primaryLight],
- onTap: () => context.push(AppRoutes.upload),
- )),
- const SizedBox(width: 16),
- Expanded(
- child: _buildActionCard(
- context,
- icon: LucideIcons.folder_open,
- title: '文档管理',
- subtitle: '查看、搜索和管理所有文档',
- color: AppColors.info,
- gradient: [AppColors.info, Colors.blue.shade300],
- onTap: () {},
- )),
- const SizedBox(width: 16),
- Expanded(
- child: _buildActionCard(
- context,
- icon: LucideIcons.sparkles,
- title: 'AI处理',
- subtitle: '智能提取、润色和批注',
- color: Colors.purple,
- gradient: [Colors.purple, Colors.purple.shade300],
- onTap: () {},
- )),
- ],
- )
- : Column(
- children: [
- _buildActionCard(
- context,
- icon: LucideIcons.upload,
- title: '上传文档',
- subtitle: '支持PDF、Word、图片等多种格式',
- color: AppColors.primary,
- gradient: [AppColors.primary, AppColors.primaryLight],
- onTap: () => context.push(AppRoutes.upload),
- ),
- const SizedBox(height: 12),
- _buildActionCard(
- context,
- icon: LucideIcons.folder_open,
- title: '文档管理',
- subtitle: '查看、搜索和管理所有文档',
- color: AppColors.info,
- gradient: [AppColors.info, Colors.blue.shade300],
- onTap: () {},
- ),
- const SizedBox(height: 12),
- _buildActionCard(
- context,
- icon: LucideIcons.sparkles,
- title: 'AI处理',
- subtitle: '智能提取、润色和批注',
- color: Colors.purple,
- gradient: [Colors.purple, Colors.purple.shade300],
- onTap: () {},
- ),
- ],
- ),
- ],
- );
- }
- Widget _buildActionCard(
- BuildContext context, {
- required IconData icon,
- required String title,
- required String subtitle,
- required Color color,
- required List<Color> gradient,
- required VoidCallback onTap,
- }) {
- return Material(
- color: Colors.transparent,
- child: InkWell(
- onTap: onTap,
- borderRadius: BorderRadius.circular(16),
- child: Container(
- padding: const EdgeInsets.all(24),
- decoration: BoxDecoration(
- gradient: LinearGradient(
- begin: Alignment.topLeft,
- end: Alignment.bottomRight,
- colors: [
- ...gradient.map((c) => c.withOpacity(0.1)),
- Colors.white,
- ],
- ),
- borderRadius: BorderRadius.circular(16),
- border: Border.all(
- color: color.withOpacity(0.2),
- width: 1,
- ),
- boxShadow: [
- BoxShadow(
- color: color.withOpacity(0.1),
- blurRadius: 12,
- offset: const Offset(0, 4),
- ),
- ],
- ),
- child: Column(
- crossAxisAlignment: CrossAxisAlignment.start,
- mainAxisSize: MainAxisSize.min,
- children: [
- Container(
- padding: const EdgeInsets.all(12),
- decoration: BoxDecoration(
- gradient: LinearGradient(colors: gradient),
- borderRadius: BorderRadius.circular(12),
- boxShadow: [
- BoxShadow(
- color: color.withOpacity(0.3),
- blurRadius: 8,
- offset: const Offset(0, 2),
- ),
- ],
- ),
- child: Icon(icon, color: Colors.white, size: 24),
- ),
- const SizedBox(height: 16),
- Text(
- title,
- style: const TextStyle(
- fontSize: 18,
- fontWeight: FontWeight.bold,
- color: AppColors.textPrimary,
- ),
- ),
- const SizedBox(height: 6),
- Text(
- subtitle,
- style: TextStyle(
- fontSize: 13,
- color: AppColors.textSecondary,
- height: 1.4,
- ),
- ),
- const SizedBox(height: 12),
- Row(
- children: [
- Text(
- '立即使用',
- style: TextStyle(
- fontSize: 13,
- fontWeight: FontWeight.w600,
- color: color,
- ),
- ),
- const SizedBox(width: 4),
- Icon(
- LucideIcons.arrow_right,
- size: 14,
- color: color,
- ),
- ],
- ),
- ],
- ),
- ),
- ),
- );
- }
- Widget _buildRecentDocuments(BuildContext context) {
- return Consumer<DocumentProvider>(
- builder: (context, provider, child) {
- final recentDocs = provider.documents.take(6).toList();
- return Column(
- crossAxisAlignment: CrossAxisAlignment.start,
- children: [
- Row(
- mainAxisAlignment: MainAxisAlignment.spaceBetween,
- children: [
- const Text(
- '最近文档',
- style: TextStyle(
- fontSize: 24,
- fontWeight: FontWeight.bold,
- color: AppColors.textPrimary,
- ),
- ),
- TextButton.icon(
- onPressed: () {},
- icon: const Icon(LucideIcons.arrow_right, size: 16),
- label: const Text('查看全部'),
- style: TextButton.styleFrom(
- foregroundColor: AppColors.primary,
- ),
- ),
- ],
- ),
- const SizedBox(height: 20),
- recentDocs.isEmpty
- ? Container(
- padding: const EdgeInsets.all(48),
- decoration: BoxDecoration(
- color: AppColors.backgroundLight,
- borderRadius: BorderRadius.circular(16),
- border: Border.all(color: AppColors.border),
- ),
- child: Column(
- children: [
- Icon(
- LucideIcons.file_x,
- size: 64,
- color: AppColors.textSecondary.withOpacity(0.5),
- ),
- const SizedBox(height: 16),
- Text(
- '暂无文档',
- style: TextStyle(
- fontSize: 16,
- color: AppColors.textSecondary,
- fontWeight: FontWeight.w500,
- ),
- ),
- const SizedBox(height: 8),
- Text(
- '上传您的第一个文档开始使用',
- style: TextStyle(
- fontSize: 14,
- color: AppColors.textSecondary.withOpacity(0.7),
- ),
- ),
- const SizedBox(height: 24),
- AppButton(
- text: '上传文档',
- type: ButtonType.primary,
- icon: LucideIcons.upload,
- onPressed: () => context.push(AppRoutes.upload),
- ),
- ],
- ),
- )
- : LayoutBuilder(
- builder: (context, constraints) {
- final width = constraints.maxWidth;
- final crossAxisCount = width > 1200
- ? 4
- : width > 900
- ? 3
- : width > 600
- ? 2
- : 1;
- return GridView.builder(
- shrinkWrap: true,
- physics: const NeverScrollableScrollPhysics(),
- gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
- crossAxisCount: crossAxisCount,
- crossAxisSpacing: 16,
- mainAxisSpacing: 16,
- childAspectRatio: crossAxisCount == 1 ? 2.4 : 1.6,
- ),
- itemCount: recentDocs.length,
- itemBuilder: (context, index) {
- final doc = recentDocs[index];
- return _buildDocumentCard(context, doc);
- },
- );
- },
- ),
- ],
- );
- },
- );
- }
- Widget _buildDocumentCard(BuildContext context, Document doc) {
- return Material(
- color: Colors.transparent,
- child: InkWell(
- onTap: () {
- if (doc.status == DocumentStatus.completed) {
- context.push('${AppRoutes.parse}/${doc.id}');
- }
- },
- borderRadius: BorderRadius.circular(16),
- child: Container(
- padding: const EdgeInsets.all(20),
- decoration: BoxDecoration(
- color: Colors.white,
- borderRadius: BorderRadius.circular(16),
- border: Border.all(
- color: _getStatusColor(doc.status).withOpacity(0.2),
- width: 1,
- ),
- boxShadow: [
- BoxShadow(
- color: Colors.black.withOpacity(0.04),
- blurRadius: 12,
- offset: const Offset(0, 4),
- ),
- ],
- ),
- child: Column(
- crossAxisAlignment: CrossAxisAlignment.start,
- children: [
- Row(
- mainAxisAlignment: MainAxisAlignment.spaceBetween,
- children: [
- Container(
- padding: const EdgeInsets.all(8),
- decoration: BoxDecoration(
- color: _getStatusColor(doc.status).withOpacity(0.1),
- borderRadius: BorderRadius.circular(8),
- ),
- child: Icon(
- _getDocumentIcon(doc.type),
- color: _getStatusColor(doc.status),
- size: 20,
- ),
- ),
- Container(
- padding: const EdgeInsets.symmetric(
- horizontal: 8,
- vertical: 4,
- ),
- decoration: BoxDecoration(
- color: _getStatusColor(doc.status).withOpacity(0.1),
- borderRadius: BorderRadius.circular(6),
- ),
- child: Text(
- doc.status.label,
- style: TextStyle(
- fontSize: 11,
- fontWeight: FontWeight.w600,
- color: _getStatusColor(doc.status),
- ),
- ),
- ),
- ],
- ),
- Expanded(child: Container(),),
- Text(
- doc.name,
- style: const TextStyle(
- fontSize: 15,
- fontWeight: FontWeight.w600,
- color: AppColors.textPrimary,
- height: 1.3,
- ),
- maxLines: 2,
- overflow: TextOverflow.ellipsis,
- ),
- const SizedBox(height: 8),
- Row(
- children: [
- Icon(
- LucideIcons.file_text,
- size: 12,
- color: AppColors.textSecondary,
- ),
- const SizedBox(width: 4),
- Text(
- doc.formattedFileSize,
- style: TextStyle(
- fontSize: 12,
- color: AppColors.textSecondary,
- ),
- ),
- const SizedBox(width: 12),
- Icon(
- LucideIcons.clock,
- size: 12,
- color: AppColors.textSecondary,
- ),
- const SizedBox(width: 4),
- Text(
- _formatDate(doc.createdAt),
- style: TextStyle(
- fontSize: 12,
- color: AppColors.textSecondary,
- ),
- ),
- ],
- ),
- ],
- ),
- ),
- ),
- );
- }
- String _formatDate(DateTime date) {
- final now = DateTime.now();
- final diff = now.difference(date);
- if (diff.inDays > 7) {
- return '${date.month}/${date.day}';
- } else if (diff.inDays > 0) {
- return '${diff.inDays}天前';
- } else if (diff.inHours > 0) {
- return '${diff.inHours}小时前';
- } else if (diff.inMinutes > 0) {
- return '${diff.inMinutes}分钟前';
- } else {
- return '刚刚';
- }
- }
- IconData _getDocumentIcon(DocumentType type) {
- switch (type) {
- case DocumentType.pdf:
- return LucideIcons.file_text;
- case DocumentType.word:
- return LucideIcons.file_text;
- case DocumentType.image:
- return LucideIcons.image;
- default:
- return LucideIcons.file;
- }
- }
- Color _getStatusColor(DocumentStatus status) {
- switch (status) {
- case DocumentStatus.completed:
- return AppColors.success;
- case DocumentStatus.processing:
- case DocumentStatus.parsing:
- return AppColors.warning;
- case DocumentStatus.failed:
- return AppColors.error;
- default:
- return AppColors.textSecondary;
- }
- }
- }
|