From c1c379098f32b11cf7d9fb3967bcd17170149aee Mon Sep 17 00:00:00 2001 From: njzy Date: Sun, 29 Nov 2020 18:45:10 +0800 Subject: [PATCH] fix: set cookie when login with phone --- src/views/loginAccount.vue | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/src/views/loginAccount.vue b/src/views/loginAccount.vue index e9646a3..37cf1d2 100644 --- a/src/views/loginAccount.vue +++ b/src/views/loginAccount.vue @@ -160,12 +160,7 @@ export default { password: "fakePassword", md5_password: md5(this.password).toString(), }) - .then((data) => { - if (data.code !== 502) { - this.updateData({ key: "user", value: data.profile }); - this.afterLogin(); - } - }) + .then(this.handleLoginResponse) .catch((error) => { this.processing = false; alert(error); @@ -177,22 +172,27 @@ export default { password: "fakePassword", md5_password: md5(this.password).toString(), }) - .then((data) => { - // 获取接口返回的 MUSIC_U 写进本地 cookie 解决登录时跳转的问题 - // 但是仍然无法完全模拟登录状态,像喜欢歌曲和喜欢列表都会遇到 301 需要登录问题 - const MUSIC_U = getMusicU(data.cookie); - setMusicU("MUSIC_U", MUSIC_U); - if (data.code !== 502) { - this.updateData({ key: "user", value: data.profile }); - this.afterLogin(); - } - }) + .then(this.handleLoginResponse) .catch((error) => { this.processing = false; alert(error); }); } }, + handleLoginResponse(data) { + if (!data) { + this.processing = false; + return; + } + // 获取接口返回的 MUSIC_U 写进本地 cookie 解决登录时跳转的问题 + // 但是仍然无法完全模拟登录状态,像喜欢歌曲和喜欢列表都会遇到 301 需要登录问题 + const MUSIC_U = getMusicU(data.cookie); + setMusicU("MUSIC_U", MUSIC_U); + if (data.code !== 502) { + this.updateData({ key: "user", value: data.profile }); + this.afterLogin(); + } + }, }, };