nft-group-list.vue 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. <template>
  2. <div class="list" v-show="detail && detail.length">
  3. <div class="list-content">
  4. <div
  5. class="item"
  6. :key="index"
  7. v-for="(item, index) in detail"
  8. @click="clickHandler(item)">
  9. <div class="logo">
  10. <img :src="item.nftGroupIcon" />
  11. <div class="badge" v-if="showBadge && item.newPostCount > 0">
  12. {{item.newPostCount}}
  13. </div>
  14. </div>
  15. <div class="text">{{item.nftGroupName}}</div>
  16. </div>
  17. </div>
  18. </div>
  19. </template>
  20. <script setup>
  21. import { onBeforeMount, ref, defineEmits, defineProps, watch } from 'vue'
  22. import { listJoinNftGroup } from '@/http/nft'
  23. const props = defineProps({
  24. showBadge: {
  25. type: Boolean,
  26. default: false,
  27. }
  28. })
  29. let pageNum = 1;
  30. let pageSize = 1000;
  31. let detail = ref(null);
  32. let emits = defineEmits(['clickCallBack', 'updateList']);
  33. watch(detail, (newVal) => {
  34. emits('updateList', newVal);
  35. })
  36. const clickHandler = (item) => {
  37. emits('clickCallBack', item);
  38. }
  39. const getDetail = () => {
  40. listJoinNftGroup({
  41. params: {
  42. pageNum,
  43. pageSize
  44. }
  45. }).then(res => {
  46. let { data } = res;
  47. if (data !== null) {
  48. detail.value = data;
  49. } else {
  50. emits('updateList', data);
  51. }
  52. })
  53. }
  54. const onPageVisbile = () => {
  55. document.addEventListener('visibilitychange', function () {
  56. let isHidden = document.hidden;
  57. if (!isHidden) {
  58. getDetail();
  59. }
  60. });
  61. }
  62. onBeforeMount(() => {
  63. getDetail();
  64. onPageVisbile();
  65. })
  66. </script>
  67. <style lang='scss'>
  68. body {
  69. margin: 0;
  70. padding: 0;
  71. user-select: none;
  72. }
  73. .list {
  74. overflow-y: auto;
  75. .item {
  76. display: flex;
  77. height: 48px;
  78. margin: 2px 0;
  79. cursor: pointer;
  80. flex-direction: row;
  81. align-items: center;
  82. .logo {
  83. width: 38px;
  84. height: 38px;
  85. border: 1px solid #E3E3E3;
  86. border-radius: 6px;
  87. background: #FFFFFF;
  88. margin-right: 16px;
  89. position: relative;
  90. img {
  91. width: 100%;
  92. height: 100%;
  93. border-radius: 6px;
  94. }
  95. .badge {
  96. min-width: 16px;
  97. min-height: 16px;
  98. padding: 0 4px;
  99. font-weight: 600;
  100. font-size: 12px;
  101. color: #fff;
  102. background: #1D9BF0;
  103. border: 1px solid #F7F9F9;
  104. border-radius: 100px;
  105. box-sizing: border-box;
  106. position: absolute;
  107. top: -8px;
  108. left: 29px;
  109. min-width: 18px;
  110. min-height: 18px;
  111. display: flex;
  112. align-items: center;
  113. justify-content: center;
  114. }
  115. }
  116. .text {
  117. display: flex;
  118. flex: 1;
  119. font-size: 16px;
  120. font-weight: 500;
  121. line-height: 19px;
  122. }
  123. }
  124. }
  125. </style>