cwg-notice.vue 6.9 KB

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