diff --git a/SafeCampus.WEB/src/api/modules/sys/auth/auth.ts b/SafeCampus.WEB/src/api/modules/sys/auth/auth.ts
new file mode 100644
index 0000000..3f79dfd
--- /dev/null
+++ b/SafeCampus.WEB/src/api/modules/sys/auth/auth.ts
@@ -0,0 +1,19 @@
+/**
+ * @description 授权模块接口
+ */
+
+import { moduleRequest } from "@/api/request";
+const http = moduleRequest("/sys/auth/activate/");
+
+const authsApi = {
+ /** 获取机器码 */
+ machineCode() {
+ return http.post("machineCode", {}, { loading: false }); // 正常 post json 请求 = application/json
+ },
+ /** 激活 */
+ activation(params: any) {
+ return http.post("activation", JSON.stringify(params), { loading: false, headers: { "Content-Type": "application/json" } });
+ }
+};
+
+export { authsApi };
diff --git a/SafeCampus.WEB/src/api/modules/sys/auth/index.ts b/SafeCampus.WEB/src/api/modules/sys/auth/index.ts
index 070b49d..19c0794 100644
--- a/SafeCampus.WEB/src/api/modules/sys/auth/index.ts
+++ b/SafeCampus.WEB/src/api/modules/sys/auth/index.ts
@@ -13,3 +13,4 @@
* @see https://gitee.com/dotnetmoyu/SimpleAdmin
*/
export * from "./login";
+export * from "./auth";
diff --git a/SafeCampus.WEB/src/api/request/instance.ts b/SafeCampus.WEB/src/api/request/instance.ts
index afe2c66..449d9e7 100644
--- a/SafeCampus.WEB/src/api/request/instance.ts
+++ b/SafeCampus.WEB/src/api/request/instance.ts
@@ -14,7 +14,7 @@
*/
import axios, { AxiosInstance, AxiosError, AxiosRequestConfig, InternalAxiosRequestConfig, AxiosResponse } from "axios";
import { showFullScreenLoading, tryHideFullScreenLoading } from "@/components/Loading/fullScreen";
-import { LOGIN_URL } from "@/config";
+import { LOGIN_URL, AUTH_URL } from "@/config";
import { ElMessage } from "element-plus";
import { ResultData } from "@/api/interface";
import { ResultEnum, TokenEnum } from "@/enums";
@@ -149,15 +149,20 @@ export default class RequestHttp {
},
async (error: AxiosError) => {
const { response } = error;
- tryHideFullScreenLoading();
- // 请求超时 && 网络错误单独判断,没有 response
- if (error.message.indexOf("timeout") !== -1) ElMessage.error("请求超时!请您稍后重试");
- if (error.message.indexOf("Network Error") !== -1) ElMessage.error("网络错误!请您稍后重试");
- // 根据服务器响应的错误状态码,做不同的处理
- if (response) checkStatus(response.status);
- // 服务器结果都没有返回(可能服务器错误可能客户端断网),断网处理:可以跳转到断网页面
- if (!window.navigator.onLine) router.replace("/500");
- return Promise.reject(error);
+ console.log(response, "err");
+ if (response?.status === 421) {
+ router.replace(AUTH_URL);
+ } else {
+ tryHideFullScreenLoading();
+ // 请求超时 && 网络错误单独判断,没有 response
+ if (error.message.indexOf("timeout") !== -1) ElMessage.error("请求超时!请您稍后重试");
+ if (error.message.indexOf("Network Error") !== -1) ElMessage.error("网络错误!请您稍后重试");
+ // 根据服务器响应的错误状态码,做不同的处理
+ if (response) checkStatus(response.status);
+ // 服务器结果都没有返回(可能服务器错误可能客户端断网),断网处理:可以跳转到断网页面
+ if (!window.navigator.onLine) router.replace("/500");
+ return Promise.reject(error);
+ }
}
);
}
diff --git a/SafeCampus.WEB/src/config/index.ts b/SafeCampus.WEB/src/config/index.ts
index dd5fccd..d856138 100644
--- a/SafeCampus.WEB/src/config/index.ts
+++ b/SafeCampus.WEB/src/config/index.ts
@@ -19,6 +19,9 @@ export const HOME_URL: string = "/home/index";
// 登录页地址(默认)
export const LOGIN_URL: string = "/login";
+// 授权页地址(默认)
+export const AUTH_URL: string = "/auth";
+
// 登录页地址(默认)
export const USER_CENTER_URL: string = "/userCenter";
diff --git a/SafeCampus.WEB/src/routers/index.ts b/SafeCampus.WEB/src/routers/index.ts
index c361d7f..4f2b957 100644
--- a/SafeCampus.WEB/src/routers/index.ts
+++ b/SafeCampus.WEB/src/routers/index.ts
@@ -15,7 +15,7 @@
import { createRouter, createWebHashHistory, createWebHistory } from "vue-router";
import { useUserStore } from "@/stores/modules/user";
import { useAuthStore } from "@/stores/modules/auth";
-import { LOGIN_URL, ROUTER_WHITE_LIST } from "@/config";
+import { LOGIN_URL, AUTH_URL, ROUTER_WHITE_LIST } from "@/config";
import { initDynamicRouter } from "@/routers/modules/dynamicRouter";
import { staticRouter, errorRouter } from "@/routers/modules/staticRouter";
import NProgress from "@/config/nprogress";
@@ -80,7 +80,11 @@ router.beforeEach(async (to, from, next) => {
// 5.判断是否有 Token,没有重定向到 login 页面
if (!userStore.accessToken) {
- return next({ path: LOGIN_URL, replace: true });
+ if (to.path.toLocaleLowerCase() === AUTH_URL) {
+ return next();
+ } else {
+ return next({ path: LOGIN_URL, replace: true });
+ }
}
// 6.如果没有菜单列表,就重新请求菜单列表并添加动态路由
diff --git a/SafeCampus.WEB/src/routers/modules/staticRouter.ts b/SafeCampus.WEB/src/routers/modules/staticRouter.ts
index f6570d0..5f0f69b 100644
--- a/SafeCampus.WEB/src/routers/modules/staticRouter.ts
+++ b/SafeCampus.WEB/src/routers/modules/staticRouter.ts
@@ -13,7 +13,7 @@
* @see https://gitee.com/dotnetmoyu/SimpleAdmin
*/
import { RouteRecordRaw } from "vue-router";
-import { HOME_URL, LOGIN_URL } from "@/config";
+import { HOME_URL, LOGIN_URL, AUTH_URL } from "@/config";
/**
* staticRouter (静态路由)
@@ -31,6 +31,14 @@ export const staticRouter: RouteRecordRaw[] = [
title: "登录"
}
},
+ {
+ path: AUTH_URL,
+ name: "auth",
+ component: () => import("@/views/login/auth.vue"),
+ meta: {
+ title: "授权"
+ }
+ },
{
path: "/layout",
name: "layout",
@@ -63,7 +71,7 @@ export const staticRouter: RouteRecordRaw[] = [
component: () => import("@/views/screen/index.vue"),
meta: {
title: "AI智能预警分析平台"
- },
+ }
},
{
name: "AI智能预警分析平台-智慧课堂",
@@ -80,7 +88,7 @@ export const staticRouter: RouteRecordRaw[] = [
},
path: "/screen/stureturn",
component: () => import("@/views/screen/stureturn.vue")
- },
+ }
];
/**
diff --git a/SafeCampus.WEB/src/views/login/auth.vue b/SafeCampus.WEB/src/views/login/auth.vue
new file mode 100644
index 0000000..2ccbadc
--- /dev/null
+++ b/SafeCampus.WEB/src/views/login/auth.vue
@@ -0,0 +1,68 @@
+
+
+
+
+
+
+
+
+
+
+
+
+ 激 活
+
+
+
+
+
+
+
+