home_controller.dart 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. import 'package:flutter_riverpod/flutter_riverpod.dart';
  2. /// 系统 Banner 模型
  3. class SysBanner {
  4. final String id;
  5. final String imageUrl;
  6. final String? linkUrl;
  7. final String? title;
  8. const SysBanner({
  9. required this.id,
  10. required this.imageUrl,
  11. this.linkUrl,
  12. this.title,
  13. });
  14. static const mockBanners = [
  15. SysBanner(id: '1', imageUrl: 'assets/img/banner_1.png', title: 'OA系统升级通知'),
  16. SysBanner(
  17. id: '2',
  18. imageUrl: 'assets/img/banner_2.png',
  19. linkUrl: 'https://example.com',
  20. title: '2026年度预算管理',
  21. ),
  22. SysBanner(id: '3', imageUrl: 'assets/img/banner_3.png', title: '端午节放假安排'),
  23. ];
  24. }
  25. /// 工作台首页聚合数据模型
  26. ///
  27. /// 角色权限优先级:admin > finance > manager > employee
  28. /// 数据全部使用 mock,角色从权限派生。
  29. class HomeSummary {
  30. /// 用户角色:admin / finance / manager / employee
  31. final String userRole;
  32. // ── 员工版:个人快捷看板 ──
  33. final double monthlyReimbursement; // 本月累计报销(本人已付款总额 ¥)
  34. final int monthlySubmittedCount; // 本月已提单据(本人提交总数 笔)
  35. // ── 经理版:待审批 + 部门范围 ──
  36. final int pendingApprovalCount; // 待审批数(红色角标)
  37. final double deptMonthlyReimbursement; // 部门本月累计报销
  38. final int deptMonthlySubmittedCount; // 部门本月已提单据
  39. final int deptPendingDocuments; // 部门在途单据
  40. // ── 财务/管理员版 ──
  41. final double paidTotal; // 本月已支付总额
  42. final double pendingPaymentTotal; // 待付款总额
  43. final double abnormalReturns; // 本周异常退回
  44. const HomeSummary({
  45. this.userRole = 'employee',
  46. this.monthlyReimbursement = 0,
  47. this.monthlySubmittedCount = 0,
  48. this.pendingApprovalCount = 0,
  49. this.deptMonthlyReimbursement = 0,
  50. this.deptMonthlySubmittedCount = 0,
  51. this.deptPendingDocuments = 0,
  52. this.paidTotal = 0,
  53. this.pendingPaymentTotal = 0,
  54. this.abnormalReturns = 0,
  55. });
  56. }
  57. /// Banner Provider — 返回模拟 Banner 列表
  58. final bannerProvider = Provider<List<SysBanner>>((ref) {
  59. return SysBanner.mockBanners;
  60. });
  61. /// 首页数据 Provider — 返回模拟 HomeSummary
  62. ///
  63. /// 修改 userRole 可测试不同角色视图:
  64. /// 'employee' → 员工版
  65. /// 'manager' → 经理版
  66. /// 'finance' → 财务版
  67. /// 'admin' → 管理员版
  68. final homeSummaryProvider = FutureProvider<HomeSummary>((ref) async {
  69. return const HomeSummary(
  70. userRole: 'admin',
  71. // 员工版数据
  72. monthlyReimbursement: 12800.50,
  73. monthlySubmittedCount: 8,
  74. // 经理版数据
  75. pendingApprovalCount: 5,
  76. deptMonthlyReimbursement: 156800.00,
  77. deptMonthlySubmittedCount: 42,
  78. deptPendingDocuments: 15,
  79. // 财务/管理员版数据
  80. paidTotal: 896500.00,
  81. pendingPaymentTotal: 283200.50,
  82. abnormalReturns: 12800.00,
  83. );
  84. });