feat: add login expiration notification (#6738)

#### What type of PR is this?

/area ui
/kind improvement
/milestone 2.20.x

#### What this PR does / why we need it:

添加登录失效的引导。

<img width="1080" alt="image" src="https://github.com/user-attachments/assets/a84c0059-b0ef-4105-b8e9-ae6b3d39d89d">


#### Does this PR introduce a user-facing change?

```release-note
None 
```
pull/6749/head
Ryan Wang 2024-09-30 19:01:52 +08:00 committed by GitHub
parent db65dd3b3a
commit e11a494c96
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 23 additions and 4 deletions

View File

@ -1748,11 +1748,13 @@ core:
titles: titles:
tip: Tip tip: Tip
warning: Warning warning: Warning
login_expired: Login expired
descriptions: descriptions:
cannot_be_recovered: This operation is irreversible. cannot_be_recovered: This operation is irreversible.
editor_not_found: >- editor_not_found: >-
No editor found that matches the {raw_type} format. Please check if No editor found that matches the {raw_type} format. Please check if
the editor plugin has been installed. the editor plugin has been installed.
login_expired: The current session has expired. Click Confirm to go to the login page. Please ensure that the current content is saved. You can click Cancel to manually copy any unsaved content.
filters: filters:
results: results:
keyword: "Keyword: {keyword}" keyword: "Keyword: {keyword}"

View File

@ -1635,9 +1635,11 @@ core:
titles: titles:
tip: 提示 tip: 提示
warning: 警告 warning: 警告
login_expired: 登录已过期
descriptions: descriptions:
cannot_be_recovered: 该操作不可恢复。 cannot_be_recovered: 该操作不可恢复。
editor_not_found: 未找到符合 {raw_type} 格式的编辑器,请检查是否已安装编辑器插件。 editor_not_found: 未找到符合 {raw_type} 格式的编辑器,请检查是否已安装编辑器插件。
login_expired: 当前登录已过期,点击确定跳转到登录页面,请确保当前内容已保存,你可以点击取消之后手动复制未保存的内容。
filters: filters:
results: results:
keyword: 关键词:{keyword} keyword: 关键词:{keyword}

View File

@ -1616,9 +1616,11 @@ core:
titles: titles:
tip: 提示 tip: 提示
warning: 警告 warning: 警告
login_expired: 登入已過期
descriptions: descriptions:
cannot_be_recovered: 該操作不可恢復。 cannot_be_recovered: 該操作不可恢復。
editor_not_found: 未找到符合 {raw_type} 格式的編輯器,請檢查是否已安裝編輯器插件。 editor_not_found: 未找到符合 {raw_type} 格式的編輯器,請檢查是否已安裝編輯器插件。
login_expired: 當前登入已過期,點擊確定跳轉到登入頁面,請確保當前內容已保存,你可以點擊取消之後手動複製未保存的內容。
filters: filters:
results: results:
keyword: 關鍵字:{keyword} keyword: 關鍵字:{keyword}

View File

@ -1,6 +1,6 @@
import { i18n } from "@/locales"; import { i18n } from "@/locales";
import { axiosInstance } from "@halo-dev/api-client"; import { axiosInstance } from "@halo-dev/api-client";
import { Toast } from "@halo-dev/components"; import { Dialog, Toast } from "@halo-dev/components";
import type { AxiosError } from "axios"; import type { AxiosError } from "axios";
export interface ProblemDetail { export interface ProblemDetail {
@ -44,9 +44,22 @@ export function setupApiClient() {
const { title, detail } = errorResponse.data; const { title, detail } = errorResponse.data;
if (status === 401) { if (status === 401) {
Toast.warning(i18n.global.t("core.common.toast.login_expired")); Dialog.warning({
title: i18n.global.t("core.common.dialog.titles.login_expired"),
// TODO: show dialog description: i18n.global.t(
"core.common.dialog.descriptions.login_expired"
),
confirmType: "secondary",
confirmText: i18n.global.t("core.common.buttons.confirm"),
cancelText: i18n.global.t("core.common.buttons.cancel"),
uniqueId: "login_expired",
onConfirm: () => {
const currentPath = `${location.pathname}${location.search}`;
location.href = `/login?redirect_uri=${encodeURIComponent(
currentPath
)}`;
},
});
return Promise.reject(error); return Promise.reject(error);
} }