panmeiyu 3 years ago
parent
commit
1d3cfe3899
1 changed files with 33 additions and 38 deletions
  1. 33 38
      src/components/Header.vue

+ 33 - 38
src/components/Header.vue

@@ -43,7 +43,7 @@
               v-if="isconnected"
               class="connect_wallet connected"
             >
-              <span>0xdf8…6f9he</span>
+              <span>{{contractAddress}}</span>
             </a>
           </div>
 
@@ -52,7 +52,7 @@
         </div>
       </div>
     </div>
-    <!-- <el-dialog
+    <el-dialog
       title=""
       :visible.sync="dialogTableVisible"
       :modal="false"
@@ -106,7 +106,7 @@
           </a>
         </div>
       </div>
-    </el-dialog> -->
+    </el-dialog>
   </div>
 </template>
 
@@ -118,9 +118,9 @@ export default {
   name: "Header",
   data() {
     return {
-      contractShow: false,
+      contractAddress: '',
       isconnected: false,
-      // dialogTableVisible: false,
+      dialogTableVisible: false,
       isphone: false,
       isTokenPocker: false,
       headerList: [
@@ -176,56 +176,51 @@ export default {
       document.querySelector("body").classList.remove("onav");
     },
     openConnect() {
-      // this.dialogTableVisible = true
+      this.dialogTableVisible = true
+    },
+    checkWalletStatus() {
       let $this = this
-      walletMgr.changeWalletType(1,(x)=>{
-          console.log(x)
+      let walletdata = JSON.parse(localStorage.getItem('walletdata'))
+      if(walletdata!=null){
+        walletMgr.changeWalletType(walletdata.type,(x)=>{
           if(x.code==0){
             $this.isconnected = true
-            let obj = {}
-            obj[connect] = $this.isconnected
-            obj[type] = 1
-            obj = JSON.stringify(obj)
-            localStorage.setItem('walletdata', obj)
+            $this.contractAddress = walletdata.contractAddress
           }
         });
+      }else{
+        $this.isconnected = false
+      }
     },
-    checkWalletStatus() {
-      walletMgr.currentAccount(1,(x)=>{
+    // 连接钱包按钮点击
+    ConnectWalletChoice(_i) {
+      let $this = this
+      walletMgr.changeWalletType(_i,(x)=>{
           console.log(x)
           if(x.code==0){
+            $this.isconnected = true
+            let contractAddress = x.data[0]
+            $this.contractAddress = contractAddress.substr(0, 5) + '...' + contractAddress.substr(contractAddress.length - 5, 5)
+            console.log($this.contractAddress)
+            let obj = {}
+            obj.connect = $this.isconnected
+            obj.type = _i
+            obj.contractAddress = $this.contractAddress
+            obj = JSON.stringify(obj)
+            localStorage.setItem('walletdata', obj)
+          }else{
+            $this.isconnected = false
           }
         });
-      let walletdata = JSON.parse(localStorage.getItem('walletdata'))
-      console.log(walletdata)
+      this.dialogTableVisible = false
     },
-    // 连接钱包按钮点击
-    // ConnectWalletChoice(_i) {
-    //   let $this = this;
-    //   if (_i == 1) {
-    //     // 连接钱包
-    //     walletMgr.changeWalletType(1,(x)=>{
-    //       console.log(x)
-    //       if(x.code==0){
-    //       }
-    //     });
-    //   } else if (_i == 2) {
-    //     walletMgr.changeWalletType(2,(x)=>{
-    //       console.log(x)
-    //     });
-    //   } else if (_i == 3) {
-    //     walletMgr.changeWalletType(3,(x)=>{
-    //       console.log(x)
-    //     });
-    //   }
-    //   this.dialogTableVisible = false
-    // },
   },
   beforeDestroy() {
     window.removeEventListener("scroll", this.toggleBodyClass);
   },
   mounted() {
     let $this = this;
+    // localStorage.setItem('walletdata', null)
     this.checkWalletStatus()
     window.addEventListener("scroll", () => {
       $this.toggleBodyClass();