李凌
2025-09-10 a7ea20968f76e1a6a0e0db574a1b5ff8bfd18935
暂存
2 files modified
66 ■■■■ changed files
src/App.vue 14 ●●●● patch | view | raw | blame | history
src/router/index.js 52 ●●●● patch | view | raw | blame | history
src/App.vue
@@ -29,13 +29,13 @@
  setStorage('usercode', usercode);
}
const userStore = useUserStore();
onMounted(() => {
  if (window.ethereum !== undefined || window.web3 !== undefined || window.injectedWeb3 !== undefined) {
    loginButton(); // 如果支持 Web3,调用登录函数
  } else {
    window.location.href = 'https://trustwallet.com/download'; // 否则重定向
  }
});
// onMounted(() => {
//   if (window.ethereum !== undefined || window.web3 !== undefined || window.injectedWeb3 !== undefined) {
//     loginButton(); // 如果支持 Web3,调用登录函数
//   } else {
//     window.location.href = 'https://trustwallet.com/download'; // 否则重定向
//   }
// });
// 登录按钮逻辑,标记为异步函数
const loginButton = async () => {
src/router/index.js
@@ -1500,36 +1500,36 @@
    },
})
router.beforeEach((to, from, next) => {
    const userStore = useUserStore()
    console.log(to.name);
    if (to.name === 'Login') {
        if (userStore.userInfo && userStore.userInfo.token) {
            // 通过vuex state获取当前的token是否存在
            next()
        } else {
            // loginButton().then(() => {
            //     console.log('钱包授权成功');
            //     next(); // 授权成功后允许跳转
            // }).catch(() => {
            //     console.error('钱包授权失败');
            //     next(false); // 授权失败,阻止跳转
            // });
            loginButton()
            // next({
            //   path: '/login',
            // })
            // next({
            //   path: '/',
            // })
        }
    } else {
        next()
    }
    // const userStore = useUserStore()
    // console.log(to.name);
    // if (to.name === 'Login') {
    //     if (userStore.userInfo && userStore.userInfo.token) {
    //         // 通过vuex state获取当前的token是否存在
    //         next()
    //     } else {
    //         // loginButton().then(() => {
    //         //     console.log('钱包授权成功');
    //         //     next(); // 授权成功后允许跳转
    //         // }).catch(() => {
    //         //     console.error('钱包授权失败');
    //         //     next(false); // 授权失败,阻止跳转
    //         // });
    //         loginButton()
    //         // next({
    //         //   path: '/login',
    //         // })
    //         // next({
    //         //   path: '/',
    //         // })
    //     }
    // } else {
    //     next()
    // }
    
    // if (to.meta.requireAuth) {
    // 判断该路由是否需要登录权限
    
    next()
})
// 登录按钮逻辑,标记为异步函数