cwg-notice.vue 5.6 KB

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