fix
This commit is contained in:
@@ -60,6 +60,7 @@
|
|||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { computed } from 'vue';
|
import { computed } from 'vue';
|
||||||
|
import { onShow } from '@dcloudio/uni-app';
|
||||||
import { useUserStore } from '@/store/user';
|
import { useUserStore } from '@/store/user';
|
||||||
import { useSellerStore } from '@/store/seller';
|
import { useSellerStore } from '@/store/seller';
|
||||||
|
|
||||||
@@ -67,6 +68,11 @@ const userStore = useUserStore();
|
|||||||
const sellerStore = useSellerStore();
|
const sellerStore = useSellerStore();
|
||||||
const userInfo = computed(() => userStore.userInfo);
|
const userInfo = computed(() => userStore.userInfo);
|
||||||
|
|
||||||
|
onShow(() => {
|
||||||
|
// 刷新用户信息
|
||||||
|
userStore.fetchUserInfo();
|
||||||
|
});
|
||||||
|
|
||||||
function goLogin() {
|
function goLogin() {
|
||||||
uni.navigateTo({ url: '/pages/login/index' });
|
uni.navigateTo({ url: '/pages/login/index' });
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import { defineStore } from 'pinia';
|
import { defineStore } from 'pinia';
|
||||||
import { ref } from 'vue';
|
import { ref } from 'vue';
|
||||||
|
import { getUserProfile } from '@/api/user/auth';
|
||||||
|
|
||||||
interface UserInfo {
|
interface UserInfo {
|
||||||
id: number;
|
id: number;
|
||||||
@@ -32,5 +33,18 @@ export const useUserStore = defineStore('user', () => {
|
|||||||
return !!token.value;
|
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 };
|
||||||
});
|
});
|
||||||
|
|||||||
Generated
+9659
-7804
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user