cwg-notice.vue 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. <template>
  2. <view class="notice-container">
  3. <cwg-dropdown ref="dropdownRef" :menu-list="[]">
  4. <view class="pc-header-btn" :class="{ 'has-dot': isRed }">
  5. <cwg-icon name="xxtz" color="#141d22" @click="openNotice" />
  6. </view>
  7. <template #btn>
  8. <view class="right-drawer">
  9. <view class="notification-list" v-if="list.length">
  10. <view v-for="item in list" :key="item.id" class="notification-item" @click="goPages(item)">
  11. <view class="item-content">
  12. <view class="item-title">{{ item.subject }}</view>
  13. <view class="item-time">{{ item.addTime }}</view>
  14. </view>
  15. <view class="item-badge" v-if="item.read == 0">
  16. <view class="dot"></view>
  17. </view>
  18. </view>
  19. </view>
  20. <view class="notification-list" v-if="list.length == 0">
  21. <cwg-empty-state />
  22. </view>
  23. <view class="logout-wrap">
  24. <view class="logout-btn" @click="goMore">
  25. <cwg-icon name="crm-mb" :size="16" color="#ff9800" />
  26. <text v-t="'News.More'" />
  27. </view>
  28. </view>
  29. </view>
  30. </template>
  31. </cwg-dropdown>
  32. </view>
  33. </template>
  34. <script setup lang="ts">
  35. import { computed, ref, onMounted } from 'vue'
  36. import { newsApi } from '@/service/news'
  37. import useRouter from "@/hooks/useRouter";
  38. import { useI18n } from 'vue-i18n'
  39. const { t, locale } = useI18n()
  40. import { userToken } from "@/composables/config";
  41. const isRed = ref(false)
  42. const dropdownRef = ref(null)
  43. const close = () => {
  44. dropdownRef.value.close()
  45. }
  46. const router = useRouter();
  47. const list = ref([])
  48. const getList = async () => {
  49. const res = await newsApi.newsNoticeList({
  50. page: { current: 1, row: 6 },
  51. lang: locale.value,
  52. read: 0
  53. })
  54. if (res.data && res.code == 200) {
  55. list.value = res.data
  56. } else {
  57. list.value = []
  58. }
  59. }
  60. const goPages = (e) => {
  61. router.push({
  62. path: '/pages/analytics/detail',
  63. query: {
  64. id: e.id,
  65. type: 7
  66. }
  67. })
  68. close()
  69. }
  70. const goMore = () => {
  71. router.push({
  72. path: '/pages/common/notice'
  73. })
  74. close()
  75. }
  76. const getData = async () => {
  77. const res = await newsApi.newsNoticeRead({
  78. read: 0
  79. })
  80. if (res.data && res.code == 200) {
  81. isRed.value = true
  82. } else {
  83. isRed.value = false
  84. }
  85. }
  86. onMounted(() => {
  87. if (!userToken.value) return
  88. getData()
  89. getList()
  90. })
  91. </script>
  92. <style scoped lang="scss">
  93. @import "@/uni.scss";
  94. .notice-container {
  95. :deep(.cwg-dropdown-menu-container) {
  96. left: px2rpx(-280) !important;
  97. right: px2rpx(0) !important;
  98. }
  99. @media screen and (max-width: 991px) {
  100. :deep(.cwg-dropdown-menu-container) {
  101. left: px2rpx(-270) !important;
  102. max-width: px2rpx(400);
  103. }
  104. }
  105. .pc-header-btn {
  106. position: relative;
  107. &::after {
  108. content: '';
  109. position: absolute;
  110. top: px2rpx(4);
  111. right: px2rpx(4);
  112. width: px2rpx(8);
  113. height: px2rpx(8);
  114. background-color: #f56c6c;
  115. border-radius: 50%;
  116. }
  117. &.has-dot::after {
  118. display: block;
  119. }
  120. }
  121. .right-drawer {
  122. width: px2rpx(300);
  123. background-color: var(--color-white);
  124. display: flex;
  125. flex-direction: column;
  126. padding: 20px 16px;
  127. box-sizing: border-box;
  128. }
  129. .notification-list {
  130. width: 100%;
  131. }
  132. .notification-item {
  133. display: flex;
  134. align-items: center;
  135. justify-content: space-between;
  136. padding: px2rpx(12) px2rpx(16);
  137. border-bottom: 1px solid #f0f0f0;
  138. cursor: pointer;
  139. transition: all 0.3s;
  140. &:hover {
  141. background-color: rgba(0, 0, 0, 0.05);
  142. }
  143. .item-content {
  144. flex: 1;
  145. .item-title {
  146. font-size: px2rpx(14);
  147. color: #333;
  148. line-height: 1.4;
  149. margin-bottom: px2rpx(4);
  150. }
  151. .item-time {
  152. font-size: px2rpx(12);
  153. color: #999;
  154. }
  155. }
  156. .item-badge {
  157. margin-left: px2rpx(12);
  158. .dot {
  159. width: px2rpx(8);
  160. height: px2rpx(8);
  161. background-color: #f56c6c;
  162. border-radius: 50%;
  163. }
  164. }
  165. }
  166. .logout-wrap {
  167. margin-top: auto;
  168. padding: 20px 16px;
  169. margin-bottom: 20px;
  170. }
  171. .logout-btn {
  172. height: 44px;
  173. background: #f4eadf;
  174. display: flex;
  175. align-items: center;
  176. justify-content: center;
  177. gap: 8px;
  178. color: #ff9800;
  179. font-weight: 600;
  180. cursor: pointer;
  181. }
  182. }
  183. </style>