浏览代码

重定向

zhuangyunsheng 1 年之前
父节点
当前提交
6ad3497487
共有 2 个文件被更改,包括 151 次插入151 次删除
  1. 1 1
      src/components/scChengTou/purchase/apply.vue
  2. 150 150
      src/router/index.js

+ 1 - 1
src/components/scChengTou/purchase/apply.vue

@@ -61,7 +61,7 @@
 					<dict-select ref="dictSelect" v-model="form.type" dic="procurement_category" filterable placeholder="请选择采购类别" @change="typeChange"></dict-select>
 				</el-form-item>
 			</el-col>
-            <el-col v-if="!isEngineering" :lg="lg" :md="12" :xs="24">
+            <el-col v-if="form.type && !isEngineering" :lg="lg" :md="12" :xs="24">
 				<el-form-item label="专项费用类型:" prop="specialFeeType">
 					<dict-select v-model="form.specialFeeType" dic="special_expenses_type" filterable placeholder="请选择专项费用类型"></dict-select>
 				</el-form-item>

+ 150 - 150
src/router/index.js

@@ -14,22 +14,22 @@ const routes = systemRouter
 
 //系统特殊路由
 const routes_404 = {
-	path: "/:pathMatch(.*)*",
-	hidden: true,
-	component: () => import(/* webpackChunkName: "404" */ "@/layout/other/404"),
+    path: "/:pathMatch(.*)*",
+    hidden: true,
+    component: () => import(/* webpackChunkName: "404" */ "@/layout/other/404"),
 }
 
 const routes_empty = {
-	path: "/:pathMatch(.*)*",
-	hidden: true,
-	component: () => import(/* webpackChunkName: "404" */ "@/layout/other/empty"),
+    path: "/:pathMatch(.*)*",
+    hidden: true,
+    component: () => import(/* webpackChunkName: "404" */ "@/layout/other/empty"),
 }
 
 let routes_404_r = () => { }
 
 const router = createRouter({
-	history: createWebHashHistory(),
-	routes: routes
+    history: createWebHashHistory(),
+    routes: routes
 })
 
 //设置标题
@@ -41,161 +41,161 @@ let isGetRouter = false;
 let MessageBox_401_show = false
 
 router.beforeEach(async (to, from, next) => {
-	// 组件iframe 不显示NProgress
-	if (to.path !== "/process-form-view") NProgress.start();
-	else isGetRouter = true;
-
-	// 动态标题
-	document.title = to.meta.title ? `${to.meta.title} - ${config.APP_NAME}` : `${config.APP_NAME}`;
-
-	let token = tool.cookie.get("TOKEN");
-
-	if (to.path === "/redirect") {
-		if (to.query.userId) {
-			const { token, user } = await api.auth.oa.getUserToken(to.query);
-			if (!token) {
-				tool.cookie.set("TOKEN", token);
-				tool.data.set("USER_INFO", user.user);
-			} else tool.data.set("OA_USER_INFO", user.user);
-		}
-		next(to.query.path && to.fullPath.replace("/redirect", to.query.path) || from.fullPath);
-		return false;
-	}
-
-	if (to.path === "/process-form-view") {
-		if (!token) {
-			const { token, user } = await api.auth.oa.getUserToken({ userId: 1 });
-			tool.session.set("TOKEN", token);
-			tool.data.set("USER_INFO", user.user);
-		}
-		isGetRouter = true;
-		next();
-		return false;
-	}
-
-	if (to.path === "/login") {
-		// 删除路由(替换当前layout路由)
-		router.addRoute(routes[0]);
-		// 删除路由(404)
-		routes_404_r();
-		isGetRouter = false
-		if (token) next(from.fullPath);
-		else {
-			to.redirectedFrom = from;
-			next();
-		}
-		return false;
-	}
-
-	if (!token) {
-		next({ path: "/login" });
-		return false;
-	}
-
-	// 整页路由处理
-	if (to.meta.fullpage) to.matched = [to.matched[to.matched.length - 1]];
-	try {
-		// 加载动态/静态路由
-		if (!isGetRouter) {
-			const menus = await api.system.menu.build();
-			let apiMenu = menus.filter(m => !(!m.name && m.children[0].component == "Layout"));
-
-			isGetRouter = true;
-			if (apiMenu.length == 0) {
-				if (!MessageBox_401_show) {
-					MessageBox_401_show = true;
-					ElMessageBox.confirm("当前用户无任何菜单权限,请联系系统管理员", "无权限访问", {
-						type: "error",
-						showClose: false,
-						closeOnPressEscape: false,
-						closeOnClickModal: false,
-						center: true,
-						confirmButtonText: "重新登录",
-						showCancelButton: false,
-						beforeClose: (action, instance, done) => {
-							MessageBox_401_show = false;
-							done();
-						}
-					}).then(() => {
-						tool.cookie.remove("TOKEN");
-						tool.data.remove("USER_INFO");
-						tool.data.remove("OA_USER_INFO");
-						location.reload(); // 为了重新实例化vue-router对象 避免bug
-					}).catch(() => { });
-				}
-
-				routes_404_r = router.addRoute(routes_empty);
-			} else {
-				apiMenu = apiMenu.map(item => {
-					// 处理直接创建的菜单路由
-					if (!item.name) {
-						item = {
-							name: item.children[0].meta.title,
-							path: item.iframe ? item.children[0].path : item.path,
-							component: item.children[0].component,
-							iframe: item.iframe,
-							meta: { ...item.children[0].meta },
-							children: undefined
-						}
-					}
-
-					if (item.children) {
-						item.children.forEach(child => {
-							if (!child.iframe) child.path = item.path + "/" + child.path
-						})
-						item.redirect = item.children[0].path
-					}
-					return item;
-				});
-
-				const permission = menus.filter(m => m.permission).map(m => m.permission);
-				tool.data.set("PERMISSIONS", [...permission]);
-				tool.data.set("MENU", [...userRoutes, ...apiMenu]);
-				filterAsyncRouter([...userRoutes, ...apiMenu]);
-				routes_404_r = router.addRoute(routes_404);
-			}
-
-			if (to.matched.length == 0) router.push(to.fullPath);
-		}
-	} catch (error) {
-		if (token) tool.cookie.remove("TOKEN");
-	}
-
-	beforeEach(to, from);
-	next();
+    // 组件iframe 不显示NProgress
+    if (to.path !== "/process-form-view") NProgress.start();
+    else isGetRouter = true;
+
+    // 动态标题
+    document.title = to.meta.title ? `${to.meta.title} - ${config.APP_NAME}` : `${config.APP_NAME}`;
+
+    if (to.path === "/redirect") {
+        if (to.query.userId) {
+            const { token, user } = await api.auth.oa.getUserToken(to.query);
+            if (!tool.cookie.get("TOKEN")) {
+                tool.cookie.set("TOKEN", token);
+                tool.data.set("USER_INFO", user.user);
+            } else tool.data.set("OA_USER_INFO", user.user);
+        }
+        console.log(to)
+        console.log(from)
+        next(to.query.path && to.fullPath.replace("/redirect", to.query.path) || (from.fullPath == "/login" && "/" || from.fullPath == "/login"));
+        return false;
+    }
+
+    if (to.path === "/process-form-view") {
+        if (!tool.cookie.get("TOKEN")) {
+            const { token, user } = await api.auth.oa.getUserToken({ userId: 1 });
+            tool.session.set("TOKEN", token);
+            tool.data.set("USER_INFO", user.user);
+        }
+        isGetRouter = true;
+        next();
+        return false;
+    }
+    console.log(to)
+    if (to.path === "/login") {
+        // 删除路由(替换当前layout路由)
+        router.addRoute(routes[0]);
+        // 删除路由(404)
+        routes_404_r();
+        isGetRouter = false
+        if (tool.cookie.get("TOKEN")) next(from.fullPath);
+        else {
+            to.redirectedFrom = from;
+            next();
+        }
+        return false;
+    }
+
+    if (!tool.cookie.get("TOKEN")) {
+        next({ path: "/login" });
+        return false;
+    }
+
+    // 整页路由处理
+    if (to.meta.fullpage) to.matched = [to.matched[to.matched.length - 1]];
+    try {
+        // 加载动态/静态路由
+        if (!isGetRouter) {
+            const menus = await api.system.menu.build();
+            let apiMenu = menus.filter(m => !(!m.name && m.children[0].component == "Layout"));
+
+            isGetRouter = true;
+            if (apiMenu.length == 0) {
+                if (!MessageBox_401_show) {
+                    MessageBox_401_show = true;
+                    ElMessageBox.confirm("当前用户无任何菜单权限,请联系系统管理员", "无权限访问", {
+                        type: "error",
+                        showClose: false,
+                        closeOnPressEscape: false,
+                        closeOnClickModal: false,
+                        center: true,
+                        confirmButtonText: "重新登录",
+                        showCancelButton: false,
+                        beforeClose: (action, instance, done) => {
+                            MessageBox_401_show = false;
+                            done();
+                        }
+                    }).then(() => {
+                        tool.cookie.remove("TOKEN");
+                        tool.data.remove("USER_INFO");
+                        tool.data.remove("OA_USER_INFO");
+                        location.reload(); // 为了重新实例化vue-router对象 避免bug
+                    }).catch(() => { });
+                }
+
+                routes_404_r = router.addRoute(routes_empty);
+            } else {
+                apiMenu = apiMenu.map(item => {
+                    // 处理直接创建的菜单路由
+                    if (!item.name) {
+                        item = {
+                            name: item.children[0].meta.title,
+                            path: item.iframe ? item.children[0].path : item.path,
+                            component: item.children[0].component,
+                            iframe: item.iframe,
+                            meta: { ...item.children[0].meta },
+                            children: undefined
+                        }
+                    }
+
+                    if (item.children) {
+                        item.children.forEach(child => {
+                            if (!child.iframe) child.path = item.path + "/" + child.path
+                        })
+                        item.redirect = item.children[0].path
+                    }
+                    return item;
+                });
+
+                const permission = menus.filter(m => m.permission).map(m => m.permission);
+                tool.data.set("PERMISSIONS", [...permission]);
+                tool.data.set("MENU", [...userRoutes, ...apiMenu]);
+                filterAsyncRouter([...userRoutes, ...apiMenu]);
+                routes_404_r = router.addRoute(routes_404);
+            }
+
+            if (to.matched.length == 0) router.push(to.fullPath);
+        }
+    } catch (error) {
+        if (tool.cookie.get("TOKEN")) tool.cookie.remove("TOKEN");
+    }
+
+    beforeEach(to, from);
+    next();
 });
 
 router.afterEach((to, from) => {
-	afterEach(to, from);
-	NProgress.done();
+    afterEach(to, from);
+    NProgress.done();
 });
 
 router.onError((error) => {
-	NProgress.done();
-	ElNotification.error({
-		title: "路由错误",
-		message: error.message
-	});
+    NProgress.done();
+    ElNotification.error({
+        title: "路由错误",
+        message: error.message
+    });
 });
 
 // 生成路由对象
 function filterAsyncRouter(routerMap) {
-	routerMap.forEach(item => {
-		const route = {
-			path: item.path,
-			name: item.name,
-			meta: item.meta ? item.meta : {},
-			redirect: item.redirect || undefined,
-			children: item.children && filterAsyncRouter(item.children) || undefined,
-			component: loadComponent(item)
-		}
-		router.addRoute("layout", route);
-	})
+    routerMap.forEach(item => {
+        const route = {
+            path: item.path,
+            name: item.name,
+            meta: item.meta ? item.meta : {},
+            redirect: item.redirect || undefined,
+            children: item.children && filterAsyncRouter(item.children) || undefined,
+            component: loadComponent(item)
+        }
+        router.addRoute("layout", route);
+    })
 }
 
 function loadComponent({ component, children }) {
-	if (!component || (component == "Layout" && !children)) return () => import(`@/layout/other/empty`);
-	return () => import(/* webpackChunkName: "[request]" */ `@/views/${component}`);
+    if (!component || (component == "Layout" && !children)) return () => import(`@/layout/other/empty`);
+    return () => import(/* webpackChunkName: "[request]" */ `@/views/${component}`);
 }
 
 export default router;