index.vue 7.5 KB

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