index.vue 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369
  1. <template>
  2. <view class="page_notice">
  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">{{ item.category }}</text>
  20. <text class="meta_text">{{ item.department }}</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" 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 } 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. const tabs = ['全部', '待发布', '已发布', '已关闭'];
  60. const activeTab = ref(-1);
  61. const typeId = ref('0');
  62. const timeType = ref(0);
  63. const word = ref('');
  64. const noticeList = ref([]);
  65. const showDeleteModal = ref(false);
  66. const deleteId = ref(null);
  67. const statusMap = {
  68. 0: '待发布',
  69. 1: '已发布',
  70. 2: '已关闭'
  71. };
  72. const statusClassMap = {
  73. 0: 'status-pending',
  74. 1: 'status-published',
  75. 2: 'status-closed'
  76. };
  77. const fetchNoticeList = async () => {
  78. try {
  79. const params = {
  80. noticeStatus: activeTab.value,
  81. pageParam: {
  82. pageNum: 1,
  83. pageSize: 9999
  84. },
  85. typeId: typeId.value,
  86. timeType: timeType.value,
  87. word: word.value
  88. };
  89. const res = await overviewApi.noticesPage(params);
  90. if (res.data && res.data.records) {
  91. noticeList.value = res.data.records.map(item => ({
  92. id: item.id,
  93. title: item.noticeName,
  94. status: statusMap[item.noticeStatus],
  95. noticeStatus: item.noticeStatus,
  96. statusClass: statusClassMap[item.noticeStatus],
  97. category: item.typeName,
  98. department: item.createTeacherName,
  99. time: item.releaseTime,
  100. readCount: item.readNum,
  101. unreadCount: item.unReadNum,
  102. icon: '/static/image/todo/xiaoxi.png'
  103. }));
  104. } else {
  105. noticeList.value = [];
  106. }
  107. } catch (error) {
  108. console.error('获取通知列表失败:', error);
  109. }
  110. };
  111. onShow(() => {
  112. fetchNoticeList();
  113. });
  114. const handleTabChange = (status) => {
  115. activeTab.value = status;
  116. fetchNoticeList();
  117. };
  118. const handleTypeChange = (id) => {
  119. typeId.value = id;
  120. fetchNoticeList();
  121. };
  122. const handleTimeChange = (time) => {
  123. timeType.value = time;
  124. fetchNoticeList();
  125. };
  126. const handleSearchChange = (searchWord) => {
  127. word.value = searchWord;
  128. fetchNoticeList();
  129. };
  130. const getDeleteClass = (item) => {
  131. if (item.noticeStatus !== 2) {
  132. return 'delete disabled';
  133. }
  134. return 'delete ';
  135. };
  136. const handleDelete = (id) => {
  137. const item = noticeList.value.find(item => item.id === id);
  138. if (item && item.noticeStatus !== 2) {
  139. return;
  140. }
  141. deleteId.value = id;
  142. showDeleteModal.value = true;
  143. };
  144. const closeDeleteModal = () => {
  145. showDeleteModal.value = false;
  146. deleteId.value = null;
  147. };
  148. const confirmDelete = async () => {
  149. if (!deleteId.value) {
  150. closeDeleteModal();
  151. return;
  152. }
  153. try {
  154. await overviewApi.delete_notices({ id: deleteId.value });
  155. noticeList.value = noticeList.value.filter(item => item.id !== deleteId.value);
  156. uni.showToast({ title: '删除成功', icon: 'success' });
  157. } catch (error) {
  158. uni.showToast({ title: '删除失败', icon: 'none' });
  159. }
  160. closeDeleteModal();
  161. };
  162. const handleEdit = (id) => {
  163. const item = noticeList.value.find(item => item.id === id);
  164. uni.navigateTo({ url: `/pages/notice/publish/index?id=${id}` });
  165. };
  166. const handleDetail = (id) => {
  167. const item = noticeList.value.find(item => item.id === id);
  168. if (item && item.status === '待发布') {
  169. uni.showToast({ title: '待发布通知暂无法查看详情', icon: 'none' });
  170. return;
  171. }
  172. const itemStr = encodeURIComponent(JSON.stringify(item));
  173. uni.navigateTo({ url: `/pages/notice/overview/noticeDetail?id=${id}&item=${itemStr}` });
  174. };
  175. </script>
  176. <style lang="scss">
  177. .page_notice {
  178. height: 100vh;
  179. display: flex;
  180. flex-direction: column;
  181. background-color: #FFFFFF;
  182. }
  183. .notice_content {
  184. flex: 1;
  185. display: flex;
  186. flex-direction: column;
  187. overflow: hidden;
  188. padding: 325rpx 0rpx 104px 0rpx;
  189. }
  190. .notice_list {
  191. flex: 1;
  192. overflow-y: auto;
  193. overflow-x: hidden;
  194. padding: 0 24rpx;
  195. }
  196. .notice_item {
  197. background-color: #F9FAFF;
  198. border-radius: 20rpx;
  199. margin-bottom: 24rpx;
  200. border: 2rpx solid #E4E7ED;
  201. .item_content {
  202. padding: 24rpx;
  203. .notice_title_row {
  204. display: flex;
  205. align-items: center;
  206. margin-bottom: 16rpx;
  207. .notice_icon {
  208. width: 32rpx;
  209. height: 32rpx;
  210. margin-right: 16rpx;
  211. }
  212. .notice_title {
  213. flex: 1;
  214. font-weight: 500;
  215. font-size: 28rpx;
  216. color: #333333;
  217. overflow: hidden;
  218. text-overflow: ellipsis;
  219. white-space: nowrap;
  220. }
  221. }
  222. .notice_meta {
  223. display: flex;
  224. align-items: center;
  225. flex-wrap: wrap;
  226. gap: 16rpx;
  227. .status_tag {
  228. font-size: 24rpx;
  229. height: 48rpx;
  230. width: 96rpx;
  231. text-align: center;
  232. line-height: 48rpx;
  233. border-radius: 4rpx;
  234. font-weight: 400;
  235. border-radius: 8rpx;
  236. &.status-pending {
  237. background: rgba(46, 100, 250, 0.1);
  238. color: #2E64FA;
  239. }
  240. &.status-published {
  241. background: rgba(82, 196, 26, 0.1);
  242. color: #2BC644;
  243. }
  244. &.status-closed {
  245. background: rgba(245, 108, 108, 0.1);
  246. color: #F56C6C;
  247. }
  248. }
  249. .meta_text {
  250. font-size: 24rpx;
  251. color: #999999;
  252. line-height: 48rpx;
  253. }
  254. }
  255. }
  256. .item_bottom {
  257. border-top: 2rpx solid #E4E7ED;
  258. display: flex;
  259. flex-direction: row;
  260. justify-content: space-between;
  261. align-items: center;
  262. padding: 24rpx 16rpx;
  263. .notice_stats {
  264. display: flex;
  265. .stats_text {
  266. font-size: 24rpx;
  267. color: #999999;
  268. &:first-child {
  269. margin-right: 32rpx;
  270. }
  271. }
  272. }
  273. .notice_actions {
  274. display: flex;
  275. justify-content: flex-end;
  276. gap: 16rpx;
  277. .action_btn {
  278. font-size: 24rpx;
  279. padding: 12rpx 24rpx;
  280. border-radius: 8rpx;
  281. border: 2rpx solid transparent;
  282. &.delete {
  283. border-color: #F56C6C;
  284. color: #F56C6C;
  285. background-color: #FFFFFF;
  286. &.disabled {
  287. border-color: #C0C4CC;
  288. color: #C0C4CC;
  289. background-color: #FFFFFF;
  290. }
  291. }
  292. &.edit {
  293. border-color: #2E64FA;
  294. color: #2E64FA;
  295. background-color: #FFFFFF;
  296. &.disabled {
  297. border-color: #C0C4CC;
  298. color: #C0C4CC;
  299. background-color: #FFFFFF;
  300. }
  301. }
  302. &.detail {
  303. background-color: #2E64FA;
  304. color: #FFFFFF;
  305. &.disabled {
  306. border-color: #C0C4CC;
  307. color: #C0C4CC;
  308. background-color: #FFFFFF;
  309. }
  310. }
  311. }
  312. }
  313. }
  314. &:last-child {
  315. margin-bottom: 0;
  316. }
  317. }
  318. </style>