announcement_list_controller.dart 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. import 'package:flutter_riverpod/flutter_riverpod.dart';
  2. import '../../core/auth/role_provider.dart';
  3. import 'announcement_model.dart';
  4. final mockAnnouncements = <AnnouncementModel>[
  5. AnnouncementModel(
  6. id: 'ann-001',
  7. title: '关于2026年端午节放假安排的通知',
  8. content:
  9. '根据国务院办公厅通知精神,现将2026年端午节放假安排通知如下:6月25日(星期四)至6月27日(星期六)放假调休,共3天。6月28日(星期日)上班。请各部门提前做好工作安排,确保节日期间各项工作正常运转。',
  10. type: 'activity',
  11. publisherId: 'u-admin',
  12. publisherName: '行政管理部',
  13. publishTime: DateTime(2026, 5, 22, 10, 0),
  14. isTop: true,
  15. expiryDate: DateTime(2026, 6, 28),
  16. readCount: 45,
  17. unreadCount: 12,
  18. isRead: false,
  19. attachments: ['放假安排表.pdf'],
  20. createTime: DateTime(2026, 5, 22, 10, 0),
  21. ),
  22. AnnouncementModel(
  23. id: 'ann-002',
  24. title: '关于启用新版考勤系统的通知',
  25. content:
  26. '为提升考勤管理效率,公司决定于2026年6月1日起全面启用新版考勤系统。新旧系统切换期间,请各部门配合完成以下事项:1. 5月28日前完成全员信息核对;2. 5月29日-31日进行系统试运行。如有问题请及时联系IT部门。',
  27. type: 'notice',
  28. publisherId: 'u-admin',
  29. publisherName: '信息技术部',
  30. publishTime: DateTime(2026, 5, 20, 14, 0),
  31. isTop: false,
  32. expiryDate: DateTime(2026, 6, 15),
  33. readCount: 30,
  34. unreadCount: 27,
  35. isRead: true,
  36. attachments: ['新版考勤系统操作手册.pdf', '考勤系统FAQ.docx'],
  37. createTime: DateTime(2026, 5, 20, 14, 0),
  38. ),
  39. AnnouncementModel(
  40. id: 'ann-003',
  41. title: '2026年第二季度团建活动报名通知',
  42. content:
  43. '为增强团队凝聚力,公司将于2026年6月10日组织第二季度团建活动。本次活动地点为北京市怀柔区雁栖湖,活动内容包括户外拓展训练、团队协作游戏和烧烤晚会。请各部门于6月3日前将参加人数报至行政管理部。',
  44. type: 'activity',
  45. publisherId: 'u-admin',
  46. publisherName: '行政管理部',
  47. publishTime: DateTime(2026, 5, 18, 9, 0),
  48. isTop: false,
  49. expiryDate: DateTime(2026, 6, 10),
  50. readCount: 52,
  51. unreadCount: 5,
  52. isRead: false,
  53. createTime: DateTime(2026, 5, 18, 9, 0),
  54. ),
  55. AnnouncementModel(
  56. id: 'ann-004',
  57. title: '员工绩效考核管理办法(2026年修订)',
  58. content:
  59. '为进一步完善公司绩效考核体系,人力资源部对原《员工绩效考核管理办法》进行了修订。主要修订内容包括:1. 考核周期由季度调整为月度;2. 新增OKR考核维度;3. 明确绩效评级比例分布。新办法自2026年7月1日起施行。',
  60. type: 'policy',
  61. publisherId: 'u-admin',
  62. publisherName: '人力资源部',
  63. publishTime: DateTime(2026, 5, 15, 11, 0),
  64. isTop: false,
  65. expiryDate: DateTime(2027, 5, 15),
  66. readCount: 38,
  67. unreadCount: 19,
  68. isRead: true,
  69. attachments: ['绩效考核管理办法(2026修订稿).pdf'],
  70. createTime: DateTime(2026, 5, 15, 11, 0),
  71. ),
  72. AnnouncementModel(
  73. id: 'ann-005',
  74. title: '关于办公区域禁止吸烟的再次通知',
  75. content: '公司办公区域全面禁止吸烟,请各位同事严格遵守。吸烟区设在大楼一层室外指定区域。违反规定者将按公司纪律条例处理。',
  76. type: 'notice',
  77. publisherId: 'u-admin',
  78. publisherName: '行政管理部',
  79. publishTime: DateTime(2026, 5, 10, 8, 30),
  80. isTop: false,
  81. expiryDate: DateTime(2026, 4, 10),
  82. readCount: 60,
  83. unreadCount: 0,
  84. isRead: true,
  85. createTime: DateTime(2026, 5, 10, 8, 30),
  86. ),
  87. AnnouncementModel(
  88. id: 'ann-006',
  89. title: '关于差旅报销标准调整的通知(草稿)',
  90. content: '根据公司财务管理制度,拟对差旅报销标准进行调整,现面向全体员工征求意见。',
  91. type: 'notice',
  92. status: 'draft',
  93. publisherId: 'u-admin',
  94. publisherName: '财务部',
  95. publishTime: DateTime(2026, 6, 1, 10, 0),
  96. isTop: false,
  97. readCount: 0,
  98. unreadCount: 0,
  99. isRead: true,
  100. createTime: DateTime(2026, 6, 1, 10, 0),
  101. ),
  102. ];
  103. final announcementTabProvider = StateProvider<int>((ref) => 0);
  104. final announcementRefreshProvider = StateProvider<int>((ref) => 0);
  105. final filteredAnnouncementsProvider = FutureProvider
  106. .family<List<AnnouncementModel>, int>((ref, tabIndex) async {
  107. ref.watch(announcementRefreshProvider);
  108. final isAdmin = ref.watch(isAdminProvider);
  109. // 模拟网络延迟,使骨架屏可见
  110. await Future.delayed(const Duration(milliseconds: 1000));
  111. // 管理员专属:我的草稿 Tab
  112. if (isAdmin && tabIndex == 4) {
  113. return mockAnnouncements.where((e) => e.status == 'draft').toList();
  114. }
  115. // 类型筛选
  116. List<AnnouncementModel> list;
  117. switch (tabIndex) {
  118. case 1: // 通知公告
  119. list = mockAnnouncements
  120. .where((e) => e.type == 'notice' && e.status != 'draft')
  121. .toList();
  122. break;
  123. case 2: // 人事与制度
  124. list = mockAnnouncements
  125. .where((e) => e.type == 'policy' && e.status != 'draft')
  126. .toList();
  127. break;
  128. case 3: // 放假与活动
  129. list = mockAnnouncements
  130. .where((e) => e.type == 'activity' && e.status != 'draft')
  131. .toList();
  132. break;
  133. default: // 全部
  134. list = mockAnnouncements.where((e) => e.status != 'draft').toList();
  135. break;
  136. }
  137. // 排序:置顶优先 → 未过期按发布时间倒序 → 已过期置灰(排末尾)
  138. list.sort((a, b) {
  139. // 置顶优先
  140. if (a.isTop != b.isTop) return a.isTop ? -1 : 1;
  141. // 未过期 vs 已过期
  142. final aExpired = a.isExpired;
  143. final bExpired = b.isExpired;
  144. if (aExpired != bExpired) return aExpired ? 1 : -1;
  145. // 按发布时间倒序
  146. return b.publishTime.compareTo(a.publishTime);
  147. });
  148. return list;
  149. });