index.vue 6.6 KB

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