Skip to content

Commit

Permalink
perf: core 掉线 luna 页面提示优化
Browse files Browse the repository at this point in the history
  • Loading branch information
feng626 committed May 11, 2024
1 parent df9f6b0 commit d7f8e75
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 10 deletions.
35 changes: 25 additions & 10 deletions src/app/services/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,12 @@ export class AppService {
status = 'ok';
User.logined = true;
} catch (err) {
status = 'error';
status = 'error'; // 默认错误状态
if (err.status === 401) {
status = 'unauthorized';
} else if (err.status === 400) {
status = 'badrequest';
}
} finally {
localStorage.setItem('CheckProfile', status + ' ' + new Date().getTime());
}
Expand All @@ -101,24 +106,34 @@ export class AppService {

async doCheckProfile(recheck = false) {
const status = await this.getProfileStatus(recheck);
if (status === 'ok') {
this.newLoginHasOpen = false;
// 重新检查时,如果好了,重启 check
if (recheck) {
this.intervalCheckLogin().then();
}
} else {
if (['unauthorized', 'badrequest', 'error'].includes(status)) {
clearInterval(this.checkIntervalId);
const ok = confirm(this._i18n.instant('LoginExpireMsg'));
const ok = confirm(this._i18n.instant(this.getErrorMsg(status)));
if (ok && !this.newLoginHasOpen) {
window.open('/core/auth/login/?next=/luna/', '_self');
this.newLoginHasOpen = true;
}
setTimeout(() => this.doCheckProfile(true), 5 * 1000);
setTimeout(() => this.doCheckProfile(true), 5000);
this._logger.debug(`${status}, redirect to login`);
} else if (status === 'ok') {
this.newLoginHasOpen = false;
if (recheck) {
this.intervalCheckLogin().then();
}
this._logger.debug('Profile is ok');
}
return status;
}

getErrorMsg(status: string) {
const messages = {
'unauthorized': 'LoginExpireMsg',
'badrequest': 'Bad request. The server does not understand the syntax of the request',
'error': 'The server encountered an error while trying to process the request'
};
return messages[status];
}

async intervalCheckLogin(second = null, clear: boolean = false) {
if (second == null) {
second = this.checkSecond;
Expand Down
2 changes: 2 additions & 0 deletions src/assets/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@
"Username@Domain": "Username@Domain",
"InstallClientMsg": "JumpServer client not found, Go to download and install?",
"LoginExpireMsg": "Login session expired, please re-login",
"Bad request. The server does not understand the syntax of the request": "Bad request. The server does not understand the syntax of the request",
"The server encountered an error while trying to process the request": "The server encountered an error while trying to process the request",
"No permission": "No permission",
"Last login": "Last login",
"Log out": "Log out",
Expand Down
2 changes: 2 additions & 0 deletions src/assets/i18n/ja.json
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,8 @@
"Username@Domain": "ユーザー名 @ ADドメイン",
"InstallClientMsg": "JumpServerクライアントがインストールされていない、今ダウンロードしてインストールしますか?",
"LoginExpireMsg": "ログインが期限切れになりました。ログインし直してください",
"Bad request. The server does not understand the syntax of the request": "要求の形式が正しくありません。 サーバーはリクエストの構文を理解していません",
"The server encountered an error while trying to process the request": "サーバーがリクエストを処理しようとしたときにエラーが発生しました",
"No permission": "権限がありません",
"Last login": "前回ログイン",
"Log out": "ログインを終了",
Expand Down
2 changes: 2 additions & 0 deletions src/assets/i18n/zh-hant.json
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,8 @@
"Username@Domain": "使用者名稱@AD域",
"InstallClientMsg": "JumpServer 用戶端沒有安裝,現在去下載安裝?",
"LoginExpireMsg": "登入已過期,請重新登入",
"Bad request. The server does not understand the syntax of the request": "錯誤的請求。 服務器不理解請求的語法",
"The server encountered an error while trying to process the request": "服務器在嘗試處理請求時遇到錯誤",
"No permission": "沒有權限",
"Last login": "上次登入",
"Log out": "退出登入",
Expand Down
2 changes: 2 additions & 0 deletions src/assets/i18n/zh.json
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@
"Username@Domain": "用户名@AD域",
"InstallClientMsg": "JumpServer 客户端没有安装,现在去下载安装?",
"LoginExpireMsg": "登录已过期,请重新登录",
"Bad request. The server does not understand the syntax of the request": "错误的请求。 服务器不理解请求的语法",
"The server encountered an error while trying to process the request": "服务器在尝试处理请求时遇到错误",
"No permission": "没有权限",
"Last login": "上次登录",
"Log out": "退出登录",
Expand Down

0 comments on commit d7f8e75

Please sign in to comment.