This commit is contained in:
孟帅
2023-05-12 16:20:22 +08:00
parent f30fd885be
commit 9198a53584
52 changed files with 982 additions and 834 deletions

View File

@@ -24,7 +24,7 @@
import { useLockscreenStore } from '@/store/modules/lockscreen';
import { useRoute } from 'vue-router';
import { useDesignSettingStore } from '@/store/modules/designSetting';
import { lighten } from '@/utils/index';
import { lighten } from '@/utils';
const route = useRoute();
const useLockscreen = useLockscreenStore();

View File

@@ -101,6 +101,21 @@ export function login(params) {
);
}
/**
* @description: 用户注销
*/
export function logout() {
return http.request<BasicResponseModel>(
{
url: ApiEnum.SiteLogout,
method: 'POST',
},
{
isTransformResponse: false,
}
);
}
/**
* @description: 用户修改密码
*/
@@ -116,14 +131,3 @@ export function changePassword(params, uid) {
}
);
}
/**
* @description: 用户登出
*/
export function logout(params) {
return http.request({
url: '/login/logout',
method: 'POST',
params,
});
}

View File

@@ -4,6 +4,7 @@ export enum ApiEnum {
// 基础
SiteLogin = '/site/login', // 登录
SiteLogout = '/site/logout', // 注销
SiteConfig = '/site/config', // 配置信息
// 用户

View File

@@ -301,16 +301,16 @@
});
};
// 退出登录
// 注销登录
const doLogout = () => {
dialog.info({
title: '提示',
content: '您确定要退出登录吗',
content: '您确定要注销登录吗',
positiveText: '确定',
negativeText: '取消',
onPositiveClick: () => {
userStore.logout().then(() => {
message.success('成功退出登录');
message.success('成功注销登录');
// 移除标签页
localStorage.removeItem(TABS_ROUTES);
router
@@ -377,7 +377,7 @@
key: 1,
},
{
label: '退出登录',
label: '注销登录',
key: 2,
},
];

View File

@@ -3,7 +3,7 @@ import { createStorage, storage } from '@/utils/Storage';
import { store } from '@/store';
import { ACCESS_TOKEN, CURRENT_CONFIG, CURRENT_USER, IS_LOCKSCREEN } from '@/store/mutation-types';
import { ResultEnum } from '@/enums/httpEnum';
import { getConfig, getUserInfo, login } from '@/api/system/user';
import { getConfig, getUserInfo, login, logout } from '@/api/system/user';
const Storage = createStorage({ storage: localStorage });
export interface UserInfoState {
@@ -114,7 +114,7 @@ export const useUserStore = defineStore({
const response = await login(userInfo);
const { data, code } = response;
if (code === ResultEnum.SUCCESS) {
const ex = 7 * 24 * 60 * 60 * 1000;
const ex = 30 * 24 * 60 * 60 * 1000;
storage.set(ACCESS_TOKEN, data.token, ex);
storage.set(CURRENT_USER, data, ex);
storage.set(IS_LOCKSCREEN, false);
@@ -168,11 +168,19 @@ export const useUserStore = defineStore({
},
// 登出
async logout() {
this.setPermissions([]);
this.setUserInfo(null);
storage.remove(ACCESS_TOKEN);
storage.remove(CURRENT_USER);
return Promise.resolve('');
try {
const response = await logout();
const { code } = response;
if (code === ResultEnum.SUCCESS) {
this.setPermissions([]);
this.setUserInfo(null);
storage.remove(ACCESS_TOKEN);
storage.remove(CURRENT_USER);
}
return Promise.resolve(response);
} catch (e) {
return Promise.reject(e);
}
},
},
});

View File

@@ -105,10 +105,10 @@ const transform: AxiosTransform = {
const LoginPath = PageEnum.BASE_LOGIN;
if (router.currentRoute.value?.name === LoginName) return;
// 到登录页
errorMsg = '登录超时,请重新登录!';
errorMsg = message ?? '登录超时,请重新登录!';
$dialog.warning({
title: '提示',
content: '登录身份已失效,请重新登录!',
content: errorMsg, // '登录身份已失效,请重新登录!',
positiveText: '确定',
//negativeText: '取消',
closable: false,

View File

@@ -203,7 +203,7 @@
message.success('更新成功');
userStore.logout().then(() => {
message.success('成功退出登录');
message.success('成功注销登录');
// 移除标签页
localStorage.removeItem(TABS_ROUTES);
router

View File

@@ -193,7 +193,7 @@
message.success('更新成功');
userStore.logout().then(() => {
message.success('成功退出登录');
message.success('成功注销登录');
// 移除标签页
localStorage.removeItem(TABS_ROUTES);
router

View File

@@ -1,6 +1,6 @@
import { h } from 'vue';
import { NAvatar, NTag } from 'naive-ui';
import { timestampToTime, formatBefore, formatAfter } from '@/utils/dateUtil';
import { timestampToTime, formatBefore } from '@/utils/dateUtil';
export const columns = [
{
@@ -31,11 +31,11 @@ export const columns = [
return row.app;
},
},
// {
// title: '用户ID',
// key: 'userId',
// width: 100,
// },
{
title: '用户ID',
key: 'userId',
width: 100,
},
{
title: '用户名',
key: 'username',
@@ -90,14 +90,6 @@ export const columns = [
return row.os;
},
},
{
title: '授权过期',
key: 'expTime',
width: 80,
render: (rows, _) => {
return formatAfter(new Date(rows.expTime * 1000));
},
},
{
title: '最后活跃',
key: 'heartbeatTime',