tab-group.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460
  1. <template>
  2. <div class="tab-group-page" ref="pageWrapperDom" @scroll="pageScroll">
  3. <div class="list-wrapper" ref="listWrapperDom">
  4. <template v-if="listData.length">
  5. <div class="list-item" v-for="(item, index) in listData" :key="index" @click="clickItem(item, index)">
  6. <div class="left">
  7. <img :src="item.avatarUrl" class="icon-avatar">
  8. </div>
  9. <div class="right">
  10. <div class="top">
  11. <div class="icon-nft-wrapper">
  12. <el-popover :width="340" placement="right-start" trigger="hover" popper-style="background: #FFFFFF;
  13. box-shadow: 0px 4px 20px rgba(0, 0, 0, 0.2);
  14. border-radius: 20px;
  15. padding: 20px;
  16. box-sizing: border-box;
  17. margin-top: -1px">
  18. <template #reference>
  19. <img v-if="item.nftItem" :src="item.nftItem.imagePath" class="icon-nft"
  20. @click.stop="">
  21. </template>
  22. <template #default>
  23. <div class="preview-nft" v-if="item.nftItem">
  24. <img :src="item.nftItem.imagePath" class="icon-nft-big">
  25. <div class="content">
  26. <div class="nft-name">
  27. {{ item.nftItem.nftItemName }}
  28. </div>
  29. <div class="nft-desc">
  30. <div v-if="item.nftItem.metadata"
  31. v-html="item.nftItem.metadata.description"></div>
  32. </div>
  33. </div>
  34. </div>
  35. </template>
  36. </el-popover>
  37. </div>
  38. <div class="nick-name" :style="{
  39. color: eleThemeStyle.color
  40. }">
  41. {{ item.nickName }}
  42. </div>
  43. <div class="screen-name" :style="{
  44. color: eleThemeStyle.screenName
  45. }">
  46. @{{ item.screenName }}
  47. </div>
  48. </div>
  49. <div class="post-content" :style="{
  50. color: eleThemeStyle.color
  51. }" v-html="item.textContent"></div>
  52. </div>
  53. </div>
  54. </template>
  55. <template v-if="loading && !listData.length">
  56. <img :src="require('@/assets/svg/icon-tweet-loading.svg')" class="icon-loading">
  57. </template>
  58. </div>
  59. </div>
  60. </template>
  61. <script setup>
  62. import { onMounted, reactive, ref } from "vue";
  63. import { getGroupPostList, getTwitterNftGroupInfo } from '@/http/nft'
  64. import { getQueryString } from '@/uilts/help.js'
  65. import { ElPopover } from "element-plus";
  66. import messageCenter from "@/uilts/messageCenter";
  67. import MESSAGE_ENUM from "@/uilts/messageCenter/messageEnum";
  68. let twitterAccount = '';
  69. let groupInfo = {};
  70. let listData = ref([])
  71. let listWrapperDom = ref(null);
  72. let pageWrapperDom = ref(null);
  73. let loading = ref(false);
  74. let eleThemeStyle = reactive({
  75. color: '#000',
  76. screenName: '#566370',
  77. borderColor: '#F0F3F4',
  78. })
  79. let listReqParams = {
  80. params: {
  81. pageSize: 100,
  82. preTimestamp: ''
  83. },
  84. loadMore: false,
  85. isInit: false,
  86. };
  87. const clickItem = (data) => {
  88. if (data.srcContentId) {
  89. let url = `https://twitter.com/${data.screenName}/status/${data.srcContentId}`;
  90. messageCenter.send({
  91. info: {
  92. actionType: MESSAGE_ENUM.IFRAME_PAGE_JUMP
  93. },
  94. data: {
  95. url
  96. }
  97. })
  98. }
  99. }
  100. const onRuntimeMsg = () =>{
  101. messageCenter.listen(MESSAGE_ENUM.CONTENT_REFRESH_TAB_GROUP_LIST, () => {
  102. listReqParams.params.preTimestamp = ''
  103. initData();
  104. })
  105. messageCenter.listen(MESSAGE_ENUM.CONTENT_GROUP_LIST_SCROLL, (data) => {
  106. nextPage(data);
  107. })
  108. messageCenter.listen(MESSAGE_ENUM.CONTENT_SEND_GROUP_NAV_TOP, (data) => {
  109. styleHandler(data);
  110. })
  111. messageCenter.listen(MESSAGE_ENUM.CONTENT_SYS_THEME_CHANGE, (data) => {
  112. setPageThemeStyle(data);
  113. })
  114. }
  115. const nextPage = (params) => {
  116. let { wrapperHeight, wrapperScrollTop, contentHeight } = params;
  117. if (wrapperHeight + wrapperScrollTop >= (contentHeight - 50)) {
  118. if (pageWrapperDom.value && pageWrapperDom.value.style.overflowY != 'auto') {
  119. pageWrapperDom.value.style.overflowY = 'auto'
  120. }
  121. }
  122. };
  123. const pageScroll = (e) => {
  124. messageCenter.send({
  125. info: {
  126. actionType: MESSAGE_ENUM.IFREME_TAB_GROUP_CONTENT_GET_NAV_TOP,
  127. },
  128. data: {
  129. scrollTop: e.target.scrollTop
  130. }
  131. })
  132. }
  133. const styleHandler = (data) => {
  134. if (data.top > 53) {
  135. if (pageWrapperDom.value && pageWrapperDom.value.style.overflowY != 'hidden') {
  136. pageWrapperDom.value.style.overflowY = 'hidden'
  137. }
  138. } else {
  139. if (pageWrapperDom.value && pageWrapperDom.value.style.overflowY != 'auto') {
  140. pageWrapperDom.value.style.overflowY = 'auto'
  141. }
  142. innerPageNext(data);
  143. }
  144. }
  145. const innerPageNext = (data) => {
  146. let wrapperHeight = pageWrapperDom.value.offsetHeight;
  147. let listContentHeight = listWrapperDom.value.offsetHeight;
  148. let scrollTop = data.scrollTop || 0;
  149. if (
  150. listReqParams.loadMore === false &&
  151. wrapperHeight + scrollTop >= (listContentHeight - 100)
  152. ) {
  153. listReqParams.loadMore = true;
  154. let dataLength = listData.value.length;
  155. if (dataLength) {
  156. listReqParams.params.preTimestamp = listData.value[dataLength - 1]['createTimestamp'];
  157. }
  158. if (listReqParams.params.preTimestamp) {
  159. getListData();
  160. }
  161. }
  162. }
  163. const getListData = () => {
  164. getGroupPostList({
  165. params: {
  166. pageSize: listReqParams.params.pageSize,
  167. preTimestamp: listReqParams.params.preTimestamp,
  168. groupId: groupInfo.nftGroupId
  169. }
  170. }).then(res => {
  171. loading.value = false;
  172. if (res.code == 0) {
  173. let resData = res.data;
  174. if (resData.length) {
  175. for (let i = 0; i < resData.length; i++) {
  176. let nftItem = resData[i]["nftItem"];
  177. if (nftItem) {
  178. let matedata = nftItem['metadata'];
  179. if (matedata) {
  180. resData[i]["nftItem"]['metadata'] = JSON.parse(matedata);
  181. }
  182. }
  183. }
  184. if (!listReqParams.params.preTimestamp) {
  185. listData.value = resData;
  186. } else {
  187. let data = listData.value;
  188. data = data.concat(resData);
  189. listData.value = data;
  190. }
  191. listReqParams.loadMore = false;
  192. }
  193. }
  194. })
  195. }
  196. const initData = () => {
  197. loading.value = true;
  198. let { windowLocation } = JSON.parse(getQueryString('params'));
  199. if (windowLocation.pathname) {
  200. let arr = windowLocation.pathname.split('/');
  201. if (arr.length >= 2) {
  202. twitterAccount = arr[1];
  203. if (twitterAccount) {
  204. getTwitterNftGroupInfo({
  205. params: {
  206. twitterAccount
  207. }
  208. }).then(res => {
  209. if (res.code == 0) {
  210. groupInfo = res.data || {};
  211. if (!groupInfo.nftGroupId) return;
  212. // loading.value = true;
  213. getListData()
  214. }
  215. })
  216. }
  217. }
  218. }
  219. }
  220. const setPageThemeStyle = (params) => {
  221. let { twitterTheme } = params;
  222. if (twitterTheme == 'light') {
  223. eleThemeStyle.color = '#000';
  224. eleThemeStyle.screenName = '#566370';
  225. eleThemeStyle.borderColor = '#F0F3F4';
  226. document.querySelector('body').style.backgroundColor = '#fff'
  227. } else if (twitterTheme == 'dark') {
  228. eleThemeStyle.color = '#fff';
  229. eleThemeStyle.screenName = '#fff';
  230. eleThemeStyle.borderColor = '#000';
  231. document.querySelector('body').style.backgroundColor = '#000'
  232. }
  233. };
  234. onMounted(() => {
  235. onRuntimeMsg();
  236. initData();
  237. messageCenter.send({
  238. info: {
  239. actionType: MESSAGE_ENUM.IFREME_TAB_GROUP_SET_IFRAME_HEIGHT,
  240. },
  241. data: {
  242. height: listWrapperDom.value.offsetHeight + 10
  243. }
  244. })
  245. })
  246. </script>
  247. <style lang="scss">
  248. html,
  249. body,
  250. #app {
  251. width: 100%;
  252. height: 100%;
  253. margin: 0;
  254. padding: 0;
  255. }
  256. .el-popper__arrow {
  257. display: none !important;
  258. }
  259. // @media (prefers-color-scheme: light) {
  260. // body {
  261. // background: #fff;
  262. // }
  263. // }
  264. // @media (prefers-color-scheme: dark) {
  265. // body {
  266. // background: #000 !important;
  267. // }
  268. // .list-item {
  269. // border-bottom: 1px solid #000 !important;
  270. // }
  271. // .nick-name {
  272. // color: #fff !important;
  273. // }
  274. // .screen-name {
  275. // color: #fff !important;
  276. // }
  277. // .post-content {
  278. // color: #fff !important;
  279. // }
  280. // }
  281. .preview-nft {
  282. box-sizing: border-box;
  283. // position: absolute;
  284. // left: 26px;
  285. // top: 0px;
  286. // z-index: 1999;
  287. // display: none;
  288. .icon-nft-big {
  289. width: 300px;
  290. height: 300px;
  291. object-fit: cover;
  292. }
  293. .content {
  294. margin-top: 19px;
  295. .nft-name {
  296. margin-bottom: 6px;
  297. font-weight: 500;
  298. font-size: 14px;
  299. color: #000;
  300. }
  301. .nft-desc {
  302. font-weight: 400;
  303. font-size: 14px;
  304. color: #787878;
  305. // margin-bottom: 18px;
  306. }
  307. .nft-date {
  308. font-weight: 500;
  309. font-size: 12px;
  310. color: #ACACAC;
  311. }
  312. }
  313. }
  314. .tab-group-page {
  315. height: 100%;
  316. overflow-y: hidden;
  317. &::-webkit-scrollbar {
  318. width: 2px;
  319. }
  320. &::-webkit-scrollbar-track {
  321. background: rgb(241, 241, 241);
  322. }
  323. &::-webkit-scrollbar-thumb {
  324. background: rgb(136, 136, 136);
  325. border-radius: 8px;
  326. }
  327. .list-wrapper {
  328. .list-item:hover {
  329. background: rgba($color: #000000, $alpha: 0.03);
  330. }
  331. .list-item {
  332. padding: 20px;
  333. box-sizing: border-box;
  334. display: flex;
  335. border-bottom: 1px solid #F0F3F4;
  336. cursor: pointer;
  337. .left {
  338. margin-right: 10px;
  339. .icon-avatar {
  340. width: 47px;
  341. height: 47px;
  342. border-radius: 50%;
  343. }
  344. }
  345. .right {
  346. flex: 1;
  347. .top {
  348. display: flex;
  349. align-items: center;
  350. margin-bottom: 7px;
  351. position: relative;
  352. .icon-nft-wrapper {
  353. height: 24px;
  354. margin-right: 8px;
  355. .icon-nft {
  356. width: 24px;
  357. height: 24px;
  358. // object-fit: cover;
  359. }
  360. }
  361. .icon-nft-wrapper:hover {
  362. .preview-nft {
  363. // display: block;
  364. }
  365. }
  366. .nick-name,
  367. .screen-name {
  368. font-size: 15px;
  369. }
  370. .nick-name {
  371. font-weight: 600;
  372. color: #000;
  373. margin-right: 8px;
  374. }
  375. .screen-name {
  376. color: #566370;
  377. }
  378. }
  379. .post-content {
  380. font-weight: 400;
  381. font-size: 16px;
  382. line-height: 24px;
  383. color: #000;
  384. font-family: TwitterChirp, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  385. word-break: break-all;
  386. white-space: pre-line;
  387. }
  388. }
  389. }
  390. }
  391. .icon-loading {
  392. width: 26px;
  393. height: 26px;
  394. display: block;
  395. margin: 20px auto;
  396. animation: loading infinite 0.8s linear;
  397. }
  398. }
  399. @keyframes loading {
  400. 0% {
  401. transform: rotate(0);
  402. }
  403. 100% {
  404. transform: rotate(360deg);
  405. }
  406. }
  407. </style>