This commit is contained in:
2026-05-07 22:20:36 +08:00
parent 632aa76fcb
commit e4e5c5192b
3 changed files with 9680 additions and 7805 deletions
+6
View File
@@ -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' });
}
+15 -1
View File
@@ -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 };
});
+9659 -7804
View File
File diff suppressed because it is too large Load Diff