index.vue 6.5 KB

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