noticeDetail.vue 11 KB

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