tab-group.vue 13 KB

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