fix: 修复token样式
This commit is contained in:
@@ -87,6 +87,7 @@ export default function useAuths(opt) {
|
|||||||
)
|
)
|
||||||
.then(() => {
|
.then(() => {
|
||||||
useUserStore().updateToken(null);
|
useUserStore().updateToken(null);
|
||||||
|
useUserStore().updateRefreshToken(null);
|
||||||
return true;
|
return true;
|
||||||
})
|
})
|
||||||
.catch(() => {
|
.catch(() => {
|
||||||
|
|||||||
@@ -1,154 +1,156 @@
|
|||||||
import { login, logout, register,retrievePassword } from "@/apis/accountApi";
|
import {login, logout, register, retrievePassword} from "@/apis/accountApi";
|
||||||
import { getUserDetailInfo, getLoginCode } from "@/apis/auth";
|
import {getUserDetailInfo, getLoginCode} from "@/apis/auth";
|
||||||
import useAuths from "@/hooks/useAuths";
|
import useAuths from "@/hooks/useAuths";
|
||||||
import { defineStore } from "pinia";
|
import {defineStore} from "pinia";
|
||||||
import { getBbsUserProfile } from '@/apis/userApi.js'
|
import {getBbsUserProfile} from '@/apis/userApi.js'
|
||||||
const { getToken, setToken, clearStorage } = useAuths();
|
|
||||||
|
const {getToken, setToken, clearStorage} = useAuths();
|
||||||
|
|
||||||
const useUserStore = defineStore("user", {
|
const useUserStore = defineStore("user", {
|
||||||
state: () => ({
|
state: () => ({
|
||||||
id: "",
|
id: "",
|
||||||
token: getToken(),
|
token: getToken(),
|
||||||
name: "游客",
|
name: "游客",
|
||||||
userName: "",
|
userName: "",
|
||||||
icon: null,
|
icon: null,
|
||||||
roles: [],
|
roles: [],
|
||||||
permissions: [],
|
permissions: [],
|
||||||
codeImageURL: "",
|
codeImageURL: "",
|
||||||
codeUUid: "",
|
codeUUid: "",
|
||||||
money:0
|
money: 0
|
||||||
}),
|
}),
|
||||||
getters: {
|
getters: {
|
||||||
moneyFixed: (state) => state.money.toFixed(2)
|
moneyFixed: (state) => state.money.toFixed(2)
|
||||||
},
|
|
||||||
actions: {
|
|
||||||
// 登录
|
|
||||||
login(userInfo) {
|
|
||||||
const userName = userInfo.userName.trim();
|
|
||||||
const password = userInfo.password;
|
|
||||||
const code = userInfo.code;
|
|
||||||
const uuid = userInfo.uuid;
|
|
||||||
return new Promise((resolve, reject) => {
|
|
||||||
login(userName, password, code, uuid)
|
|
||||||
.then((response) => {
|
|
||||||
const res = response.data;
|
|
||||||
setToken(res.token);
|
|
||||||
|
|
||||||
this.token = res.token;
|
|
||||||
resolve(response);
|
|
||||||
})
|
|
||||||
.catch((error) => {
|
|
||||||
reject(error);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
},
|
},
|
||||||
// 获取用户信息
|
actions: {
|
||||||
getInfo() {
|
// 登录
|
||||||
return new Promise((resolve, reject) => {
|
login(userInfo) {
|
||||||
|
const userName = userInfo.userName.trim();
|
||||||
|
const password = userInfo.password;
|
||||||
|
const code = userInfo.code;
|
||||||
|
const uuid = userInfo.uuid;
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
login(userName, password, code, uuid)
|
||||||
|
.then((response) => {
|
||||||
|
const res = response.data;
|
||||||
|
setToken(res.token);
|
||||||
|
|
||||||
getUserDetailInfo()
|
this.token = res.token;
|
||||||
.then(async (response) => {
|
resolve(response);
|
||||||
|
})
|
||||||
const res = response.data;
|
.catch((error) => {
|
||||||
const user = res.user;
|
reject(error);
|
||||||
const avatar =
|
});
|
||||||
user.icon == "" || user.icon == null
|
});
|
||||||
? "/acquiesce.png"
|
},
|
||||||
: import.meta.env.VITE_APP_BASEAPI + "/file/" + user.icon;
|
// 获取用户信息
|
||||||
if (res.roleCodes && res.roleCodes.length > 0) {
|
getInfo() {
|
||||||
// 验证返回的roles是否是一个非空数组
|
return new Promise((resolve, reject) => {
|
||||||
this.roles = res.roleCodes;
|
|
||||||
this.permissions = res.permissionCodes;
|
|
||||||
// this.roles = ["admin"];
|
|
||||||
// this.permissions=["*:*:*"]
|
|
||||||
} else {
|
|
||||||
this.roles = ["ROLE_DEFAULT"];
|
|
||||||
}
|
|
||||||
|
|
||||||
// this.roles = ["admin"];
|
|
||||||
// this.permissions=["*:*:*"]
|
|
||||||
this.name = user.nick;
|
|
||||||
this.icon = avatar;
|
|
||||||
|
|
||||||
this.userName = user.userName;
|
getUserDetailInfo()
|
||||||
this.id = user.id;
|
.then(async (response) => {
|
||||||
|
|
||||||
|
|
||||||
//获取bbs信息
|
const res = response.data;
|
||||||
const {data:bbsData}= await getBbsUserProfile(this.id)
|
const user = res.user;
|
||||||
|
const avatar =
|
||||||
|
user.icon == "" || user.icon == null
|
||||||
this.money= bbsData.money;
|
? "/acquiesce.png"
|
||||||
|
: import.meta.env.VITE_APP_BASEAPI + "/file/" + user.icon;
|
||||||
resolve(res);
|
if (res.roleCodes && res.roleCodes.length > 0) {
|
||||||
})
|
// 验证返回的roles是否是一个非空数组
|
||||||
.catch((error) => {
|
this.roles = res.roleCodes;
|
||||||
reject(error);
|
this.permissions = res.permissionCodes;
|
||||||
});
|
// this.roles = ["admin"];
|
||||||
|
// this.permissions=["*:*:*"]
|
||||||
|
} else {
|
||||||
|
this.roles = ["ROLE_DEFAULT"];
|
||||||
|
}
|
||||||
|
|
||||||
|
// this.roles = ["admin"];
|
||||||
|
// this.permissions=["*:*:*"]
|
||||||
|
this.name = user.nick;
|
||||||
|
this.icon = avatar;
|
||||||
|
|
||||||
|
this.userName = user.userName;
|
||||||
|
this.id = user.id;
|
||||||
|
|
||||||
|
|
||||||
|
//获取bbs信息
|
||||||
|
const {data: bbsData} = await getBbsUserProfile(this.id)
|
||||||
|
|
||||||
|
|
||||||
});
|
this.money = bbsData.money;
|
||||||
},
|
|
||||||
// 退出系统
|
resolve(res);
|
||||||
logOut() {
|
})
|
||||||
return new Promise((resolve, reject) => {
|
.catch((error) => {
|
||||||
logout()
|
reject(error);
|
||||||
.then(() => {
|
});
|
||||||
this.token = "";
|
|
||||||
|
|
||||||
|
});
|
||||||
|
},
|
||||||
|
// 退出系统
|
||||||
|
logOut() {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
logout()
|
||||||
|
.then(() => {
|
||||||
|
this.token = "";
|
||||||
|
this.roles = [];
|
||||||
|
this.permissions = [];
|
||||||
|
clearStorage();
|
||||||
|
resolve();
|
||||||
|
})
|
||||||
|
.catch((error) => {
|
||||||
|
reject(error);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
},
|
||||||
|
// 注册
|
||||||
|
register(userInfo) {
|
||||||
|
const userName = userInfo.userName.trim();
|
||||||
|
const password = userInfo.password.trim();
|
||||||
|
const phone = userInfo.phone;
|
||||||
|
const uuid = userInfo.uuid;
|
||||||
|
const code = userInfo.code;
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
register(userName, password, phone, code, uuid)
|
||||||
|
.then((response) => {
|
||||||
|
resolve(response);
|
||||||
|
})
|
||||||
|
.catch((error) => {
|
||||||
|
reject(error);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
},
|
||||||
|
// 重置用户信息
|
||||||
|
resetInfo() {
|
||||||
this.roles = [];
|
this.roles = [];
|
||||||
this.permissions = [];
|
this.permissions = [];
|
||||||
clearStorage();
|
this.name = "未登录";
|
||||||
resolve();
|
this.icon = "/login.svg";
|
||||||
})
|
this.userName = "";
|
||||||
.catch((error) => {
|
this.id = "";
|
||||||
reject(error);
|
},
|
||||||
});
|
async updateCodeImage() {
|
||||||
});
|
const {data} = await getLoginCode();
|
||||||
|
this.codeImageURL = "data:image/jpg;base64," + data.img;
|
||||||
|
this.codeUUid = data.uuid;
|
||||||
|
},
|
||||||
|
updateToken(token) {
|
||||||
|
this.token = token;
|
||||||
|
},
|
||||||
|
updateRefreshToken(refreshToken) {
|
||||||
|
this.refreshToken = refreshToken;
|
||||||
|
},
|
||||||
|
//更新钱钱
|
||||||
|
updateMoney(updateMoneyNumber) {
|
||||||
|
this.money = this.money + updateMoneyNumber
|
||||||
|
}
|
||||||
},
|
},
|
||||||
// 注册
|
persist: {
|
||||||
register(userInfo) {
|
key: "userInfo",
|
||||||
const userName = userInfo.userName.trim();
|
storage: window.sessionStorage,
|
||||||
const password = userInfo.password.trim();
|
|
||||||
const phone = userInfo.phone;
|
|
||||||
const uuid = userInfo.uuid;
|
|
||||||
const code = userInfo.code;
|
|
||||||
return new Promise((resolve, reject) => {
|
|
||||||
register(userName, password, phone, code, uuid)
|
|
||||||
.then((response) => {
|
|
||||||
resolve(response);
|
|
||||||
})
|
|
||||||
.catch((error) => {
|
|
||||||
reject(error);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
},
|
},
|
||||||
// 重置用户信息
|
|
||||||
resetInfo() {
|
|
||||||
this.roles = [];
|
|
||||||
this.permissions = [];
|
|
||||||
this.name = "未登录";
|
|
||||||
this.icon = "/login.svg";
|
|
||||||
this.userName = "";
|
|
||||||
this.id = "";
|
|
||||||
},
|
|
||||||
async updateCodeImage() {
|
|
||||||
const { data } = await getLoginCode();
|
|
||||||
this.codeImageURL = "data:image/jpg;base64," + data.img;
|
|
||||||
this.codeUUid = data.uuid;
|
|
||||||
},
|
|
||||||
updateToken(token) {
|
|
||||||
this.token = token;
|
|
||||||
},
|
|
||||||
//更新钱钱
|
|
||||||
updateMoney(updateMoneyNumber){
|
|
||||||
this.money=this.money+updateMoneyNumber
|
|
||||||
}
|
|
||||||
},
|
|
||||||
persist: {
|
|
||||||
key: "userInfo",
|
|
||||||
storage: window.sessionStorage,
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
export default useUserStore;
|
export default useUserStore;
|
||||||
|
|||||||
Reference in New Issue
Block a user