Ver código fonte

fix: bug#8919、8920、8841

xieyonghong 3 anos atrás
pai
commit
7c88a650d5

+ 2 - 17
src/pages/system/Apply/Api/base.tsx

@@ -3,28 +3,12 @@ import Table from '@/pages/system/Platforms/Api/basePage';
 import SwaggerUI from '@/pages/system/Platforms/Api/swagger-ui';
 import { useCallback, useEffect, useState } from 'react';
 import { service } from '@/pages/system/Platforms';
-import { model } from '@formily/reactive';
 import { observer } from '@formily/react';
 import './index.less';
 import { useLocation } from 'umi';
 import { useDomFullHeight } from '@/hooks';
 import Home from '../Home';
-
-export const ApiModel = model<{
-  data: any[] | undefined;
-  baseUrl: string;
-  showTable: boolean;
-  components: any;
-  swagger: any;
-  debugger: any;
-}>({
-  data: [],
-  baseUrl: '',
-  showTable: true,
-  components: {},
-  swagger: {},
-  debugger: {},
-});
+import { ApiModel } from '@/pages/system/Platforms/Api/base';
 
 interface ApiPageProps {
   showDebugger?: boolean;
@@ -96,6 +80,7 @@ export default observer((props: ApiPageProps) => {
   useEffect(() => {
     console.log(ApiModel.data);
   }, [ApiModel.data]);
+  console.log(ApiModel.showTable);
 
   return (
     <div className={'platforms-api'} style={{ minHeight }}>

+ 49 - 48
src/pages/system/Apply/View/index.tsx

@@ -1,10 +1,10 @@
 import { PageContainer } from '@ant-design/pro-layout';
-import { Button, Card, Col, Input, Popover, Row } from 'antd';
+import { Card, Col, Row } from 'antd';
 import ApiPage from '../Api/base';
 import { useEffect, useState } from 'react';
 import { useLocation } from 'umi';
 import { service } from '@/pages/system/Platforms';
-import * as moment from 'moment';
+// import * as moment from 'moment';
 
 const defaultHeight = 50;
 
@@ -13,7 +13,7 @@ export default () => {
 
   const [clientId, setClientId] = useState('');
   const [secureKey, setSecureKey] = useState('');
-  const [sdkDetail, setSdkDetail] = useState<any>({});
+  // const [sdkDetail, setSdkDetail] = useState<any>({});
 
   const getDetail = async (id: string) => {
     const resp = await service.getDetail(id);
@@ -26,22 +26,22 @@ export default () => {
   const getSDKDetail = async () => {
     const resp = await service.getSdk();
     if (resp.status === 200) {
-      setSdkDetail(resp.result[0]);
+      // setSdkDetail(resp.result[0]);
     }
   };
 
-  const downLoad = (url: string) => {
-    if (url) {
-      const downNode = document.createElement('a');
-      downNode.href = url;
-      downNode.download = `${moment(new Date()).format('YYYY-MM-DD-HH-mm-ss')}.sdk`;
-      downNode.style.display = 'none';
-      downNode.setAttribute('target', '_blank');
-      document.body.appendChild(downNode);
-      downNode.click();
-      document.body.removeChild(downNode);
-    }
-  };
+  // const downLoad = (url: string) => {
+  //   if (url) {
+  //     const downNode = document.createElement('a');
+  //     downNode.href = url;
+  //     downNode.download = `${moment(new Date()).format('YYYY-MM-DD-HH-mm-ss')}.sdk`;
+  //     downNode.style.display = 'none';
+  //     downNode.setAttribute('target', '_blank');
+  //     document.body.appendChild(downNode);
+  //     downNode.click();
+  //     document.body.removeChild(downNode);
+  //   }
+  // };
 
   useEffect(() => {
     const param = new URLSearchParams(location.search);
@@ -56,35 +56,35 @@ export default () => {
     getSDKDetail();
   }, []);
 
-  const downLoadJDK = (
-    <div>
-      <div
-        style={{
-          width: 500,
-          borderRadius: 2,
-          marginBottom: 12,
-        }}
-      >
-        <Input.TextArea value={sdkDetail?.dependency} rows={6} readOnly />
-      </div>
-      <Button
-        type={'primary'}
-        style={{ width: '100%' }}
-        onClick={() => {
-          downLoad(sdkDetail.sdk);
-        }}
-      >
-        jar下载
-      </Button>
-    </div>
-  );
+  // const downLoadJDK = (
+  //   <div>
+  //     <div
+  //       style={{
+  //         width: 500,
+  //         borderRadius: 2,
+  //         marginBottom: 12,
+  //       }}
+  //     >
+  //       <Input.TextArea value={sdkDetail?.dependency} rows={6} readOnly />
+  //     </div>
+  //     <Button
+  //       type={'primary'}
+  //       style={{ width: '100%' }}
+  //       onClick={() => {
+  //         downLoad(sdkDetail.sdk);
+  //       }}
+  //     >
+  //       jar下载
+  //     </Button>
+  //   </div>
+  // );
 
   return (
     <PageContainer>
       <Row gutter={[16, 16]}>
         <Col span={24}>
           <Row gutter={16}>
-            <Col span={12}>
+            <Col span={24}>
               <Card title="基本信息">
                 <div style={{ height: defaultHeight }}>
                   <div>
@@ -98,15 +98,16 @@ export default () => {
                 </div>
               </Card>
             </Col>
-            <Col span={12}>
-              <Card title="SDK下载">
-                <div style={{ height: defaultHeight }}>
-                  <Popover trigger="click" title={'POM依赖'} content={downLoadJDK}>
-                    <Button> Java </Button>
-                  </Popover>
-                </div>
-              </Card>
-            </Col>
+            {/* 没有SDK下载,暂时屏蔽 */}
+            {/*<Col span={12}>*/}
+            {/*  <Card title="SDK下载">*/}
+            {/*    <div style={{ height: defaultHeight }}>*/}
+            {/*      <Popover trigger="click" title={'POM依赖'} content={downLoadJDK}>*/}
+            {/*        <Button> Java </Button>*/}
+            {/*      </Popover>*/}
+            {/*    </div>*/}
+            {/*  </Card>*/}
+            {/*</Col>*/}
           </Row>
         </Col>
         <Col span={24}>

+ 51 - 3
src/pages/system/Department/Tree/tree.tsx

@@ -10,11 +10,11 @@ import { useEffect, useRef, useState } from 'react';
 import { service } from '@/pages/system/Department';
 import { Ellipsis, Empty, PermissionButton } from '@/components';
 import { useIntl, useLocation } from 'umi';
-import { debounce } from 'lodash';
+import { cloneDeep, debounce, omit } from 'lodash';
 import Save from '../save';
 import { ISchema } from '@formily/json-schema';
 import { DepartmentItem } from '@/pages/system/Department/typings';
-import { onlyMessage } from '@/utils/util';
+import { ArrayToTree, onlyMessage } from '@/utils/util';
 import classnames from 'classnames';
 import _ from 'lodash';
 
@@ -43,6 +43,8 @@ export const getSortIndex = (data: DepartmentItem[], pId?: string): number => {
   return sortIndex;
 };
 
+const TreeMap = new Map();
+
 export default (props: TreeProps) => {
   const intl = useIntl();
   const [treeData, setTreeData] = useState<undefined | any[]>(undefined);
@@ -59,6 +61,17 @@ export default (props: TreeProps) => {
 
   const { permission } = PermissionButton.usePermission('system/Department');
 
+  const handleTreeMap = (_data: any[]) => {
+    if (_data) {
+      _data.map((item) => {
+        TreeMap.set(item.id, omit(cloneDeep(item), ['children']));
+        if (item.children) {
+          handleTreeMap(item.children);
+        }
+      });
+    }
+  };
+
   const queryTreeData = async () => {
     setKeys([]);
     const terms: Record<string, any> = {};
@@ -74,6 +87,7 @@ export default (props: TreeProps) => {
     setLoading(false);
 
     if (resp.status === 200) {
+      handleTreeMap(resp.result);
       setTreeData(resp.result);
       if (resp.result && resp.result.length) {
         setKeys([resp.result[0].id]);
@@ -115,9 +129,42 @@ export default (props: TreeProps) => {
     }
   };
 
+  const searchByTreeMap = (key: string) => {
+    const searchTree: string[] = [];
+    const treeArray = new Map();
+    if (key) {
+      TreeMap.forEach((item) => {
+        if (item.name.includes(key)) {
+          searchTree.push(item.parentId);
+          treeArray.set(item.id, item);
+        }
+      });
+
+      function dig(_data: any[]): any {
+        const pIds: string[] = [];
+        if (!_data.length) return;
+        _data.forEach((item) => {
+          if (TreeMap.has(item)) {
+            const _item = TreeMap.get(item);
+            pIds.push(_item.parentId);
+            treeArray.set(item, _item);
+          }
+        });
+      }
+
+      dig(searchTree);
+
+      const arr = ArrayToTree([...treeArray.values()]);
+      setTreeData(arr);
+    } else {
+      setTreeData([...TreeMap.values()]);
+    }
+  };
+
   const onSearchChange = (e: any) => {
     searchKey.current = e.target.value;
-    queryTreeData();
+    // queryTreeData();
+    searchByTreeMap(e.target.value);
   };
 
   const schema: ISchema = {
@@ -196,6 +243,7 @@ export default (props: TreeProps) => {
 
   useEffect(() => {
     queryTreeData();
+    TreeMap.clear();
   }, []);
 
   useEffect(() => {

+ 31 - 0
src/utils/util.ts

@@ -4,6 +4,7 @@ import { action } from '@formily/reactive';
 import Token from '@/utils/token';
 import { message } from 'antd';
 import SystemConst from '@/utils/const';
+
 /**
  * 下载文件
  * @param url 下载链接
@@ -164,3 +165,33 @@ export const phoneRegEx = (value: string) => {
   const mobile = /(0[0-9]{2,3})([2-9][0-9]{6,7})+([0-9]{8,11})?$/;
   return phone.test(value) || mobile.test(value);
 };
+
+export const ArrayToTree = (list: any[]): any[] => {
+  const treeList: any[] = [];
+  // 所有项都使用对象存储起来
+  const map = {};
+
+  // 建立一个映射关系:通过id快速找到对应的元素
+  list.forEach((item) => {
+    if (!item.children) {
+      item.children = [];
+    }
+    map[item.id] = item;
+  });
+
+  list.forEach((item) => {
+    // 对于每一个元素来说,先找它的上级
+    //    如果能找到,说明它有上级,则要把它添加到上级的children中去
+    //    如果找不到,说明它没有上级,直接添加到 treeList
+    const parent = map[item.parentId];
+    // 如果存在则表示item不是最顶层的数据
+    if (parent) {
+      parent.children.push(item);
+    } else {
+      // 如果不存在 则是顶层数据
+      treeList.push(item);
+    }
+  });
+  // 返回出去
+  return treeList;
+};