cwg-notice.vue 6.3 KB

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