fix
This commit is contained in:
@@ -60,6 +60,7 @@
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed } from 'vue';
|
||||
import { onShow } from '@dcloudio/uni-app';
|
||||
import { useUserStore } from '@/store/user';
|
||||
import { useSellerStore } from '@/store/seller';
|
||||
|
||||
@@ -67,6 +68,11 @@ const userStore = useUserStore();
|
||||
const sellerStore = useSellerStore();
|
||||
const userInfo = computed(() => userStore.userInfo);
|
||||
|
||||
onShow(() => {
|
||||
// 刷新用户信息
|
||||
userStore.fetchUserInfo();
|
||||
});
|
||||
|
||||
function goLogin() {
|
||||
uni.navigateTo({ url: '/pages/login/index' });
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { defineStore } from 'pinia';
|
||||
import { ref } from 'vue';
|
||||
import { getUserProfile } from '@/api/user/auth';
|
||||
|
||||
interface UserInfo {
|
||||
id: number;
|
||||
@@ -32,5 +33,18 @@ export const useUserStore = defineStore('user', () => {
|
||||
return !!token.value;
|
||||
}
|
||||
|
||||
return { token, userInfo, setLogin, logout, isLoggedIn };
|
||||
async function fetchUserInfo() {
|
||||
if (!token.value) return;
|
||||
try {
|
||||
const res = await getUserProfile();
|
||||
if (res.code === 200) {
|
||||
userInfo.value = res.data;
|
||||
uni.setStorageSync('userInfo', res.data);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Failed to fetch user info:', error);
|
||||
}
|
||||
}
|
||||
|
||||
return { token, userInfo, setLogin, logout, isLoggedIn, fetchUserInfo };
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user