index.vue 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347
  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. if (item && item.status === '已关闭') {
  151. uni.showToast({ title: '已关闭通知无法编辑', icon: 'none' });
  152. return;
  153. }
  154. uni.navigateTo({ url: `/pages/notice/publish/index?id=${id}` });
  155. };
  156. const handleDetail = (id) => {
  157. const item = noticeList.value.find(item => item.id === id);
  158. if (item && item.status === '待发布') {
  159. uni.showToast({ title: '待发布通知暂无法查看详情', icon: 'none' });
  160. return;
  161. }
  162. const itemStr = encodeURIComponent(JSON.stringify(item));
  163. uni.navigateTo({ url: `/pages/notice/overview/noticeDetail?id=${id}&item=${itemStr}` });
  164. };
  165. </script>
  166. <style lang="scss">
  167. .page_notice {
  168. // min-height: 100vh;
  169. // background-color: #F5F5F5;
  170. }
  171. .notice_content {
  172. padding-top: 325rpx;
  173. // background-color: #000;
  174. padding-bottom: 104px;
  175. }
  176. .notice_list {
  177. padding: 0rpx 24rpx;
  178. box-sizing: border-box;
  179. // flex: 1;
  180. // overflow-y: auto;
  181. }
  182. .notice_item {
  183. background-color: #F9FAFF;
  184. border-radius: 20rpx;
  185. // padding: 24rpx;
  186. margin-bottom: 24rpx;
  187. border: 2rpx solid #E4E7ED;
  188. .item_content {
  189. padding: 24rpx;
  190. .notice_title_row {
  191. display: flex;
  192. align-items: center;
  193. margin-bottom: 16rpx;
  194. .notice_icon {
  195. width: 32rpx;
  196. height: 32rpx;
  197. margin-right: 16rpx;
  198. }
  199. .notice_title {
  200. flex: 1;
  201. font-weight: 500;
  202. font-size: 28rpx;
  203. color: #333333;
  204. overflow: hidden;
  205. text-overflow: ellipsis;
  206. white-space: nowrap;
  207. }
  208. }
  209. .notice_meta {
  210. display: flex;
  211. align-items: center;
  212. flex-wrap: wrap;
  213. gap: 16rpx;
  214. .status_tag {
  215. font-size: 24rpx;
  216. height: 48rpx;
  217. width: 96rpx;
  218. text-align: center;
  219. line-height: 48rpx;
  220. border-radius: 4rpx;
  221. font-weight: 400;
  222. border-radius: 8rpx;
  223. &.status-pending {
  224. background: rgba(46, 100, 250, 0.1);
  225. color: #2E64FA;
  226. }
  227. &.status-published {
  228. background: rgba(82, 196, 26, 0.1);
  229. color: #2BC644;
  230. }
  231. &.status-closed {
  232. background: rgba(245, 108, 108, 0.1);
  233. color: #F56C6C;
  234. }
  235. }
  236. .meta_text {
  237. font-size: 24rpx;
  238. color: #999999;
  239. line-height: 48rpx;
  240. }
  241. }
  242. }
  243. .item_bottom {
  244. border-top: 2rpx solid #E4E7ED;
  245. display: flex;
  246. flex-direction: row;
  247. justify-content: space-between;
  248. align-items: center;
  249. padding: 24rpx 16rpx;
  250. .notice_stats {
  251. display: flex;
  252. .stats_text {
  253. font-size: 24rpx;
  254. color: #999999;
  255. &:first-child {
  256. margin-right: 32rpx;
  257. }
  258. }
  259. }
  260. .notice_actions {
  261. display: flex;
  262. justify-content: flex-end;
  263. gap: 16rpx;
  264. .action_btn {
  265. font-size: 24rpx;
  266. padding: 12rpx 24rpx;
  267. border-radius: 8rpx;
  268. border: 2rpx solid transparent;
  269. &.delete {
  270. border-color: #F56C6C;
  271. color: #F56C6C;
  272. background-color: #FFFFFF;
  273. &.disabled {
  274. border-color: #C0C4CC;
  275. color: #C0C4CC;
  276. background-color: #FFFFFF;
  277. }
  278. }
  279. &.edit {
  280. border-color: #2E64FA;
  281. color: #2E64FA;
  282. background-color: #FFFFFF;
  283. &.disabled {
  284. border-color: #C0C4CC;
  285. color: #C0C4CC;
  286. background-color: #FFFFFF;
  287. }
  288. }
  289. &.detail {
  290. background-color: #2E64FA;
  291. color: #FFFFFF;
  292. &.disabled {
  293. border-color: #C0C4CC;
  294. color: #C0C4CC;
  295. background-color: #FFFFFF;
  296. }
  297. }
  298. }
  299. }
  300. }
  301. &:last-child {
  302. margin-bottom: 0;
  303. }
  304. }
  305. </style>