announcement_detail_page.dart 13 KB

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