cwg-notice.vue 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  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">
  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. })
  53. if (res.data && res.code == 200) {
  54. list.value = res.data
  55. } else {
  56. list.value = []
  57. }
  58. }
  59. const goPages = (e) => {
  60. router.push({
  61. path: '/pages/analytics/detail',
  62. query: {
  63. id: e.id,
  64. type: 7
  65. }
  66. })
  67. close()
  68. }
  69. const goMore = () => {
  70. router.push({
  71. path: '/pages/common/notice'
  72. })
  73. close()
  74. }
  75. const getData = async () => {
  76. const res = await newsApi.newsNoticeRead({
  77. read: 0
  78. })
  79. if (res.data && res.code == 200) {
  80. isRed.value = true
  81. } else {
  82. isRed.value = false
  83. }
  84. }
  85. onMounted(() => {
  86. if (!userToken.value) return
  87. getData()
  88. getList()
  89. })
  90. </script>
  91. <style scoped lang="scss">
  92. @import "@/uni.scss";
  93. .notice-container {
  94. :deep(.cwg-dropdown-menu-container) {
  95. left: px2rpx(-280) !important;
  96. right: px2rpx(0) !important;
  97. }
  98. @media screen and (max-width: 991px) {
  99. :deep(.cwg-dropdown-menu-container) {
  100. left: px2rpx(-270) !important;
  101. max-width: px2rpx(400);
  102. }
  103. }
  104. .pc-header-btn {
  105. position: relative;
  106. &::after {
  107. content: '';
  108. position: absolute;
  109. top: px2rpx(4);
  110. right: px2rpx(4);
  111. width: px2rpx(8);
  112. height: px2rpx(8);
  113. background-color: #f56c6c;
  114. border-radius: 50%;
  115. }
  116. &.has-dot::after {
  117. display: block;
  118. }
  119. }
  120. .right-drawer {
  121. width: px2rpx(300);
  122. background-color: var(--color-white);
  123. display: flex;
  124. flex-direction: column;
  125. padding: 20px 16px;
  126. box-sizing: border-box;
  127. }
  128. .notification-list {
  129. width: 100%;
  130. }
  131. .notification-item {
  132. display: flex;
  133. align-items: center;
  134. justify-content: space-between;
  135. padding: px2rpx(12) px2rpx(16);
  136. border-bottom: 1px solid #f0f0f0;
  137. cursor: pointer;
  138. transition: all 0.3s;
  139. &:hover {
  140. background-color: rgba(0, 0, 0, 0.05);
  141. }
  142. .item-content {
  143. flex: 1;
  144. .item-title {
  145. font-size: px2rpx(14);
  146. color: #333;
  147. line-height: 1.4;
  148. margin-bottom: px2rpx(4);
  149. }
  150. .item-time {
  151. font-size: px2rpx(12);
  152. color: #999;
  153. }
  154. }
  155. .item-badge {
  156. margin-left: px2rpx(12);
  157. .dot {
  158. width: px2rpx(8);
  159. height: px2rpx(8);
  160. background-color: #f56c6c;
  161. border-radius: 50%;
  162. }
  163. }
  164. }
  165. .logout-wrap {
  166. margin-top: auto;
  167. padding: 20px 16px;
  168. margin-bottom: 20px;
  169. }
  170. .logout-btn {
  171. height: 44px;
  172. background: #f4eadf;
  173. display: flex;
  174. align-items: center;
  175. justify-content: center;
  176. gap: 8px;
  177. color: #ff9800;
  178. font-weight: 600;
  179. cursor: pointer;
  180. }
  181. }
  182. </style>