announcement_detail_page.dart 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371
  1. import 'dart:async';
  2. import 'package:flutter/material.dart';
  3. import 'package:tdesign_flutter/tdesign_flutter.dart';
  4. import 'package:go_router/go_router.dart';
  5. import 'package:flutter_riverpod/flutter_riverpod.dart';
  6. import '../shell/nav_bar_config.dart';
  7. import '../../core/utils/date_utils.dart' as du;
  8. import '../../core/i18n/app_localizations.dart';
  9. import 'announcement_list_controller.dart';
  10. import 'announcement_model.dart';
  11. import '../../core/theme/app_colors_extension.dart';
  12. class AnnouncementDetailPage extends ConsumerStatefulWidget {
  13. final String id;
  14. const AnnouncementDetailPage({super.key, required this.id});
  15. @override
  16. ConsumerState<AnnouncementDetailPage> createState() =>
  17. _AnnouncementDetailPageState();
  18. }
  19. class _AnnouncementDetailPageState
  20. extends ConsumerState<AnnouncementDetailPage> {
  21. late AnnouncementModel _item;
  22. final bool _isAdmin = true;
  23. @override
  24. void initState() {
  25. super.initState();
  26. _item = mockAnnouncements.firstWhere(
  27. (e) => e.id == widget.id,
  28. orElse: () => mockAnnouncements.first,
  29. );
  30. // 停留 ≥2s 自动标记已读
  31. Timer(const Duration(seconds: 2), () {
  32. if (mounted) {
  33. TDToast.showText(
  34. '已标记为已读',
  35. context: context,
  36. duration: const Duration(seconds: 1),
  37. );
  38. }
  39. });
  40. }
  41. @override
  42. Widget build(BuildContext context) {
  43. final colors = Theme.of(context).extension<AppColorsExtension>()!;
  44. final l10n = AppLocalizations.of(context);
  45. ref
  46. .read(navBarConfigProvider.notifier)
  47. .update(
  48. NavBarConfig(
  49. title: l10n.get('announcementDetail'),
  50. showBack: true,
  51. onBack: () => context.pop(),
  52. ),
  53. );
  54. _item = mockAnnouncements.firstWhere(
  55. (e) => e.id == widget.id,
  56. orElse: () => mockAnnouncements.first,
  57. );
  58. return SingleChildScrollView(
  59. child: Column(
  60. crossAxisAlignment: CrossAxisAlignment.start,
  61. children: [
  62. // 已过期红色横幅
  63. if (_item.isExpired)
  64. Container(
  65. width: double.infinity,
  66. padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 10),
  67. color: colors.danger,
  68. child: Text(
  69. '该公告已于 ${du.DateUtils.formatDateTime(_item.expiryDate!)} 过期',
  70. style: const TextStyle(fontSize: 13, color: Colors.white),
  71. textAlign: TextAlign.center,
  72. ),
  73. ),
  74. // 红头文件样式标题区
  75. Container(
  76. width: double.infinity,
  77. padding: const EdgeInsets.all(24),
  78. color: colors.bgCard,
  79. child: Column(
  80. crossAxisAlignment: CrossAxisAlignment.start,
  81. children: [
  82. // 红色上划线(红头文件风格)
  83. Container(width: 60, height: 4, color: colors.danger),
  84. const SizedBox(height: 16),
  85. Text(
  86. _item.title,
  87. style: TextStyle(
  88. fontSize: 20,
  89. fontWeight: FontWeight.w700,
  90. color: colors.textPrimary,
  91. height: 1.4,
  92. ),
  93. ),
  94. const SizedBox(height: 12),
  95. Row(
  96. children: [
  97. _buildTypeTag(_item.typeLabel),
  98. const SizedBox(width: 12),
  99. Text(
  100. _item.publisherName,
  101. style: TextStyle(
  102. fontSize: 13,
  103. color: colors.textSecondary,
  104. ),
  105. ),
  106. const SizedBox(width: 12),
  107. Text(
  108. du.DateUtils.formatDateTime(_item.publishTime),
  109. style: TextStyle(
  110. fontSize: 13,
  111. color: colors.textPlaceholder,
  112. ),
  113. ),
  114. ],
  115. ),
  116. ],
  117. ),
  118. ),
  119. Container(width: double.infinity, height: 2, color: colors.danger),
  120. // 正文内容
  121. Padding(
  122. padding: const EdgeInsets.all(16),
  123. child: Container(
  124. width: double.infinity,
  125. padding: const EdgeInsets.all(20),
  126. decoration: BoxDecoration(
  127. color: colors.bgCard,
  128. borderRadius: BorderRadius.circular(8),
  129. ),
  130. child: Column(
  131. crossAxisAlignment: CrossAxisAlignment.start,
  132. children: [
  133. Text(
  134. '各部门、各位同事:',
  135. style: TextStyle(
  136. fontSize: 14,
  137. color: colors.textPrimary,
  138. height: 1.7,
  139. ),
  140. ),
  141. const SizedBox(height: 12),
  142. Text(
  143. _item.content,
  144. style: TextStyle(
  145. fontSize: 14,
  146. color: colors.textSecondary,
  147. height: 1.7,
  148. ),
  149. ),
  150. ],
  151. ),
  152. ),
  153. ),
  154. // 附件列表
  155. if (_item.attachments.isNotEmpty)
  156. Padding(
  157. padding: const EdgeInsets.symmetric(horizontal: 16),
  158. child: Column(
  159. crossAxisAlignment: CrossAxisAlignment.start,
  160. children: [
  161. Text(
  162. '附件下载',
  163. style: TextStyle(
  164. fontSize: 14,
  165. fontWeight: FontWeight.w600,
  166. color: colors.textPrimary,
  167. ),
  168. ),
  169. const SizedBox(height: 8),
  170. ..._item.attachments.map(
  171. (att) => GestureDetector(
  172. onTap: () {
  173. TDToast.showText('模拟下载:$att', context: context);
  174. },
  175. child: Container(
  176. width: double.infinity,
  177. margin: const EdgeInsets.only(bottom: 8),
  178. padding: const EdgeInsets.all(12),
  179. decoration: BoxDecoration(
  180. color: colors.bgCard,
  181. borderRadius: BorderRadius.circular(8),
  182. ),
  183. child: Row(
  184. children: [
  185. Icon(
  186. Icons.description_outlined,
  187. size: 20,
  188. color: colors.primary,
  189. ),
  190. const SizedBox(width: 8),
  191. Expanded(
  192. child: Text(
  193. att,
  194. style: TextStyle(
  195. fontSize: 14,
  196. color: colors.textPrimary,
  197. ),
  198. ),
  199. ),
  200. Text(
  201. '${(att.length * 100) ~/ 1000}KB',
  202. style: TextStyle(
  203. fontSize: 12,
  204. color: colors.textPlaceholder,
  205. ),
  206. ),
  207. const SizedBox(width: 8),
  208. Icon(
  209. Icons.download_outlined,
  210. size: 16,
  211. color: colors.textPlaceholder,
  212. ),
  213. ],
  214. ),
  215. ),
  216. ),
  217. ),
  218. ],
  219. ),
  220. ),
  221. // 管理员增量:已读/未读统计 + DING
  222. if (_isAdmin)
  223. Padding(
  224. padding: const EdgeInsets.all(16),
  225. child: Container(
  226. width: double.infinity,
  227. padding: const EdgeInsets.all(16),
  228. decoration: BoxDecoration(
  229. color: colors.bgCard,
  230. borderRadius: BorderRadius.circular(8),
  231. ),
  232. child: Column(
  233. crossAxisAlignment: CrossAxisAlignment.start,
  234. children: [
  235. Text(
  236. '全员触达率',
  237. style: TextStyle(
  238. fontSize: 14,
  239. fontWeight: FontWeight.w600,
  240. color: colors.textPrimary,
  241. ),
  242. ),
  243. const SizedBox(height: 12),
  244. Row(
  245. children: [
  246. GestureDetector(
  247. onTap: () {
  248. TDToast.showText('模拟:展开已读员工列表', context: context);
  249. },
  250. child: Container(
  251. padding: const EdgeInsets.symmetric(
  252. horizontal: 12,
  253. vertical: 6,
  254. ),
  255. decoration: BoxDecoration(
  256. color: colors.successBg,
  257. borderRadius: BorderRadius.circular(16),
  258. ),
  259. child: Text(
  260. '已读 ${_item.readCount} 人',
  261. style: TextStyle(
  262. fontSize: 12,
  263. color: colors.success,
  264. ),
  265. ),
  266. ),
  267. ),
  268. const SizedBox(width: 12),
  269. GestureDetector(
  270. onTap: () {
  271. TDToast.showText('模拟:展开未读员工列表', context: context);
  272. },
  273. child: Container(
  274. padding: const EdgeInsets.symmetric(
  275. horizontal: 12,
  276. vertical: 6,
  277. ),
  278. decoration: BoxDecoration(
  279. color: colors.bgPage,
  280. borderRadius: BorderRadius.circular(16),
  281. ),
  282. child: Text(
  283. '未读 ${_item.unreadCount} 人',
  284. style: TextStyle(
  285. fontSize: 12,
  286. color: colors.statusGray,
  287. ),
  288. ),
  289. ),
  290. ),
  291. ],
  292. ),
  293. const SizedBox(height: 12),
  294. GestureDetector(
  295. onTap: () {
  296. TDToast.showText(
  297. '已向 ${_item.unreadCount} 名未读员工发送催办通知',
  298. context: context,
  299. );
  300. },
  301. child: Container(
  302. width: double.infinity,
  303. padding: const EdgeInsets.symmetric(
  304. horizontal: 16,
  305. vertical: 12,
  306. ),
  307. decoration: BoxDecoration(
  308. color: colors.danger,
  309. borderRadius: BorderRadius.circular(20),
  310. ),
  311. child: const Text(
  312. 'DING 催办',
  313. textAlign: TextAlign.center,
  314. style: TextStyle(
  315. fontSize: 14,
  316. fontWeight: FontWeight.w600,
  317. color: Colors.white,
  318. ),
  319. ),
  320. ),
  321. ),
  322. ],
  323. ),
  324. ),
  325. ),
  326. const SizedBox(height: 24),
  327. ],
  328. ),
  329. );
  330. }
  331. Widget _buildTypeTag(String type) {
  332. final colors = Theme.of(context).extension<AppColorsExtension>()!;
  333. Color bgColor;
  334. Color textColor;
  335. switch (type) {
  336. case '人事与制度':
  337. bgColor = colors.successBg;
  338. textColor = colors.success;
  339. break;
  340. case '放假与活动':
  341. bgColor = colors.warningBg;
  342. textColor = colors.warning;
  343. break;
  344. default:
  345. bgColor = colors.primaryLight;
  346. textColor = colors.primary;
  347. }
  348. return Container(
  349. padding: const EdgeInsets.symmetric(horizontal: 6, vertical: 2),
  350. decoration: BoxDecoration(
  351. color: bgColor,
  352. borderRadius: BorderRadius.circular(3),
  353. ),
  354. child: Text(type, style: TextStyle(fontSize: 11, color: textColor)),
  355. );
  356. }
  357. }