index.vue 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  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. padding-bottom: env(safe-area-inset-bottom);
  113. box-sizing: border-box;
  114. }
  115. .message_content {
  116. flex: 1;
  117. display: flex;
  118. flex-direction: column;
  119. overflow: hidden;
  120. padding-top: calc(140rpx + env(safe-area-inset-top));
  121. padding-bottom: calc(160rpx + env(safe-area-inset-bottom));
  122. padding-left: 0rpx;
  123. padding-right: 0rpx;
  124. }
  125. .message_header {
  126. display: flex;
  127. align-items: center;
  128. justify-content: space-between;
  129. margin-bottom: 24rpx;
  130. flex-shrink: 0;
  131. padding:0 24rpx;
  132. .message_title {
  133. font-weight: 500;
  134. font-size: 32rpx;
  135. color: #333333;
  136. }
  137. .mark_all_read {
  138. border-radius: 8rpx;
  139. border: 2rpx solid #2E64FA;
  140. background: #FFFFFF;
  141. font-weight: 400;
  142. font-size: 24rpx;
  143. color: #2E64FA;
  144. width: 136rpx;
  145. height: 64rpx;
  146. display: flex;
  147. align-items: center;
  148. justify-content: center;
  149. }
  150. }
  151. .message_list {
  152. flex: 1;
  153. overflow-y: auto;
  154. padding:0 24rpx;
  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. .schedule_empty {
  246. display: flex;
  247. flex-direction: column;
  248. align-items: center;
  249. font-size: 28rpx;
  250. color: #999999;
  251. position: relative;
  252. .empty_image {
  253. width: 400rpx;
  254. height: 400rpx;
  255. }
  256. .empty_text {
  257. position: absolute;
  258. bottom: 15%;
  259. left: 50%;
  260. transform: translate(-50%, -50%);
  261. }
  262. }
  263. </style>