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, isPlay: false,
playMusic: {} as SongResult, playMusic: {} as SongResult,
playMusicUrl: '', playMusicUrl: '',
user: null, user: localStorage.getItem('user') ? JSON.parse(localStorage.getItem('user') as string) : null,
playList: [], playList: [],
playListIndex: 0, playListIndex: 0,
setData: null, setData: null,
+1
View File
@@ -48,6 +48,7 @@ watch(
() => route.query, () => route.query,
async (newParams) => { async (newParams) => {
if (newParams.type) { if (newParams.type) {
recommendList.value = null;
loadList(newParams.type as string); loadList(newParams.type as string);
} }
}, },
+1
View File
@@ -52,6 +52,7 @@ const timerIsQr = (key: string) => {
localStorage.setItem('token', data.cookie); localStorage.setItem('token', data.cookie);
const user = await getUserDetail(); const user = await getUserDetail();
store.state.user = user.data.profile; store.state.user = user.data.profile;
localStorage.setItem('user', JSON.stringify(store.state.user));
message.success('登录成功'); message.success('登录成功');
clearInterval(timer); clearInterval(timer);
-1
View File
@@ -66,7 +66,6 @@ const store = useStore();
onMounted(async () => { onMounted(async () => {
const res = await getTopMv(30); const res = await getTopMv(30);
mvList.value = res.data.data; mvList.value = res.data.data;
console.log('mvList.value', mvList.value);
}); });
const handleShowMv = async (item: IMvItem) => { const handleShowMv = async (item: IMvItem) => {
+12 -10
View File
@@ -21,29 +21,31 @@ const router = useRouter();
const userDetail = ref<IUserDetail>(); const userDetail = ref<IUserDetail>();
const playList = ref<any[]>([]); const playList = ref<any[]>([]);
const recordList = ref(); const recordList = ref();
let { user } = store.state;
const user = computed(() => store.state.user);
const loadPage = async () => { const loadPage = async () => {
if (!user) { if (!user.value) {
router.push('/login'); router.push('/login');
return; return;
} }
const { data: userData } = await getUserDetail(user.userId); const { data: userData } = await getUserDetail(user.value.userId);
userDetail.value = userData; userDetail.value = userData;
const { data: playlistData } = await getUserPlaylist(user.userId); const { data: playlistData } = await getUserPlaylist(user.value.userId);
playList.value = playlistData.playlist; playList.value = playlistData.playlist;
const { data: recordData } = await getUserRecord(user.userId); const { data: recordData } = await getUserRecord(user.value.userId);
recordList.value = recordData.allData; recordList.value = recordData.allData;
}; };
onMounted(() => { onActivated(() => {
const localUser = localStorage.getItem('user'); if (!user.value) {
store.state.user = localUser ? JSON.parse(localUser) : null; router.push('/login');
user = store.state.user; } else {
loadPage(); loadPage();
}
}); });
const isShowList = ref(false); const isShowList = ref(false);