tab-group.vue 13 KB

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