From fc89095b0461332cbf40744c5907878d08fa7c41 Mon Sep 17 00:00:00 2001
From: zouyu <2723363702@qq.com>
Date: 星期二, 12 八月 2025 14:44:17 +0800
Subject: [PATCH] 浪潮平台对接单点登录

---
 src/store/modules/user.js |   67 +++++++++++++++++++++++++++++++--
 1 files changed, 63 insertions(+), 4 deletions(-)

diff --git a/src/store/modules/user.js b/src/store/modules/user.js
index d127d9e..1c0d1d2 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,tideLogin} 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(
@@ -30,13 +31,23 @@
           })
         })
       },
+      getCurrentTime() {
+        const now = new Date();
+        const year = now.getFullYear();       // 鑾峰彇骞翠唤
+        const month = String(now.getMonth() + 1).padStart(2, '0');  // 鏈堜唤浠�0寮�濮嬶紝瑕�+1锛屽苟琛ラ浂
+        const day = String(now.getDate()).padStart(2, '0');         // 鏃ユ湡琛ラ浂
+        const hours = String(now.getHours()).padStart(2, '0');      // 灏忔椂琛ラ浂
+        const minutes = String(now.getMinutes()).padStart(2, '0');  // 鍒嗛挓琛ラ浂
+        const seconds = String(now.getSeconds()).padStart(2, '0');  // 绉掓暟琛ラ浂
+        return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
+      },
       // 鑾峰彇鐢ㄦ埛淇℃伅
       getInfo() {
         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
@@ -46,6 +57,11 @@
             this.id = user.userId
             this.name = user.userName
             this.avatar = avatar
+            this.currentFactoryName = user.currentFactoryName
+            this.nickName = user.nickName
+            this.roleName = user.roles[0].roleName
+            this.currentDeptId = user.tenantId
+            this.currentLoginTime = this.getCurrentTime()
             resolve(res)
           }).catch(error => {
             reject(error)
@@ -65,7 +81,50 @@
             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)
+          })
+        })
+      },
+      TideLogin({ commit }, code) {
+        return new Promise((resolve, reject) => {
+          tideLogin(code)
+              .then((res) => {
+                setToken(res.token);
+                commit("SET_TOKEN", res.token);
+                Vue.prototype.uploadHeader = {
+                  Authorization: "Bearer " + res.token,
+                };
+                resolve();
+              })
+              .catch((error) => {
+                reject(error);
+              });
+        });
+      },
     }
   })
 

--
Gitblit v1.9.3