cwg-notice.vue 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  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. <text v-if="isRed"
  6. class="position-absolute top-0 end-0 p-1 mt-1 me-1 bg-danger border border-3 border-light rounded-circle" />
  7. <cwg-icon name="cwg-bell" color="#97A1C0" :size="20" @click="openNotice" />
  8. </view>
  9. <template #btn>
  10. <view class="dropdown-menu dropdown-menu-lg-end p-0 w-300px mt-2 show">
  11. <view class="px-3 py-3 border-bottom d-flex justify-content-between align-items-center">
  12. <h6 class="mb-0" v-t="'News.Notice'"></h6>
  13. </view>
  14. <view class="p-2" v-if="list.length > 0">
  15. <view class="list-group list-group-hover list-group-smooth list-group-unlined">
  16. <view
  17. class="list-group-item d-flex justify-content-between align-items-center cursor-pointer"
  18. v-for="item in list" :key="item.id" @click="goPages(item)">
  19. <view class="ms-2 me-auto">
  20. <h6 class="mb-2 position-relative">{{ item.subject
  21. }} <view class="item-badge" v-if="item.read == 0">
  22. <view class="dot" />
  23. </view>
  24. </h6>
  25. <small class="text-body d-block">{{ item.addTime }}</small>
  26. </view>
  27. </view>
  28. </view>
  29. </view>
  30. <view class="list-empty-state-compact" v-else>
  31. <cwg-empty-state />
  32. </view>
  33. <view class="p-2">
  34. <view @click="goMore" class="btn w-100 btn-danger waves-effect waves-light " v-t="'News.More'">
  35. </view>
  36. </view>
  37. </view>
  38. </template>
  39. </cwg-dropdown>
  40. </view>
  41. </template>
  42. <script setup lang="ts">
  43. import { computed, ref, onMounted, onUnmounted } from 'vue'
  44. import { newsApi } from '@/service/news'
  45. import useRouter from "@/hooks/useRouter";
  46. import { useI18n } from 'vue-i18n'
  47. const { t, locale } = useI18n()
  48. import { userToken } from "@/composables/config";
  49. const isRed = ref(false)
  50. const dropdownRef = ref(null)
  51. const close = () => {
  52. dropdownRef.value.close()
  53. }
  54. const router = useRouter();
  55. const list = ref([])
  56. const getList = async () => {
  57. const res = await newsApi.newsNoticeList({
  58. page: { current: 1, row: 4 },
  59. lang: locale.value,
  60. read: 0
  61. })
  62. if (res.data && res.code == 200) {
  63. list.value = res.data
  64. } else {
  65. list.value = []
  66. }
  67. }
  68. const goPages = (e) => {
  69. router.push({
  70. path: '/pages/analytics/detail',
  71. query: {
  72. id: e.id,
  73. type: 7
  74. }
  75. })
  76. close()
  77. }
  78. const goMore = () => {
  79. router.push({
  80. path: '/pages/common/notice'
  81. })
  82. close()
  83. }
  84. const openNotice = () => {
  85. if (!userToken.value) return
  86. getData()
  87. getList()
  88. }
  89. const getData = async () => {
  90. const res = await newsApi.newsNoticeRead({
  91. read: 0
  92. })
  93. if (res.data && res.code == 200) {
  94. isRed.value = res.data > 0
  95. } else {
  96. isRed.value = false
  97. }
  98. }
  99. onMounted(() => {
  100. if (!userToken.value) return
  101. uni.$on('open-notice', () => {
  102. getData()
  103. getList()
  104. })
  105. getData()
  106. getList()
  107. uni.$on('updateUnreadCount', (value) => {
  108. console.log('updateUnreadCount', value)
  109. isRed.value = value > 0
  110. if (!userToken.value) return
  111. getList()
  112. })
  113. })
  114. onUnmounted(() => {
  115. uni.$off('updateUnreadCount')
  116. })
  117. </script>
  118. <style scoped lang="scss">
  119. @import "@/uni.scss";
  120. .notice-container {
  121. :deep(.cwg-dropdown-menu-container) {
  122. left: px2rpx(-260) !important;
  123. right: px2rpx(0) !important;
  124. .menu {
  125. border: 0;
  126. overflow: visible;
  127. }
  128. }
  129. @media screen and (max-width: 991px) {
  130. :deep(.cwg-dropdown-menu-container) {
  131. left: px2rpx(-230) !important;
  132. max-width: px2rpx(400);
  133. }
  134. }
  135. .item-badge {
  136. position: absolute;
  137. top: px2rpx(1);
  138. right: px2rpx(-14);
  139. margin-left: px2rpx(12);
  140. .dot {
  141. width: px2rpx(6);
  142. height: px2rpx(6);
  143. background-color: #f56c6c;
  144. border-radius: 50%;
  145. }
  146. }
  147. .pc-header-btn {
  148. position: relative;
  149. &.has-dot::after {
  150. content: '';
  151. position: absolute;
  152. top: px2rpx(4);
  153. right: px2rpx(4);
  154. width: px2rpx(8);
  155. height: px2rpx(8);
  156. background-color: #f56c6c;
  157. border-radius: 50%;
  158. }
  159. }
  160. .right-drawer {
  161. width: px2rpx(300);
  162. background-color: rgba(var(--bs-body-bg-rgb), var(--bs-bg-opacity)) !important;
  163. display: flex;
  164. flex-direction: column;
  165. padding: 20px 16px;
  166. box-sizing: border-box;
  167. }
  168. .notification-list {
  169. width: 100%;
  170. }
  171. .notification-item {
  172. display: flex;
  173. align-items: center;
  174. justify-content: space-between;
  175. padding: px2rpx(12) px2rpx(16);
  176. border-bottom: 1px solid var(--bs-border-color);
  177. cursor: pointer;
  178. transition: all 0.3s;
  179. &:hover {
  180. background-color: rgba(0, 0, 0, 0.05);
  181. }
  182. .item-content {
  183. flex: 1;
  184. .item-title {
  185. font-size: px2rpx(14);
  186. color: var(--bs-heading-color);
  187. line-height: 1.4;
  188. margin-bottom: px2rpx(4);
  189. }
  190. .item-time {
  191. font-size: px2rpx(12);
  192. color: var(--bs-heading-color);
  193. }
  194. }
  195. }
  196. .logout-wrap {
  197. margin-top: auto;
  198. padding: 20px 16px;
  199. margin-bottom: 20px;
  200. }
  201. .logout-btn {
  202. height: 44px;
  203. background-color: var(--bs-btn-bg);
  204. display: flex;
  205. align-items: center;
  206. justify-content: center;
  207. gap: 8px;
  208. color: #fff;
  209. font-weight: 600;
  210. font-size: 16px;
  211. cursor: pointer;
  212. }
  213. }
  214. </style>