feat: 退出登录调用接口

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

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

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

@ -31,6 +31,10 @@ export const ApiPutUser = (data) =>
* @param {*} 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

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

@ -6,7 +6,7 @@
* @Description: file content
*/
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 state = () => ({
@ -48,6 +48,12 @@ const actions = {
commit("setUserInfo", result);
}
},
// 退出登录
async logout({ commit }) {
await ApiPostLogout();
commit("setLoginOut");
},
};
export { state, mutations, actions };

Loading…
Cancel
Save