tab-group.vue 14 KB

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