|
@@ -6,6 +6,7 @@ import {
|
|
|
import routes from "./routes";
|
|
|
import LibForWeixin from "@/utils/LibForWeixin";
|
|
|
import { useUserStore, useAppStore } from "@/store";
|
|
|
+import { getUrlParam } from "../utils";
|
|
|
|
|
|
const router = createRouter({
|
|
|
// history: createWebHistory(import.meta.env.VITE_BASE),
|
|
@@ -17,11 +18,26 @@ const router = createRouter({
|
|
|
behavior: "smooth",
|
|
|
}),
|
|
|
});
|
|
|
+let pattern =
|
|
|
+ /^(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9])\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[0-9])$/;
|
|
|
const whiteList = ["Login", "WxLogin"];
|
|
|
router.beforeEach(async (to, from, next) => {
|
|
|
console.log("to:", to);
|
|
|
+ const code = getUrlParam("code");
|
|
|
const appStore = useAppStore();
|
|
|
- if (!appStore.globalConfig && to.name !== "WxLogin") {
|
|
|
+ const userStore = useUserStore();
|
|
|
+ if (
|
|
|
+ !userStore.openId &&
|
|
|
+ !code &&
|
|
|
+ !(
|
|
|
+ pattern.test(location.hostname) ||
|
|
|
+ location.hostname === "apply-test.qmth.com.cn"
|
|
|
+ )
|
|
|
+ ) {
|
|
|
+ LibForWeixin.auth();
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (!appStore.globalConfig && to.name !== "WxLogin" && userStore.openId) {
|
|
|
let config = await appStore.getGlobalConfig();
|
|
|
if (((config && !config?.taskTitle) || !config) && to.name !== "Login") {
|
|
|
next({ name: "Login", replace: true });
|
|
@@ -41,7 +57,6 @@ router.beforeEach(async (to, from, next) => {
|
|
|
next();
|
|
|
return;
|
|
|
}
|
|
|
- const userStore = useUserStore();
|
|
|
if (!userStore.loginInfo) {
|
|
|
next({ name: "Login", replace: true });
|
|
|
} else {
|