index.vue 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  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. height: 100vh;
  109. display: flex;
  110. flex-direction: column;
  111. background-color: #FFFFFF;
  112. }
  113. .message_content {
  114. flex: 1;
  115. display: flex;
  116. flex-direction: column;
  117. overflow: hidden;
  118. padding: 140rpx 0rpx 160rpx 0rpx;
  119. }
  120. .message_header {
  121. display: flex;
  122. align-items: center;
  123. justify-content: space-between;
  124. margin-bottom: 24rpx;
  125. flex-shrink: 0;
  126. padding:0 24rpx;
  127. .message_title {
  128. font-weight: 500;
  129. font-size: 32rpx;
  130. color: #333333;
  131. }
  132. .mark_all_read {
  133. border-radius: 8rpx;
  134. border: 2rpx solid #2E64FA;
  135. background: #FFFFFF;
  136. font-weight: 400;
  137. font-size: 24rpx;
  138. color: #2E64FA;
  139. width: 136rpx;
  140. height: 64rpx;
  141. display: flex;
  142. align-items: center;
  143. justify-content: center;
  144. }
  145. }
  146. .message_list {
  147. flex: 1;
  148. overflow-y: auto;
  149. padding:0 24rpx;
  150. .message_item {
  151. display: flex;
  152. align-items: center;
  153. justify-content: space-between;
  154. padding: 20rpx 16rpx;
  155. background: #F9FAFF;
  156. border-radius: 20rpx;
  157. margin-bottom: 24rpx;
  158. border: 2rpx solid #E4E7ED;
  159. &:last-child {
  160. margin-bottom: 0;
  161. }
  162. .message_left {
  163. display: flex;
  164. flex: 1;
  165. align-items: flex-start;
  166. gap: 16rpx;
  167. }
  168. .message_icon {
  169. flex-shrink: 0;
  170. margin-top: 4rpx;
  171. width: 32rpx;
  172. height: 32rpx;
  173. }
  174. .message_info {
  175. flex: 1;
  176. overflow: hidden;
  177. }
  178. .message_title_row {
  179. display: flex;
  180. align-items: center;
  181. gap: 16rpx;
  182. margin-bottom: 16rpx;
  183. .message_name {
  184. font-size: 28rpx;
  185. color: #333333;
  186. font-weight: 500;
  187. flex: 1;
  188. width: 0;
  189. overflow: hidden;
  190. text-overflow: ellipsis;
  191. white-space: nowrap;
  192. }
  193. }
  194. .message_meta {
  195. display: flex;
  196. align-items: center;
  197. justify-content: space-between;
  198. .meta_left {
  199. display: flex;
  200. align-items: center;
  201. flex-wrap: wrap;
  202. gap: 16rpx;
  203. flex: 1;
  204. overflow: hidden;
  205. }
  206. .meta_tag {
  207. font-size: 22rpx;
  208. padding: 8rpx 12rpx;
  209. background-color: rgba(74, 108, 247, 0.1);
  210. color: #4A6CF7;
  211. border-radius: 4rpx;
  212. }
  213. .mark_read {
  214. font-weight: 400;
  215. font-size: 24rpx;
  216. color: #2E64FA;
  217. flex-shrink: 0;
  218. margin-left: 16rpx;
  219. }
  220. .meta_tag_red {
  221. background-color: rgba(245, 108, 108, 0.1);
  222. color: #F56C6C;
  223. }
  224. .meta_tag_green {
  225. background-color: rgba(43, 198, 68, 0.1);
  226. color: #2BC644;
  227. }
  228. .meta_type {
  229. font-size: 24rpx;
  230. color: #999999;
  231. }
  232. .meta_time {
  233. margin-top: 5rpx;
  234. font-size: 24rpx;
  235. color: #999999;
  236. }
  237. }
  238. }
  239. }
  240. .schedule_empty {
  241. display: flex;
  242. flex-direction: column;
  243. align-items: center;
  244. font-size: 28rpx;
  245. color: #999999;
  246. position: relative;
  247. .empty_image {
  248. width: 400rpx;
  249. height: 400rpx;
  250. }
  251. .empty_text {
  252. position: absolute;
  253. bottom: 15%;
  254. left: 50%;
  255. transform: translate(-50%, -50%);
  256. }
  257. }
  258. </style>