card.vue 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  1. <template>
  2. <div class="nft" :class="{ border: isShare }">
  3. <template v-if="!isLoading">
  4. <div class="title">
  5. <div class="tag" :class="{ share: !isShare }">
  6. <img class="logo" :src="saleData.nftProjectAvatar" />
  7. <font class="text" :class="{ share: !isShare }">{{saleData.nftProjectName}}</font>
  8. <img class="tagImg" :src=" require('@/assets/img/icon-nft.png') " />
  9. </div>
  10. <div class="share" v-if="!isShare" @click="share">
  11. <img :src=" require('@/assets/img/icon-ntf-share.png') " />
  12. </div>
  13. </div>
  14. <div class="content">
  15. <img :src="saleData.windowImagePath" />
  16. </div>
  17. <div
  18. v-if="saleData.purchaseStatus === 0"
  19. class="buy disabled">
  20. <img class="guide" v-if="isShowGuide" :src=" require('@/assets/img/icon-arrow.png') " />
  21. <button>Buy NFT</button>
  22. </div>
  23. <div
  24. v-else
  25. class="buy"
  26. @click="buy">
  27. <img class="guide" v-if="isShowGuide" :src=" require('@/assets/img/icon-arrow.png') " />
  28. <button>Buy NFT</button>
  29. </div>
  30. </template>
  31. </div>
  32. </template>
  33. <script setup>
  34. import { onBeforeMount, ref, onMounted, onBeforeUnmount } from 'vue'
  35. import { getTwitterSaleNftProjectInfo, getNftProjectInfo } from '@/http/nft'
  36. import { pageUrl } from "@/http/configAPI.js"
  37. import { getChromeStorage, setChromeStorage } from '@/uilts/chromeExtension.js'
  38. const saleData = ref({});
  39. const isShare = ref(false);
  40. const isLoading = ref(true);
  41. const isShowGuide = ref(false);
  42. const getSaleInfo = () => {
  43. chrome.tabs.getCurrent((tab) => {
  44. let url = new URL(tab.url);
  45. let pathname = url.pathname;
  46. let pathArr, account;
  47. if (pathname) {
  48. pathname = decodeURIComponent(pathname);
  49. pathname = pathname.slice(1);
  50. pathArr = pathname.split('/');
  51. account = pathArr[0];
  52. getSaleProjectInfo(account);
  53. }
  54. })
  55. }
  56. const getSaleData = (projectId) => {
  57. getNftProjectInfo({
  58. params: {
  59. nftProjectId: projectId
  60. }
  61. }).then(res => {
  62. let { data } = res;
  63. if (data !== null) {
  64. // setData
  65. saleData.value = data;
  66. isLoading.value = false;
  67. }
  68. })
  69. }
  70. const getSaleProjectInfo = (account) => {
  71. getTwitterSaleNftProjectInfo({
  72. params: {
  73. twitterAccount: account
  74. }
  75. }).then(res => {
  76. let { data } = res;
  77. if (data !== null) {
  78. // setData
  79. saleData.value = data;
  80. isLoading.value = false;
  81. // postMessage
  82. chrome.tabs.getCurrent((tab) => {
  83. chrome.tabs.sendMessage(tab.id, { actionType: "IFRAME_NFT_SHOW_SALE" });
  84. })
  85. getChromeStorage('nft_guide', (info) => {
  86. if (!info) {
  87. isShowGuide.value = true
  88. setTimeout(() => {
  89. setChromeStorage({ nft_guide: Date.now() })
  90. }, 2000)
  91. }
  92. })
  93. }
  94. })
  95. }
  96. const share = () => {
  97. chrome.tabs.getCurrent((tab) => {
  98. let tagUrl = new URL(tab.url);
  99. let tagPathName = tagUrl.pathname.slice(1);
  100. let tagSearch = ``;
  101. if (tagPathName) {
  102. let tagArr = tagPathName.split('/');
  103. tagSearch = `${btoa(tagArr[0])}`
  104. }
  105. let url = pageUrl + `/nft/${saleData.value.nftProjectId}/${tagSearch}`
  106. let content = `#DNFT\r\r${url}`
  107. chrome.tabs.getCurrent((tab) => {
  108. chrome.tabs.sendMessage(tab.id, { actionType: "IFRAME_TWITTER_PUBLISH", publishRes: { srcContent: content } });
  109. });
  110. });
  111. }
  112. const buy = () => {
  113. getChromeStorage('userInfo', (_userInfo) => {
  114. if (!_userInfo) {
  115. setChromeStorage({ buyNFTCardData: JSON.stringify({ action: 'buy' })});
  116. chrome.runtime.sendMessage(
  117. { actionType: "POPUP_LOGIN", data: "" },
  118. (response) => {
  119. console.log("res", response);
  120. }
  121. )
  122. } else {
  123. chrome.tabs.getCurrent((tab) => {
  124. chrome.tabs.sendMessage(tab.id, {
  125. actionType: "IFRAME_TWITTER_SHOW_BUY_NFT",
  126. data: {
  127. nft_project_Id: saleData.value.nftProjectId
  128. }
  129. }, (res) => { });
  130. })
  131. }
  132. })
  133. }
  134. const loginSuccessHandler = async () => {
  135. let {action = ''} = await getChromeStorage('buyNFTCardData') || {};
  136. if(action == 'buy') {
  137. chrome.storage.local.remove("buyNFTCardData");
  138. buy();
  139. }
  140. }
  141. onBeforeMount(() => {
  142. let urlParams = new URL(window.location.href);
  143. let searchParmas = new URLSearchParams(urlParams.search);
  144. let projectId = searchParmas.get('projectId') || '';
  145. if (projectId) {
  146. isShare.value = true;
  147. getSaleData(projectId)
  148. } else {
  149. getSaleInfo()
  150. }
  151. })
  152. const onRuntimeMsg = () => {
  153. chrome.runtime.onMessage.addListener(msgListener)
  154. }
  155. const msgListener = (req, sender, sendResponse) => {
  156. switch (req.actionType) {
  157. case 'BG_LOGIN_SET_USERINFO_CB':
  158. loginSuccessHandler();
  159. break;
  160. }
  161. }
  162. onMounted(() => {
  163. onRuntimeMsg();
  164. })
  165. onBeforeUnmount(() => {
  166. chrome.runtime.onMessage.removeListener(msgListener);
  167. })
  168. </script>
  169. <style lang='scss'>
  170. body {
  171. margin: 0;
  172. padding: 0;
  173. }
  174. .nft {
  175. width: 100%;
  176. height: 290px;
  177. user-select:none;
  178. border-radius:20px;
  179. background:#F7F9F9;
  180. &.border {
  181. box-sizing: border-box;
  182. border: solid 1px #DCDCDC;
  183. }
  184. .title {
  185. height: 46px;
  186. display: flex;
  187. justify-content: space-between;
  188. align-items: center;
  189. .tag {
  190. display: flex;
  191. width: 93%;
  192. align-items: center;
  193. padding-left: 15px;
  194. &.share {
  195. width: 84%;
  196. }
  197. .logo {
  198. overflow: hidden;
  199. width: 20px;
  200. height: 20px;
  201. border-radius: 50%;
  202. background-color: #eee;
  203. }
  204. .text {
  205. font-size: 18px;
  206. font-weight: bold;
  207. width: calc(100% - 50px);
  208. margin: 0 7px;
  209. overflow: hidden;
  210. white-space: nowrap;
  211. text-overflow: ellipsis;
  212. &.share {
  213. width: calc(100% - 80px);
  214. }
  215. }
  216. .tagImg {
  217. width: 37px;
  218. height: 22px;
  219. }
  220. }
  221. .share {
  222. cursor: pointer;
  223. padding-right: 15px;
  224. img {
  225. width: 19px;
  226. height: 18px;
  227. }
  228. }
  229. }
  230. .content {
  231. height: 190px;
  232. img {
  233. width: 100%;
  234. height: 100%;
  235. }
  236. }
  237. .buy {
  238. position: relative;
  239. height: 54px;
  240. display: flex;
  241. justify-content: center;
  242. &.disabled {
  243. opacity: .1;
  244. }
  245. .guide {
  246. position: absolute;
  247. top: 6px;
  248. right: 30%;
  249. width: 26px;
  250. animation: fade 1s infinite;
  251. }
  252. button {
  253. width: 100%;
  254. height: 34px;
  255. margin: 0 20px;
  256. cursor: pointer;
  257. color: #ffffff;
  258. font-size: 15px;
  259. font-weight: bold;
  260. background: #000;
  261. border: 0;
  262. border-radius: 44px;
  263. }
  264. }
  265. }
  266. @keyframes fade {
  267. 0%, 100% {
  268. opacity: .5;
  269. transform: scale(1);
  270. }
  271. 50% {
  272. opacity: 1;
  273. transform: scale(1.4);
  274. }
  275. }
  276. </style>