소스 검색

Merge branch 'dev_1.1.0' of https://git.yishihui.com/DeNet/de-net into dev_1.1.0

# Conflicts:
#	src/logic/content/twitter.js
wenliming 2 년 전
부모
커밋
42f9b1d747
5개의 변경된 파일137개의 추가작업 그리고 62개의 파일을 삭제
  1. 8 0
      src/entry/content.js
  2. 36 10
      src/logic/content/twitter.js
  3. 11 5
      src/view/iframe/buy-nft/buy/home.vue
  4. 6 1
      src/view/iframe/buy-nft/buy/open-box.vue
  5. 76 46
      src/view/iframe/nft/card.vue

+ 8 - 0
src/entry/content.js

@@ -21,6 +21,8 @@ import {
     doTaskTwitterAPI,
     onTweetReplyClick,
     showNFTSale,
+    showBuyNFT,
+    hideBuyNFT
 } from "@/logic/content/twitter.js";
 
 import {
@@ -99,6 +101,12 @@ chrome.runtime.onMessage.addListener((req, sender, sendResponse) => {
         case "IFRAME_TWITTER_PUBLISH":
             twitterPublishHandler(req.publishRes);
             break;
+        case "IFRAME_TWITTER_SHOW_BUY_NFT":
+            showBuyNFT(req.data)
+            break
+        case 'IFRAME_TWITTER_HIDE_BUY_NFT':
+            hideBuyNFT()
+            break
     }
 })
 

+ 36 - 10
src/logic/content/twitter.js

@@ -714,13 +714,15 @@ export function initExecuteScript(changes) {
     }
 }
 
-const createIframe = ({ url, tweet_Id }, callback) => {
+const createNFTIframe = ({ url, id }, callback) => {
     let iframe = document.createElement('iframe')
-    iframe.id = `tweetId${tweet_Id}`
+    iframe.id = id
     iframe.src = url
+    iframe.style.cssText = 'border:medium none; width:100%; height:100%; z-index:100; position: fixed; top:0;left:0; display:none;';
     iframe.onload = () => {
-        callback()
+        callback && callback()
     }
+    document.body.appendChild(iframe);
 }
 
 
@@ -765,8 +767,8 @@ function initParseCard() {
 let inited = false
 // 初始化
 export function init() {
-    if(inited){
-        return 
+    if (inited) {
+        return
     }
     inited = true
     console.log('init')
@@ -785,6 +787,7 @@ export function init() {
     appendPopupPage();
     
     onBodyClick();
+    initBuyNFT()
 
     getChromeStorage("popupShowPublishDialog", (res) => {
         console.log("popupShowPublishDialog", res);
@@ -1178,6 +1181,28 @@ const TwitterLikeAPI = (tweet_Id) => {
     })
 }
 
+export const hideBuyNFT = () => {
+    let iframe = document.querySelector('#nftProjectId')
+    iframe.style.display = 'none'
+}
+
+export const showBuyNFT = ({ nft_project_Id }) => {
+    if (!nft_project_Id) {
+        return
+    }
+    let iframe = document.querySelector('#nftProjectId')
+    if(!iframe.src.includes(nft_project_Id)){
+        iframe.src = chrome.runtime.getURL(`/iframe/buy-nft.html?nftProjectId=${nft_project_Id}`)
+    }
+    iframe.style.display = 'block'
+}
+
+const initBuyNFT = () => {
+    let url = chrome.runtime.getURL(`/iframe/buy-nft.html`)
+    let id = `nftProjectId`
+    createNFTIframe({ url, id })
+}
+
 export const showNFTCard = () => {
     let urlInfo = new URL(window.location.href)
     let isTwitter = urlInfo.hostname === 'twitter.com'
@@ -1188,11 +1213,11 @@ export const showNFTCard = () => {
     let where = isTwitter && userElem && tabIndex;
     if (where) {
         let iframe = document.createElement('iframe');
-            iframe.src = chrome.runtime.getURL(`/iframe/nft-card.html?pathname=${encodeURIComponent(urlInfo.pathname)}`)
-            iframe.style.cssText = 'border:medium none; width:100%; height:297px;';
+        iframe.src = chrome.runtime.getURL(`/iframe/nft-card.html?pathname=${encodeURIComponent(urlInfo.pathname)}`)
+        iframe.style.cssText = 'border:medium none; width:100%; height:297px;';
         let nftElement = document.createElement('div');
-            nftElement.id = 'de-nft-node';
-            nftElement.innerHTML = `
+        nftElement.id = 'de-nft-node';
+        nftElement.innerHTML = `
                 ${iframe.outerHTML}
                 <style>
                     #de-nft-node {height:297px; margin-bottom:17px; display:none;}
@@ -1221,7 +1246,8 @@ export const appendPopupPage = () => {
     }
 }
 
-export const showPopupPage = (path = '') => {
+export const showPopupPage = (params) => {
+    let { path = '' } = params;
     let iframe = document.getElementById('de-extension-popup');
     if (iframe) {
         iframe.src = chrome.runtime.getURL('/iframe/popup.html') + `#${path}`;

+ 11 - 5
src/view/iframe/buy-nft/buy/home.vue

@@ -111,14 +111,21 @@ let state = reactive({
     }
 })
 const clickClose = () => {
-
+    chrome.tabs.getCurrent((tab) => {
+        chrome.tabs.sendMessage(tab.id, {
+            actionType: "IFRAME_TWITTER_HIDE_BUY_NFT",
+        }, (res) => { });
+    })
 }
 const clickJump = (item) => {
     pay_info.home.sale_plan = item
     router.push({ path: '/pay' });
 }
 onMounted(() => {
-    let nft_project_Id = getQueryString('nftProjectId') || '9b491fe0fa51499ca0fc3a78abdf0eb0'
+    let nft_project_Id = getQueryString('nftProjectId') || ''
+    if(!nft_project_Id){
+        return
+    }
     getNftMysteryBoxSaleInfo({
         params: {
             nftProjectId: nft_project_Id
@@ -197,9 +204,8 @@ onMounted(() => {
         .mark {
             position: absolute;
             left: 20px;
-            .sold {
-                
-            }
+
+            .sold {}
 
             .limit {
                 color: #AF934E;

+ 6 - 1
src/view/iframe/buy-nft/buy/open-box.vue

@@ -6,7 +6,7 @@
             <div class="detail">
                 <img :src="item.imagePath" alt="" />
             </div>
-            <p>{{item.nftItemName}}</p>
+            <p>{{ item.nftItemName }}</p>
         </div>
     </div>
 </template>
@@ -43,6 +43,11 @@ const showNFTs = () => {
             state.nft.data[i].show = true
         } else {
             clearInterval(timer)
+            chrome.tabs.getCurrent((tab) => {
+                chrome.tabs.sendMessage(tab.id, {
+                    actionType: "IFRAME_TWITTER_HIDE_BUY_NFT",
+                }, (res) => { });
+            })
         }
         i++
     }, 2000)

+ 76 - 46
src/view/iframe/nft/card.vue

@@ -3,11 +3,11 @@
         <div class="title">
             <div class="tag">
                 <img class="logo" :src="saleData.nftProjectAvatar" />
-                <font class="text">{{saleData.nftProjectName}}</font>
-                <img class="tagImg" :src=" require('@/assets/img/icon-nft.png') " />
+                <font class="text">{{ saleData.nftProjectName }}</font>
+                <img class="tagImg" :src="require('@/assets/img/icon-nft.png')" />
             </div>
             <div class="share" @click="share">
-                <img :src=" require('@/assets/img/icon-ntf-share.png') " />
+                <img :src="require('@/assets/img/icon-ntf-share.png')" />
             </div>
         </div>
         <div class="content">
@@ -23,7 +23,7 @@
 import { onBeforeMount, ref } from 'vue'
 import { getTwitterSaleNftProjectInfo } from '@/http/nft'
 import { pageUrl } from "@/http/configAPI.js"
-
+import { getChromeStorage } from '@/uilts/chromeExtension.js'
 const saleData = ref({});
 
 const getSaleInfo = () => {
@@ -61,12 +61,30 @@ const getSaleProjectInfo = (account) => {
 const share = () => {
     let url = pageUrl + `/nft/${saleData.value.nftProjectId}`
     chrome.tabs.getCurrent((tab) => {
-        chrome.tabs.sendMessage(tab.id, { actionType: "IFRAME_TWITTER_PUBLISH", publishRes: { srcContent: url }  });
+        chrome.tabs.sendMessage(tab.id, { actionType: "IFRAME_TWITTER_PUBLISH", publishRes: { srcContent: url } });
     })
 }
 
 const buy = () => {
-    console.log(1111, saleData.value.nftProjectId)
+    getChromeStorage('userInfo', (_userInfo) => {
+        if (!_userInfo) {
+            chrome.runtime.sendMessage(
+                { actionType: "POPUP_LOGIN", data: "" },
+                (response) => {
+                    console.log("res", response);
+                }
+            )
+        } else {
+            chrome.tabs.getCurrent((tab) => {
+                chrome.tabs.sendMessage(tab.id, {
+                    actionType: "IFRAME_TWITTER_SHOW_BUY_NFT",
+                    data: {
+                        nft_project_Id: saleData.value.nftProjectId
+                    }
+                }, (res) => { });
+            })
+        }
+    })
 }
 
 onBeforeMount(() => {
@@ -79,69 +97,81 @@ body {
     margin: 0;
     padding: 0;
 }
+
 .nft {
     width: 100%;
-    height:297px;
-    user-select:none;
-    border-radius:20px;
-    background:#F7F9F9;
+    height: 297px;
+    user-select: none;
+    border-radius: 20px;
+    background: #F7F9F9;
+
     .title {
-        height:46px;
-        display:flex;
-        justify-content:space-between;
-        align-items:center;
+        height: 46px;
+        display: flex;
+        justify-content: space-between;
+        align-items: center;
+
         .tag {
-            display:flex;
-            align-items:center;
-            padding-left:15px;
+            display: flex;
+            align-items: center;
+            padding-left: 15px;
+
             .logo {
-                overflow:hidden;
-                width:20px;
-                height:20px;
-                border-radius:50%;
-                background-color:#eee;
+                overflow: hidden;
+                width: 20px;
+                height: 20px;
+                border-radius: 50%;
+                background-color: #eee;
             }
+
             .text {
-                font-size:18px;
-                font-weight:bold;
-                margin:0 7px;
+                font-size: 18px;
+                font-weight: bold;
+                margin: 0 7px;
             }
+
             .tagImg {
-                width:37px;
-                height:22px;
+                width: 37px;
+                height: 22px;
             }
         }
+
         .share {
             cursor: pointer;
-            padding-right:15px;
-            img{
-                width:19px;
-                height:18px;
+            padding-right: 15px;
+
+            img {
+                width: 19px;
+                height: 18px;
             }
         }
     }
+
     .content {
-        height:190px;
+        height: 190px;
+
         img {
-            width:100%;
-            height:100%;
+            width: 100%;
+            height: 100%;
         }
     }
+
     .buy {
-        height:61px;
-        display:flex;
-        justify-content:center;
-        align-items:center;
+        height: 61px;
+        display: flex;
+        justify-content: center;
+        align-items: center;
+
         button {
-            width:310px;
-            height:34px;
+            width: 310px;
+            height: 34px;
             cursor: pointer;
-            color:#ffffff;
-            font-size:15px;
-            font-weight:bold;
-            background:#000;
-            border:0;
-            border-radius:44px;
+            color: #ffffff;
+            font-size: 15px;
+            font-weight: bold;
+            background: #000;
+            border: 0;
+            border-radius: 44px;
         }
     }
 }