mirror of
https://github.com/GiriNeko/YesPlayMusic.git
synced 2025-12-16 13:17:46 +00:00
Merge branch 'master' into deploy
This commit is contained in:
commit
e74c34c2c2
2 changed files with 31 additions and 36 deletions
|
|
@ -2,27 +2,33 @@ import Cookies from 'js-cookie';
|
|||
import { logout } from '@/api/auth';
|
||||
import store from '@/store';
|
||||
|
||||
export function doLogout() {
|
||||
logout();
|
||||
// 网易云的接口会自动移除该 cookies
|
||||
Cookies.remove('MUSIC_U');
|
||||
// 更新状态仓库中的用户信息
|
||||
store.commit('updateData', { key: 'user', value: {} });
|
||||
// 更新状态仓库中的登录状态
|
||||
store.commit('updateData', { key: 'loginMode', value: null });
|
||||
// 更新状态仓库中的喜欢列表
|
||||
store.commit('updateData', { key: 'likedSongPlaylistID', value: undefined });
|
||||
export function setCookies(string) {
|
||||
const cookies = string.split(';;');
|
||||
cookies.map(cookie => {
|
||||
document.cookie = cookie;
|
||||
const cookieKeyValue = cookie.split(';')[0].split('=');
|
||||
localStorage.setItem(`cookie-${cookieKeyValue[0]}`, cookieKeyValue[1]);
|
||||
});
|
||||
}
|
||||
|
||||
export function getCookie(key) {
|
||||
return Cookies.get(key) ?? localStorage.getItem(`cookie-${key}`);
|
||||
}
|
||||
|
||||
export function removeCookie(key) {
|
||||
Cookies.remove(key);
|
||||
localStorage.removeItem(`cookie-${key}`);
|
||||
}
|
||||
|
||||
// MUSIC_U 只有在账户登录的情况下才有
|
||||
export function isLoggedIn() {
|
||||
return Cookies.get('MUSIC_U') !== undefined ? true : false;
|
||||
return getCookie('MUSIC_U') !== undefined;
|
||||
}
|
||||
|
||||
// 账号登录
|
||||
export function isAccountLoggedIn() {
|
||||
return (
|
||||
Cookies.get('MUSIC_U') !== undefined &&
|
||||
getCookie('MUSIC_U') !== undefined &&
|
||||
store.state.data.loginMode === 'account'
|
||||
);
|
||||
}
|
||||
|
|
@ -37,25 +43,14 @@ export function isLooseLoggedIn() {
|
|||
return isAccountLoggedIn() || isUsernameLoggedIn();
|
||||
}
|
||||
|
||||
export function getMusicU(string) {
|
||||
const temp = string.split(';');
|
||||
if (!temp.length) {
|
||||
return undefined;
|
||||
}
|
||||
const MUSIC_U = temp.find(item => item.includes('MUSIC_U'));
|
||||
if (MUSIC_U) {
|
||||
return MUSIC_U.split('=')[1];
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
export function setMusicU(key, value) {
|
||||
return Cookies.set(key, value);
|
||||
}
|
||||
|
||||
export function setCookies(string) {
|
||||
const cookies = string.split(';;');
|
||||
cookies.map(cookie => {
|
||||
document.cookie = cookie;
|
||||
});
|
||||
export function doLogout() {
|
||||
logout();
|
||||
removeCookie('MUSIC_U');
|
||||
removeCookie('__csrf');
|
||||
// 更新状态仓库中的用户信息
|
||||
store.commit('updateData', { key: 'user', value: {} });
|
||||
// 更新状态仓库中的登录状态
|
||||
store.commit('updateData', { key: 'loginMode', value: null });
|
||||
// 更新状态仓库中的喜欢列表
|
||||
store.commit('updateData', { key: 'likedSongPlaylistID', value: undefined });
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import axios from 'axios';
|
||||
import Cookies from 'js-cookie';
|
||||
import { getCookie } from '@/utils/auth';
|
||||
|
||||
let baseURL = '';
|
||||
// Web 和 Electron 跑在不同端口避免同时启动时冲突
|
||||
|
|
@ -22,10 +22,10 @@ const service = axios.create({
|
|||
service.interceptors.request.use(function (config) {
|
||||
if (!config.params) config.params = {};
|
||||
if (baseURL[0] !== '/' && !process.env.IS_ELECTRON) {
|
||||
config.params.cookie = `MUSIC_U=${Cookies.get('MUSIC_U')};`;
|
||||
config.params.cookie = `MUSIC_U=${getCookie('MUSIC_U')};`;
|
||||
}
|
||||
|
||||
if (!process.env.IS_ELECTRON) {
|
||||
if (!process.env.IS_ELECTRON && !config.url.includes('/login')) {
|
||||
config.params.realIP = '211.161.244.70';
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue