Skip to content

Commit

Permalink
fix: 🧩 修复 axios 请求超时未拦截错误
Browse files Browse the repository at this point in the history
  • Loading branch information
Halsey committed Jul 21, 2022
1 parent d49b227 commit 856468e
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 18 deletions.
12 changes: 0 additions & 12 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,6 @@ All notable changes to this project will be documented in this file. See [standa

### [0.0.2](/~https://github.com/HalseySpicy/Geeker-Admin/compare/v0.0.3...v0.0.2) (2022-06-29)

### Bug Fixes

- 🧩 修改文件导出失败 bug ([208e720](/~https://github.com/HalseySpicy/Geeker-Admin/commit/208e720688969d2bc0fa0a6cc2bae3e3b991c806))
- 🧩 fix use pinia bug ([609aa69](/~https://github.com/HalseySpicy/Geeker-Admin/commit/609aa69aa9b3e0bb4e667ee7f76ab44051c2d2e8))

### [0.0.2](/~https://github.com/HalseySpicy/Geeker-Admin/compare/v0.0.3...v0.0.2) (2022-06-29)

### Bug Fixes

- 🧩 修改文件导出失败 bug ([208e720](/~https://github.com/HalseySpicy/Geeker-Admin/commit/208e720688969d2bc0fa0a6cc2bae3e3b991c806))
- 🧩 fix use pinia bug ([609aa69](/~https://github.com/HalseySpicy/Geeker-Admin/commit/609aa69aa9b3e0bb4e667ee7f76ab44051c2d2e8))

### 0.0.2 (2022-06-20)

### Features
Expand Down
10 changes: 6 additions & 4 deletions src/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { GlobalStore } from "@/store";
import router from "@/routers";

/**
* pinia 错误使用说明
* pinia 错误使用说明示例
* /~https://github.com/vuejs/pinia/discussions/971
* /~https://github.com/vuejs/pinia/discussions/664#discussioncomment-1329898
* https://pinia.vuejs.org/core-concepts/outside-component-usage.html#single-page-applications
Expand All @@ -36,7 +36,7 @@ class RequestHttp {
/**
* @description 请求拦截器
* 客户端发送请求 -> [请求拦截器] -> 服务器
* token校验(JWT) : 接受服务器返回的token,存储到vuex/本地储存当中
* token校验(JWT) : 接受服务器返回的token,存储到vuex/pinia/本地储存当中
*/
this.service.interceptors.request.use(
(config: AxiosRequestConfig) => {
Expand Down Expand Up @@ -84,10 +84,12 @@ class RequestHttp {
async (error: AxiosError) => {
const { response } = error;
tryHideFullScreenLoading();
// 请求超时单独判断,请求超时没有 response
if (error.message.indexOf("timeout") !== -1) ElMessage.error("请求超时,请稍后再试");
// 根据响应的错误状态码,做不同的处理
if (response) return checkStatus(response.status);
if (response) checkStatus(response.status);
// 服务器结果都没有返回(可能服务器错误可能客户端断网),断网处理:可以跳转到断网页面
if (!window.navigator.onLine) return router.replace({ path: "/500" });
if (!window.navigator.onLine) router.replace({ path: "/500" });
return Promise.reject(error);
}
);
Expand Down
2 changes: 1 addition & 1 deletion src/hooks/useTable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export const useTable = (api: (params: any) => Promise<any>, initParam: object =
* */
const getTableList = async () => {
try {
// 先更新查询参数
// 先把初始化参数和分页参数放到总参数里面
Object.assign(state.totalParam, initParam, isPageable ? pageParam.value : {});
const { data } = await api(state.totalParam);
state.tableData = isPageable ? data.datalist : data;
Expand Down
2 changes: 1 addition & 1 deletion src/views/login/components/LoginForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ onMounted(() => {
// 监听enter事件(调用登录)
document.onkeydown = (e: any) => {
e = window.event || e;
if (e.code === "Enter" || e.code === "enter") {
if (e.code === "Enter" || e.code === "enter" || e.code === "NumpadEnter") {
if (loading.value) return;
login(loginFormRef.value);
}
Expand Down

0 comments on commit 856468e

Please sign in to comment.