From a47397d8c778bd80684371dff9a944bb3e5ce483 Mon Sep 17 00:00:00 2001
From: gaoluyang <2820782392@qq.com>
Date: 星期二, 22 七月 2025 11:59:09 +0800
Subject: [PATCH] 1.头像未展示bug

---
 src/store/modules/user.js |   45 +++++++++++++++++++++++++++++++++++++++------
 1 files changed, 39 insertions(+), 6 deletions(-)

diff --git a/src/store/modules/user.js b/src/store/modules/user.js
index 20350e4..7c392fc 100644
--- a/src/store/modules/user.js
+++ b/src/store/modules/user.js
@@ -1,5 +1,6 @@
-import { login, logout, getInfo } from '@/api/login'
+import {login, logout, getInfo, loginCheck, loginCheckFactory} from '@/api/login'
 import { getToken, setToken, removeToken } from '@/utils/auth'
+import { isHttp, isEmpty } from "@/utils/validate"
 import defAva from '@/assets/images/profile.jpg'
 
 const useUserStore = defineStore(
@@ -7,6 +8,7 @@
   {
     state: () => ({
       token: getToken(),
+      id: '',
       name: '',
       avatar: '',
       roles: [],
@@ -34,16 +36,20 @@
         return new Promise((resolve, reject) => {
           getInfo().then(res => {
             const user = res.user
-            const avatar = (user.avatar == "" || user.avatar == null) ? defAva : import.meta.env.VITE_APP_BASE_API + user.avatar;
-
+            let avatar = user.avatar || ""
+            avatar = import.meta.env.VITE_APP_BASE_API + '/profile/' + avatar
             if (res.roles && res.roles.length > 0) { // 楠岃瘉杩斿洖鐨剅oles鏄惁鏄竴涓潪绌烘暟缁�
               this.roles = res.roles
               this.permissions = res.permissions
             } else {
-              this.setRoutes = ['ROLE_DEFAULT']
+              this.roles = ['ROLE_DEFAULT']
             }
+            this.id = user.userId
             this.name = user.userName
-            this.avatar = avatar;
+            this.avatar = avatar
+            this.currentFactoryName = user.currentFactoryName
+            this.nickName = user.nickName
+            this.currentDeptId = user.tenantId
             resolve(res)
           }).catch(error => {
             reject(error)
@@ -63,7 +69,34 @@
             reject(error)
           })
         })
-      }
+      },
+      // 鐧诲綍鏍¢獙
+      loginCheck(userInfo) {
+        const username = userInfo.username.trim()
+        const password = userInfo.password
+        return new Promise((resolve, reject) => {
+          loginCheck(username, password).then(res => {
+            resolve(res)
+          }).catch(error => {
+            reject(error)
+          })
+        })
+      },
+      // 閮ㄩ棬鐧诲綍
+      loginCheckFactory(userInfo) {
+        const username = userInfo.username.trim()
+        const password = userInfo.password
+        const factoryId = userInfo.currentFatoryId
+        return new Promise((resolve, reject) => {
+          loginCheckFactory(username, password, factoryId).then(res => {
+            setToken(res.token)
+            this.token = res.token
+            resolve()
+          }).catch(error => {
+            reject(error)
+          })
+        })
+      },
     }
   })
 

--
Gitblit v1.9.3