From 901c277599e4abd4fc2f0cde8f9c2b853e779d5a Mon Sep 17 00:00:00 2001
From: chenyc <501753378@qq.com>
Date: 星期六, 14 九月 2024 12:42:59 +0800
Subject: [PATCH] 更新膳食调差
---
src/stores/userInfo.ts | 37 +++++++++++++++++++++++++++++++------
1 files changed, 31 insertions(+), 6 deletions(-)
diff --git a/src/stores/userInfo.ts b/src/stores/userInfo.ts
index 33e7970..3272e74 100644
--- a/src/stores/userInfo.ts
+++ b/src/stores/userInfo.ts
@@ -1,6 +1,7 @@
import { defineStore } from 'pinia';
import Cookies from 'js-cookie';
import { Session } from '/@/utils/storage';
+import { getuserinfo } from '../api/login';
/**
* 用户信息
@@ -10,10 +11,13 @@
state: (): UserInfosState => ({
userInfos: {
userName: '',
+ code:'',
photo: '',
time: 0,
roles: [],
authBtnList: [],
+ clientCode:'',
+ clientName:''
},
}),
actions: {
@@ -22,17 +26,24 @@
if (Session.get('userInfo')) {
this.userInfos = Session.get('userInfo');
} else {
+ console.log('Session里没有userInfo')
const userInfos = <UserInfos>await this.getApiUserInfo();
this.userInfos = userInfos;
+ console.log('完成了')
}
},
// 模拟接口数据
// https://gitee.com/lyt-top/vue-next-admin/issues/I5F1HP
async getApiUserInfo() {
+ const userinfoRes = await getuserinfo()
+ console.log('-----------用token 换用户信息---------------')
+ console.log(userinfoRes.data)
+ const userRet=userinfoRes.data
return new Promise((resolve) => {
setTimeout(() => {
// 模拟数据,请求接口时,记得删除多余代码及对应依赖的引入
- const userName = Cookies.get('userName');
+ const userName = userRet.userName
+ const userCode = userRet.code
// 模拟数据
let defaultRoles: Array<string> = [];
let defaultAuthBtnList: Array<string> = [];
@@ -45,7 +56,17 @@
// test 按钮权限标识
let testAuthBtnList: Array<string> = ['btn.add', 'btn.link'];
// 不同用户模拟不同的用户权限
- if (userName === 'admin') {
+ let isadmin=false;
+ if(userRet.roles.length > 0){
+ const x=userRet.roles.findIndex(e=>{return e.roleName==='admin'})
+ if(x>=0){
+ isadmin=true
+ }
+ else{
+ isadmin=false
+ }
+ }
+ if (isadmin) {
defaultRoles = adminRoles;
defaultAuthBtnList = adminAuthBtnList;
} else {
@@ -55,15 +76,19 @@
// 用户信息模拟数据
const userInfos = {
userName: userName,
- photo:
- userName === 'admin'
+ code:userCode,
+ photo:userRet.userAvatar===''
? 'https://img2.baidu.com/it/u=1978192862,2048448374&fm=253&fmt=auto&app=138&f=JPEG?w=504&h=500'
- : 'https://img2.baidu.com/it/u=2370931438,70387529&fm=253&fmt=auto&app=138&f=JPEG?w=500&h=500',
+ : userRet.userAvatar,
time: new Date().getTime(),
roles: defaultRoles,
authBtnList: defaultAuthBtnList,
+ clientCode:userRet.currentClientInfo.code,
+ clientName:userRet.currentClientInfo.clientName,
};
- Session.set('userInfo', userInfos);
+ console.log('-----------------2222------------------------------')
+ console.log(defaultRoles)
+ // Session.set('userInfo', userInfos);
resolve(userInfos);
}, 0);
});
--
Gitblit v1.8.0