|
@@ -6,12 +6,7 @@ import type { StorageConfigs } from "/#/index";
|
|
|
import { useMultiTagsStoreHook } from "/@/store/modules/multiTags";
|
|
|
import { usePermissionStoreHook } from "/@/store/modules/permission";
|
|
|
import { useNav } from "../layout/hooks/nav";
|
|
|
-import { loadEnv } from "@build/index";
|
|
|
-import { ref } from "vue";
|
|
|
-import * as dd from "dingtalk-jsapi";
|
|
|
-const { VITE_CORP_ID } = loadEnv();
|
|
|
-import { JudgeEnvironment } from "/@/utils/validate";
|
|
|
-import { useUserStoreHook } from "/@/store/modules/user";
|
|
|
+
|
|
|
import {
|
|
|
Router,
|
|
|
RouteMeta,
|
|
@@ -79,176 +74,131 @@ export const router: Router = createRouter({
|
|
|
}
|
|
|
});
|
|
|
|
|
|
-const code = ref("");
|
|
|
-
|
|
|
-function testing() {
|
|
|
- dd?.ready(() => {
|
|
|
- //使用SDK 获取免登授权码
|
|
|
- dd?.runtime?.permission?.requestAuthCode({
|
|
|
- corpId: VITE_CORP_ID,
|
|
|
- onSuccess: info => {
|
|
|
- alert("dd-success");
|
|
|
- code.value = info?.code ?? "";
|
|
|
- // 根据钉钉提供的api 获得code后,再次调用这个callback方法
|
|
|
- // 由于是钉钉获取code是异步操作,不知道什么时候执行完毕
|
|
|
- // callback 函数会等他执行完毕后在自己调用自己
|
|
|
- alert(code.value);
|
|
|
- setcode(code.value);
|
|
|
- },
|
|
|
- onFail: err => {
|
|
|
- alert("fail");
|
|
|
- alert(JSON.stringify(err));
|
|
|
- }
|
|
|
- });
|
|
|
- });
|
|
|
-}
|
|
|
-function setcode(code) {
|
|
|
- const model = { code };
|
|
|
- useUserStoreHook()
|
|
|
- .dingUserInfor(model)
|
|
|
- .then(res => {
|
|
|
- console.log(res);
|
|
|
- // alert(res);
|
|
|
- if (res == "success") {
|
|
|
- router.push("/");
|
|
|
- } else {
|
|
|
- router.push("/login");
|
|
|
- }
|
|
|
- })
|
|
|
- .catch(() => {});
|
|
|
-}
|
|
|
-
|
|
|
// 路由白名单
|
|
|
const whiteList = ["/login"];
|
|
|
-// alert(JudgeEnvironment());
|
|
|
-// console.log("111111111", JudgeEnvironment());
|
|
|
-// setcode("1111111");
|
|
|
if (usePermissionStoreHook().wholeMenus.length === 0)
|
|
|
- if (JudgeEnvironment() === "isDingDing") {
|
|
|
- testing();
|
|
|
- }
|
|
|
-router.beforeEach((to: toRouteType, _from, next) => {
|
|
|
- if (to.meta?.keepAlive) {
|
|
|
- const newMatched = to.matched;
|
|
|
- handleAliveRoute(newMatched, "add");
|
|
|
- // 页面整体刷新和点击标签页刷新
|
|
|
- if (_from.name === undefined || _from.name === "Redirect") {
|
|
|
- handleAliveRoute(newMatched);
|
|
|
+ router.beforeEach((to: toRouteType, _from, next) => {
|
|
|
+ if (to.meta?.keepAlive) {
|
|
|
+ const newMatched = to.matched;
|
|
|
+ handleAliveRoute(newMatched, "add");
|
|
|
+ // 页面整体刷新和点击标签页刷新
|
|
|
+ if (_from.name === undefined || _from.name === "Redirect") {
|
|
|
+ handleAliveRoute(newMatched);
|
|
|
+ }
|
|
|
}
|
|
|
- }
|
|
|
- const name = storageSession.getItem<StorageConfigs>("info");
|
|
|
- NProgress.start();
|
|
|
- const externalLink = isUrl(to?.name as string);
|
|
|
- if (!externalLink)
|
|
|
- to.matched.some(item => {
|
|
|
- if (!item.meta.title) return "";
|
|
|
- const Title = getConfig().Title;
|
|
|
- if (Title) document.title = `${item.meta.title} | ${Title}`;
|
|
|
- else document.title = `${item.meta.title}`;
|
|
|
- });
|
|
|
- if (name) {
|
|
|
- if (_from?.name) {
|
|
|
- // name为超链接
|
|
|
- if (externalLink) {
|
|
|
- openLink(to?.name as string);
|
|
|
- NProgress.done();
|
|
|
+ const name = storageSession.getItem<StorageConfigs>("info");
|
|
|
+
|
|
|
+ const externalLink = isUrl(to?.name as string);
|
|
|
+ if (!externalLink)
|
|
|
+ to.matched.some(item => {
|
|
|
+ if (!item.meta.title) return "";
|
|
|
+ const Title = getConfig().Title;
|
|
|
+ if (Title) document.title = `${item.meta.title} | ${Title}`;
|
|
|
+ else document.title = `${item.meta.title}`;
|
|
|
+ });
|
|
|
+ if (name) {
|
|
|
+ if (_from?.name) {
|
|
|
+ // name为超链接
|
|
|
+ if (externalLink) {
|
|
|
+ openLink(to?.name as string);
|
|
|
+ NProgress.done();
|
|
|
+ } else {
|
|
|
+ next();
|
|
|
+ }
|
|
|
} else {
|
|
|
+ // 刷新
|
|
|
+
|
|
|
+ initRouter()
|
|
|
+ .then((router: Router) => {
|
|
|
+ if (!useMultiTagsStoreHook().getMultiTagsCache) {
|
|
|
+ const handTag = (
|
|
|
+ path: string,
|
|
|
+ parentPath: string,
|
|
|
+ name: RouteRecordName,
|
|
|
+ meta: RouteMeta
|
|
|
+ ): void => {
|
|
|
+ useMultiTagsStoreHook().handleTags("push", {
|
|
|
+ path,
|
|
|
+ parentPath,
|
|
|
+ name,
|
|
|
+ meta
|
|
|
+ });
|
|
|
+ };
|
|
|
+ // 未开启标签页缓存,刷新页面重定向到顶级路由(参考标签页操作例子,只针对静态路由)
|
|
|
+ if (to.meta?.refreshRedirect) {
|
|
|
+ const routes = router.options.routes;
|
|
|
+ const { refreshRedirect } = to.meta;
|
|
|
+ const { name, meta } = findRouteByPath(refreshRedirect, routes);
|
|
|
+ handTag(
|
|
|
+ refreshRedirect,
|
|
|
+ getParentPaths(refreshRedirect, routes)[1],
|
|
|
+ name,
|
|
|
+ meta
|
|
|
+ );
|
|
|
+ return router.push(refreshRedirect);
|
|
|
+ } else {
|
|
|
+ // const { path } = to;
|
|
|
+ // const index = findIndex(remainingRouter, v => {
|
|
|
+ // return v.path == path;
|
|
|
+ // });
|
|
|
+ // const routes =
|
|
|
+ // index === -1
|
|
|
+ // ? router.options.routes[0].children
|
|
|
+ // : router.options.routes;
|
|
|
+ // const route = findRouteByPath(path, routes);
|
|
|
+ // const routePartent = getParentPaths(path, routes);
|
|
|
+ // 未开启标签页缓存,刷新页面重定向到顶级路由(参考标签页操作例子,只针对动态路由)
|
|
|
+ // if (
|
|
|
+ // path !== routes[0].path &&
|
|
|
+ // route?.meta?.rank !== 0 &&
|
|
|
+ // routePartent.length === 0
|
|
|
+ // ) {
|
|
|
+ // if (!route?.meta?.refreshRedirect) return;
|
|
|
+ // const { name, meta } = findRouteByPath(
|
|
|
+ // route.meta.refreshRedirect,
|
|
|
+ // routes
|
|
|
+ // );
|
|
|
+ // handTag(
|
|
|
+ // route.meta?.refreshRedirect,
|
|
|
+ // getParentPaths(route.meta?.refreshRedirect, routes)[0],
|
|
|
+ // name,
|
|
|
+ // meta
|
|
|
+ // );
|
|
|
+ // return router.push(route.meta?.refreshRedirect);
|
|
|
+ // } else {
|
|
|
+ // handTag(
|
|
|
+ // route.path,
|
|
|
+ // routePartent[routePartent.length - 1],
|
|
|
+ // route.name,
|
|
|
+ // route.meta
|
|
|
+ // );
|
|
|
+ // return router.push(path);
|
|
|
+ // }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // router.push(to.fullPath);
|
|
|
+ next();
|
|
|
+ })
|
|
|
+ .catch(s => {
|
|
|
+ console.log(s);
|
|
|
+ logout();
|
|
|
+
|
|
|
+ next({ path: "/login" });
|
|
|
+ });
|
|
|
next();
|
|
|
}
|
|
|
} else {
|
|
|
- // 刷新
|
|
|
-
|
|
|
- initRouter()
|
|
|
- .then((router: Router) => {
|
|
|
- if (!useMultiTagsStoreHook().getMultiTagsCache) {
|
|
|
- const handTag = (
|
|
|
- path: string,
|
|
|
- parentPath: string,
|
|
|
- name: RouteRecordName,
|
|
|
- meta: RouteMeta
|
|
|
- ): void => {
|
|
|
- useMultiTagsStoreHook().handleTags("push", {
|
|
|
- path,
|
|
|
- parentPath,
|
|
|
- name,
|
|
|
- meta
|
|
|
- });
|
|
|
- };
|
|
|
- // 未开启标签页缓存,刷新页面重定向到顶级路由(参考标签页操作例子,只针对静态路由)
|
|
|
- if (to.meta?.refreshRedirect) {
|
|
|
- const routes = router.options.routes;
|
|
|
- const { refreshRedirect } = to.meta;
|
|
|
- const { name, meta } = findRouteByPath(refreshRedirect, routes);
|
|
|
- handTag(
|
|
|
- refreshRedirect,
|
|
|
- getParentPaths(refreshRedirect, routes)[1],
|
|
|
- name,
|
|
|
- meta
|
|
|
- );
|
|
|
- return router.push(refreshRedirect);
|
|
|
- } else {
|
|
|
- // const { path } = to;
|
|
|
- // const index = findIndex(remainingRouter, v => {
|
|
|
- // return v.path == path;
|
|
|
- // });
|
|
|
- // const routes =
|
|
|
- // index === -1
|
|
|
- // ? router.options.routes[0].children
|
|
|
- // : router.options.routes;
|
|
|
- // const route = findRouteByPath(path, routes);
|
|
|
- // const routePartent = getParentPaths(path, routes);
|
|
|
- // 未开启标签页缓存,刷新页面重定向到顶级路由(参考标签页操作例子,只针对动态路由)
|
|
|
- // if (
|
|
|
- // path !== routes[0].path &&
|
|
|
- // route?.meta?.rank !== 0 &&
|
|
|
- // routePartent.length === 0
|
|
|
- // ) {
|
|
|
- // if (!route?.meta?.refreshRedirect) return;
|
|
|
- // const { name, meta } = findRouteByPath(
|
|
|
- // route.meta.refreshRedirect,
|
|
|
- // routes
|
|
|
- // );
|
|
|
- // handTag(
|
|
|
- // route.meta?.refreshRedirect,
|
|
|
- // getParentPaths(route.meta?.refreshRedirect, routes)[0],
|
|
|
- // name,
|
|
|
- // meta
|
|
|
- // );
|
|
|
- // return router.push(route.meta?.refreshRedirect);
|
|
|
- // } else {
|
|
|
- // handTag(
|
|
|
- // route.path,
|
|
|
- // routePartent[routePartent.length - 1],
|
|
|
- // route.name,
|
|
|
- // route.meta
|
|
|
- // );
|
|
|
- // return router.push(path);
|
|
|
- // }
|
|
|
- }
|
|
|
- }
|
|
|
- router.push(to.fullPath);
|
|
|
+ if (to.path !== "/login") {
|
|
|
+ if (whiteList.indexOf(to.path) !== -1) {
|
|
|
next();
|
|
|
- })
|
|
|
- .catch(s => {
|
|
|
- console.log(s);
|
|
|
- logout();
|
|
|
-
|
|
|
+ } else {
|
|
|
next({ path: "/login" });
|
|
|
- });
|
|
|
- next();
|
|
|
- }
|
|
|
- } else {
|
|
|
- if (to.path !== "/login") {
|
|
|
- if (whiteList.indexOf(to.path) !== -1) {
|
|
|
- next();
|
|
|
+ }
|
|
|
} else {
|
|
|
- next({ path: "/login" });
|
|
|
+ next();
|
|
|
}
|
|
|
- } else {
|
|
|
- next();
|
|
|
}
|
|
|
- }
|
|
|
-});
|
|
|
+ });
|
|
|
|
|
|
router.afterEach(() => {
|
|
|
NProgress.done();
|