cwg-notice.vue 7.0 KB

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