index.vue 8.6 KB

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