Browse Source

Merge pull request #614 from jetlinks/next-wzy

Next wzy
孙超 3 years ago
parent
commit
c0e7ae1484

+ 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);
+    // 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 || '';
+//   // }
+// }

+ 2 - 2
src/pages/device/DashBoard/index.tsx

@@ -180,8 +180,8 @@ const DeviceBoard = () => {
       },
     ]);
     if (res.status === 200) {
-      const thisMonth = res.result.find((item: any) => item.group === 'thisMonth').data.value;
-      const oneDay = res.result.find((item: any) => item.group === 'oneday').data.value;
+      const thisMonth = res.result.find((item: any) => item.group === 'thisMonth')?.data.value;
+      const oneDay = res.result.find((item: any) => item.group === 'oneday')?.data.value;
       setDay(oneDay);
       setMonth(thisMonth);
       const today = res.result.filter((item: any) => item.group === 'today');

+ 31 - 8
src/pages/iframe/index.tsx

@@ -1,18 +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';
 
 const Iframe = () => {
+  const [iframeUrl, setIframeUrl] = useState<string>('');
   const location = useLocation();
-  console.log(location, 22222);
-  useEffect(() => {}, []);
+
+  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(() => {
+    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>
   );
 };

+ 55 - 22
src/pages/system/Apply/Menu/index.tsx

@@ -15,19 +15,52 @@ const MenuPage = (props: Props) => {
   const [keys, setKeys] = useState<any>([]);
   const [expandedKeys, setExpandedKeys] = useState<string[]>([]);
   const [half, setHalf] = useState<string[]>([]);
-  // const [owner, setOwner] = useState<string>('iot');
   const [ownerList, setOwenrList] = useState<any>([]);
-  // const [menu,setMenu] = useState<string>('')
+  const [owner, setOwner] = useState<any>();
 
-  const getTree = async () => {
-    const res = await service.queryOwner(['iot']);
+  //获取集成菜单
+  const getMenus = async () => {
+    const res = await service.queryTree({
+      terms: [
+        {
+          column: 'appId',
+          value: data.id,
+        },
+      ],
+    });
     if (res.status === 200) {
-      setOwenrList(res.result);
       console.log(res.result);
-      // if (data.provider !== 'internal-standalone') {
-      //   setOwner(res.result?.[0])
-      // }
-      const resp = await service.queryOwnerTree(res.result?.[0]);
+      setTreeData(res.result);
+      const pid = res.result.map((item: any) => item.id);
+      setExpandedKeys(pid);
+      setKeys(pid);
+    }
+  };
+  //获取所属系统
+  const getOwner = async () => {
+    if (data.provider !== 'internal-standalone') {
+      const res = await service.queryOwner(['iot']);
+      if (res.status === 200) {
+        setOwenrList(res.result);
+      }
+    } else {
+      const resp = await service.queryOwnerStandalone(data.id, ['iot']);
+      if (resp.status === 200) {
+        setOwenrList(resp.result);
+      }
+    }
+  };
+  //获取对应系统菜单树
+  const getTree = async (parms: any) => {
+    if (data.provider !== 'internal-standalone') {
+      const res = await service.queryOwnerTree(parms);
+      if (res.status === 200) {
+        setTreeData(res.result);
+        const pid = res.result.map((item: any) => item.id);
+        setExpandedKeys(pid);
+      }
+    } else {
+      const resp = await service.queryOwnerTreeStandalone(data.id, parms);
       if (resp.status === 200) {
         setTreeData(resp.result);
         const pid = resp.result.map((item: any) => item.id);
@@ -36,13 +69,6 @@ const MenuPage = (props: Props) => {
     }
   };
 
-  // const getMenu = async ()=>{
-  //   const res = await service.queryOwner(['iot']);
-  //   if(res.status === 200){
-  //     setOwenrList(res.result)
-  //   }
-  // }
-
   const save = async (datalist: any) => {
     const res = await service.saveOwnerTree('iot', data.id, datalist);
     if (res?.status === 200) {
@@ -67,8 +93,8 @@ const MenuPage = (props: Props) => {
   };
 
   useEffect(() => {
-    // console.log(data);
-    getTree();
+    getOwner();
+    getMenus();
   }, []);
 
   return (
@@ -82,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');
         }
       }}
     >
@@ -93,7 +123,10 @@ const MenuPage = (props: Props) => {
         style={{ width: 200, marginBottom: 20 }}
         placeholder="请选择集成系统"
         onChange={(value) => {
-          console.log(value);
+          setOwner(value);
+          if (value) {
+            getTree(value);
+          }
         }}
       >
         {ownerList.map((item: any) => (

+ 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',

+ 9 - 4
src/pages/system/Apply/service.ts

@@ -36,16 +36,21 @@ class Service extends BaseService<any> {
       method: 'PATCH',
       data,
     });
-  queryOwnerStandalone = (api: string, data: any) =>
-    request(`${api}/menu/owner`, {
+  queryOwnerStandalone = (appId: string, data: any) =>
+    request(`/${SystemConst.API_BASE}/application/${appId}/_/api/menu/owner`, {
       method: 'POST',
       data,
     });
-  queryOwnerTreeStandalone = (api: string, owner: string) =>
-    request(`${api}/menu/owner/tree/${owner}`, {
+  queryOwnerTreeStandalone = (appId: string, owner: string) =>
+    request(`{/${SystemConst.API_BASE}/application/${appId}/_/api/menu/owner/${owner}`, {
       method: 'POST',
       data: {},
     });
+  queryTree = (data: any) =>
+    request(`${SystemConst.API_BASE}/menu/_all/tree`, {
+      method: 'POST',
+      data,
+    });
 }
 
 export default Service;

+ 12 - 13
src/utils/menu/index.ts

@@ -192,10 +192,12 @@ const findExtraRoutes = (baseCode: string, children: any[], url: string) => {
  * @param level
  */
 export const handleRoutes = (routes?: MenuItem[], level = 1): MenuItem[] => {
+  // console.log(routes)
   return routes
     ? routes.map((item) => {
         // 判断当前是否有额外子路由
         const extraRoutes = extraRouteObj[item.code];
+
         if (extraRoutes) {
           if (extraRoutes.children) {
             const eRoutes = findExtraRoutes(item.code, extraRoutes.children, item.url);
@@ -214,6 +216,9 @@ export const handleRoutes = (routes?: MenuItem[], level = 1): MenuItem[] => {
         }
         item.level = level;
 
+        if (item.appId) {
+          item.url = `/${item.appId}${item.url}`;
+        }
         return item;
       })
     : [];
@@ -228,24 +233,19 @@ const getRoutes = (extraRoutes: MenuItem[], level = 1): IRouteProps[] => {
   const allComponents = findComponents(require.context('@/pages', true, /index(\.tsx)$/));
   return extraRoutes.map((route) => {
     let component;
-    let _route: IRouteProps;
+    const _route: IRouteProps = {
+      key: route.url,
+      name: route.name,
+      path: route.url,
+    };
     if (route.appId) {
       component = allComponents['iframe'];
-      _route = {
-        key: `${route.url}`,
-        name: route.name,
-        path: `${route.url}`,
-      };
     } else {
       component = allComponents[route.code] || null;
-      _route = {
-        key: route.url,
-        name: route.name,
-        path: route.url,
-      };
+      // _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;
@@ -274,7 +274,6 @@ const getRoutes = (extraRoutes: MenuItem[], level = 1): IRouteProps[] => {
 export const getMenus = (extraRoutes: IRouteProps[]): any[] => {
   return extraRoutes.map((route) => {
     const children = route.children && route.children.length ? route.children : [];
-
     return {
       key: route.url,
       name: route.name,