feat: 退出登录调用接口

merge-requests/37/head
xiaoguang 3 years ago
parent c2d4c8103d
commit 9dcde1aac8

@ -147,11 +147,17 @@ export default {
Message.error("请勾选同意《用户协议》和《隐私协议》"); Message.error("请勾选同意《用户协议》和《隐私协议》");
return; return;
} }
const { result } = await ApiPostLogin({ const { result, error } = await ApiPostLogin({
...this.form, ...this.form,
clientId: 1, clientId: 1,
systemId: 3, systemId: 3,
}); });
if (error !== null) {
Message.error(
error.message || "登录失败,请检查手机号或验证码是否正确"
);
return;
}
if (result) { if (result) {
this.dialogTableVisible = false; this.dialogTableVisible = false;
this.$store.commit("setToken", result.token); this.$store.commit("setToken", result.token);

@ -122,7 +122,7 @@ export default {
this.$router.push("/account/address"); this.$router.push("/account/address");
break; break;
case MENU_VALUE.LOGON_OUT: case MENU_VALUE.LOGON_OUT:
this.$store.commit("setLoginOut"); this.$store.dispatch("logout");
} }
}, },

@ -31,6 +31,10 @@ export const ApiPutUser = (data) =>
* @param {*} data * @param {*} data
*/ */
export const ApiPostLogin = (data) => ToAsyncAwait(axios.post(`${BASE_URL}/user/login`, data)); export const ApiPostLogin = (data) => ToAsyncAwait(axios.post(`${BASE_URL}/user/login`, data));
/**
* 退出登录
*/
export const ApiPostLogout = () => ToAsyncAwait(axiosTk.get(`${BASE_URL}/user/logout`));
/** /**
* 获取手机验证码 * 获取手机验证码
* @param {*} params * @param {*} params

@ -16,15 +16,15 @@ export default function ({$axios, store, route}, inject) {
config.headers.Authorization = store.state.token; config.headers.Authorization = store.state.token;
return config; return config;
}); });
$axiosTk.onResponse(response => { $axiosTk.onResponse(async response => {
const result = response.data; const result = response.data;
if(response.status === 200){ if(response.status === 200){
if(result.code === 'SUCCESS'){ if(result.code === 'SUCCESS'){
return result.data; return result.data;
} }
if(result.code === 'TOKEN_FAIL'){ if(result.code === 'TOKEN_FAIL'){
alert('这里要弹登录') await store.dispatch('logout');
store.commit('setLoginOut'); store.commit('setLoginVisible');
return result; return result;
} }
return Promise.reject(result); return Promise.reject(result);

@ -6,7 +6,7 @@
* @Description: file content * @Description: file content
*/ */
import { TOKEN_KEY } from "@/constants"; import { TOKEN_KEY } from "@/constants";
import { ApiGetCurrentUser } from "@/plugins/api/account"; import { ApiGetCurrentUser, ApiPostLogout } from "@/plugins/api/account";
const ONE_DAY = 86400000; // 一天的毫秒数 24 * 60 * 60 * 1000; const ONE_DAY = 86400000; // 一天的毫秒数 24 * 60 * 60 * 1000;
const state = () => ({ const state = () => ({
@ -48,6 +48,12 @@ const actions = {
commit("setUserInfo", result); commit("setUserInfo", result);
} }
}, },
// 退出登录
async logout({ commit }) {
await ApiPostLogout();
commit("setLoginOut");
},
}; };
export { state, mutations, actions }; export { state, mutations, actions };

Loading…
Cancel
Save