Quellcode durchsuchen

feat: 支持iframe 内嵌路由

luoyali vor 10 Monaten
Ursprung
Commit
ee1c751dcd

+ 11 - 7
src/layout/components/Menu/SubMenu.vue

@@ -27,7 +27,7 @@ import { useRouter } from 'vue-router'
 import { generateTitle } from '@/utils/i18n'
 import PickerIcon from '@/components/IconPicker/PickerIcon.vue'
 import { isExternal } from '@/utils/validate'
-import {ElMessage} from "element-plus";
+import { ElMessage } from 'element-plus'
 
 defineProps<{ menuList: RouteMenu.Item[] }>()
 
@@ -40,14 +40,18 @@ const router = useRouter()
  * @param subItem
  */
 const handleClickMenu = (subItem: RouteMenu.Item) => {
-	if (subItem.meta.type === 'iframe') {
-		if (!isExternal(subItem.path)) return ElMessage.error(`当前路由 ${subItem.path} 不是外链地址,请检查配置~`)
-		return window.open(subItem.path, '_blank')
-	} else {
+	const { type } = subItem.meta
+	const isIframe = ['iframe', 'link'].includes(type) // true 外链 false 系统路由
+	if (!isIframe) {
 		router.push(subItem.path)
+	} else {
+		if (!isExternal(subItem.props.url)) return ElMessage.error(`当前Url不是外链地址,请检查重定向配置~`)
+		if (type === 'link') {
+			return window.open(subItem.redirect, '_blank')
+		} else {
+			router.push({ path: `${subItem.path}` })
+		}
 	}
-	// router.push({ name: subItem.name })
-	// router.push('/404')
 }
 </script>
 

+ 10 - 1
src/store/modules/permission.ts

@@ -45,7 +45,9 @@ export const filterAsyncRoutes = (routes: AppRouteRecordRaw[], roles: string[],
 		// 特殊Layout 配置 标识
 		/*if (!tmp.component) {
 			tmp.component = RouteView
-		} else*/ if (!tmp.component || tmp.component === 'Layout') {
+		} else*/
+
+		if (!tmp.component || tmp.component === 'Layout') {
 			tmp.component = Layout
 		} else if (typeof tmp.component === 'string') {
 			if (tmp.component === 'RouteView') {
@@ -60,6 +62,13 @@ export const filterAsyncRoutes = (routes: AppRouteRecordRaw[], roles: string[],
 				}
 			}
 		}
+
+		// 处理判断iframe和路由
+		if (tmp.meta.type === 'iframe') {
+			tmp.props = { url: tmp.redirect }
+			Reflect.deleteProperty(tmp, 'redirect')
+		}
+
 		res.push(tmp)
 
 		// 递归

+ 0 - 0
src/views/setting/iframe-page/[url].vue → src/views/iframe-page/[url].vue