From 7732b7b1b9732c84ae657838b045e1ea4d693815 Mon Sep 17 00:00:00 2001 From: zhuoqinglian <1035449612@qq.com> Date: Fri, 20 Mar 2026 14:42:47 +0800 Subject: [PATCH] =?UTF-8?q?update:=20mobile=20=E7=BC=93=E5=AD=98=E7=94=A8?= =?UTF-8?q?=E6=88=B7=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main/manager-mobile/src/pages/login/index.vue | 5 +++-- main/manager-mobile/src/store/user.ts | 22 +++++++++---------- 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/main/manager-mobile/src/pages/login/index.vue b/main/manager-mobile/src/pages/login/index.vue index 4a83d710..adaf5fb3 100644 --- a/main/manager-mobile/src/pages/login/index.vue +++ b/main/manager-mobile/src/pages/login/index.vue @@ -15,7 +15,7 @@ import { computed, onMounted, ref } from 'vue' import { login } from '@/api/auth' // 导入国际化相关功能 import { changeLanguage, getCurrentLanguage, getSupportedLanguages, initI18n, t } from '@/i18n' -import { useConfigStore } from '@/store' +import { useConfigStore, useUserStore } from '@/store' // 导入SM2加密工具 import { getEnvBaseUrl, sm2Encrypt } from '@/utils' import { toast } from '@/utils/toast' @@ -61,6 +61,7 @@ const loginType = ref<'username' | 'mobile'>('username') // 获取配置store const configStore = useConfigStore() +const userStore = useUserStore() // 区号选择相关 const showAreaCodeSheet = ref(false) @@ -227,6 +228,7 @@ async function handleLogin() { const response = await login(loginData) // 存储token uni.setStorageSync('token', JSON.stringify(response)) + await userStore.getUserInfo() toast.success(t('message.loginSuccess')) @@ -581,7 +583,6 @@ onMounted(async () => { .input-wrapper { position: relative; - background: #f8f9fa; border-radius: 16rpx; padding: 20rpx 16rpx; border: 2rpx solid #e9ecef; diff --git a/main/manager-mobile/src/store/user.ts b/main/manager-mobile/src/store/user.ts index 1e19f34b..a062fcc5 100644 --- a/main/manager-mobile/src/store/user.ts +++ b/main/manager-mobile/src/store/user.ts @@ -19,7 +19,7 @@ const userInfoState: UserInfo & { avatar?: string, token?: string } = { } export const useUserStore = defineStore( - 'user', + 'userInfo', () => { // 定义用户信息 const userInfo = ref({ ...userInfoState }) @@ -51,16 +51,8 @@ export const useUserStore = defineStore( */ const getUserInfo = async () => { const userData = await _getUserInfo() - const authInfo = JSON.parse(uni.getStorageSync('token') || '{}') - const userInfoWithExtras = { - ...userData, - avatar: userInfoState.avatar, - token: authInfo.token || '', - } - setUserInfo(userInfoWithExtras) - uni.setStorageSync('userInfo', userInfoWithExtras) - // TODO 这里可以增加获取用户路由的方法 根据用户的角色动态生成路由 - return userInfoWithExtras + setUserInfo(userData) + return userData } /** * 退出登录 并 删除用户信息 @@ -79,6 +71,12 @@ export const useUserStore = defineStore( } }, { - persist: true, + persist: { + key: 'userInfo', + serializer: { + serialize: state => JSON.stringify(state.userInfo), + deserialize: value => ({ userInfo: JSON.parse(value) }), + }, + }, }, )