From fa482274a588e97784c10099e45d030664aa4ceb Mon Sep 17 00:00:00 2001
From: zhangxiao <898441624@qq.com>
Date: 星期四, 26 九月 2024 10:42:02 +0800
Subject: [PATCH] 登录界面添加新用户注册功能

---
 src/store/modules/user/index.ts |   24 ++++++++++++++++++++----
 1 files changed, 20 insertions(+), 4 deletions(-)

diff --git a/src/store/modules/user/index.ts b/src/store/modules/user/index.ts
index 51faef3..22143e5 100644
--- a/src/store/modules/user/index.ts
+++ b/src/store/modules/user/index.ts
@@ -9,6 +9,7 @@
 import { removeRouteListener } from '@/utils/route-listener';
 import { UserState } from './types';
 import useAppStore from '../app';
+import router from "@/router";
 
 
 const useUserStore = defineStore('user', {
@@ -70,16 +71,28 @@
         const res = await userLogin(loginForm);
 
         setToken(res.data.access_token);
+       
         const userInfo = {
           avatar: res.data.avatar,
-          name: res.data.nickname,
+          name: res.data.loginName,
           email: res.data.email,
+          role: res.data.roles[0].roleKey,
         };
-        this.resources=res.data.resources;
-        setUserInfo(JSON.stringify(userInfo));
-        setUserResources(JSON.stringify(this.resources))
+        this.name=res.data.userName
+     
+        if(res.data?.roles.length>0)
+          //閬嶅巻roles
+          for (const r of res.data.roles) {
+            if (!(this.resources)) {
+              this.resources = [];
+            }
+            this.resources = this.resources.concat(r.resources);
+          }
+            setUserInfo(JSON.stringify(userInfo));
+            setUserResources(JSON.stringify(this.resources))
         for (const r of this.resources) {
           if (r.menuType == 0) {
+            
             return r.component
           }
         }
@@ -100,6 +113,9 @@
       try {
         await userLogout();
       } finally {
+        router.push({
+          name: "login",
+        });
         this.logoutCallBack();
       }
     },

--
Gitblit v1.8.0