index.vue 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391
  1. <template>
  2. <view class="page_notice" :style="{paddingTop: statusBarHeight + 352 + 'rpx', paddingBottom: safeAreaBottom + 160 + 'rpx' }">
  3. <notice-header title="校内通知" :showSearch="true" :showFilter="true" :showTabs="true" :tabs="tabs"
  4. :activeTab="activeTab" @tabChange="handleTabChange" @typeChange="handleTypeChange"
  5. @timeChange="handleTimeChange" @searchChange="handleSearchChange"></notice-header>
  6. <view class="notice_content">
  7. <view class="notice_list">
  8. <scroll-view scroll-y v-for="item in noticeList" :key="item.id" class="notice_item">
  9. <!-- 通知内容 -->
  10. <view class="item_content">
  11. <view class="notice_title_row">
  12. <image class="notice_icon" :src="item.icon" mode="aspectFit"></image>
  13. <text class="notice_title">{{ item.title }}</text>
  14. </view>
  15. <view class="notice_meta">
  16. <view class="status_tag" :class="item.statusClass">
  17. <text>{{ item.status }}</text>
  18. </view>
  19. <text class="meta_text ">{{ truncateText(item.category, 5) }}</text>
  20. <text class="meta_text ">{{ truncateText(item.department, 5) }}</text>
  21. <text class="meta_text">{{ item.time }}</text>
  22. </view>
  23. </view>
  24. <!-- 通知底部 -->
  25. <view class="item_bottom">
  26. <view class="notice_stats">
  27. <text class="stats_text">已读: {{ item.readCount }}人</text>
  28. <text class="stats_text">未读: {{ item.unreadCount }}人</text>
  29. </view>
  30. <view class="notice_actions">
  31. <view class="action_btn " :class="getDeleteClass(item)" @click="handleDelete(item.id)">
  32. <text>删除</text>
  33. </view>
  34. <view class="action_btn edit" @click="handleEdit(item.id)">
  35. <text>编辑</text>
  36. </view>
  37. <view class="action_btn detail" @click="handleDetail(item.id)">
  38. <text>详情</text>
  39. </view>
  40. </view>
  41. </view>
  42. </scroll-view>
  43. <no-data v-if="noticeList.length === 0" centered text="暂无通知" />
  44. </view>
  45. </view>
  46. <common-tabbar></common-tabbar>
  47. <ConfirmModal :visible="showDeleteModal" title="提示" content="确定要删除该通知吗?" cancelText="取消" confirmText="确定"
  48. @cancel="closeDeleteModal" @confirm="confirmDelete"></ConfirmModal>
  49. </view>
  50. </template>
  51. <script setup>
  52. import { ref, onMounted } from 'vue';
  53. import { onShow } from '@dcloudio/uni-app';
  54. import NoticeHeader from '@/components/notice-header.vue';
  55. import ConfirmModal from '@/components/confirm-modal.vue';
  56. import overviewApi from '@/reqApi/overview.js';
  57. import store from '@/store/index.js';
  58. import NoData from '@/components/no-data.vue';
  59. import { useSafeArea } from '@/common/safeArea';
  60. const { statusBarHeight, safeAreaBottom, initSafeArea } = useSafeArea();
  61. const tabs = ['全部', '待发布', '已发布', '已关闭'];
  62. const activeTab = ref(-1);
  63. const typeId = ref('0');
  64. const timeType = ref(0);
  65. const word = ref('');
  66. const noticeList = ref([]);
  67. const showDeleteModal = ref(false);
  68. const deleteId = ref(null);
  69. const statusMap = {
  70. 0: '待发布',
  71. 1: '已发布',
  72. 2: '已关闭'
  73. };
  74. const statusClassMap = {
  75. 0: 'status-pending',
  76. 1: 'status-published',
  77. 2: 'status-closed'
  78. };
  79. const fetchNoticeList = async () => {
  80. try {
  81. const params = {
  82. noticeStatus: activeTab.value,
  83. pageParam: {
  84. pageNum: 1,
  85. pageSize: 9999
  86. },
  87. typeId: typeId.value,
  88. timeType: timeType.value,
  89. word: word.value
  90. };
  91. const res = await overviewApi.noticesPage(params);
  92. if (res.data && res.data.records) {
  93. noticeList.value = res.data.records.map(item => ({
  94. id: item.id,
  95. title: item.noticeName,
  96. status: statusMap[item.noticeStatus],
  97. noticeStatus: item.noticeStatus,
  98. statusClass: statusClassMap[item.noticeStatus],
  99. category: item.typeName,
  100. department: item.createTeacherName,
  101. time: item.releaseTime,
  102. readCount: item.readNum,
  103. unreadCount: item.unReadNum,
  104. icon: '/static/image/todo/xiaoxi.png'
  105. }));
  106. } else {
  107. noticeList.value = [];
  108. }
  109. } catch (error) {
  110. console.error('获取通知列表失败:', error);
  111. }
  112. };
  113. onMounted(() => {
  114. initSafeArea();
  115. });
  116. onShow(() => {
  117. fetchNoticeList();
  118. });
  119. const handleTabChange = (status) => {
  120. activeTab.value = status;
  121. fetchNoticeList();
  122. };
  123. const handleTypeChange = (id) => {
  124. typeId.value = id;
  125. fetchNoticeList();
  126. };
  127. const handleTimeChange = (time) => {
  128. timeType.value = time;
  129. fetchNoticeList();
  130. };
  131. const handleSearchChange = (searchWord) => {
  132. word.value = searchWord;
  133. fetchNoticeList();
  134. };
  135. const getDeleteClass = (item) => {
  136. if (item.noticeStatus !== 2) {
  137. return 'delete disabled';
  138. }
  139. return 'delete ';
  140. };
  141. const truncateText = (text, maxLength) => {
  142. if (!text) return '';
  143. if (text.length > maxLength) {
  144. return text.substring(0, maxLength) + '...';
  145. }
  146. return text;
  147. };
  148. const handleDelete = (id) => {
  149. const item = noticeList.value.find(item => item.id === id);
  150. if (item && item.noticeStatus !== 2) {
  151. return;
  152. }
  153. deleteId.value = id;
  154. showDeleteModal.value = true;
  155. };
  156. const closeDeleteModal = () => {
  157. showDeleteModal.value = false;
  158. deleteId.value = null;
  159. };
  160. const confirmDelete = async () => {
  161. if (!deleteId.value) {
  162. closeDeleteModal();
  163. return;
  164. }
  165. try {
  166. await overviewApi.delete_notices({ id: deleteId.value });
  167. noticeList.value = noticeList.value.filter(item => item.id !== deleteId.value);
  168. uni.showToast({ title: '删除成功', icon: 'success' });
  169. } catch (error) {
  170. uni.showToast({ title: '删除失败', icon: 'none' });
  171. }
  172. closeDeleteModal();
  173. };
  174. const handleEdit = (id) => {
  175. const item = noticeList.value.find(item => item.id === id);
  176. if (item) {
  177. uni.setStorageSync('editNoticeData', JSON.stringify(item));
  178. }
  179. uni.navigateTo({ url: `/pages/notice/publish/index?id=${id}` });
  180. };
  181. const handleDetail = (id) => {
  182. const item = noticeList.value.find(item => item.id === id);
  183. if (item) {
  184. uni.setStorageSync('detailNoticeData', JSON.stringify(item));
  185. }
  186. if (item && item.status === '待发布') {
  187. uni.showToast({ title: '待发布通知暂无法查看详情', icon: 'none' });
  188. return;
  189. }
  190. uni.navigateTo({ url: `/pages/notice/overview/noticeDetail?id=${id}` });
  191. };
  192. </script>
  193. <style lang="scss">
  194. .page_notice {
  195. min-height: 100vh;
  196. display: flex;
  197. flex-direction: column;
  198. background-color: #FFFFFF;
  199. box-sizing: border-box;
  200. }
  201. .notice_content {
  202. flex: 1;
  203. display: flex;
  204. flex-direction: column;
  205. overflow: hidden;
  206. padding-left: 0rpx;
  207. padding-right: 0rpx;
  208. }
  209. .notice_list {
  210. flex: 1;
  211. overflow-y: auto;
  212. overflow-x: hidden;
  213. padding: 0 24rpx;
  214. display: flex;
  215. flex-direction: column;
  216. }
  217. .notice_item {
  218. background-color: #F9FAFF;
  219. border-radius: 20rpx;
  220. margin-bottom: 24rpx;
  221. border: 2rpx solid #E4E7ED;
  222. .item_content {
  223. padding: 24rpx;
  224. .notice_title_row {
  225. display: flex;
  226. align-items: center;
  227. margin-bottom: 16rpx;
  228. .notice_icon {
  229. width: 32rpx;
  230. height: 32rpx;
  231. margin-right: 16rpx;
  232. }
  233. .notice_title {
  234. flex: 1;
  235. font-weight: 500;
  236. font-size: 28rpx;
  237. color: #333333;
  238. overflow: hidden;
  239. text-overflow: ellipsis;
  240. white-space: nowrap;
  241. }
  242. }
  243. .notice_meta {
  244. display: flex;
  245. align-items: center;
  246. flex-wrap: wrap;
  247. gap: 16rpx;
  248. .status_tag {
  249. font-size: 24rpx;
  250. height: 48rpx;
  251. width: 96rpx;
  252. text-align: center;
  253. line-height: 48rpx;
  254. border-radius: 4rpx;
  255. font-weight: 400;
  256. border-radius: 8rpx;
  257. &.status-pending {
  258. background: rgba(46, 100, 250, 0.1);
  259. color: #2E64FA;
  260. }
  261. &.status-published {
  262. background: rgba(82, 196, 26, 0.1);
  263. color: #2BC644;
  264. }
  265. &.status-closed {
  266. background: rgba(245, 108, 108, 0.1);
  267. color: #F56C6C;
  268. }
  269. }
  270. .meta_text {
  271. font-size: 24rpx;
  272. color: #999999;
  273. line-height: 48rpx;
  274. }
  275. }
  276. }
  277. .item_bottom {
  278. border-top: 2rpx solid #E4E7ED;
  279. display: flex;
  280. flex-direction: row;
  281. justify-content: space-between;
  282. align-items: center;
  283. padding: 24rpx 16rpx;
  284. .notice_stats {
  285. display: flex;
  286. .stats_text {
  287. font-size: 24rpx;
  288. color: #999999;
  289. &:first-child {
  290. margin-right: 32rpx;
  291. }
  292. }
  293. }
  294. .notice_actions {
  295. display: flex;
  296. justify-content: flex-end;
  297. gap: 16rpx;
  298. .action_btn {
  299. font-size: 24rpx;
  300. padding: 12rpx 24rpx;
  301. border-radius: 8rpx;
  302. border: 2rpx solid transparent;
  303. &.delete {
  304. border-color: #F56C6C;
  305. color: #F56C6C;
  306. background-color: #FFFFFF;
  307. &.disabled {
  308. border-color: #C0C4CC;
  309. color: #C0C4CC;
  310. background-color: #FFFFFF;
  311. }
  312. }
  313. &.edit {
  314. border-color: #2E64FA;
  315. color: #2E64FA;
  316. background-color: #FFFFFF;
  317. &.disabled {
  318. border-color: #C0C4CC;
  319. color: #C0C4CC;
  320. background-color: #FFFFFF;
  321. }
  322. }
  323. &.detail {
  324. background-color: #2E64FA;
  325. color: #FFFFFF;
  326. &.disabled {
  327. border-color: #C0C4CC;
  328. color: #C0C4CC;
  329. background-color: #FFFFFF;
  330. }
  331. }
  332. }
  333. }
  334. }
  335. &:last-child {
  336. margin-bottom: 0;
  337. }
  338. }
  339. </style>