index.vue 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  1. <template>
  2. <view class="page_message">
  3. <page-header></page-header>
  4. <view class="message_content">
  5. <view class="message_header">
  6. <text class="message_title">系统消息({{ unreadCount }}项)</text>
  7. <text class="mark_all_read" @click="mark_all_read">全部已读</text>
  8. </view>
  9. <view class="message_list">
  10. <view v-for="item in messageList" :key="item.id" class="message_item">
  11. <view class="message_left">
  12. <view class="message_info">
  13. <view class="message_title_row">
  14. <image src="/static/image/todo/daiban.png" class="message_icon" mode="aspectFit"></image>
  15. <text class="message_name">{{ item.taskName }}</text>
  16. </view>
  17. <view class="message_meta">
  18. <view class="meta_left">
  19. <text class="meta_tag" :class="getTagStyle(item.taskStatus)">{{ item.taskStatus }}</text>
  20. <text class="meta_type">{{ item.taskRemark }}</text>
  21. <text class="meta_time">{{ item.taskTime }}</text>
  22. </view>
  23. <text class="mark_read" @click="markNoticeRead(item.id)">{{ item.readStatus === 0 ? '标记已读' : '' }}</text>
  24. </view>
  25. </view>
  26. </view>
  27. </view>
  28. </view>
  29. <no-data v-if="messageList.length === 0" centered text="暂无系统消息" />
  30. </view>
  31. <common-tabbar></common-tabbar>
  32. </view>
  33. </template>
  34. <script setup>
  35. import { ref, onMounted } from 'vue';
  36. import { onShow } from '@dcloudio/uni-app';
  37. import uniIcons from '@/uni_modules/uni-icons/components/uni-icons/uni-icons.vue';
  38. import PageHeader from '@/components/page-header.vue';
  39. import NoData from '@/components/no-data.vue';
  40. import workspace from '@/reqApi/workspace.js';
  41. const messageList = ref([]);
  42. const unreadCount = ref(0);
  43. const getTagStyle = (status) => {
  44. if (status === '已驳回') {
  45. return 'meta_tag_red'
  46. }
  47. if (status === '进行中' || status === "已通过") {
  48. return 'meta_tag_green'
  49. }
  50. return ''
  51. }
  52. const fetchMessageList = async () => {
  53. try {
  54. const res = await workspace.getNoticeList();
  55. if (res && res.data) {
  56. messageList.value = res.data
  57. unreadCount.value = messageList.value.filter((item) => item.readStatus === 0).length;
  58. }
  59. } catch (error) {
  60. console.error('获取系统消息列表失败:', error);
  61. }
  62. };
  63. const markNoticeRead = async (id) => {
  64. try {
  65. const res = await workspace.markNoticeRead(id);
  66. if (res.code === 200) {
  67. const item = messageList.value.find((item) => item.id === id);
  68. if (item) {
  69. item.readStatus = 1;
  70. }
  71. unreadCount.value--;
  72. uni.showToast({
  73. title: '当前消息标记成功',
  74. icon: 'success',
  75. duration: 2000
  76. });
  77. }
  78. } catch (error) {
  79. console.error('标记系统消息已读失败:', error);
  80. }
  81. };
  82. const mark_all_read = async () => {
  83. try {
  84. const res = await workspace.mark_all_as_read();
  85. if (res.code === 200) {
  86. messageList.value.forEach((item) => {
  87. item.readStatus = 1;
  88. });
  89. unreadCount.value = 0;
  90. uni.showToast({
  91. title: '全部消息标记成功',
  92. icon: 'success',
  93. duration: 2000
  94. });
  95. }
  96. } catch (error) {
  97. console.error('标记所有消息已读失败:', error);
  98. }
  99. };
  100. onShow(() => {
  101. fetchMessageList();
  102. });
  103. </script>
  104. <style lang="scss">
  105. .page_message {
  106. height: 100vh;
  107. display: flex;
  108. flex-direction: column;
  109. background-color: #FFFFFF;
  110. padding-bottom: env(safe-area-inset-bottom);
  111. box-sizing: border-box;
  112. }
  113. .message_content {
  114. flex: 1;
  115. display: flex;
  116. flex-direction: column;
  117. overflow: hidden;
  118. padding-top: calc(140rpx + env(safe-area-inset-top));
  119. padding-bottom: calc(160rpx + env(safe-area-inset-bottom));
  120. padding-left: 0rpx;
  121. padding-right: 0rpx;
  122. }
  123. .message_header {
  124. display: flex;
  125. align-items: center;
  126. justify-content: space-between;
  127. margin-bottom: 24rpx;
  128. flex-shrink: 0;
  129. padding:0 24rpx;
  130. .message_title {
  131. font-weight: 500;
  132. font-size: 32rpx;
  133. color: #333333;
  134. }
  135. .mark_all_read {
  136. border-radius: 8rpx;
  137. border: 2rpx solid #2E64FA;
  138. background: #FFFFFF;
  139. font-weight: 400;
  140. font-size: 24rpx;
  141. color: #2E64FA;
  142. width: 136rpx;
  143. height: 64rpx;
  144. display: flex;
  145. align-items: center;
  146. justify-content: center;
  147. }
  148. }
  149. .message_list {
  150. flex: 1;
  151. overflow-y: auto;
  152. padding:0 24rpx;
  153. display: flex;
  154. flex-direction: column;
  155. .message_item {
  156. display: flex;
  157. align-items: center;
  158. justify-content: space-between;
  159. padding: 20rpx 16rpx;
  160. background: #F9FAFF;
  161. border-radius: 20rpx;
  162. margin-bottom: 24rpx;
  163. border: 2rpx solid #E4E7ED;
  164. &:last-child {
  165. margin-bottom: 0;
  166. }
  167. .message_left {
  168. display: flex;
  169. flex: 1;
  170. align-items: flex-start;
  171. gap: 16rpx;
  172. }
  173. .message_icon {
  174. flex-shrink: 0;
  175. margin-top: 4rpx;
  176. width: 32rpx;
  177. height: 32rpx;
  178. }
  179. .message_info {
  180. flex: 1;
  181. overflow: hidden;
  182. }
  183. .message_title_row {
  184. display: flex;
  185. align-items: center;
  186. gap: 16rpx;
  187. margin-bottom: 16rpx;
  188. .message_name {
  189. font-size: 28rpx;
  190. color: #333333;
  191. font-weight: 500;
  192. flex: 1;
  193. width: 0;
  194. overflow: hidden;
  195. text-overflow: ellipsis;
  196. white-space: nowrap;
  197. }
  198. }
  199. .message_meta {
  200. display: flex;
  201. align-items: center;
  202. justify-content: space-between;
  203. .meta_left {
  204. display: flex;
  205. align-items: center;
  206. flex-wrap: wrap;
  207. gap: 16rpx;
  208. flex: 1;
  209. overflow: hidden;
  210. }
  211. .meta_tag {
  212. font-size: 22rpx;
  213. padding: 8rpx 12rpx;
  214. background-color: rgba(74, 108, 247, 0.1);
  215. color: #4A6CF7;
  216. border-radius: 4rpx;
  217. }
  218. .mark_read {
  219. font-weight: 400;
  220. font-size: 24rpx;
  221. color: #2E64FA;
  222. flex-shrink: 0;
  223. margin-left: 16rpx;
  224. }
  225. .meta_tag_red {
  226. background-color: rgba(245, 108, 108, 0.1);
  227. color: #F56C6C;
  228. }
  229. .meta_tag_green {
  230. background-color: rgba(43, 198, 68, 0.1);
  231. color: #2BC644;
  232. }
  233. .meta_type {
  234. font-size: 24rpx;
  235. color: #999999;
  236. }
  237. .meta_time {
  238. margin-top: 5rpx;
  239. font-size: 24rpx;
  240. color: #999999;
  241. }
  242. }
  243. }
  244. }
  245. </style>