From 552ec6b7d8ccc56c379da195fc6c9c74312b1070 Mon Sep 17 00:00:00 2001
From: yyb <995253665@qq.com>
Date: 星期五, 22 五月 2026 17:57:46 +0800
Subject: [PATCH] OA部分查询条件变更
---
src/store/modules/user.ts | 95 ++++++++++++++++++++++++++++++++++-------------
1 files changed, 68 insertions(+), 27 deletions(-)
diff --git a/src/store/modules/user.ts b/src/store/modules/user.ts
index b63c5f5..07b0f1c 100644
--- a/src/store/modules/user.ts
+++ b/src/store/modules/user.ts
@@ -1,38 +1,49 @@
-import { login, logout, getInfo } from "@/api/login";
+import { logout, getInfo, loginCheckFactory } from "@/api/login";
+import { getRouters as getRoutersApi } from "@/api/menu";
import { getToken, setToken, removeToken } from "@/utils/auth";
import defAva from "@/static/images/profile.jpg";
import { defineStore } from "pinia";
+import config from "@/config.js";
export interface LoginForm {
- username: string;
+ userName: string;
password: string;
- code: string;
- uuid: string;
}
const useUserStore = defineStore("user", {
state: () => ({
token: getToken(),
+ id: "",
name: "",
avatar: "",
+ currentFactoryName: "",
+ nickName: "",
+ roleName: "",
+ currentDeptId: "",
+ currentLoginTime: "",
roles: Array(),
permissions: [],
+ routers: [], // 璺敱鏉冮檺鏁版嵁
}),
actions: {
- // 鐧诲綍
- login(userInfo: LoginForm) {
- const username = userInfo.username.trim();
+ // 閮ㄩ棬鐧诲綍
+ loginCheckFactory(userInfo: any) {
+ const userName = userInfo.userName.trim();
const password = userInfo.password;
- const code = userInfo.code;
- const uuid = userInfo.uuid;
+ const factoryId = userInfo.factoryId;
return new Promise((resolve, reject) => {
- login(username, password, code, uuid)
+ loginCheckFactory(userName, password, factoryId)
.then((res: any) => {
- setToken(res.token);
- this.token = res.token;
- resolve(null);
+ const token = res.token || res.data?.token;
+ if (token) {
+ setToken(token);
+ this.token = token;
+ resolve(null);
+ } else {
+ reject("鏈幏鍙栧埌鐧诲綍浠ょ墝");
+ }
})
- .catch((error) => {
+ .catch((error: any) => {
reject(error);
});
});
@@ -42,24 +53,29 @@
return new Promise((resolve, reject) => {
getInfo()
.then((res: any) => {
- const user = res.user;
- const avatar =
- user.avatar == "" || user.avatar == null
- ? defAva
- : import.meta.env.VITE_APP_BASE_API + user.avatar;
-
- if (res.roles && res.roles.length > 0) {
+ // 鍏煎 res.data 缁撴瀯
+ const data = res.data || res;
+ const user = data.user || {};
+ let avatar = user.avatar || "";
+ avatar = config.baseUrl + "/profile/" + avatar;
+ if (data.roles && data.roles.length > 0) {
// 楠岃瘉杩斿洖鐨剅oles鏄惁鏄竴涓潪绌烘暟缁�
- this.roles = res.roles;
- this.permissions = res.permissions;
+ this.roles = data.roles;
+ this.permissions = data.permissions;
} else {
this.roles = ["ROLE_DEFAULT"];
}
- this.name = user.userName;
+ this.id = user.userId || "";
+ this.name = user.userName || "";
this.avatar = avatar;
- resolve(res);
+ this.currentFactoryName = user.currentFactoryName || "";
+ this.nickName = user.nickName || "";
+ this.roleName = Array.isArray(user.roles) && user.roles.length > 0 ? user.roles[0].roleName || "" : "";
+ this.currentDeptId = user.tenantId || "";
+ this.currentLoginTime = this.getCurrentTime();
+ resolve(data);
})
- .catch((error) => {
+ .catch(error => {
reject(error);
});
});
@@ -72,12 +88,37 @@
this.token = "";
this.roles = [];
this.permissions = [];
+ this.routers = [];
this.name = "";
this.avatar = "";
removeToken();
resolve(null);
})
- .catch((error) => {
+ .catch(error => {
+ reject(error);
+ });
+ });
+ },
+ 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}`;
+ },
+ // 鑾峰彇璺敱鏉冮檺
+ getRouters() {
+ return new Promise((resolve, reject) => {
+ getRoutersApi()
+ .then((res: any) => {
+ // 瀛樺偍璺敱鏉冮檺鏁版嵁
+ this.routers = res.data || [];
+ resolve(res);
+ })
+ .catch(error => {
reject(error);
});
});
--
Gitblit v1.9.3