feat: 登录问题修复

This commit is contained in:
alger
2024-05-22 15:14:26 +08:00
parent 32b39c7927
commit 449a6fd335
5 changed files with 15 additions and 12 deletions
+1 -1
View File
@@ -25,7 +25,7 @@ const state: State = {
isPlay: false,
playMusic: {} as SongResult,
playMusicUrl: '',
user: null,
user: localStorage.getItem('user') ? JSON.parse(localStorage.getItem('user') as string) : null,
playList: [],
playListIndex: 0,
setData: null,
+1
View File
@@ -48,6 +48,7 @@ watch(
() => route.query,
async (newParams) => {
if (newParams.type) {
recommendList.value = null;
loadList(newParams.type as string);
}
},
+1
View File
@@ -52,6 +52,7 @@ const timerIsQr = (key: string) => {
localStorage.setItem('token', data.cookie);
const user = await getUserDetail();
store.state.user = user.data.profile;
localStorage.setItem('user', JSON.stringify(store.state.user));
message.success('登录成功');
clearInterval(timer);
-1
View File
@@ -66,7 +66,6 @@ const store = useStore();
onMounted(async () => {
const res = await getTopMv(30);
mvList.value = res.data.data;
console.log('mvList.value', mvList.value);
});
const handleShowMv = async (item: IMvItem) => {
+12 -10
View File
@@ -21,29 +21,31 @@ const router = useRouter();
const userDetail = ref<IUserDetail>();
const playList = ref<any[]>([]);
const recordList = ref();
let { user } = store.state;
const user = computed(() => store.state.user);
const loadPage = async () => {
if (!user) {
if (!user.value) {
router.push('/login');
return;
}
const { data: userData } = await getUserDetail(user.userId);
const { data: userData } = await getUserDetail(user.value.userId);
userDetail.value = userData;
const { data: playlistData } = await getUserPlaylist(user.userId);
const { data: playlistData } = await getUserPlaylist(user.value.userId);
playList.value = playlistData.playlist;
const { data: recordData } = await getUserRecord(user.userId);
const { data: recordData } = await getUserRecord(user.value.userId);
recordList.value = recordData.allData;
};
onMounted(() => {
const localUser = localStorage.getItem('user');
store.state.user = localUser ? JSON.parse(localUser) : null;
user = store.state.user;
loadPage();
onActivated(() => {
if (!user.value) {
router.push('/login');
} else {
loadPage();
}
});
const isShowList = ref(false);