Kaynağa Gözat

优化删除钱包功能

wkw 3 hafta önce
ebeveyn
işleme
6685be0dfa

+ 35 - 3
src/stores/modules/walletStore.js

@@ -3,6 +3,8 @@ import Web3 from "web3";
 import CryptoJS from "crypto-js";
 import { cloneDeep, forEach } from "lodash";
 import { sysLogin } from "@/common/login.js";
+import { showNotify } from 'vant';
+import router from '@/router/index'
 
 
 export const useWalletStore = defineStore("useWalletStore", {
@@ -124,9 +126,39 @@ export const useWalletStore = defineStore("useWalletStore", {
       }
     },
     // 删除钱包
-    deleteWallet(id) {
-      const list = this.walletList.filter(item =>  item.id != id);
-      this.walletList = list
+    deleteWallet(id, password) {
+      const wallet = this.walletList.find(item => item.id === id);
+      if (!wallet) {
+        showNotify({ type: 'warning', message: '钱包不存在' });
+        return;
+      }
+      if (wallet.accountPassword !== password) {
+        showNotify({ type: 'warning', message: '请输入正确的密码' });
+        return;
+      }
+      // 删除钱包
+      const newList = this.walletList.filter(item => item.id !== id);
+      this.walletList = newList;
+      if (id === this.id) {
+        if (newList.length > 0) {
+          // 切换到第一个钱包
+          this.switchWallet(newList[0].id);
+        } else {
+          // 当前钱包被删除,且没有其他钱包,清空状态并跳转
+          for (const key in this.$state) {
+            if (key !== 'walletList') {
+              this.$state[key] = typeof this.$state[key] === 'string' ? '' : null;
+            }
+          }
+          this.isAuthenticated = false;
+          this.id = '';
+     
+          router.push({
+            path: '/login'
+          })
+        }
+      }
+      this.$persist();
     },
     // 切换钱包
     switchWallet(id) { 

+ 4 - 2
src/views/wallet/index.vue

@@ -128,7 +128,7 @@
           </div>
           <!-- 1 -->
           <div class="pop-ul" v-if="type == 1">
-            <div class="pop-li" v-for="(item,i) in hotTokensList">
+            <div class="pop-li" v-for="(item,i) in dbList">
               <div class="pop-li-lf">
                 <van-image
                   width="32px"
@@ -141,7 +141,7 @@
                   <div class="pop-address">{{ formatAddress(item.address) }}</div>
                 </div>
               </div>
-              <svg-icon style="width: 20px; height: 20px;" :name="item.hide?'add-icon':'del-icon'" />
+              <svg-icon style="width: 20px; height: 20px;" :name="item.hide?'add-icon':'del-icon'" @click="item.hide = !item.hide"/>
             </div>
           </div>
           <!-- 2 -->
@@ -194,6 +194,7 @@
   const showHistory = ref(false);
   const networkList = ref([]);
   const hotTokensList = ref([]);
+  const dbList = ref([]);
   const netWorkIndex = ref(0);
   const totalMoney = ref(0);//总数
   const type = ref('');
@@ -241,6 +242,7 @@
   const gethotTokens = async () => {
     const {data} = await hotTokens({chain: walletStore.accountName,address:walletStore.account});
     hotTokensList.value = data;
+    dbList.value = data.slice(1, 3);
     totalMoney.value = data.reduce((sum, item) => sum + Number(item.money || 0), 0).toFixed(8);
   }
   const formatAddress = (address) => {

+ 5 - 4
src/views/wallet/proceeds/index.vue

@@ -7,7 +7,7 @@
             </div>
             <div class="qrcode">
                 <qrcode-vue :value="qrtext" :size="239" :margin="2" background="transparent"/>
-                <div class="address">18gyff43443967676764566000ACC</div>
+                <div class="address">{{walletStore.account}}</div>
             </div>
         </div>
         <van-button class="footer-btn" type="primary" size="large">复制</van-button>
@@ -16,9 +16,9 @@
 
 <script setup>
 import QrcodeVue from 'qrcode.vue'
-import { useRouter } from 'vue-router'
-const router = useRouter();
-const qrtext = ref('123');
+import { useWalletStore } from "@/stores/modules/walletStore";
+const walletStore = useWalletStore();
+const qrtext = walletStore.account;
 </script>
 
 <style lang="less" scoped>
@@ -65,6 +65,7 @@ const qrtext = ref('123');
                 font-weight: 400;
                 font-size: 15px;
                 color: #000000;
+                word-break: break-all;
             }
         }
         

+ 16 - 5
src/views/wallet/walletDetail/index.vue

@@ -34,7 +34,7 @@
                     <svg-icon style="width: 24px; height: 24px;" name="left-arrow" />
                     <div class="title">查看私钥</div>
                 </div>
-                <div class="pop-text">0x4d8d38c6433c9552a11181b64a234814cd83f5b0d2c7306545ee097da9c0e4b2</div>
+                <div class="pop-text">{{walletStore.privateKey}}</div>
                 <div class="qrcode">
                     <qrcode-vue :value="qrtext" :size="156" :margin="1" background="transparent"/>
                 </div>
@@ -49,13 +49,14 @@
 <script setup>
 import QrcodeVue from 'qrcode.vue'
 import { useWalletStore } from "@/stores/modules/walletStore";
+import { showNotify } from 'vant';
 const walletStore = useWalletStore();
 
 const show = ref(false);
 const showkey = ref(false);
 const text = ref('');
 const type = ref('');
-const qrtext = ref('123');
+const qrtext = walletStore.privateKey;
 const changePop = (v) => {
     show.value = true;
     type.value = v;
@@ -65,12 +66,22 @@ const cancel = () => {
     show.value = false;
 }
 const confirm = () => {
-    if(type.value == '1'){
-        walletStore. updateWalletName(walletStore.id,text.value)
+    if(type.value == 1){
+        // 修改钱包名称
+        walletStore.updateWalletName(walletStore.id,text.value)
+    }else if(type.value == 3){
+        // 删除钱包
+        walletStore.deleteWallet(walletStore.id,text.value)
+    }else if(type.value == 2){
+        // 查看私钥
+        if(text.value != walletStore.accountPassword){
+            showNotify({ type: 'warning', message: '请输入正确的密码' });
+        }else{
+            showkey.value = true
+        }
     }
     text.value = ''
     show.value = false;
-    if(type.value == 2) showkey.value = true;
 }
 const formatAddress = (address) => {
     if (!address) return '';