index.vue 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372
  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. padding-bottom: env(safe-area-inset-bottom);
  183. box-sizing: border-box;
  184. }
  185. .notice_content {
  186. flex: 1;
  187. display: flex;
  188. flex-direction: column;
  189. overflow: hidden;
  190. padding-top: calc(325rpx + env(safe-area-inset-top));
  191. padding-bottom: calc(208rpx + env(safe-area-inset-bottom));
  192. padding-left: 0rpx;
  193. padding-right: 0rpx;
  194. }
  195. .notice_list {
  196. flex: 1;
  197. overflow-y: auto;
  198. overflow-x: hidden;
  199. padding: 0 24rpx;
  200. }
  201. .notice_item {
  202. background-color: #F9FAFF;
  203. border-radius: 20rpx;
  204. margin-bottom: 24rpx;
  205. border: 2rpx solid #E4E7ED;
  206. .item_content {
  207. padding: 24rpx;
  208. .notice_title_row {
  209. display: flex;
  210. align-items: center;
  211. margin-bottom: 16rpx;
  212. .notice_icon {
  213. width: 32rpx;
  214. height: 32rpx;
  215. margin-right: 16rpx;
  216. }
  217. .notice_title {
  218. flex: 1;
  219. font-weight: 500;
  220. font-size: 28rpx;
  221. color: #333333;
  222. overflow: hidden;
  223. text-overflow: ellipsis;
  224. white-space: nowrap;
  225. }
  226. }
  227. .notice_meta {
  228. display: flex;
  229. align-items: center;
  230. flex-wrap: wrap;
  231. gap: 16rpx;
  232. .status_tag {
  233. font-size: 24rpx;
  234. height: 48rpx;
  235. width: 96rpx;
  236. text-align: center;
  237. line-height: 48rpx;
  238. border-radius: 4rpx;
  239. font-weight: 400;
  240. border-radius: 8rpx;
  241. &.status-pending {
  242. background: rgba(46, 100, 250, 0.1);
  243. color: #2E64FA;
  244. }
  245. &.status-published {
  246. background: rgba(82, 196, 26, 0.1);
  247. color: #2BC644;
  248. }
  249. &.status-closed {
  250. background: rgba(245, 108, 108, 0.1);
  251. color: #F56C6C;
  252. }
  253. }
  254. .meta_text {
  255. font-size: 24rpx;
  256. color: #999999;
  257. line-height: 48rpx;
  258. }
  259. }
  260. }
  261. .item_bottom {
  262. border-top: 2rpx solid #E4E7ED;
  263. display: flex;
  264. flex-direction: row;
  265. justify-content: space-between;
  266. align-items: center;
  267. padding: 24rpx 16rpx;
  268. .notice_stats {
  269. display: flex;
  270. .stats_text {
  271. font-size: 24rpx;
  272. color: #999999;
  273. &:first-child {
  274. margin-right: 32rpx;
  275. }
  276. }
  277. }
  278. .notice_actions {
  279. display: flex;
  280. justify-content: flex-end;
  281. gap: 16rpx;
  282. .action_btn {
  283. font-size: 24rpx;
  284. padding: 12rpx 24rpx;
  285. border-radius: 8rpx;
  286. border: 2rpx solid transparent;
  287. &.delete {
  288. border-color: #F56C6C;
  289. color: #F56C6C;
  290. background-color: #FFFFFF;
  291. &.disabled {
  292. border-color: #C0C4CC;
  293. color: #C0C4CC;
  294. background-color: #FFFFFF;
  295. }
  296. }
  297. &.edit {
  298. border-color: #2E64FA;
  299. color: #2E64FA;
  300. background-color: #FFFFFF;
  301. &.disabled {
  302. border-color: #C0C4CC;
  303. color: #C0C4CC;
  304. background-color: #FFFFFF;
  305. }
  306. }
  307. &.detail {
  308. background-color: #2E64FA;
  309. color: #FFFFFF;
  310. &.disabled {
  311. border-color: #C0C4CC;
  312. color: #C0C4CC;
  313. background-color: #FFFFFF;
  314. }
  315. }
  316. }
  317. }
  318. }
  319. &:last-child {
  320. margin-bottom: 0;
  321. }
  322. }
  323. </style>