index.vue 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368
  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" @timeChange="handleTimeChange" @searchChange="handleSearchChange"></notice-header>
  5. <view class="notice_content">
  6. <view class="notice_list">
  7. <scroll-view scroll-y v-for="item in noticeList" :key="item.id" class="notice_item">
  8. <!-- 通知内容 -->
  9. <view class="item_content">
  10. <view class="notice_title_row">
  11. <image class="notice_icon" :src="item.icon" mode="aspectFit"></image>
  12. <text class="notice_title">{{ item.title }}</text>
  13. </view>
  14. <view class="notice_meta">
  15. <view class="status_tag" :class="item.statusClass">
  16. <text>{{ item.status }}</text>
  17. </view>
  18. <text class="meta_text">{{ item.category }}</text>
  19. <text class="meta_text">{{ item.department }}</text>
  20. <text class="meta_text">{{ item.time }}</text>
  21. </view>
  22. </view>
  23. <!-- 通知底部 -->
  24. <view class="item_bottom">
  25. <view class="notice_stats">
  26. <text class="stats_text">已读: {{ item.readCount }}人</text>
  27. <text class="stats_text">未读: {{ item.unreadCount }}人</text>
  28. </view>
  29. <view class="notice_actions">
  30. <view class="action_btn " :class="getDeleteClass(item)" @click="handleDelete(item.id)">
  31. <text>删除</text>
  32. </view>
  33. <view class="action_btn edit"
  34. @click="handleEdit(item.id)">
  35. <text>编辑</text>
  36. </view>
  37. <view class="action_btn detail"
  38. @click="handleDetail(item.id)">
  39. <text>详情</text>
  40. </view>
  41. </view>
  42. </view>
  43. </scroll-view>
  44. <no-data v-if="noticeList.length === 0" text="暂无通知" />
  45. </view>
  46. </view>
  47. <common-tabbar></common-tabbar>
  48. <ConfirmModal
  49. :visible="showDeleteModal"
  50. title="提示"
  51. content="确定要删除该通知吗?"
  52. cancelText="取消"
  53. confirmText="确定"
  54. @cancel="closeDeleteModal"
  55. @confirm="confirmDelete"
  56. ></ConfirmModal>
  57. </view>
  58. </template>
  59. <script setup>
  60. import { ref } from 'vue';
  61. import { onShow } from '@dcloudio/uni-app';
  62. import NoticeHeader from '@/components/notice-header.vue';
  63. import ConfirmModal from '@/components/confirm-modal.vue';
  64. import overviewApi from '@/reqApi/overview.js';
  65. import store from '@/store/index.js';
  66. import NoData from '@/components/no-data.vue';
  67. const tabs = ['全部', '待发布', '已发布', '已关闭'];
  68. const activeTab = ref(-1);
  69. const typeId = ref('0');
  70. const timeType = ref(0);
  71. const word = ref('');
  72. const noticeList = ref([]);
  73. const showDeleteModal = ref(false);
  74. const deleteId = ref(null);
  75. const statusMap = {
  76. 0: '待发布',
  77. 1: '已发布',
  78. 2: '已关闭'
  79. };
  80. const statusClassMap = {
  81. 0: 'status-pending',
  82. 1: 'status-published',
  83. 2: 'status-closed'
  84. };
  85. const fetchNoticeList = async () => {
  86. try {
  87. const params = {
  88. noticeStatus: activeTab.value,
  89. pageParam: {
  90. pageNum: 1,
  91. pageSize: 9999
  92. },
  93. typeId: typeId.value,
  94. timeType: timeType.value,
  95. word: word.value
  96. };
  97. const res = await overviewApi.noticesPage(params);
  98. if (res.data && res.data.records) {
  99. noticeList.value = res.data.records.map(item => ({
  100. id: item.id,
  101. title: item.noticeName,
  102. status: statusMap[item.noticeStatus],
  103. noticeStatus: item.noticeStatus,
  104. statusClass: statusClassMap[item.noticeStatus],
  105. category: item.typeName,
  106. department: item.createTeacherName,
  107. time: item.releaseTime,
  108. readCount: item.readNum,
  109. unreadCount: item.unReadNum,
  110. icon: '/static/image/todo/xiaoxi.png'
  111. }));
  112. }else{
  113. noticeList.value = [];
  114. }
  115. } catch (error) {
  116. console.error('获取通知列表失败:', error);
  117. }
  118. };
  119. onShow(() => {
  120. fetchNoticeList();
  121. });
  122. const handleTabChange = (status) => {
  123. activeTab.value = status;
  124. fetchNoticeList();
  125. };
  126. const handleTypeChange = (id) => {
  127. typeId.value = id;
  128. fetchNoticeList();
  129. };
  130. const handleTimeChange = (time) => {
  131. timeType.value = time;
  132. fetchNoticeList();
  133. };
  134. const handleSearchChange = (searchWord) => {
  135. word.value = searchWord;
  136. fetchNoticeList();
  137. };
  138. const getDeleteClass = (item) => {
  139. if (item.noticeStatus !== 2) {
  140. return 'delete disabled';
  141. }
  142. return 'delete ';
  143. };
  144. const handleDelete = (id) => {
  145. const item = noticeList.value.find(item => item.id === id);
  146. if (item && item.noticeStatus !== 2) {
  147. return;
  148. }
  149. deleteId.value = id;
  150. showDeleteModal.value = true;
  151. };
  152. const closeDeleteModal = () => {
  153. showDeleteModal.value = false;
  154. deleteId.value = null;
  155. };
  156. const confirmDelete = async () => {
  157. if (!deleteId.value) {
  158. closeDeleteModal();
  159. return;
  160. }
  161. try {
  162. await overviewApi.delete_notices({ id: deleteId.value });
  163. noticeList.value = noticeList.value.filter(item => item.id !== deleteId.value);
  164. uni.showToast({ title: '删除成功', icon: 'success' });
  165. } catch (error) {
  166. uni.showToast({ title: '删除失败', icon: 'none' });
  167. }
  168. closeDeleteModal();
  169. };
  170. const handleEdit = (id) => {
  171. const item = noticeList.value.find(item => item.id === id);
  172. uni.navigateTo({ url: `/pages/notice/publish/index?id=${id}` });
  173. };
  174. const handleDetail = (id) => {
  175. const item = noticeList.value.find(item => item.id === id);
  176. if (item && item.status === '待发布') {
  177. uni.showToast({ title: '待发布通知暂无法查看详情', icon: 'none' });
  178. return;
  179. }
  180. const itemStr = encodeURIComponent(JSON.stringify(item));
  181. uni.navigateTo({ url: `/pages/notice/overview/noticeDetail?id=${id}&item=${itemStr}` });
  182. };
  183. </script>
  184. <style lang="scss">
  185. .page_notice {
  186. // min-height: 100vh;
  187. // background-color: #F5F5F5;
  188. }
  189. .notice_content {
  190. padding-top: 325rpx;
  191. // background-color: #000;
  192. padding-bottom: 104px;
  193. }
  194. .notice_list {
  195. padding: 0rpx 24rpx;
  196. box-sizing: border-box;
  197. // flex: 1;
  198. // overflow-y: auto;
  199. }
  200. .notice_item {
  201. background-color: #F9FAFF;
  202. border-radius: 20rpx;
  203. // padding: 24rpx;
  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>