Browse Source

feat: 应用管理

wzyyy 3 years atrás
parent
commit
04778cfb2b

+ 18 - 2
src/app.tsx

@@ -172,7 +172,7 @@ export const request: RequestConfig = {
     const { response } = error;
     if (response.status === 401) {
       history.push('/user/login');
-      return;
+      return {};
     }
     if (
       response.status === 400 ||
@@ -282,6 +282,7 @@ export const layout: RunTimeLayoutConfig = ({ initialState }) => {
     onPageChange: () => {
       const { location } = history;
       // 如果没有登录,重定向到 login
+      console.log(location, 'location');
       if (
         !initialState?.currentUser &&
         location.pathname !== loginPath &&
@@ -297,10 +298,16 @@ export const layout: RunTimeLayoutConfig = ({ initialState }) => {
     menuItemRender: (menuItemProps, defaultDom) => {
       return MenuItemIcon(menuItemProps, defaultDom, {
         onClick: () => {
+          console.log('menuItemProps', menuItemProps);
           history.push(menuItemProps.path!);
         },
       });
     },
+    // menuRender:(props,defaultDom)=>{
+    //   console.log(defaultDom,'11111111111111')
+    //   return true
+    // },
+    // headerRender:false,
     links: isDev
       ? [
           <Link key={1} to="/umi/plugin/openapi" target="_blank">
@@ -341,6 +348,7 @@ export const layout: RunTimeLayoutConfig = ({ initialState }) => {
 };
 
 export function patchRoutes(routes: any) {
+  // console.log(routes,'11111111111')
   if (extraRoutes && extraRoutes.length) {
     const basePath = routes.routes.find((_route: any) => _route.path === '/')!;
 
@@ -356,7 +364,7 @@ export function patchRoutes(routes: any) {
       ],
     };
     basePath.routes = [...basePath.routes, baseRedirect];
-    console.log(basePath.routes, 'basePath.routes,');
+    // console.log(basePath.routes, 'basePath.routes,');
   }
 }
 
@@ -408,3 +416,11 @@ export function render(oldRender: any) {
     oldRender();
   }
 }
+
+// export function onRouteChange({ routes, location }) {
+//   console.log(routes,location,'onRouteChange')
+//   // const route = matchRoutes(clientRoutes, location.pathname)?.pop()?.route
+//   // if (route) {
+//   //   document.title = route.title || '';
+//   // }
+// }

+ 28 - 9
src/pages/iframe/index.tsx

@@ -1,22 +1,41 @@
 import { PageContainer } from '@ant-design/pro-layout';
-import { useEffect } from 'react';
+import { useEffect, useState } from 'react';
 import { useLocation } from 'umi';
-// import { service } from '../system/Apply'
+import { service } from '../system/Apply';
 
 const Iframe = () => {
+  const [iframeUrl, setIframeUrl] = useState<string>('');
   const location = useLocation();
 
+  const handle = async (appId: string, url: string) => {
+    const res = await service.detail(appId);
+    let menuUrl: any = url;
+    if (res.status === 200) {
+      if (res.result.page.routeType === 'hash') {
+        menuUrl = `/#/${url}`;
+      }
+      if (res.result.provider === 'internal-standalone') {
+        //{baseUrl}/api/application/sso/{appId}/login?redirect={menuUrl}
+        const urlStandalone = `${res.result.page}/api/application/sso/${appId}/login?redirect=${menuUrl}`;
+        setIframeUrl(urlStandalone);
+      } else {
+        const urlOther = `${res.result.page}/${menuUrl}`;
+        setIframeUrl(urlOther);
+      }
+    }
+  };
+
   useEffect(() => {
-    console.log(location);
-  }, [location]);
+    const params = location.pathname.split('/')?.[1];
+    const url = location.pathname.split('/').slice(2).join('/');
+    // console.log(url)
+    handle(params, url);
+    // console.log(location)
+  }, [location, iframeUrl]);
 
   return (
     <PageContainer>
-      <iframe
-        style={{ width: '100%', height: '800px' }}
-        src={'http://47.108.170.157:9010/#/login'}
-        frameBorder="0"
-      ></iframe>
+      <iframe style={{ width: '100%', height: '800px' }} src={iframeUrl} frameBorder="0"></iframe>
     </PageContainer>
   );
 };

+ 12 - 20
src/pages/system/Apply/Menu/index.tsx

@@ -16,21 +16,9 @@ const MenuPage = (props: Props) => {
   const [expandedKeys, setExpandedKeys] = useState<string[]>([]);
   const [half, setHalf] = useState<string[]>([]);
   const [ownerList, setOwenrList] = useState<any>([]);
+  const [owner, setOwner] = useState<any>();
 
-  // const getTree = async () => {
-  //   const res = await service.queryOwner(['iot']);
-  //   if (res.status === 200) {
-  //     setOwenrList(res.result);
-  //     console.log(res.result);
-  //     const resp = await service.queryOwnerTree(res.result?.[0]);
-  //     if (resp.status === 200) {
-  //       setTreeData(resp.result);
-  //       const pid = resp.result.map((item: any) => item.id);
-  //       setExpandedKeys(pid);
-  //     }
-  //   }
-  // };
-
+  //获取集成菜单
   const getMenus = async () => {
     const res = await service.queryTree({
       terms: [
@@ -48,7 +36,7 @@ const MenuPage = (props: Props) => {
       setKeys(pid);
     }
   };
-
+  //获取所属系统
   const getOwner = async () => {
     if (data.provider !== 'internal-standalone') {
       const res = await service.queryOwner(['iot']);
@@ -62,7 +50,7 @@ const MenuPage = (props: Props) => {
       }
     }
   };
-
+  //获取对应系统菜单树
   const getTree = async (parms: any) => {
     if (data.provider !== 'internal-standalone') {
       const res = await service.queryOwnerTree(parms);
@@ -120,10 +108,14 @@ const MenuPage = (props: Props) => {
       }}
       onOk={() => {
         const items = filterTree(treeData, [...keys, ...half]);
-        if (items && items.length !== 0) {
-          save(items);
+        if (owner) {
+          if (items && items.length !== 0) {
+            save(items);
+          } else {
+            onlyMessage('请勾选配置菜单', 'warning');
+          }
         } else {
-          onlyMessage('请勾选配置菜单', 'warning');
+          onlyMessage('请选择所属系统', 'warning');
         }
       }}
     >
@@ -131,7 +123,7 @@ const MenuPage = (props: Props) => {
         style={{ width: 200, marginBottom: 20 }}
         placeholder="请选择集成系统"
         onChange={(value) => {
-          // console.log(value);
+          setOwner(value);
           if (value) {
             getTree(value);
           }

+ 8 - 8
src/pages/system/Apply/Save/index.tsx

@@ -1328,14 +1328,14 @@ const Save = () => {
                 type: 'string',
                 title: '路由方式',
                 'x-decorator': 'FormItem',
-                'x-reactions': {
-                  dependencies: ['provider'],
-                  fulfill: {
-                    state: {
-                      visible: '{{$deps[0]==="internal-integrated"}}',
-                    },
-                  },
-                },
+                // 'x-reactions': {
+                //   dependencies: ['provider'],
+                //   fulfill: {
+                //     state: {
+                //       visible: '{{$deps[0]==="internal-integrated"}}',
+                //     },
+                //   },
+                // },
                 'x-decorator-props': {
                   gridSpan: 2,
                   layout: 'vertical',

+ 3 - 2
src/utils/menu/index.ts

@@ -217,7 +217,7 @@ export const handleRoutes = (routes?: MenuItem[], level = 1): MenuItem[] => {
         item.level = level;
 
         if (item.appId) {
-          item.url = `/iframe${item.url}`;
+          item.url = `/${item.appId}${item.url}`;
         }
         return item;
       })
@@ -242,9 +242,10 @@ const getRoutes = (extraRoutes: MenuItem[], level = 1): IRouteProps[] => {
       component = allComponents['iframe'];
     } else {
       component = allComponents[route.code] || null;
+      // _route.layout=false
     }
 
-    // console.log(_route)
+    // console.log(_route,'layout')
     if (route.children && route.children.length) {
       const flatRoutes = getRoutes(flatRoute(route.children || []), level + 1);
       const redirect = flatRoutes.filter((r) => r.component)[0]?.path;