cwg-notice.vue 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  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 = res.data > 0
  82. } else {
  83. isRed.value = false
  84. }
  85. }
  86. onMounted(() => {
  87. if (!userToken.value) return
  88. uni.$on('open-notice', () => {
  89. getData()
  90. getList()
  91. })
  92. getData()
  93. getList()
  94. })
  95. </script>
  96. <style scoped lang="scss">
  97. @import "@/uni.scss";
  98. .notice-container {
  99. :deep(.cwg-dropdown-menu-container) {
  100. left: px2rpx(-280) !important;
  101. right: px2rpx(0) !important;
  102. }
  103. @media screen and (max-width: 991px) {
  104. :deep(.cwg-dropdown-menu-container) {
  105. left: px2rpx(-270) !important;
  106. max-width: px2rpx(400);
  107. }
  108. }
  109. .pc-header-btn {
  110. position: relative;
  111. &.has-dot::after {
  112. content: '';
  113. position: absolute;
  114. top: px2rpx(4);
  115. right: px2rpx(4);
  116. width: px2rpx(8);
  117. height: px2rpx(8);
  118. background-color: #f56c6c;
  119. border-radius: 50%;
  120. }
  121. }
  122. .right-drawer {
  123. width: px2rpx(300);
  124. background-color: var(--color-white);
  125. display: flex;
  126. flex-direction: column;
  127. padding: 20px 16px;
  128. box-sizing: border-box;
  129. }
  130. .notification-list {
  131. width: 100%;
  132. }
  133. .notification-item {
  134. display: flex;
  135. align-items: center;
  136. justify-content: space-between;
  137. padding: px2rpx(12) px2rpx(16);
  138. border-bottom: 1px solid #f0f0f0;
  139. cursor: pointer;
  140. transition: all 0.3s;
  141. &:hover {
  142. background-color: rgba(0, 0, 0, 0.05);
  143. }
  144. .item-content {
  145. flex: 1;
  146. .item-title {
  147. font-size: px2rpx(14);
  148. color: #333;
  149. line-height: 1.4;
  150. margin-bottom: px2rpx(4);
  151. }
  152. .item-time {
  153. font-size: px2rpx(12);
  154. color: #999;
  155. }
  156. }
  157. .item-badge {
  158. margin-left: px2rpx(12);
  159. .dot {
  160. width: px2rpx(8);
  161. height: px2rpx(8);
  162. background-color: #f56c6c;
  163. border-radius: 50%;
  164. }
  165. }
  166. }
  167. .logout-wrap {
  168. margin-top: auto;
  169. padding: 20px 16px;
  170. margin-bottom: 20px;
  171. }
  172. .logout-btn {
  173. height: 44px;
  174. background: #f4eadf;
  175. display: flex;
  176. align-items: center;
  177. justify-content: center;
  178. gap: 8px;
  179. color: #ff9800;
  180. font-weight: 600;
  181. cursor: pointer;
  182. }
  183. }
  184. </style>