announcement_list_controller.dart 5.7 KB

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