accountService.js 1.04 KB
Newer Older
1 2
import { request, METHOD } from '@/utils/requestUtil';
import md5 from 'crypto-js/md5';
水落(YangLei)'s avatar
水落(YangLei) committed
3 4
import { clearToken, clearUserId } from '@/utils';
import { logoutApi } from '@/api';
wb-ct393452's avatar
wb-ct393452 committed
5 6 7 8 9 10 11

/**
 * 登录服务,登录成功后 根据用户ID 获取用户 角色 + 菜单 + 功能权限 + 用户基本信息
 * @param name 账户名
 * @param password 账户密码
 * @returns {Promise<AxiosResponse<T>>}
 */
12 13 14 15 16
export async function login(userName, password) {
    return request('/api/v1/login', METHOD.POST, {
        userName,
        password: md5(password).toString(),
    });
wb-ct393452's avatar
wb-ct393452 committed
17 18 19 20 21 22
}

/**
 * 退出登录
 */
export function logout() {
水落(YangLei)'s avatar
水落(YangLei) committed
23 24 25 26 27
    // //清除所有保存的信息
    // localStorage.removeItem(process.env.VUE_APP_ROUTES_KEY);
    // localStorage.removeItem(process.env.VUE_APP_PERMISSIONS_KEY);
    // localStorage.removeItem(process.env.VUE_APP_ROLES_KEY);
    // localStorage.removeItem(process.env.VUE_APP_USER_KEY);
水落(YangLei)'s avatar
水落(YangLei) committed
28 29 30 31 32
    return logoutApi().then(res => {
        clearToken();
        clearUserId();
        return res;
    });
wb-ct393452's avatar
wb-ct393452 committed
33 34 35
}

export default {
36 37 38
    login,
    logout,
};