index.vue 5.7 KB

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