🐞 fix: 修复登录状态问题 修复播放退出登录的问题

This commit is contained in:
alger
2025-01-25 21:49:22 +08:00
parent 599b0251af
commit 4fa1295b84
6 changed files with 23 additions and 27 deletions

View File

@@ -14,15 +14,19 @@ export const getMusicQualityDetail = (id: number) => {
// 根据音乐Id获取音乐播放URl
export const getMusicUrl = async (id: number) => {
const res = await request.get('/song/download/url/v1', {
params: {
id,
level: store.state.setData.musicQuality || 'higher'
}
});
// 判断是否登录
if (store.state.user) {
const res = await request.get('/song/download/url/v1', {
params: {
id,
level: store.state.setData.musicQuality || 'higher',
cookie: `${localStorage.getItem('token')} os=pc;`
}
});
if (res.data.data.url) {
return { data: { data: [{ ...res.data.data }] } };
if (res.data.data.url) {
return { data: { data: [{ ...res.data.data }] } };
}
}
return await request.get('/song/url/v1', {

View File

@@ -27,14 +27,11 @@ declare module 'vue' {
NInput: typeof import('naive-ui')['NInput']
NInputNumber: typeof import('naive-ui')['NInputNumber']
NLayout: typeof import('naive-ui')['NLayout']
NList: typeof import('naive-ui')['NList']
NListItem: typeof import('naive-ui')['NListItem']
NMessageProvider: typeof import('naive-ui')['NMessageProvider']
NModal: typeof import('naive-ui')['NModal']
NPopover: typeof import('naive-ui')['NPopover']
NProgress: typeof import('naive-ui')['NProgress']
NRadio: typeof import('naive-ui')['NRadio']
NRadioButton: typeof import('naive-ui')['NRadioButton']
NRadioGroup: typeof import('naive-ui')['NRadioGroup']
NScrollbar: typeof import('naive-ui')['NScrollbar']
NSelect: typeof import('naive-ui')['NSelect']
@@ -46,7 +43,6 @@ declare module 'vue' {
NTabs: typeof import('naive-ui')['NTabs']
NTag: typeof import('naive-ui')['NTag']
NTooltip: typeof import('naive-ui')['NTooltip']
NTransfer: typeof import('naive-ui')['NTransfer']
NVirtualList: typeof import('naive-ui')['NVirtualList']
RouterLink: typeof import('vue-router')['RouterLink']
RouterView: typeof import('vue-router')['RouterView']

View File

@@ -50,7 +50,7 @@ request.interceptors.request.use(
};
const token = localStorage.getItem('token');
if (token) {
config.params.cookie = `${token} os=pc;`;
config.params.cookie = config.params.cookie || token;
}
if (isElectron) {
const proxyConfig = setData?.proxyConfig;

View File

@@ -132,6 +132,7 @@ onBeforeUnmount(() => {
const checkLoginStatus = () => {
const token = localStorage.getItem('token');
const userData = localStorage.getItem('user');
console.log('触发了', token, userData);
if (!token || !userData) {
router.push('/login');
@@ -152,6 +153,10 @@ const loadPage = async () => {
// 检查登录状态
if (!checkLoginStatus()) return;
await loadData();
};
const loadData = async () => {
try {
infoLoading.value = true;
@@ -188,10 +193,10 @@ const loadPage = async () => {
watch(
() => router.currentRoute.value.path,
(newPath) => {
console.log('newPath', newPath);
if (newPath === '/user') {
checkLoginStatus();
} else {
loadPage();
loadData();
}
}
);