From 228a3095452f9787ae930adf525bd8fd1a3be897 Mon Sep 17 00:00:00 2001 From: ccnetcore Date: Sun, 29 Jun 2025 15:22:57 +0800 Subject: [PATCH] =?UTF-8?q?Revert=20"fix:=20=E4=BF=AE=E5=A4=8Dtoken?= =?UTF-8?q?=E6=A0=B7=E5=BC=8F"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit b15ad8eb5eef03316737124377447e26a27c9028. --- Yi.Bbs.Vue3/src/hooks/useAuths.js | 1 - Yi.Bbs.Vue3/src/stores/user.js | 276 +++++++++++++++--------------- 2 files changed, 137 insertions(+), 140 deletions(-) diff --git a/Yi.Bbs.Vue3/src/hooks/useAuths.js b/Yi.Bbs.Vue3/src/hooks/useAuths.js index 7bc1a46b..6e227ae2 100644 --- a/Yi.Bbs.Vue3/src/hooks/useAuths.js +++ b/Yi.Bbs.Vue3/src/hooks/useAuths.js @@ -87,7 +87,6 @@ export default function useAuths(opt) { ) .then(() => { useUserStore().updateToken(null); - useUserStore().updateRefreshToken(null); return true; }) .catch(() => { diff --git a/Yi.Bbs.Vue3/src/stores/user.js b/Yi.Bbs.Vue3/src/stores/user.js index ef8015ae..d68d5124 100644 --- a/Yi.Bbs.Vue3/src/stores/user.js +++ b/Yi.Bbs.Vue3/src/stores/user.js @@ -1,156 +1,154 @@ -import {login, logout, register, retrievePassword} from "@/apis/accountApi"; -import {getUserDetailInfo, getLoginCode} from "@/apis/auth"; +import { login, logout, register,retrievePassword } from "@/apis/accountApi"; +import { getUserDetailInfo, getLoginCode } from "@/apis/auth"; import useAuths from "@/hooks/useAuths"; -import {defineStore} from "pinia"; -import {getBbsUserProfile} from '@/apis/userApi.js' - -const {getToken, setToken, clearStorage} = useAuths(); +import { defineStore } from "pinia"; +import { getBbsUserProfile } from '@/apis/userApi.js' +const { getToken, setToken, clearStorage } = useAuths(); const useUserStore = defineStore("user", { - state: () => ({ - id: "", - token: getToken(), - name: "游客", - userName: "", - icon: null, - roles: [], - permissions: [], - codeImageURL: "", - codeUUid: "", - money: 0 - }), - getters: { - moneyFixed: (state) => state.money.toFixed(2) + state: () => ({ + id: "", + token: getToken(), + name: "游客", + userName: "", + icon: null, + roles: [], + permissions: [], + codeImageURL: "", + codeUUid: "", + money:0 + }), + getters: { + 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: { - // 登录 - 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); + // 获取用户信息 + getInfo() { + return new Promise((resolve, reject) => { - this.token = res.token; - resolve(response); - }) - .catch((error) => { - reject(error); - }); - }); - }, - // 获取用户信息 - getInfo() { - return new Promise((resolve, reject) => { + getUserDetailInfo() + .then(async (response) => { + + const res = response.data; + const user = res.user; + 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) { + // 验证返回的roles是否是一个非空数组 + 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; - getUserDetailInfo() - .then(async (response) => { + this.userName = user.userName; + this.id = user.id; + - const res = response.data; - const user = res.user; - 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) { - // 验证返回的roles是否是一个非空数组 - 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; - this.id = user.id; + //获取bbs信息 + const {data:bbsData}= await getBbsUserProfile(this.id) + + + this.money= bbsData.money; + + resolve(res); + }) + .catch((error) => { + reject(error); + }); - //获取bbs信息 - const {data: bbsData} = await getBbsUserProfile(this.id) - this.money = bbsData.money; - - resolve(res); - }) - .catch((error) => { - reject(error); - }); - - - }); - }, - // 退出系统 - 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() { + }); + }, + // 退出系统 + logOut() { + return new Promise((resolve, reject) => { + logout() + .then(() => { + this.token = ""; 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; - }, - updateRefreshToken(refreshToken) { - this.refreshToken = refreshToken; - }, - //更新钱钱 - updateMoney(updateMoneyNumber) { - this.money = this.money + updateMoneyNumber - } + clearStorage(); + resolve(); + }) + .catch((error) => { + reject(error); + }); + }); }, - persist: { - key: "userInfo", - storage: window.sessionStorage, + // 注册 + 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.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;