Home.vue 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. <script setup lang="ts">
  2. import { ref, onMounted, computed, onUnmounted } from 'vue'
  3. import { ElMessage } from 'element-plus'
  4. import { useRouter } from 'vue-router'
  5. import { GlobalStore } from '@/stores/index'
  6. import type { TabsPaneContext } from 'element-plus'
  7. import { User_News_See } from '@/api/user/index'
  8. interface NoticeType {
  9. CreateTime: string
  10. Id: number
  11. T_Tag: number
  12. T_Title: string
  13. T_Url: string
  14. T_uuid: string
  15. }
  16. let tabs__content: HTMLDivElement
  17. const router = useRouter()
  18. const globalStore = GlobalStore()
  19. const activeName = ref('first')
  20. const newsList = computed<NoticeType[]>(() => {
  21. return globalStore.noticeList
  22. })
  23. const handleClick = (tab: TabsPaneContext) => {
  24. const { props } = tab
  25. globalStore.SET_NoticeList([], true)
  26. globalStore.SET_NoticePage(1)
  27. switch (props.name) {
  28. case 'first':
  29. globalStore.SET_User_News_List()
  30. break
  31. case 'second':
  32. globalStore.SET_User_News_List(1)
  33. break
  34. }
  35. }
  36. /**
  37. * 查看通知消息
  38. */
  39. const previewNotice = async (item: NoticeType) => {
  40. router.push(item.T_Url)
  41. const res: any = await User_News_See({ User_tokey: globalStore.GET_User_tokey, Id: item.Id })
  42. if (res.Code) {
  43. ElMessage({
  44. type: 'success',
  45. message: '确认查看消息!'
  46. })
  47. globalStore.SET_NoticeList(
  48. newsList.value.filter((notice: NoticeType) => item.Id !== notice.Id),
  49. true
  50. )
  51. }
  52. }
  53. const ScrollHandle = (e: any) => {
  54. const { target } = e
  55. if (
  56. target.scrollHeight - target.scrollTop === target.clientHeight &&
  57. globalStore.noticeTotal !== newsList.value.length
  58. ) {
  59. globalStore.SET_NoticePage()
  60. globalStore.SET_User_News_List()
  61. }
  62. }
  63. onMounted(() => {
  64. tabs__content = document.querySelector('#home')?.getElementsByClassName('el-tabs__content')[0] as HTMLDivElement
  65. tabs__content?.addEventListener('scroll', ScrollHandle)
  66. })
  67. onUnmounted(() => {
  68. tabs__content.removeEventListener('scroll', ScrollHandle)
  69. })
  70. </script>
  71. <template>
  72. <div class="home">
  73. <div class="notice">
  74. <h1>消息通知</h1>
  75. <el-tabs v-model="activeName" @tab-click="handleClick" id="home">
  76. <transition-group
  77. appear
  78. leave-active-class="animate__animated animate__fadeOutRight"
  79. enter-active-class="animate__animated animate__fadeInLeft"
  80. >
  81. <el-tab-pane label="未读" name="first" key="first">
  82. <div class="item" v-for="item in newsList" :key="item.T_uuid + 'first'" @click="previewNotice(item)">
  83. <div class="item-box">
  84. <el-badge :value="item.T_Tag === 0 ? 'new' : ''">{{ item.T_Title }}</el-badge>
  85. </div>
  86. <span>{{ item.CreateTime.split(' ')[0] }}</span>
  87. </div>
  88. </el-tab-pane>
  89. <el-tab-pane label="全部" name="second" key="second">
  90. <div v-for="item in newsList" :key="item.T_uuid + 'second'" class="item" @click="previewNotice(item)">
  91. <div class="item-box">
  92. <el-badge :value="item.T_Tag === 0 ? 'new' : ''">{{ item.T_Title }}</el-badge>
  93. </div>
  94. <span>{{ item.CreateTime.split(' ')[0] }}</span>
  95. </div>
  96. </el-tab-pane>
  97. </transition-group>
  98. </el-tabs>
  99. </div>
  100. </div>
  101. </template>
  102. <style scoped lang="scss">
  103. .home {
  104. width: 100%;
  105. height: 100%;
  106. padding-top: 50px;
  107. display: flex;
  108. justify-content: center;
  109. // align-items: center;
  110. .notice {
  111. width: 50%;
  112. height: 60%;
  113. padding: 15px;
  114. display: flex;
  115. flex-direction: column;
  116. align-items: center;
  117. box-shadow: 0px 0px 6px #ccc;
  118. .el-tabs {
  119. width: 100%;
  120. height: calc(100% - 25px);
  121. :deep(.el-tabs__content) {
  122. padding-top: 10px;
  123. height: calc(100% - 60px);
  124. overflow-y: scroll;
  125. }
  126. }
  127. .item {
  128. width: 100%;
  129. display: flex;
  130. padding: 5px 16px;
  131. cursor: pointer;
  132. transition: transform 0.5s ease-in-out;
  133. justify-content: space-between;
  134. &:hover {
  135. background-color: #ecf5ff;
  136. color: #409eff;
  137. box-shadow: 0 0 6px #dfdfdf;
  138. transform: translateX(-2px);
  139. }
  140. .item-box {
  141. width: 80%;
  142. .el-badge {
  143. max-width: 100%;
  144. .item-content {
  145. overflow: hidden;
  146. white-space: nowrap;
  147. text-overflow: ellipsis;
  148. max-width: 100%;
  149. display: inline-block;
  150. }
  151. }
  152. }
  153. span {
  154. white-space: nowrap;
  155. }
  156. }
  157. }
  158. h1 {
  159. font-size: 2rem;
  160. }
  161. }
  162. </style>