|
@@ -2,12 +2,13 @@ import {globalConfig} from '@/config';
|
|
|
import storage from '@/utils/storage';
|
|
import storage from '@/utils/storage';
|
|
|
import {constant} from '@/utils/constant';
|
|
import {constant} from '@/utils/constant';
|
|
|
import { login, logout, getInfo } from '@/api/login';
|
|
import { login, logout, getInfo } from '@/api/login';
|
|
|
-import { getToken, setToken, removeToken } from '@/utils/auth';
|
|
|
|
|
|
|
+import { getToken, setToken, removeToken, setCurrentUserSync, setCurrentUserNameSync } from '@/utils/auth';
|
|
|
import profileImg from '@/static/images/profile.jpg';
|
|
import profileImg from '@/static/images/profile.jpg';
|
|
|
|
|
|
|
|
type State = {
|
|
type State = {
|
|
|
token: string,
|
|
token: string,
|
|
|
name: string,
|
|
name: string,
|
|
|
|
|
+ username: string,
|
|
|
avatar: string,
|
|
avatar: string,
|
|
|
roles: string[],
|
|
roles: string[],
|
|
|
permissions: string[],
|
|
permissions: string[],
|
|
@@ -19,6 +20,9 @@ console.log('Token value:', tokenValue);
|
|
|
const nameValue = storage.get(constant.name)??'' as string;
|
|
const nameValue = storage.get(constant.name)??'' as string;
|
|
|
console.log('Name value:', nameValue);
|
|
console.log('Name value:', nameValue);
|
|
|
|
|
|
|
|
|
|
+const usernameValue = storage.get(constant.username)??'' as string;
|
|
|
|
|
+console.log('UserName value:', usernameValue);
|
|
|
|
|
+
|
|
|
const avatarValue = storage.get(constant.avatar)??'' as string;
|
|
const avatarValue = storage.get(constant.avatar)??'' as string;
|
|
|
console.log('Avatar value:', avatarValue);
|
|
console.log('Avatar value:', avatarValue);
|
|
|
|
|
|
|
@@ -31,6 +35,7 @@ console.log('Permissions value:', permissionsValue);
|
|
|
export const state = reactive({
|
|
export const state = reactive({
|
|
|
token: tokenValue,
|
|
token: tokenValue,
|
|
|
name: nameValue as string,
|
|
name: nameValue as string,
|
|
|
|
|
+ username: usernameValue as string,
|
|
|
avatar: avatarValue as string,
|
|
avatar: avatarValue as string,
|
|
|
roles: rolesValue as string[],
|
|
roles: rolesValue as string[],
|
|
|
permissions: permissionsValue as string[]
|
|
permissions: permissionsValue as string[]
|
|
@@ -41,9 +46,14 @@ export const SetToken=(token: string)=>{
|
|
|
setToken(token)
|
|
setToken(token)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-export const SetName=(name: string)=>{
|
|
|
|
|
|
|
+export const SetCurrentUser=(username: string)=>{
|
|
|
|
|
+ state.username = username;
|
|
|
|
|
+ setCurrentUserNameSync(username)
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+export const SetUserName=(name: string)=>{
|
|
|
state.name = name;
|
|
state.name = name;
|
|
|
- storage.set(constant.name, name);
|
|
|
|
|
|
|
+ setCurrentUserSync(name)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
export const cleanAll=()=>{
|
|
export const cleanAll=()=>{
|
|
@@ -72,17 +82,18 @@ export const Login=(userInfo:UTSJSONObject):Promise<void>=> {
|
|
|
const uuid:string = userInfo.getString("uuid") as string;
|
|
const uuid:string = userInfo.getString("uuid") as string;
|
|
|
|
|
|
|
|
return new Promise((resolve, reject) => {
|
|
return new Promise((resolve, reject) => {
|
|
|
-
|
|
|
|
|
login(username, password, code, uuid).then((res:UTSJSONObject) => {
|
|
login(username, password, code, uuid).then((res:UTSJSONObject) => {
|
|
|
//SetToken(res.getString("token") as string);
|
|
//SetToken(res.getString("token") as string);
|
|
|
- console.log(res)
|
|
|
|
|
let msg = res.getString("errMsg")
|
|
let msg = res.getString("errMsg")
|
|
|
let data = res.getArray("data") as UTSJSONObject[]
|
|
let data = res.getArray("data") as UTSJSONObject[]
|
|
|
if(msg == 'ok' && data.length>0){
|
|
if(msg == 'ok' && data.length>0){
|
|
|
SetToken(data[0].getString("token") as string)
|
|
SetToken(data[0].getString("token") as string)
|
|
|
|
|
+ SetUserName(data[0].getString("name") as string)
|
|
|
|
|
+ SetUserName(username)
|
|
|
|
|
+ SetCurrentUser(username)
|
|
|
resolve()
|
|
resolve()
|
|
|
}else{
|
|
}else{
|
|
|
- reject('登录失败')
|
|
|
|
|
|
|
+ reject('登录失败,账户或密码不匹配!')
|
|
|
}
|
|
}
|
|
|
})
|
|
})
|
|
|
})
|
|
})
|
|
@@ -92,8 +103,10 @@ export const Login=(userInfo:UTSJSONObject):Promise<void>=> {
|
|
|
export const GetInfo=():Promise<UTSJSONObject>=> {
|
|
export const GetInfo=():Promise<UTSJSONObject>=> {
|
|
|
return new Promise((resolve, reject) => {
|
|
return new Promise((resolve, reject) => {
|
|
|
getInfo().then((res:UTSJSONObject) => {
|
|
getInfo().then((res:UTSJSONObject) => {
|
|
|
|
|
+ console.log(res)
|
|
|
let avatar:string=profileImg as string
|
|
let avatar:string=profileImg as string
|
|
|
let username:string="" as string
|
|
let username:string="" as string
|
|
|
|
|
+ let name:string="" as string
|
|
|
let roles=[] as string[]
|
|
let roles=[] as string[]
|
|
|
const resMap=res.toMap() as Map<string,any>
|
|
const resMap=res.toMap() as Map<string,any>
|
|
|
if(resMap.has("data")){
|
|
if(resMap.has("data")){
|
|
@@ -108,6 +121,9 @@ export const GetInfo=():Promise<UTSJSONObject>=> {
|
|
|
if(userMap.has("username")&&user.getString("username")!=null&&user.getString("username")!=""){
|
|
if(userMap.has("username")&&user.getString("username")!=null&&user.getString("username")!=""){
|
|
|
username= user.getString("username") as string
|
|
username= user.getString("username") as string
|
|
|
}
|
|
}
|
|
|
|
|
+ if(userMap.has("name")&&user.getString("name")!=null&&user.getString("name")!=""){
|
|
|
|
|
+ name= user.getString("name") as string
|
|
|
|
|
+ }
|
|
|
if(userMap.has("role") &&user.getString("role")!=null&&user.getString("role")!=""){
|
|
if(userMap.has("role") &&user.getString("role")!=null&&user.getString("role")!=""){
|
|
|
roles.push(user.getString("role") as string)
|
|
roles.push(user.getString("role") as string)
|
|
|
}
|
|
}
|
|
@@ -125,7 +141,8 @@ export const GetInfo=():Promise<UTSJSONObject>=> {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
SetRoles?.(roles)
|
|
SetRoles?.(roles)
|
|
|
- SetName?.(username);
|
|
|
|
|
|
|
+ SetUserName?.(name);
|
|
|
|
|
+ SetCurrentUser?.(username);
|
|
|
SetAvatar?.(avatar);
|
|
SetAvatar?.(avatar);
|
|
|
resolve(res)
|
|
resolve(res)
|
|
|
})
|
|
})
|
|
@@ -139,6 +156,8 @@ export const GetInfo=():Promise<UTSJSONObject>=> {
|
|
|
logout(state.token).then(() => {
|
|
logout(state.token).then(() => {
|
|
|
SetToken('');
|
|
SetToken('');
|
|
|
SetRoles([]);
|
|
SetRoles([]);
|
|
|
|
|
+ SetCurrentUser('');
|
|
|
|
|
+ SetUserName('');
|
|
|
SetPermissions([]);
|
|
SetPermissions([]);
|
|
|
removeToken();
|
|
removeToken();
|
|
|
cleanAll();
|
|
cleanAll();
|