|
@@ -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) {
|