noticeDetail.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499
  1. <template>
  2. <view class="notice_detail">
  3. <view class="detail_header" :style="{ paddingTop: statusBarHeight+64 + 'rpx' }">
  4. <uni-icons type="back" size="24" color="#333333" @click="handleBack"></uni-icons>
  5. <text class="header_title">通知详情</text>
  6. <text class="header_placeholder"></text>
  7. </view>
  8. <view class="detail_content">
  9. <view class="notice_info">
  10. <text class="notice_title">{{ noticeItem.title }}</text>
  11. <view class="notice_meta">
  12. <view class="notice_left">
  13. <text class="meta_item">{{ truncateText(noticeItem.category, 8) }}</text>
  14. <text class="meta_item">{{ truncateText(noticeItem.department, 8) }}</text>
  15. <text class="meta_item">{{ noticeItem.time }}</text>
  16. </view>
  17. <view class="notice_right">
  18. <view class="status_tag" :class="getStatusClass(noticeItem.noticeStatus)">
  19. <text>{{ getStatusText(noticeItem.noticeStatus) }}</text>
  20. </view>
  21. </view>
  22. </view>
  23. </view>
  24. <view class="reader_container">
  25. <view class="tabs_bar">
  26. <view class="tabs_left">
  27. <text v-for="(tab, idx) in tabs" :key="idx" class="tab_item" :class="{ active: activeTab === idx }"
  28. @click="handleTabChange(idx)">
  29. {{ tab }}
  30. </text>
  31. </view>
  32. <view class="search_box">
  33. <image src="/static/image/overview/search.png" class="search_icon"></image>
  34. <input type="text" class="search_input" placeholder="请输入关键字搜索"
  35. placeholder-class="search_placeholder" v-model="searchWord" @input="handleSearch" />
  36. </view>
  37. </view>
  38. <view class="stats_row">
  39. <text class="stats_text">共 {{ readerList.length }} 人</text>
  40. </view>
  41. <scroll-view v-if="filteredReaders.length > 0" scroll-y class="reader_list">
  42. <view v-for="item in filteredReaders" :key="item.id" class="reader_item">
  43. <view class="reader_row reader_row_first">
  44. <text class="reader_name">{{ item.name }}</text>
  45. <view class="read_status" :class="item.readStatus === 1 ? 'read' : 'unread'">
  46. <text>{{ item.readStatus === 1 ? '已读' : '未读' }}</text>
  47. </view>
  48. </view>
  49. <view class="reader_row reader_row_second">
  50. <!-- 部门 -->
  51. <text v-if="item.departmentName" class="reader_detail">{{ item.departmentName }}</text>
  52. <text v-if="item.groupName" class="reader_detail">{{ item.groupName }}</text>
  53. <!-- 班级 -->
  54. <text v-if="item.gradeName" class="reader_detail">{{ item.gradeName }}</text>
  55. <text v-if="item.classTypeName" class="reader_detail">{{ item.classTypeName }}</text>
  56. <text v-if="item.classTypeName" class="reader_detail">{{ item.classTypeName }}</text>
  57. <!-- 科目 -->
  58. <text v-if="item.subjectName" class="reader_detail">{{ item.subjectName }}</text>
  59. <text v-if="item.readTime" class="reader_detail">{{ item.readTime }}</text>
  60. </view>
  61. </view>
  62. </scroll-view>
  63. <no-data v-else centered text="暂无数据" />
  64. </view>
  65. </view>
  66. </view>
  67. </template>
  68. <script setup>
  69. import { ref, computed, onMounted } from 'vue';
  70. import { onLoad } from '@dcloudio/uni-app';
  71. import uniIcons from '@/uni_modules/uni-icons/components/uni-icons/uni-icons.vue';
  72. import overviewApi from '@/reqApi/overview.js';
  73. import NoData from '@/components/no-data.vue';
  74. import { useSafeArea } from '@/common/safeArea';
  75. const { statusBarHeight, safeAreaBottom, initSafeArea } = useSafeArea();
  76. const tabs = ['全部', '已读', '未读'];
  77. const activeTab = ref(0);
  78. const searchWord = ref('');
  79. const noticeItem = ref({
  80. title: '',
  81. category: '',
  82. department: '',
  83. time: '',
  84. noticeStatus: ''
  85. });
  86. const readerList = ref([]);
  87. const noticeId = ref('');
  88. const statusMap = {
  89. 0: '待发布',
  90. 1: '已发布',
  91. 2: '已关闭'
  92. };
  93. const statusClassMap = {
  94. 0: 'status-pending',
  95. 1: 'status-published',
  96. 2: 'status-closed'
  97. };
  98. const getStatusText = (status) => {
  99. return statusMap[status] || '';
  100. };
  101. const getStatusClass = (status) => {
  102. return statusClassMap[status] || '';
  103. };
  104. const truncateText = (text, maxLength) => {
  105. if (!text) return '';
  106. if (text.length > maxLength) {
  107. return text.substring(0, maxLength) + '...';
  108. }
  109. return text;
  110. };
  111. const filteredReaders = computed(() => {
  112. let list = readerList.value;
  113. if (activeTab.value === 1) {
  114. list = list.filter(item => item.readStatus === 1);
  115. } else if (activeTab.value === 2) {
  116. list = list.filter(item => item.readStatus !== 1);
  117. }
  118. if (searchWord.value) {
  119. const keyword = searchWord.value.toLowerCase();
  120. list = list.filter(item => item.name && item.name.toLowerCase().includes(keyword));
  121. }
  122. return list;
  123. });
  124. const loadNoticeData = () => {
  125. try {
  126. const storedData = uni.getStorageSync('detailNoticeData');
  127. if (storedData) {
  128. const item = JSON.parse(storedData);
  129. noticeItem.value = {
  130. title: item.title || '',
  131. category: item.category || '',
  132. department: item.department || '',
  133. time: item.time || '',
  134. noticeStatus: item.noticeStatus
  135. };
  136. noticeId.value = item.id || noticeId.value;
  137. }
  138. } catch (error) {
  139. console.error('读取通知详情数据失败:', error);
  140. }
  141. };
  142. const fetchNoticeInfo = async () => {
  143. if (!noticeId.value) {
  144. return;
  145. }
  146. try {
  147. const res = await overviewApi.notices_edit({ id: noticeId.value });
  148. if (res.data) {
  149. noticeItem.value = {
  150. title: res.data.noticeName || '',
  151. category: res.data.typeName || '',
  152. department: res.data.createTeacherName || '',
  153. time: res.data.releaseTime || '',
  154. noticeStatus: res.data.noticeStatus
  155. };
  156. }
  157. } catch (error) {
  158. console.error('获取通知详情失败:', error);
  159. }
  160. };
  161. const fetchReaderList = async () => {
  162. try {
  163. const readStatusMap = [-1, 1, 0];
  164. const params = {
  165. id: noticeId.value,
  166. pageNum: 1,
  167. pageSize: 20,
  168. readStatus: readStatusMap[activeTab.value],
  169. word: searchWord.value || ''
  170. };
  171. const res = await overviewApi.user_page(params);
  172. if (res.data && res.data.records && res.data.records.length > 0 && res.data.records[0].userList) {
  173. readerList.value = res.data.records[0].userList;
  174. } else {
  175. readerList.value = [];
  176. }
  177. } catch (error) {
  178. console.error('获取读者列表失败:', error);
  179. readerList.value = [];
  180. }
  181. };
  182. const handleSearch = () => {
  183. fetchReaderList();
  184. };
  185. const handleTabChange = (idx) => {
  186. activeTab.value = idx;
  187. fetchReaderList();
  188. };
  189. const handleBack = () => {
  190. const pages = getCurrentPages();
  191. if (pages.length > 1) {
  192. const prevPage = pages[pages.length - 2];
  193. if (prevPage.route === 'pages/notice/overview/index') {
  194. uni.navigateBack();
  195. } else {
  196. uni.redirectTo({ url: '/pages/notice/overview/index' });
  197. }
  198. } else {
  199. uni.redirectTo({ url: '/pages/notice/overview/index' });
  200. }
  201. };
  202. onMounted(() => {
  203. initSafeArea();
  204. });
  205. onLoad((options) => {
  206. // 优先从全局变量读取数据
  207. loadNoticeData();
  208. if (options && options.id) {
  209. noticeId.value = options.id;
  210. }
  211. // 如果没有从全局变量读取到数据,则调用接口获取
  212. if (!noticeItem.value.title) {
  213. fetchNoticeInfo();
  214. }
  215. fetchReaderList();
  216. });
  217. </script>
  218. <style lang="scss" scoped>
  219. .notice_detail {
  220. width: 100%;
  221. height: 100vh;
  222. background-color: #F5F5F5;
  223. display: flex;
  224. flex-direction: column;
  225. position: fixed;
  226. top: 0;
  227. left: 0;
  228. z-index: 1000;
  229. .detail_header {
  230. display: flex;
  231. align-items: center;
  232. justify-content: space-between;
  233. padding-left: 24rpx;
  234. padding-right: 24rpx;
  235. padding-bottom: 24rpx;
  236. background-color: #FFFFFF;
  237. border-bottom: 2rpx solid #F3F3F3;
  238. .header_title {
  239. font-size: 32rpx;
  240. font-weight: 500;
  241. color: #333333;
  242. }
  243. .header_placeholder {
  244. width: 48rpx;
  245. }
  246. }
  247. .detail_content {
  248. flex: 1;
  249. display: flex;
  250. flex-direction: column;
  251. overflow: hidden;
  252. }
  253. .notice_info {
  254. background-color: #FFFFFF;
  255. padding: 32rpx 24rpx;
  256. margin-bottom: 16rpx;
  257. .notice_title {
  258. font-size: 32rpx;
  259. font-weight: 500;
  260. color: #333333;
  261. line-height: 1.5;
  262. display: block;
  263. margin-bottom: 16rpx;
  264. }
  265. .notice_meta {
  266. display: flex;
  267. align-items: center;
  268. justify-content: space-between;
  269. .notice_left {
  270. display: flex;
  271. align-items: center;
  272. gap: 16rpx;
  273. .meta_item {
  274. font-size: 24rpx;
  275. color: #999999;
  276. line-height: 48rpx;
  277. }
  278. }
  279. .notice_right {
  280. .status_tag {
  281. font-size: 24rpx;
  282. height: 48rpx;
  283. width: 96rpx;
  284. text-align: center;
  285. line-height: 48rpx;
  286. border-radius: 8rpx;
  287. font-weight: 400;
  288. &.status-pending {
  289. background: rgba(46, 100, 250, 0.1);
  290. color: #2E64FA;
  291. }
  292. &.status-published {
  293. background: rgba(82, 196, 26, 0.1);
  294. color: #2BC644;
  295. }
  296. &.status-closed {
  297. background: rgba(245, 108, 108, 0.1);
  298. color: #F56C6C;
  299. }
  300. }
  301. }
  302. }
  303. }
  304. .reader_container {
  305. background-color: #FFFFFF;
  306. border-radius: 8rpx;
  307. overflow: hidden;
  308. padding: 24rpx;
  309. flex: 1;
  310. display: flex;
  311. flex-direction: column;
  312. .tabs_bar {
  313. display: flex;
  314. align-items: center;
  315. gap: 48rpx;
  316. // border-bottom: 2rpx solid #EBEEF5;
  317. height: 72rpx;
  318. .tabs_left {
  319. display: flex;
  320. align-items: center;
  321. gap: 48rpx;
  322. .tab_item {
  323. font-size: 28rpx;
  324. color: #999999;
  325. font-weight: 400;
  326. position: relative;
  327. // margin-right: 48rpx;
  328. &.active {
  329. color: #2E64FA;
  330. font-weight: 500;
  331. font-size: 32rpx;
  332. &::after {
  333. content: '';
  334. position: absolute;
  335. bottom: -10rpx;
  336. left: 50%;
  337. transform: translateX(-50%);
  338. width: 64rpx;
  339. height: 4rpx;
  340. background-color: #2E64FA;
  341. // border-radius: 2rpx;
  342. }
  343. }
  344. }
  345. }
  346. .search_box {
  347. flex: 1;
  348. display: flex;
  349. align-items: center;
  350. // background-color: #F5F7FA;
  351. border-radius: 8rpx;
  352. border: 2rpx solid #DCDFE6;
  353. width: 320rpx;
  354. height: 72rpx;
  355. .search_icon {
  356. width: 32rpx;
  357. height: 32rpx;
  358. margin-left: 24rpx;
  359. margin-right: 8rpx;
  360. }
  361. .search_input {
  362. flex: 1;
  363. font-size: 28rpx;
  364. color: #333;
  365. margin-right: 32rpx;
  366. }
  367. .search_placeholder {
  368. color: #C0C4CC;
  369. }
  370. }
  371. }
  372. .stats_row {
  373. // padding: 0 24rpx;
  374. margin-bottom: 16rpx;
  375. margin-top: 24rpx;
  376. .stats_text {
  377. font-weight: 400;
  378. font-size: 28rpx;
  379. color: #333333;
  380. }
  381. }
  382. .reader_list {
  383. flex: 1;
  384. overflow-y: auto;
  385. display: flex;
  386. flex-direction: column;
  387. ::-webkit-scrollbar {
  388. display: none;
  389. }
  390. .reader_item {
  391. border-top: 2rpx solid #F3F3F3;
  392. padding: 24rpx 0;
  393. .reader_row {
  394. display: flex;
  395. align-items: center;
  396. gap: 16rpx;
  397. &.reader_row_first {
  398. justify-content: space-between;
  399. margin-bottom: 16rpx;
  400. }
  401. &.reader_row_second {
  402. flex-wrap: wrap;
  403. height: 34rpx;
  404. line-height: 34rpx;
  405. }
  406. .reader_name {
  407. font-size: 24rpx;
  408. font-weight: 500;
  409. color: #333333;
  410. }
  411. .reader_detail {
  412. font-size: 24rpx;
  413. color: #999999;
  414. }
  415. .read_status {
  416. padding: 8rpx 16rpx;
  417. border-radius: 8rpx;
  418. font-size: 24rpx;
  419. &.read {
  420. background: rgba(82, 196, 26, 0.1);
  421. color: #2BC644;
  422. }
  423. &.unread {
  424. background: rgba(46, 100, 250, 0.1);
  425. color: #2E64FA;
  426. }
  427. }
  428. }
  429. }
  430. }
  431. }
  432. }
  433. </style>