card.vue 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. <template>
  2. <div class="nft" :class="{ border: isShare }">
  3. <template v-if="!isLoading">
  4. <div class="title">
  5. <div class="tag">
  6. <img class="logo" :src="saleData.nftProjectAvatar" />
  7. <font class="text">{{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 class="buy" @click="buy">
  18. <button>Buy NFT</button>
  19. </div>
  20. </template>
  21. </div>
  22. </template>
  23. <script setup>
  24. import { onBeforeMount, ref } from 'vue'
  25. import { getTwitterSaleNftProjectInfo, getNftProjectInfo } from '@/http/nft'
  26. import { pageUrl } from "@/http/configAPI.js"
  27. import { getChromeStorage } from '@/uilts/chromeExtension.js'
  28. const saleData = ref({});
  29. const isShare = ref(false);
  30. const isLoading = ref(true);
  31. const getSaleInfo = () => {
  32. chrome.tabs.getCurrent((tab) => {
  33. let url = new URL(tab.url);
  34. let pathname = url.pathname;
  35. let pathArr, account;
  36. if (pathname) {
  37. pathname = decodeURIComponent(pathname);
  38. pathname = pathname.slice(1);
  39. pathArr = pathname.split('/');
  40. account = pathArr[0];
  41. getSaleProjectInfo(account);
  42. }
  43. })
  44. }
  45. const getSaleData = (projectId) => {
  46. getNftProjectInfo({
  47. params: {
  48. nftProjectId: projectId
  49. }
  50. }).then(res => {
  51. let { data } = res;
  52. if (data !== null) {
  53. // setData
  54. saleData.value = data;
  55. isLoading.value = false;
  56. }
  57. })
  58. }
  59. const getSaleProjectInfo = (account) => {
  60. getTwitterSaleNftProjectInfo({
  61. params: {
  62. twitterAccount: account
  63. }
  64. }).then(res => {
  65. let { data } = res;
  66. if (data !== null) {
  67. // setData
  68. saleData.value = data;
  69. isLoading.value = false;
  70. // postMessage
  71. chrome.tabs.getCurrent((tab) => {
  72. chrome.tabs.sendMessage(tab.id, { actionType: "IFRAME_NFT_SHOW_SALE" });
  73. })
  74. }
  75. })
  76. }
  77. const share = () => {
  78. let url = pageUrl + `/nft/${saleData.value.nftProjectId}`
  79. let content = `#DNFT\r${url}`
  80. chrome.tabs.getCurrent((tab) => {
  81. chrome.tabs.sendMessage(tab.id, { actionType: "IFRAME_TWITTER_PUBLISH", publishRes: { srcContent: content } });
  82. })
  83. }
  84. const buy = () => {
  85. getChromeStorage('userInfo', (_userInfo) => {
  86. if (!_userInfo) {
  87. chrome.runtime.sendMessage(
  88. { actionType: "POPUP_LOGIN", data: "" },
  89. (response) => {
  90. console.log("res", response);
  91. }
  92. )
  93. } else {
  94. chrome.tabs.getCurrent((tab) => {
  95. chrome.tabs.sendMessage(tab.id, {
  96. actionType: "IFRAME_TWITTER_SHOW_BUY_NFT",
  97. data: {
  98. nft_project_Id: saleData.value.nftProjectId
  99. }
  100. }, (res) => { });
  101. })
  102. }
  103. })
  104. }
  105. onBeforeMount(() => {
  106. let urlParams = new URL(window.location.href);
  107. let searchParmas = new URLSearchParams(urlParams.search);
  108. let projectId = searchParmas.get('projectId') || '';
  109. if (projectId) {
  110. isShare.value = true;
  111. getSaleData(projectId)
  112. } else {
  113. getSaleInfo()
  114. }
  115. })
  116. </script>
  117. <style lang='scss'>
  118. body {
  119. margin: 0;
  120. padding: 0;
  121. }
  122. .nft {
  123. width: 100%;
  124. height:297px;
  125. user-select:none;
  126. border-radius:20px;
  127. background:#F7F9F9;
  128. &.border {
  129. box-sizing: border-box;
  130. border: solid 1px #DCDCDC;
  131. }
  132. .title {
  133. height: 46px;
  134. display: flex;
  135. justify-content: space-between;
  136. align-items: center;
  137. .tag {
  138. display: flex;
  139. align-items: center;
  140. padding-left: 15px;
  141. .logo {
  142. overflow: hidden;
  143. width: 20px;
  144. height: 20px;
  145. border-radius: 50%;
  146. background-color: #eee;
  147. }
  148. .text {
  149. font-size: 18px;
  150. font-weight: bold;
  151. margin: 0 7px;
  152. }
  153. .tagImg {
  154. width: 37px;
  155. height: 22px;
  156. }
  157. }
  158. .share {
  159. cursor: pointer;
  160. padding-right: 15px;
  161. img {
  162. width: 19px;
  163. height: 18px;
  164. }
  165. }
  166. }
  167. .content {
  168. height: 190px;
  169. img {
  170. width: 100%;
  171. height: 100%;
  172. }
  173. }
  174. .buy {
  175. height: 61px;
  176. display: flex;
  177. justify-content: center;
  178. align-items: center;
  179. button {
  180. width: 310px;
  181. height: 34px;
  182. cursor: pointer;
  183. color: #ffffff;
  184. font-size: 15px;
  185. font-weight: bold;
  186. background: #000;
  187. border: 0;
  188. border-radius: 44px;
  189. }
  190. }
  191. }
  192. </style>