소스 검색

feat(部门管理): 重构部门管理

xieyonghong 3 년 전
부모
커밋
a2d253710a

+ 91 - 4
src/components/ProTableCard/CardItems/device.tsx

@@ -1,25 +1,112 @@
-import React from 'react';
+import React, { useState } from 'react';
 import type { DeviceInstance } from '@/pages/device/Instance/typings';
 import { StatusColorEnum } from '@/components/BadgeStatus';
 import { TableCard } from '@/components';
 import '@/style/common.less';
 import '../index.less';
+import { DisconnectOutlined } from '@ant-design/icons';
+import { Popconfirm } from 'antd';
+import { useIntl } from '@@/plugin-locale/localeExports';
 
-export interface DeviceCardProps extends DeviceInstance {
+export interface DeviceCardProps extends Partial<DeviceInstance> {
   detail?: React.ReactNode;
   actions?: React.ReactNode[];
   avatarSize?: number;
+  className?: string;
+  content?: React.ReactNode[];
+  onClick?: () => void;
+  grantedPermissions?: string[];
+  onUnBind?: (e: any) => void;
 }
 
 const defaultImage = require('/public/images/device-type-3-big.png');
 
+export const PermissionsMap = {
+  read: '查看',
+  save: '编辑',
+  delete: '删除',
+};
+
+export const handlePermissionsMap = (permissions?: string[]) => {
+  return permissions && permissions.length
+    ? permissions.map((item) => PermissionsMap[item]).toString()
+    : '--';
+};
+
+export const ExtraDeviceCard = (props: DeviceCardProps) => {
+  const intl = useIntl();
+  const [imgUrl, setImgUrl] = useState<string>(props.photoUrl || defaultImage);
+
+  return (
+    <TableCard
+      showTool={false}
+      showMask={false}
+      status={props.state?.value}
+      statusText={props.state?.text}
+      statusNames={{
+        online: StatusColorEnum.processing,
+        offline: StatusColorEnum.error,
+        notActive: StatusColorEnum.warning,
+      }}
+      onClick={props.onClick}
+      className={props.className}
+    >
+      <div className={'pro-table-card-item'}>
+        <div className={'card-item-avatar'}>
+          <img
+            width={88}
+            height={88}
+            src={imgUrl}
+            alt={''}
+            onError={() => {
+              setImgUrl(defaultImage);
+            }}
+          />
+        </div>
+        <div className={'card-item-body'}>
+          <div className={'card-item-header'}>
+            <span className={'card-item-header-name ellipsis'}>{props.name}</span>
+          </div>
+          <div className={'card-item-content-flex'}>
+            <div className={'flex-auto'}>
+              <label>ID</label>
+              <div className={'ellipsis'}>{props.id || '--'}</div>
+            </div>
+            <div className={'flex-auto'}>
+              <label>资产权限</label>
+              <div className={'ellipsis'}>{handlePermissionsMap(props.grantedPermissions)}</div>
+            </div>
+            <Popconfirm
+              title={intl.formatMessage({
+                id: 'pages.system.role.option.unBindUser',
+                defaultMessage: '是否解除绑定',
+              })}
+              key="unBind"
+              onConfirm={(e) => {
+                e?.stopPropagation();
+                if (props.onUnBind) {
+                  props.onUnBind(e);
+                }
+              }}
+            >
+              <div className={'flex-button'}>
+                <DisconnectOutlined />
+              </div>
+            </Popconfirm>
+          </div>
+        </div>
+      </div>
+    </TableCard>
+  );
+};
+
 export default (props: DeviceCardProps) => {
   return (
     <TableCard
       detail={props.detail}
       actions={props.actions}
-      status={props.state.value}
-      statusText={props.state.text}
+      status={props.state?.value}
+      statusText={props.state?.text}
       statusNames={{
         online: StatusColorEnum.processing,
         offline: StatusColorEnum.error,

+ 94 - 2
src/components/ProTableCard/CardItems/product.tsx

@@ -1,18 +1,110 @@
-import React from 'react';
+import React, { useState } from 'react';
 import type { ProductItem } from '@/pages/device/Product/typings';
 import { StatusColorEnum } from '@/components/BadgeStatus';
 import { useIntl } from 'umi';
 import { TableCard } from '@/components';
 import '@/style/common.less';
 import '../index.less';
+import { Popconfirm } from 'antd';
+import { DisconnectOutlined } from '@ant-design/icons';
 
-export interface ProductCardProps extends ProductItem {
+export interface ProductCardProps extends Partial<ProductItem> {
   detail?: React.ReactNode;
   actions?: React.ReactNode[];
   avatarSize?: number;
+  className?: string;
+  content?: React.ReactNode[];
+  onClick?: () => void;
+  grantedPermissions?: string[];
+  onUnBind?: (e: any) => void;
 }
+
 const defaultImage = require('/public/images/device-product.png');
 
+export const PermissionsMap = {
+  read: '查看',
+  save: '编辑',
+  delete: '删除',
+};
+
+export const handlePermissionsMap = (permissions?: string[]) => {
+  return permissions && permissions.length
+    ? permissions.map((item) => PermissionsMap[item]).toString()
+    : '--';
+};
+
+export const ExtraProductCard = (props: ProductCardProps) => {
+  const intl = useIntl();
+  const [imgUrl, setImgUrl] = useState<string>(props.photoUrl || defaultImage);
+
+  return (
+    <TableCard
+      showTool={false}
+      showMask={false}
+      status={props.state}
+      statusText={intl.formatMessage({
+        id: `pages.system.tenant.assetInformation.${props.state ? 'published' : 'unpublished'}`,
+        defaultMessage: '已发布',
+      })}
+      statusNames={{
+        0: StatusColorEnum.error,
+        1: StatusColorEnum.processing,
+      }}
+      className={props.className}
+      onClick={props.onClick}
+    >
+      <div className={'pro-table-card-item'}>
+        <div className={'card-item-avatar'}>
+          <img
+            width={88}
+            height={88}
+            src={imgUrl}
+            alt={''}
+            onError={() => {
+              setImgUrl(defaultImage);
+            }}
+          />
+        </div>
+        <div className={'card-item-body'}>
+          <div className={'card-item-header'}>
+            <span className={'card-item-header-name ellipsis'}>{props.name}</span>
+          </div>
+          <div className={'card-item-content-items'} style={{ display: 'flex', gap: 12 }}>
+            {props.content}
+          </div>
+          <div className={'card-item-content-flex'}>
+            <div className={'flex-auto'}>
+              <label>ID</label>
+              <div className={'ellipsis'}>{props.id || '--'}</div>
+            </div>
+            <div className={'flex-auto'}>
+              <label>资产权限</label>
+              <div className={'ellipsis'}>{handlePermissionsMap(props.grantedPermissions)}</div>
+            </div>
+            <Popconfirm
+              title={intl.formatMessage({
+                id: 'pages.system.role.option.unBindUser',
+                defaultMessage: '是否解除绑定',
+              })}
+              key="unBind"
+              onConfirm={(e) => {
+                e?.stopPropagation();
+                if (props.onUnBind) {
+                  props.onUnBind(e);
+                }
+              }}
+            >
+              <div className={'flex-button'}>
+                <DisconnectOutlined />
+              </div>
+            </Popconfirm>
+          </div>
+        </div>
+      </div>
+    </TableCard>
+  );
+};
+
 export default (props: ProductCardProps) => {
   const intl = useIntl();
   return (

+ 5 - 1
src/components/ProTableCard/TableCard.tsx

@@ -17,6 +17,7 @@ export interface TableCardProps {
   children?: React.ReactNode;
   actions?: React.ReactNode[];
   contentClassName?: string;
+  onClick?: () => void;
 }
 
 function getAction(actions: React.ReactNode[]) {
@@ -73,7 +74,10 @@ export default (props: TableCardProps) => {
     );
 
   return (
-    <div className={classNames('iot-card', { hover: maskShow }, props.className)}>
+    <div
+      className={classNames('iot-card', { hover: maskShow }, props.className)}
+      onClick={props.onClick}
+    >
       <div className={'card-warp'}>
         <div
           className={classNames('card-content', props.contentClassName)}

+ 37 - 1
src/components/ProTableCard/index.less

@@ -52,6 +52,38 @@
           }
         }
 
+        .card-item-content-flex {
+          display: flex;
+          flex-wrap: wrap;
+          gap: 12px;
+
+          .flex-auto {
+            flex: 1 1 auto;
+          }
+
+          .flex-button {
+            display: flex;
+            flex: 0 0 50px;
+            align-items: center;
+            justify-content: center;
+            height: 50px;
+            color: @primary-color;
+            border: 1px solid @primary-color-active;
+            cursor: pointer;
+          }
+
+          label {
+            color: rgba(#000, 0.75);
+            font-size: 12px;
+          }
+
+          .ellipsis {
+            width: 70%;
+            font-weight: bold;
+            font-size: 14px;
+          }
+        }
+
         .card-item-content {
           display: flex;
           flex-wrap: wrap;
@@ -71,7 +103,7 @@
           }
 
           .ellipsis {
-            width: 100%;
+            width: 70%;
             font-weight: bold;
             font-size: 14px;
           }
@@ -109,6 +141,10 @@
   width: 100%;
   background-color: #fff;
 
+  &.item-active {
+    border: 1px solid @primary-color-active;
+  }
+
   &.hover {
     box-shadow: 0 0 24px rgba(#000, 0.1);
   }

+ 43 - 3
src/components/ProTableCard/index.tsx

@@ -47,8 +47,48 @@ const ProTableCard = <
    * @param dataSource
    */
   const handleCard = useCallback(
-    (dataSource: readonly T[] | undefined): JSX.Element => {
+    (dataSource: readonly T[] | undefined, rowSelection?: any): JSX.Element => {
       setDataLength(dataSource ? dataSource.length : 0);
+
+      const Item = (dom: React.ReactNode) => {
+        if (!rowSelection || (rowSelection && !rowSelection.selectedRowKeys)) {
+          return dom;
+        }
+        const { selectedRowKeys, onChange } = rowSelection;
+
+        // @ts-ignore
+        const id = dom.props.id;
+
+        // @ts-ignore
+        return React.cloneElement(dom, {
+          // @ts-ignore
+          className: classNames(dom.props.className, {
+            'item-active': selectedRowKeys && selectedRowKeys.includes(id),
+          }),
+          key: id,
+          onClick: (e) => {
+            e.stopPropagation();
+            if (onChange) {
+              const isSelect = selectedRowKeys.includes(id);
+
+              if (isSelect) {
+                const nowRowKeys = selectedRowKeys.filter((key: string) => key !== id);
+                onChange(
+                  nowRowKeys,
+                  dataSource!.filter((item) => nowRowKeys.includes(item.id)),
+                );
+              } else {
+                const nowRowKeys = [...selectedRowKeys, id];
+                onChange(
+                  nowRowKeys,
+                  dataSource!.filter((item) => nowRowKeys.includes(item.id)),
+                );
+              }
+            }
+          },
+        });
+      };
+
       return (
         <>
           {dataSource && dataSource.length ? (
@@ -57,7 +97,7 @@ const ProTableCard = <
               style={{ gridTemplateColumns: `repeat(${column}, 1fr)` }}
             >
               {dataSource.map((item) =>
-                cardRender && isFunction(cardRender) ? cardRender(item) : null,
+                cardRender && isFunction(cardRender) ? Item(cardRender(item)) : null,
               )}
             </div>
           ) : (
@@ -190,7 +230,7 @@ const ProTableCard = <
         tableViewRender={
           model === ModelEnum.CARD
             ? (tableProps) => {
-                return handleCard(tableProps.dataSource);
+                return handleCard(tableProps.dataSource, extraProps?.rowSelection);
               }
             : undefined
         }

+ 2 - 2
src/pages/device/Instance/Detail/Running/Property/PropertyCard.tsx

@@ -49,7 +49,7 @@ const Property = (props: Props) => {
           <Tooltip title={title}>{title}</Tooltip>
         </div>
         <Space style={{ fontSize: 12 }}>
-          {data.expands?.type.includes('write') && (
+          {data.expands?.type?.includes('write') && (
             <Tooltip placement="top" title="设置属性至设备">
               <EditOutlined
                 onClick={() => {
@@ -70,7 +70,7 @@ const Property = (props: Props) => {
                 />
               </Tooltip>
             )}
-          {data.expands?.type.includes('read') && (
+          {data.expands?.type?.includes('read') && (
             <Tooltip placement="top" title="获取最新属性值">
               <SyncOutlined onClick={refreshProperty} />
             </Tooltip>

+ 11 - 9
src/pages/system/Department/Assets/deivce/bind.tsx

@@ -1,9 +1,7 @@
 // 资产-产品分类-绑定
 import type { ActionType, ProColumns } from '@jetlinks/pro-table';
-import ProTable from '@jetlinks/pro-table';
 import { DeviceBadge, service } from './index';
 import { message, Modal } from 'antd';
-import { useParams } from 'umi';
 import Models from './model';
 import { useEffect, useRef, useState } from 'react';
 import { observer } from '@formily/react';
@@ -11,19 +9,21 @@ import { useIntl } from '@@/plugin-locale/localeExports';
 import type { DeviceItem } from '@/pages/system/Department/typings';
 import PermissionModal from '@/pages/system/Department/Assets/permissionModal';
 import SearchComponent from '@/components/SearchComponent';
+import { ExtraDeviceCard } from '@/components/ProTableCard/CardItems/device';
+import { ProTableCard } from '@/components';
 
 interface Props {
   reload: () => void;
   visible: boolean;
   onCancel: () => void;
+  parentId: string;
 }
 
 const Bind = observer((props: Props) => {
   const intl = useIntl();
-  const param = useParams<{ id: string }>();
   const actionRef = useRef<ActionType>();
-  const [perVisible, setPerVisible] = useState(false);
   const [searchParam, setSearchParam] = useState({});
+  const saveRef = useRef<{ saveData: Function }>();
 
   const columns: ProColumns<DeviceItem>[] = [
     {
@@ -100,7 +100,7 @@ const Bind = observer((props: Props) => {
 
   const handleBind = () => {
     if (Models.bindKeys.length) {
-      setPerVisible(true);
+      saveRef.current?.saveData();
     } else {
       message.warn('请先勾选数据');
       // props.onCancel();
@@ -122,11 +122,11 @@ const Bind = observer((props: Props) => {
       title="绑定"
     >
       <PermissionModal
-        visible={perVisible}
         type="device"
         bindKeys={Models.bindKeys}
+        parentId={props.parentId}
+        ref={saveRef}
         onCancel={(type) => {
-          setPerVisible(false);
           if (type) {
             props.reload();
             props.onCancel();
@@ -146,7 +146,7 @@ const Bind = observer((props: Props) => {
               targets: [
                 {
                   type: 'org',
-                  id: param.id,
+                  id: props.parentId,
                 },
               ],
             },
@@ -163,11 +163,13 @@ const Bind = observer((props: Props) => {
         // }}
         target="department-assets-device"
       />
-      <ProTable<DeviceItem>
+      <ProTableCard<DeviceItem>
         actionRef={actionRef}
         columns={columns}
         rowKey="id"
         search={false}
+        gridColumn={2}
+        cardRender={(record) => <ExtraDeviceCard {...record} />}
         rowSelection={{
           selectedRowKeys: Models.bindKeys,
           onChange: (selectedRowKeys, selectedRows) => {

+ 87 - 15
src/pages/system/Department/Assets/deivce/index.tsx

@@ -1,10 +1,8 @@
-// 资产分配-产品分类
+// 资产分配-设备管理
 import type { ActionType, ProColumns } from '@jetlinks/pro-table';
-import ProTable from '@jetlinks/pro-table';
 import { useIntl } from '@@/plugin-locale/localeExports';
 import { Badge, Button, message, Popconfirm, Tooltip } from 'antd';
-import { useRef, useState } from 'react';
-import { useParams } from 'umi';
+import { useEffect, useRef, useState } from 'react';
 import { observer } from '@formily/react';
 import type { DeviceItem } from '@/pages/system/Department/typings';
 import { DisconnectOutlined, PlusOutlined } from '@ant-design/icons';
@@ -12,6 +10,8 @@ import Models from './model';
 import Service from '@/pages/system/Department/Assets/service';
 import Bind from './bind';
 import SearchComponent from '@/components/SearchComponent';
+import { ExtraDeviceCard, handlePermissionsMap } from '@/components/ProTableCard/CardItems/device';
+import { ProTableCard } from '@/components';
 
 export const service = new Service<DeviceItem>('assets');
 
@@ -28,11 +28,10 @@ export const DeviceBadge = (props: DeviceBadgeProps) => {
   return <Badge status={STATUS[props.type]} text={props.text} />;
 };
 
-export default observer(() => {
+export default observer((props: { parentId: string }) => {
   const intl = useIntl();
   const actionRef = useRef<ActionType>();
 
-  const param = useParams<{ id: string }>();
   const [searchParam, setSearchParam] = useState({});
   /**
    * 解除资产绑定
@@ -43,7 +42,7 @@ export default observer(() => {
         .unBind('device', [
           {
             targetType: 'org',
-            targetId: param.id,
+            targetId: props.parentId,
             assetType: 'device',
             assetIdList: Models.unBindKeys,
           },
@@ -90,6 +89,14 @@ export default observer(() => {
       },
     },
     {
+      title: '资产权限',
+      dataIndex: 'grantedPermissions',
+      hideInSearch: true,
+      render: (_, row) => {
+        return handlePermissionsMap(row.grantedPermissions);
+      },
+    },
+    {
       title: intl.formatMessage({
         id: 'pages.device.instance.registrationTime',
         defaultMessage: '注册时间',
@@ -178,13 +185,48 @@ export default observer(() => {
     Models.bindKeys = [];
   };
 
+  const getData = (params: any, parentId: string) => {
+    return new Promise((resolve) => {
+      service.queryDeviceList2(params, parentId).subscribe((data) => {
+        resolve(data);
+      });
+    });
+  };
+
+  useEffect(() => {
+    setSearchParam({
+      terms: [
+        {
+          column: 'id',
+          termType: 'dim-assets',
+          value: {
+            assetType: 'device',
+            targets: [
+              {
+                type: 'org',
+                id: props.parentId,
+              },
+            ],
+          },
+        },
+      ],
+    });
+    actionRef.current?.reset?.();
+    //  初始化所有状态
+    Models.bindKeys = [];
+    Models.unBindKeys = [];
+  }, [props.parentId]);
+
   return (
     <>
-      <Bind
-        visible={Models.bind}
-        onCancel={closeModal}
-        reload={() => actionRef.current?.reload()}
-      />
+      {Models.bind && (
+        <Bind
+          visible={Models.bind}
+          onCancel={closeModal}
+          reload={() => actionRef.current?.reload()}
+          parentId={props.parentId}
+        />
+      )}
       <SearchComponent<DeviceItem>
         field={columns}
         defaultParam={[
@@ -196,7 +238,7 @@ export default observer(() => {
               targets: [
                 {
                   type: 'org',
-                  id: param.id,
+                  id: props.parentId,
                 },
               ],
             },
@@ -213,19 +255,48 @@ export default observer(() => {
         // }}
         target="department-assets-device"
       />
-      <ProTable<DeviceItem>
+      <ProTableCard<DeviceItem>
         actionRef={actionRef}
         columns={columns}
         rowKey="id"
         search={false}
         params={searchParam}
-        request={(params) => service.queryDeviceList(params)}
+        gridColumn={2}
+        request={async (params) => {
+          if (!props.parentId) {
+            return {
+              code: 200,
+              result: {
+                data: [],
+                pageIndex: 0,
+                pageSize: 0,
+                total: 0,
+              },
+              status: 200,
+            };
+          }
+          const resp: any = await getData(params, props.parentId);
+          return {
+            code: resp.status,
+            result: resp.result,
+            status: resp.status,
+          };
+        }}
         rowSelection={{
           selectedRowKeys: Models.unBindKeys,
           onChange: (selectedRowKeys, selectedRows) => {
             Models.unBindKeys = selectedRows.map((item) => item.id);
           },
         }}
+        cardRender={(record) => (
+          <ExtraDeviceCard
+            {...record}
+            onUnBind={(e) => {
+              e.stopPropagation();
+              singleUnBind(record.id);
+            }}
+          />
+        )}
         toolBarRender={() => [
           <Button
             onClick={() => {
@@ -234,6 +305,7 @@ export default observer(() => {
             icon={<PlusOutlined />}
             type="primary"
             key="bind"
+            disabled={!props.parentId}
           >
             {intl.formatMessage({
               id: 'pages.data.option.assets',

+ 36 - 25
src/pages/system/Department/Assets/index.tsx

@@ -4,35 +4,46 @@ import { useIntl } from '@@/plugin-locale/localeExports';
 import ProductCategory from './productCategory';
 import Product from './product';
 import Device from '@/pages/system/Department/Assets/deivce';
+import Member from '@/pages/system/Department/Member';
 
-// 资产类型
-const TabsArray = [
-  {
-    intlTitle: '1',
-    defaultMessage: '产品分类',
-    key: 'ProductCategory',
-    components: ProductCategory,
-  },
-  {
-    intlTitle: '2',
-    defaultMessage: '产品',
-    key: 'Product',
-    components: Product,
-  },
-  {
-    intlTitle: '3',
-    defaultMessage: '设备',
-    key: 'Device',
-    components: Device,
-  },
-];
+interface AssetsProps {
+  parentId: string;
+}
 
-const Assets = () => {
+const Assets = (props: AssetsProps) => {
   const intl = useIntl();
 
+  // 资产类型
+  const TabsArray = [
+    {
+      intlTitle: '1',
+      defaultMessage: '产品分类',
+      key: 'ProductCategory',
+      components: ProductCategory,
+    },
+    {
+      intlTitle: '2',
+      defaultMessage: '产品',
+      key: 'Product',
+      components: Product,
+    },
+    {
+      intlTitle: '3',
+      defaultMessage: '设备',
+      key: 'Device',
+      components: Device,
+    },
+    {
+      intlTitle: '4',
+      defaultMessage: '用户',
+      key: 'User',
+      components: Member,
+    },
+  ];
+
   return (
-    <div style={{ background: '#fff', padding: 12 }}>
-      <Tabs tabPosition="left" defaultActiveKey="ProductCategory">
+    <div>
+      <Tabs defaultActiveKey="ProductCategory">
         {TabsArray.map((item) => (
           <Tabs.TabPane
             tab={intl.formatMessage({
@@ -41,7 +52,7 @@ const Assets = () => {
             })}
             key={item.key}
           >
-            <item.components />
+            <item.components parentId={props.parentId} />
           </Tabs.TabPane>
         ))}
       </Tabs>

+ 16 - 23
src/pages/system/Department/Assets/permissionModal.tsx

@@ -1,19 +1,18 @@
 import { createForm } from '@formily/core';
 import { createSchemaField } from '@formily/react';
 import { Form, FormItem, Checkbox } from '@formily/antd';
-import { message, Modal } from 'antd';
-import { useIntl } from '@@/plugin-locale/localeExports';
+import { message } from 'antd';
 import type { ISchema } from '@formily/json-schema';
 import type { ModalProps } from 'antd/lib/modal/Modal';
-import { useParams } from 'umi';
 import Service from './service';
+import { forwardRef, useImperativeHandle } from 'react';
 
 type PermissionType = 'device' | 'product' | 'deviceCategory';
 
 export interface PerModalProps extends Omit<ModalProps, 'onOk' | 'onCancel'> {
   type: PermissionType;
+  parentId: string;
   bindKeys: string[];
-  visible: boolean;
   /**
    * Model关闭事件
    * @param type 是否为请求接口后关闭,用于外部table刷新数据
@@ -23,10 +22,7 @@ export interface PerModalProps extends Omit<ModalProps, 'onOk' | 'onCancel'> {
 
 const service = new Service('assets');
 
-export default (props: PerModalProps) => {
-  const intl = useIntl();
-  const params = useParams<{ id: string }>();
-
+const Permission = forwardRef((props: PerModalProps, ref) => {
   const SchemaField = createSchemaField({
     components: {
       Form,
@@ -56,7 +52,7 @@ export default (props: PerModalProps) => {
       .bind(props.type, [
         {
           targetType: 'org',
-          targetId: params.id,
+          targetId: props.parentId,
           assetType: props.type,
           assetIdList: props.bindKeys,
           permission: formData.permission,
@@ -71,6 +67,10 @@ export default (props: PerModalProps) => {
       });
   };
 
+  useImperativeHandle(ref, () => ({
+    saveData,
+  }));
+
   const schema: ISchema = {
     type: 'object',
     properties: {
@@ -84,26 +84,19 @@ export default (props: PerModalProps) => {
           { label: '编辑', value: 'save' },
           { label: '删除', value: 'delete' },
         ],
+        required: true,
         'x-value': ['read'],
       },
     },
   };
 
   return (
-    <Modal
-      title={intl.formatMessage({
-        id: `pages.data.option.`,
-        defaultMessage: '资产权限',
-      })}
-      visible={props.visible}
-      onOk={saveData}
-      onCancel={() => {
-        modalClose(false);
-      }}
-    >
-      <Form form={form} labelCol={5} wrapperCol={16}>
+    <div style={{ borderBottom: '1px solid #f0f0f0' }}>
+      <Form form={form}>
         <SchemaField schema={schema} />
       </Form>
-    </Modal>
+    </div>
   );
-};
+});
+
+export default Permission;

+ 12 - 10
src/pages/system/Department/Assets/product/bind.tsx

@@ -1,9 +1,7 @@
 // 资产-产品分类-绑定
 import type { ActionType, ProColumns } from '@jetlinks/pro-table';
-import ProTable from '@jetlinks/pro-table';
 import { service } from './index';
 import { message, Modal } from 'antd';
-import { useParams } from 'umi';
 import Models from './model';
 import { useEffect, useRef, useState } from 'react';
 import { observer } from '@formily/react';
@@ -11,19 +9,21 @@ import { useIntl } from '@@/plugin-locale/localeExports';
 import PermissionModal from '@/pages/system/Department/Assets/permissionModal';
 import type { ProductItem } from '@/pages/system/Department/typings';
 import SearchComponent from '@/components/SearchComponent';
+import { ExtraProductCard } from '@/components/ProTableCard/CardItems/product';
+import { ProTableCard } from '@/components';
 
 interface Props {
   reload: () => void;
   visible: boolean;
   onCancel: () => void;
+  parentId: string;
 }
 
 const Bind = observer((props: Props) => {
   const intl = useIntl();
-  const param = useParams<{ id: string }>();
   const actionRef = useRef<ActionType>();
-  const [perVisible, setPerVisible] = useState(false);
   const [searchParam, setSearchParam] = useState({});
+  const saveRef = useRef<{ saveData: Function }>();
 
   const columns: ProColumns<ProductItem>[] = [
     {
@@ -52,8 +52,8 @@ const Bind = observer((props: Props) => {
   ];
 
   const handleBind = () => {
-    if (Models.bindKeys.length) {
-      setPerVisible(true);
+    if (Models.bindKeys.length && saveRef.current) {
+      saveRef.current?.saveData();
     } else {
       message.warn('请先勾选数据');
       // props.onCancel();
@@ -75,11 +75,11 @@ const Bind = observer((props: Props) => {
       title="绑定"
     >
       <PermissionModal
-        visible={perVisible}
         type="product"
+        parentId={props.parentId}
         bindKeys={Models.bindKeys}
+        ref={saveRef}
         onCancel={(type) => {
-          setPerVisible(false);
           if (type) {
             props.reload();
             props.onCancel();
@@ -99,7 +99,7 @@ const Bind = observer((props: Props) => {
               targets: [
                 {
                   type: 'org',
-                  id: param.id,
+                  id: props.parentId,
                 },
               ],
             },
@@ -116,11 +116,12 @@ const Bind = observer((props: Props) => {
         // }}
         target="department-assets-product"
       />
-      <ProTable<ProductItem>
+      <ProTableCard<ProductItem>
         actionRef={actionRef}
         columns={columns}
         rowKey="id"
         search={false}
+        gridColumn={2}
         rowSelection={{
           selectedRowKeys: Models.bindKeys,
           onChange: (selectedRowKeys, selectedRows) => {
@@ -129,6 +130,7 @@ const Bind = observer((props: Props) => {
         }}
         request={(params) => service.queryProductList(params)}
         params={searchParam}
+        cardRender={(record) => <ExtraProductCard {...record} />}
       />
     </Modal>
   );

+ 89 - 14
src/pages/system/Department/Assets/product/index.tsx

@@ -1,10 +1,8 @@
 // 资产分配-产品分类
 import type { ActionType, ProColumns } from '@jetlinks/pro-table';
-import ProTable from '@jetlinks/pro-table';
 import { useIntl } from '@@/plugin-locale/localeExports';
 import { Button, message, Popconfirm, Tooltip } from 'antd';
-import { useRef, useState } from 'react';
-import { useParams } from 'umi';
+import { useEffect, useRef, useState } from 'react';
 import { observer } from '@formily/react';
 import type { ProductItem } from '@/pages/system/Department/typings';
 import { DisconnectOutlined, PlusOutlined } from '@ant-design/icons';
@@ -12,14 +10,18 @@ import Service from '@/pages/system/Department/Assets/service';
 import Models from './model';
 import Bind from './bind';
 import SearchComponent from '@/components/SearchComponent';
+import {
+  ExtraProductCard,
+  handlePermissionsMap,
+} from '@/components/ProTableCard/CardItems/product';
+import { ProTableCard } from '@/components';
 
 export const service = new Service<ProductItem>('assets');
 
-export default observer(() => {
+export default observer((props: { parentId: string }) => {
   const intl = useIntl();
   const actionRef = useRef<ActionType>();
 
-  const param = useParams<{ id: string }>();
   const [searchParam, setSearchParam] = useState({});
 
   /**
@@ -31,7 +33,7 @@ export default observer(() => {
         .unBind('product', [
           {
             targetType: 'org',
-            targetId: param.id,
+            targetId: props.parentId,
             assetType: 'product',
             assetIdList: Models.unBindKeys,
           },
@@ -71,6 +73,14 @@ export default observer(() => {
       },
     },
     {
+      title: '资产权限',
+      dataIndex: 'grantedPermissions',
+      hideInSearch: true,
+      render: (_, row) => {
+        return handlePermissionsMap(row.grantedPermissions);
+      },
+    },
+    {
       title: intl.formatMessage({
         id: 'pages.system.description',
         defaultMessage: '说明',
@@ -117,13 +127,48 @@ export default observer(() => {
     Models.bindKeys = [];
   };
 
+  useEffect(() => {
+    setSearchParam({
+      terms: [
+        {
+          column: 'id',
+          termType: 'dim-assets',
+          value: {
+            assetType: 'product',
+            targets: [
+              {
+                type: 'org',
+                id: props.parentId,
+              },
+            ],
+          },
+        },
+      ],
+    });
+    actionRef.current?.reload();
+    //  初始化所有状态
+    Models.bindKeys = [];
+    Models.unBindKeys = [];
+  }, [props.parentId]);
+
+  const getData = (params: any, parentId: string) => {
+    return new Promise((resolve) => {
+      service.queryProductList2(params, parentId).subscribe((data) => {
+        resolve(data);
+      });
+    });
+  };
+
   return (
     <>
-      <Bind
-        visible={Models.bind}
-        onCancel={closeModal}
-        reload={() => actionRef.current?.reload()}
-      />
+      {Models.bind && (
+        <Bind
+          visible={Models.bind}
+          onCancel={closeModal}
+          reload={() => actionRef.current?.reload()}
+          parentId={props.parentId}
+        />
+      )}
       <SearchComponent<ProductItem>
         field={columns}
         defaultParam={[
@@ -135,7 +180,7 @@ export default observer(() => {
               targets: [
                 {
                   type: 'org',
-                  id: param.id,
+                  id: props.parentId,
                 },
               ],
             },
@@ -152,19 +197,48 @@ export default observer(() => {
         // }}
         target="department-assets-product"
       />
-      <ProTable<ProductItem>
+      <ProTableCard<ProductItem>
         actionRef={actionRef}
         columns={columns}
         rowKey="id"
         search={false}
+        gridColumn={2}
         params={searchParam}
-        request={(params) => service.queryProductList(params)}
+        request={async (params) => {
+          if (!props.parentId) {
+            return {
+              code: 200,
+              result: {
+                data: [],
+                pageIndex: 0,
+                pageSize: 0,
+                total: 0,
+              },
+              status: 200,
+            };
+          }
+          const resp: any = await getData(params, props.parentId);
+          return {
+            code: resp.status,
+            result: resp.result,
+            status: resp.status,
+          };
+        }}
         rowSelection={{
           selectedRowKeys: Models.unBindKeys,
           onChange: (selectedRowKeys, selectedRows) => {
+            console.log(selectedRows);
             Models.unBindKeys = selectedRows.map((item) => item.id);
           },
         }}
+        cardRender={(record) => (
+          <ExtraProductCard
+            {...record}
+            onUnBind={() => {
+              singleUnBind(record.id);
+            }}
+          />
+        )}
         toolBarRender={() => [
           <Button
             onClick={() => {
@@ -173,6 +247,7 @@ export default observer(() => {
             icon={<PlusOutlined />}
             type="primary"
             key="bind"
+            disabled={!props.parentId}
           >
             {intl.formatMessage({
               id: 'pages.data.option.assets',

+ 7 - 8
src/pages/system/Department/Assets/productCategory/bind.tsx

@@ -3,7 +3,6 @@ import type { ActionType, ProColumns } from '@jetlinks/pro-table';
 import ProTable from '@jetlinks/pro-table';
 import { getTableKeys, service } from './index';
 import { Button, message, Modal, Space } from 'antd';
-import { useParams } from 'umi';
 import Models from './model';
 import { useEffect, useRef, useState } from 'react';
 import { observer } from '@formily/react';
@@ -17,14 +16,14 @@ interface Props {
   reload: () => void;
   visible: boolean;
   onCancel: () => void;
+  parentId: string;
 }
 
 const Bind = observer((props: Props) => {
   const intl = useIntl();
-  const param = useParams<{ id: string }>();
   const actionRef = useRef<ActionType>();
-  const [perVisible, setPerVisible] = useState(false);
   const [searchParam, setSearchParam] = useState({});
+  const saveRef = useRef<{ saveData: Function }>();
 
   const columns: ProColumns<ProductCategoryItem>[] = [
     {
@@ -52,8 +51,8 @@ const Bind = observer((props: Props) => {
   ];
 
   const handleBind = () => {
-    if (Models.bindKeys.length) {
-      setPerVisible(true);
+    if (Models.bindKeys.length && saveRef.current) {
+      saveRef.current.saveData();
     } else {
       message.warn('请先勾选数据');
       // props.onCancel();
@@ -75,11 +74,11 @@ const Bind = observer((props: Props) => {
       title="绑定"
     >
       <PermissionModal
-        visible={perVisible}
         type="deviceCategory"
         bindKeys={Models.bindKeys}
+        ref={saveRef}
+        parentId={props.parentId}
         onCancel={(type) => {
-          setPerVisible(false);
           if (type) {
             props.reload();
             props.onCancel();
@@ -99,7 +98,7 @@ const Bind = observer((props: Props) => {
               targets: [
                 {
                   type: 'org',
-                  id: param.id,
+                  id: props.parentId,
                 },
               ],
             },

+ 50 - 11
src/pages/system/Department/Assets/productCategory/index.tsx

@@ -3,8 +3,7 @@ import type { ActionType, ProColumns } from '@jetlinks/pro-table';
 import ProTable from '@jetlinks/pro-table';
 import { useIntl } from '@@/plugin-locale/localeExports';
 import { Button, message, Popconfirm, Space, Tooltip } from 'antd';
-import { useRef, useState } from 'react';
-import { useParams } from 'umi';
+import { useEffect, useRef, useState } from 'react';
 import { observer } from '@formily/react';
 import type { ProductCategoryItem } from '@/pages/system/Department/typings';
 import { DisconnectOutlined, PlusOutlined } from '@ant-design/icons';
@@ -29,10 +28,9 @@ export const getTableKeys = (rows: ProductCategoryItem[]): string[] => {
   return keys;
 };
 
-export default observer(() => {
+export default observer((props: { parentId: string }) => {
   const intl = useIntl();
   const actionRef = useRef<ActionType>();
-  const param = useParams<{ id: string }>();
   const [searchParam, setSearchParam] = useState({});
 
   /**
@@ -44,7 +42,7 @@ export default observer(() => {
         .unBind('deviceCategory', [
           {
             targetType: 'org',
-            targetId: param.id,
+            targetId: props.parentId,
             assetType: 'deviceCategory',
             assetIdList: Models.unBindKeys,
           },
@@ -137,13 +135,41 @@ export default observer(() => {
     Models.bindKeys = [];
   };
 
+  useEffect(() => {
+    setSearchParam({
+      terms: [
+        {
+          column: 'id',
+          termType: 'dim-assets',
+          value: {
+            assetType: 'deviceCategory',
+            targets: [
+              {
+                type: 'org',
+                id: props.parentId,
+              },
+            ],
+          },
+        },
+      ],
+    });
+    actionRef.current?.reset?.();
+    //  初始化所有状态
+    Models.bindKeys = [];
+    Models.unBindKeys = [];
+    console.log(props.parentId);
+  }, [props.parentId]);
+
   return (
     <>
-      <Bind
-        visible={Models.bind}
-        onCancel={closeModal}
-        reload={() => actionRef.current?.reload()}
-      />
+      {Models.bind && (
+        <Bind
+          visible={Models.bind}
+          onCancel={closeModal}
+          reload={() => actionRef.current?.reload()}
+          parentId={props.parentId}
+        />
+      )}
       <SearchComponent<ProductCategoryItem>
         field={columns}
         defaultParam={[
@@ -155,7 +181,7 @@ export default observer(() => {
               targets: [
                 {
                   type: 'org',
-                  id: param.id,
+                  id: props.parentId,
                 },
               ],
             },
@@ -179,6 +205,18 @@ export default observer(() => {
         search={false}
         rowKey="id"
         request={async (params) => {
+          if (!props.parentId) {
+            return {
+              code: 200,
+              result: {
+                data: [],
+                pageIndex: 0,
+                pageSize: 0,
+                total: 0,
+              },
+              status: 200,
+            };
+          }
           const response = await service.queryProductCategoryList(params);
           return {
             code: response.message,
@@ -240,6 +278,7 @@ export default observer(() => {
             }}
             icon={<PlusOutlined />}
             type="primary"
+            disabled={!props.parentId}
             key="bind"
           >
             {intl.formatMessage({

+ 57 - 1
src/pages/system/Department/Assets/service.ts

@@ -2,7 +2,7 @@ import BaseService from '@/utils/BaseService';
 import { request } from '@@/plugin-request/request';
 import SystemConst from '@/utils/const';
 import { defer, from } from 'rxjs';
-import { filter, map } from 'rxjs/operators';
+import { filter, map, mergeMap } from 'rxjs/operators';
 
 class Service<T> extends BaseService<T> {
   // 资产绑定
@@ -29,6 +29,7 @@ class Service<T> extends BaseService<T> {
       },
     });
   };
+
   // 资产-设备
   queryDeviceList = (params: any) => {
     return request<T>(`${SystemConst.API_BASE}/device/instance/_query`, {
@@ -36,6 +37,34 @@ class Service<T> extends BaseService<T> {
       data: params,
     });
   };
+
+  queryDeviceList2 = (params: any, parentId: string) =>
+    from(
+      request(`${SystemConst.API_BASE}/device/instance/_query`, { method: 'POST', data: params }),
+    ).pipe(
+      filter((item) => item.status === 200),
+      mergeMap((result) => {
+        const ids = result?.result?.data?.map((item: any) => item.id) || [];
+        return from(
+          request(`${SystemConst.API_BASE}/assets/bindings/device/org/${parentId}/_query`, {
+            method: 'POST',
+            data: ids,
+          }),
+        ).pipe(
+          filter((item) => item.status === 200),
+          map((item: any) => item.result || []),
+          map((item: any) => {
+            result.result.data = result.result.data.map((a: any) => {
+              a.grantedPermissions =
+                item.find((b: any) => b.assetId === a.id)?.grantedPermissions || [];
+              return a;
+            });
+            return result;
+          }),
+        );
+      }),
+    );
+
   // 资产-产品
   queryProductList = (params: any) => {
     return request<T>(`${SystemConst.API_BASE}/device-product/_query`, {
@@ -43,6 +72,33 @@ class Service<T> extends BaseService<T> {
       data: params,
     });
   };
+
+  queryProductList2 = (params: any, parentId: string) =>
+    from(
+      request(`${SystemConst.API_BASE}/device-product/_query`, { method: 'POST', data: params }),
+    ).pipe(
+      filter((item) => item.status === 200),
+      mergeMap((result) => {
+        const ids = result?.result?.data?.map((item: any) => item.id) || [];
+        return from(
+          request(`${SystemConst.API_BASE}/assets/bindings/device-product/org/${parentId}/_query`, {
+            method: 'POST',
+            data: ids,
+          }),
+        ).pipe(
+          filter((item) => item.status === 200),
+          map((item: any) => item.result || []),
+          map((item: any) => {
+            result.result.data = result.result.data.map((a: any) => {
+              a.grantedPermissions =
+                item.find((b: any) => b.assetId === a.id)?.grantedPermissions || [];
+              return a;
+            });
+            return result;
+          }),
+        );
+      }),
+    );
 }
 
 export default Service;

+ 3 - 4
src/pages/system/Department/Member/bind.tsx

@@ -3,7 +3,6 @@ import type { ActionType, ProColumns } from '@jetlinks/pro-table';
 import ProTable from '@jetlinks/pro-table';
 import { service } from '@/pages/system/Department/Member';
 import { message, Modal } from 'antd';
-import { useParams } from 'umi';
 import MemberModel from '@/pages/system/Department/Member/model';
 import { observer } from '@formily/react';
 import { useEffect, useRef, useState } from 'react';
@@ -14,11 +13,11 @@ interface Props {
   reload: () => void;
   visible: boolean;
   onCancel: () => void;
+  parentId: string;
 }
 
 const Bind = observer((props: Props) => {
   const intl = useIntl();
-  const param = useParams<{ id: string }>();
   const [searchParam, setSearchParam] = useState({});
   const actionRef = useRef<ActionType>();
 
@@ -53,7 +52,7 @@ const Bind = observer((props: Props) => {
 
   const handleBind = () => {
     if (MemberModel.bindUsers.length) {
-      service.handleUser(param.id, MemberModel.bindUsers, 'bind').subscribe({
+      service.handleUser(props.parentId, MemberModel.bindUsers, 'bind').subscribe({
         next: () => message.success('操作成功'),
         error: () => message.error('操作失败'),
         complete: () => {
@@ -80,7 +79,7 @@ const Bind = observer((props: Props) => {
         // pattern={'simple'}
         enableSave={false}
         field={columns}
-        defaultParam={[{ column: 'id$in-dimension$org$not', value: param.id }]}
+        defaultParam={[{ column: 'id$in-dimension$org$not', value: props.parentId }]}
         onSearch={async (data) => {
           actionRef.current?.reset?.();
           setSearchParam(data);

+ 39 - 12
src/pages/system/Department/Member/index.tsx

@@ -3,8 +3,7 @@ import type { ActionType, ProColumns } from '@jetlinks/pro-table';
 import ProTable from '@jetlinks/pro-table';
 import { useIntl } from '@@/plugin-locale/localeExports';
 import { Badge, Button, message, Popconfirm, Tooltip } from 'antd';
-import { useRef, useState } from 'react';
-import { useParams } from 'umi';
+import { useEffect, useRef, useState } from 'react';
 import { observer } from '@formily/react';
 import MemberModel from '@/pages/system/Department/Member/model';
 import type { MemberItem } from '@/pages/system/Department/typings';
@@ -12,19 +11,19 @@ import Service from '@/pages/system/Department/Member/service';
 import { DisconnectOutlined, PlusOutlined } from '@ant-design/icons';
 import Bind from './bind';
 import SearchComponent from '@/components/SearchComponent';
+import Models from '@/pages/system/Department/Assets/productCategory/model';
 
 export const service = new Service('tenant');
 
-const Member = observer(() => {
+const Member = observer((props: { parentId: string }) => {
   const intl = useIntl();
   const actionRef = useRef<ActionType>();
 
-  const param = useParams<{ id: string }>();
   const [searchParam, setSearchParam] = useState({});
 
   const handleUnBind = () => {
     if (MemberModel.unBindUsers.length) {
-      service.handleUser(param.id, MemberModel.unBindUsers, 'unbind').subscribe({
+      service.handleUser(props.parentId, MemberModel.unBindUsers, 'unbind').subscribe({
         next: () => message.success('操作成功'),
         error: () => message.error('操作失败'),
         complete: () => {
@@ -149,17 +148,30 @@ const Member = observer(() => {
     MemberModel.bind = false;
   };
 
+  useEffect(() => {
+    setSearchParam({
+      terms: [{ column: 'id$in-dimension$org', value: props.parentId }],
+    });
+    actionRef.current?.reset?.();
+    //  初始化所有状态
+    Models.bindKeys = [];
+    Models.unBindKeys = [];
+  }, [props.parentId]);
+
   return (
     <>
-      <Bind
-        visible={MemberModel.bind}
-        onCancel={closeModal}
-        reload={() => actionRef.current?.reload()}
-      />
+      {MemberModel.bind && (
+        <Bind
+          visible={MemberModel.bind}
+          onCancel={closeModal}
+          reload={() => actionRef.current?.reload()}
+          parentId={props.parentId}
+        />
+      )}
       <SearchComponent<MemberItem>
         // pattern={'simple'}
         field={columns}
-        defaultParam={[{ column: 'id$in-dimension$org', value: param.id }]}
+        defaultParam={[{ column: 'id$in-dimension$org', value: props.parentId }]}
         onSearch={async (data) => {
           actionRef.current?.reset?.();
           setSearchParam(data);
@@ -176,7 +188,21 @@ const Member = observer(() => {
         columns={columns}
         search={false}
         rowKey="id"
-        request={(params) => service.queryUser(params)}
+        request={(params) => {
+          if (!props.parentId) {
+            return {
+              code: 200,
+              result: {
+                data: [],
+                pageIndex: 0,
+                pageSize: 0,
+                total: 0,
+              },
+              status: 200,
+            };
+          }
+          return service.queryUser(params);
+        }}
         rowSelection={{
           selectedRowKeys: MemberModel.unBindUsers,
           onChange: (selectedRowKeys, selectedRows) => {
@@ -192,6 +218,7 @@ const Member = observer(() => {
             icon={<PlusOutlined />}
             type="primary"
             key="bind"
+            disabled={!props.parentId}
           >
             {intl.formatMessage({
               id: 'pages.system.role.option.bindUser',

+ 3 - 0
src/pages/system/Department/Tree/index.tsx

@@ -0,0 +1,3 @@
+import Tree from './tree';
+
+export default Tree;

+ 331 - 0
src/pages/system/Department/Tree/tree.tsx

@@ -0,0 +1,331 @@
+import { Button, Input, message, Tree } from 'antd';
+import {
+  DeleteOutlined,
+  EditOutlined,
+  LoadingOutlined,
+  PlusCircleOutlined,
+  SearchOutlined,
+} from '@ant-design/icons';
+import { useEffect, useRef, useState } from 'react';
+import { service } from '@/pages/system/Department';
+import { Empty, PermissionButton } from '@/components';
+import { useIntl } from 'umi';
+import { debounce } from 'lodash';
+import Save from '../save';
+import { ISchema } from '@formily/json-schema';
+import { useLocation } from 'umi';
+import { DepartmentItem } from '@/pages/system/Department/typings';
+
+interface TreeProps {
+  onSelect: (id: string) => void;
+}
+
+export const getSortIndex = (data: DepartmentItem[], pId?: string): number => {
+  let sortIndex = 0;
+  if (data.length) {
+    if (!pId) {
+      return data.sort((a, b) => b.sortIndex - a.sortIndex)[0].sortIndex + 1;
+    }
+    data.some((department) => {
+      if (department.id === pId && department.children) {
+        const sortArray = department.children.sort((a, b) => b.sortIndex - a.sortIndex);
+        sortIndex = sortArray[0].sortIndex + 1;
+        return true;
+      } else if (department.children) {
+        sortIndex = getSortIndex(department.children, pId);
+        return !!sortIndex;
+      }
+      return false;
+    });
+  }
+  return sortIndex;
+};
+
+export default (props: TreeProps) => {
+  const intl = useIntl();
+  const [treeData, setTreeData] = useState<undefined | any[]>(undefined);
+  const [loading, setLoading] = useState(false);
+  const [keys, setKeys] = useState<any[]>([]);
+  const [visible, setVisible] = useState(false);
+  const [data, setData] = useState<any>();
+  const [expandedKeys, setExpandedKeys] = useState<string[]>([]);
+  const searchKey = useRef('');
+
+  const location = useLocation();
+
+  const { permission } = PermissionButton.usePermission('system/Department');
+
+  const queryTreeData = async () => {
+    setKeys([]);
+    const terms: Record<string, any> = {};
+    if (searchKey.current) {
+      terms.terms = [{ column: 'name$LIKE', value: `%${searchKey.current}%` }];
+    }
+    setLoading(true);
+    const resp = await service.queryOrgThree({
+      paging: false,
+      sorts: [{ name: 'sortIndex', order: 'asc' }],
+      ...terms,
+    });
+    setLoading(false);
+
+    if (resp.status === 200) {
+      setTreeData(resp.result);
+    }
+  };
+
+  const deleteItem = async (id: string) => {
+    const response: any = await service.remove(id);
+    if (response.status === 200) {
+      message.success(
+        intl.formatMessage({
+          id: 'pages.data.option.success',
+          defaultMessage: '操作成功!',
+        }),
+      );
+      queryTreeData();
+    }
+  };
+
+  const onSearchChange = (e: any) => {
+    searchKey.current = e.target.value;
+    queryTreeData();
+  };
+
+  const schema: ISchema = {
+    type: 'object',
+    properties: {
+      parentId: {
+        type: 'string',
+        title: '上级部门',
+        'x-decorator': 'FormItem',
+        'x-component': 'TreeSelect',
+        'x-component-props': {
+          fieldNames: {
+            label: 'name',
+            value: 'id',
+          },
+          placeholder: '请选择上级部门',
+        },
+        enum: treeData,
+      },
+      name: {
+        type: 'string',
+        title: intl.formatMessage({
+          id: 'pages.table.name',
+          defaultMessage: '名称',
+        }),
+        required: true,
+        'x-decorator': 'FormItem',
+        'x-component': 'Input',
+        'x-component-props': {
+          placeholder: '请输入名称',
+        },
+        'x-validator': [
+          {
+            max: 64,
+            message: '最多可输入64个字符',
+          },
+          {
+            required: true,
+            message: '请输入名称',
+          },
+        ],
+      },
+      sortIndex: {
+        type: 'string',
+        title: intl.formatMessage({
+          id: 'pages.device.instanceDetail.detail.sort',
+          defaultMessage: '排序',
+        }),
+        required: true,
+        'x-decorator': 'FormItem',
+        'x-component': 'NumberPicker',
+        'x-component-props': {
+          placeholder: '请输入排序',
+        },
+        'x-validator': [
+          {
+            required: true,
+            message: '请输入排序',
+          },
+          {
+            pattern: /^[0-9]*[1-9][0-9]*$/,
+            message: '请输入大于0的整数',
+          },
+        ],
+      },
+    },
+  };
+
+  useEffect(() => {
+    if ((location as any).query?.save === 'true') {
+      setData({ sortIndex: treeData && treeData.length + 1 });
+      setVisible(true);
+    }
+  }, [location]);
+
+  useEffect(() => {
+    queryTreeData();
+  }, []);
+
+  useEffect(() => {
+    if (keys.length) {
+      props.onSelect(keys[0]);
+    }
+  }, [keys]);
+
+  return (
+    <div className={'left-tree-content border-left'}>
+      {loading && (
+        <div className={'left-tree-loading'}>
+          <LoadingOutlined />
+        </div>
+      )}
+      <Input
+        placeholder={'请输入部门名称'}
+        className={'left-tree-search'}
+        suffix={<SearchOutlined />}
+        onChange={debounce(onSearchChange, 500)}
+      />
+      <Button
+        style={{ width: '100%', margin: '24px 0' }}
+        type={'primary'}
+        onClick={() => {
+          setData({ sortIndex: treeData && treeData.length + 1 });
+          setVisible(true);
+        }}
+      >
+        新增
+      </Button>
+      {treeData ? (
+        <div className={'left-tree-body'}>
+          <Tree
+            fieldNames={{
+              title: 'name',
+              key: 'id',
+            }}
+            blockNode={true}
+            treeData={treeData}
+            selectedKeys={keys}
+            onSelect={(_keys: any[]) => {
+              if (_keys && _keys.length) {
+                setKeys(_keys);
+              }
+            }}
+            expandedKeys={expandedKeys}
+            onExpand={(_keys: any[]) => {
+              setExpandedKeys(_keys);
+            }}
+            titleRender={(nodeData: any) => {
+              return (
+                <div>
+                  <span>{nodeData.name}</span>
+                  <span>
+                    <PermissionButton
+                      key="editable"
+                      tooltip={{
+                        title: intl.formatMessage({
+                          id: 'pages.data.option.edit',
+                          defaultMessage: '编辑',
+                        }),
+                      }}
+                      isPermission={permission.update}
+                      style={{ padding: '0 0 0 6px' }}
+                      type="link"
+                      onClick={(e) => {
+                        e.stopPropagation();
+                        setData({
+                          ...nodeData,
+                        });
+                        setVisible(true);
+                      }}
+                    >
+                      <EditOutlined />
+                    </PermissionButton>
+                    <PermissionButton
+                      key={'addChildren'}
+                      style={{ padding: '0 0 0 6px' }}
+                      tooltip={{
+                        title: intl.formatMessage({
+                          id: 'pages.system.department.option.add',
+                          defaultMessage: '新增子部门',
+                        }),
+                      }}
+                      type="link"
+                      isPermission={permission.add}
+                      onClick={(e) => {
+                        e.stopPropagation();
+                        setData({
+                          parentId: nodeData.id,
+                          sortIndex: nodeData.children ? nodeData.children.length + 1 : 1,
+                        });
+                        setVisible(true);
+                      }}
+                    >
+                      <PlusCircleOutlined />
+                    </PermissionButton>
+                    <PermissionButton
+                      type="link"
+                      key="delete"
+                      style={{ padding: '0 0 0 6px' }}
+                      popConfirm={{
+                        title: intl.formatMessage({
+                          id: 'pages.system.role.option.delete',
+                          defaultMessage: '确定要删除吗',
+                        }),
+                        onConfirm(e) {
+                          e?.stopPropagation();
+                          deleteItem(nodeData.id);
+                        },
+                      }}
+                      onClick={(e) => {
+                        e.stopPropagation();
+                      }}
+                      tooltip={{
+                        title: intl.formatMessage({
+                          id: 'pages.data.option.delete',
+                          defaultMessage: '删除',
+                        }),
+                      }}
+                      isPermission={permission.delete}
+                    >
+                      <DeleteOutlined />
+                    </PermissionButton>
+                  </span>
+                </div>
+              );
+            }}
+          />
+        </div>
+      ) : (
+        <div style={{ height: 200 }}>
+          <Empty />
+        </div>
+      )}
+      <Save
+        visible={visible}
+        title={
+          data && data.parentId
+            ? intl.formatMessage({
+                id: 'pages.system.department.option.add',
+              })
+            : undefined
+        }
+        service={service}
+        onCancel={() => {
+          setVisible(false);
+          setData(undefined);
+        }}
+        reload={async (pId) => {
+          await queryTreeData();
+          if (pId && !expandedKeys.includes(pId)) {
+            setExpandedKeys([...expandedKeys, pId]);
+          }
+        }}
+        data={data}
+        schema={schema}
+      />
+    </div>
+  );
+};

+ 52 - 0
src/pages/system/Department/index.less

@@ -0,0 +1,52 @@
+.department {
+  .ant-card-body {
+    height: 100%;
+  }
+
+  .department-warp {
+    display: flex;
+    height: 100%;
+
+    .department-left {
+      display: flex;
+      flex-basis: 300px;
+      height: 100%;
+
+      .border-left {
+        padding-right: 24px;
+        border-right: 1px solid #f0f0f0;
+      }
+
+      .left-tree-content {
+        position: relative;
+        display: flex;
+        flex-direction: column;
+        width: 100%;
+
+        .left-tree-loading {
+          position: absolute;
+          top: 0;
+          left: 0;
+          z-index: 2;
+          display: flex;
+          align-items: center;
+          justify-content: center;
+          width: 100%;
+          height: 100%;
+          font-size: 30px;
+          background-color: rgba(#fff, 0.1);
+        }
+      }
+
+      .left-tree-body {
+        flex: 1 1 auto;
+        overflow-y: auto;
+      }
+    }
+
+    .department-right {
+      flex: 1 1 auto;
+      padding-left: 24px;
+    }
+  }
+}

+ 122 - 369
src/pages/system/Department/index.tsx

@@ -1,28 +1,15 @@
 // 部门管理
 import { PageContainer } from '@ant-design/pro-layout';
-import type { ActionType, ProColumns } from '@jetlinks/pro-table';
-import ProTable from '@jetlinks/pro-table';
-import * as React from 'react';
-import { useEffect, useRef, useState } from 'react';
-import { history, useIntl, useLocation } from 'umi';
-import { message } from 'antd';
-import {
-  DeleteOutlined,
-  EditOutlined,
-  MedicineBoxOutlined,
-  PlusCircleOutlined,
-  PlusOutlined,
-  TeamOutlined,
-} from '@ant-design/icons';
+import { useEffect, useState } from 'react';
+import { Card } from 'antd';
 import Service from '@/pages/system/Department/service';
-import type { ISchema } from '@formily/json-schema';
 import type { DepartmentItem } from '@/pages/system/Department/typings';
 import { observer } from '@formily/react';
 import { model } from '@formily/reactive';
-import Save from './save';
-import SearchComponent from '@/components/SearchComponent';
-import { getMenuPathByParams, MENUS_CODE } from '@/utils/menu';
-import { PermissionButton } from '@/components';
+import { getDomFullHeight } from '@/utils/util';
+import Assets from './Assets';
+import Tree from './Tree';
+import './style';
 
 export const service = new Service('organization');
 
@@ -37,364 +24,130 @@ export const State = model<ModelType>({
   parentId: undefined,
 });
 
-export const getSortIndex = (data: DepartmentItem[], pId?: string): number => {
-  let sortIndex = 0;
-  if (data.length) {
-    if (!pId) {
-      return data.sort((a, b) => b.sortIndex - a.sortIndex)[0].sortIndex + 1;
-    }
-    data.some((department) => {
-      if (department.id === pId && department.children) {
-        const sortArray = department.children.sort((a, b) => b.sortIndex - a.sortIndex);
-        sortIndex = sortArray[0].sortIndex + 1;
-        return true;
-      } else if (department.children) {
-        sortIndex = getSortIndex(department.children, pId);
-        return !!sortIndex;
-      }
-      return false;
-    });
-  }
-  return sortIndex;
-};
-
 export default observer(() => {
-  const actionRef = useRef<ActionType>();
-  const permissionCode = 'system/Department';
-  const intl = useIntl();
-  const [param, setParam] = useState({});
-  const [expandedRowKeys, setExpandedRowKeys] = useState<React.Key[]>([]);
-  const [treeData, setTreeData] = useState<any[]>([]);
-  const [sortParam, setSortParam] = useState<any>({ name: 'sortIndex', order: 'asc' });
-  const rowKeys = useRef<React.Key[]>([]);
-  const { permission } = PermissionButton.usePermission(permissionCode);
-
-  /**
-   * 根据部门ID删除数据
-   * @param id
-   */
-  const deleteItem = async (id: string) => {
-    const response: any = await service.remove(id);
-    if (response.status === 200) {
-      message.success(
-        intl.formatMessage({
-          id: 'pages.data.option.success',
-          defaultMessage: '操作成功!',
-        }),
-      );
-    }
-    actionRef.current?.reload();
-  };
-
-  const columns: ProColumns<DepartmentItem>[] = [
-    {
-      title: intl.formatMessage({
-        id: 'pages.table.name',
-        defaultMessage: '名称',
-      }),
-      dataIndex: 'name',
-    },
-    {
-      title: intl.formatMessage({
-        id: 'pages.device.instanceDetail.detail.sort',
-        defaultMessage: '排序',
-      }),
-      search: false,
-      valueType: 'digit',
-      dataIndex: 'sortIndex',
-      sorter: true,
-    },
-    {
-      title: intl.formatMessage({
-        id: 'pages.data.option',
-        defaultMessage: '操作',
-      }),
-      valueType: 'option',
-      width: 240,
-      render: (text, record) => [
-        <PermissionButton
-          key="editable"
-          tooltip={{
-            title: intl.formatMessage({
-              id: 'pages.data.option.edit',
-              defaultMessage: '编辑',
-            }),
-          }}
-          isPermission={permission.update}
-          style={{ padding: 0 }}
-          type="link"
-          onClick={() => {
-            State.current = record;
-            State.visible = true;
-          }}
-        >
-          <EditOutlined />
-        </PermissionButton>,
-        <PermissionButton
-          key={'addChildren'}
-          style={{ padding: 0 }}
-          tooltip={{
-            title: intl.formatMessage({
-              id: 'pages.system.department.option.add',
-              defaultMessage: '新增子部门',
-            }),
-          }}
-          type="link"
-          isPermission={permission.add}
-          onClick={() => {
-            State.current = {
-              parentId: record.id,
-            };
-            State.visible = true;
-          }}
-        >
-          <PlusCircleOutlined />
-        </PermissionButton>,
-        <PermissionButton
-          key={'assets'}
-          style={{ padding: 0 }}
-          tooltip={{
-            title: intl.formatMessage({
-              id: 'pages.data.option.assets',
-              defaultMessage: '资产分配',
-            }),
-          }}
-          type="link"
-          isPermission={permission.assert}
-          onClick={() => {
-            history.push(
-              `${getMenuPathByParams(
-                MENUS_CODE['system/Department/Detail'],
-                record.id,
-              )}?type=assets`,
-            );
-          }}
-        >
-          <MedicineBoxOutlined />
-        </PermissionButton>,
-        <PermissionButton
-          type="link"
-          key="user"
-          style={{ padding: 0 }}
-          tooltip={{
-            title: intl.formatMessage({
-              id: 'pages.system.department.user',
-              defaultMessage: '用户',
-            }),
-          }}
-          isPermission={permission['bind-user']}
-          onClick={() =>
-            history.push(
-              `${getMenuPathByParams(MENUS_CODE['system/Department/Detail'], record.id)}?type=user`,
-            )
-          }
-        >
-          <TeamOutlined />
-        </PermissionButton>,
-        <PermissionButton
-          type="link"
-          key="delete"
-          style={{ padding: 0 }}
-          popConfirm={{
-            title: intl.formatMessage({
-              id: 'pages.system.role.option.delete',
-              defaultMessage: '确定要删除吗',
-            }),
-            onConfirm() {
-              deleteItem(record.id);
-            },
-          }}
-          tooltip={{
-            title: intl.formatMessage({
-              id: 'pages.data.option.delete',
-              defaultMessage: '删除',
-            }),
-          }}
-          isPermission={permission.delete}
-        >
-          <DeleteOutlined />
-        </PermissionButton>,
-      ],
-    },
-  ];
-
-  const schema: ISchema = {
-    type: 'object',
-    properties: {
-      parentId: {
-        type: 'string',
-        title: '上级部门',
-        'x-decorator': 'FormItem',
-        'x-component': 'TreeSelect',
-        'x-component-props': {
-          fieldNames: {
-            label: 'name',
-            value: 'id',
-          },
-          placeholder: '请选择上级部门',
-        },
-        enum: treeData,
-      },
-      name: {
-        type: 'string',
-        title: intl.formatMessage({
-          id: 'pages.table.name',
-          defaultMessage: '名称',
-        }),
-        required: true,
-        'x-decorator': 'FormItem',
-        'x-component': 'Input',
-        'x-component-props': {
-          placeholder: '请输入名称',
-        },
-        'x-validator': [
-          {
-            max: 64,
-            message: '最多可输入64个字符',
-          },
-          {
-            required: true,
-            message: '请输入名称',
-          },
-        ],
-      },
-      sortIndex: {
-        type: 'string',
-        title: intl.formatMessage({
-          id: 'pages.device.instanceDetail.detail.sort',
-          defaultMessage: '排序',
-        }),
-        required: true,
-        'x-decorator': 'FormItem',
-        'x-component': 'NumberPicker',
-        'x-component-props': {
-          placeholder: '请输入排序',
-        },
-        'x-validator': [
-          {
-            required: true,
-            message: '请输入排序',
-          },
-          {
-            pattern: /^[0-9]*[1-9][0-9]*$/,
-            message: '请输入大于0的整数',
-          },
-        ],
-      },
-    },
-  };
-
-  const location = useLocation();
+  const [parentId, setParentId] = useState('');
+  const [minHeight, setMinHeight] = useState(100);
 
   useEffect(() => {
-    if ((location as any).query?.save === 'true') {
-      State.visible = true;
-    }
+    setTimeout(() => {
+      setMinHeight(getDomFullHeight('department'));
+    }, 0);
+
     /* eslint-disable */
   }, []);
 
   return (
     <PageContainer>
-      <SearchComponent<DepartmentItem>
-        field={columns}
-        defaultParam={[{ column: 'typeId', value: 'org', termType: 'eq' }]}
-        onSearch={async (data) => {
-          // 重置分页数据
-          actionRef.current?.reset?.();
-          setParam(data);
-        }}
-        // onReset={() => {
-        //   // 重置分页及搜索参数
-        //   actionRef.current?.reset?.();
-        //   setParam({});
-        // }}
-        target="department"
-      />
-      <ProTable<DepartmentItem>
-        columns={columns}
-        actionRef={actionRef}
-        request={async (params) => {
-          const response = await service.queryOrgThree({
-            paging: false,
-            sorts: [sortParam],
-            ...params,
-          });
-          setTreeData(response.result);
-          return {
-            code: response.message,
-            result: {
-              data: response.result,
-              pageIndex: 0,
-              pageSize: 0,
-              total: 0,
-            },
-            status: response.status,
-          };
-        }}
-        onChange={(_, f, sorter: any) => {
-          if (sorter.order) {
-            setSortParam({ name: sorter.columnKey, order: sorter.order.replace('end', '') });
-          } else {
-            setSortParam({ name: 'sortIndex', value: 'asc' });
-          }
-        }}
-        rowKey="id"
-        expandable={{
-          expandedRowKeys: [...rowKeys.current],
-          onExpandedRowsChange: (keys) => {
-            rowKeys.current = keys as React.Key[];
-            setExpandedRowKeys(keys as React.Key[]);
-          },
-        }}
-        pagination={false}
-        search={false}
-        params={param}
-        headerTitle={
-          <PermissionButton
-            isPermission={permission.add}
-            onClick={() => {
-              State.visible = true;
-            }}
-            key="button"
-            icon={<PlusOutlined />}
-            type="primary"
-          >
-            {intl.formatMessage({
-              id: 'pages.data.option.add',
-              defaultMessage: '新增',
-            })}
-          </PermissionButton>
-        }
-      />
-      <Save<DepartmentItem>
-        parentChange={(pId) => {
-          return getSortIndex(treeData, pId);
-        }}
-        title={
-          State.current.parentId
-            ? intl.formatMessage({
-                id: 'pages.system.department.option.add',
-                defaultMessage: '新增子部门',
-              })
-            : undefined
-        }
-        service={service}
-        onCancel={(type, pId) => {
-          if (pId) {
-            expandedRowKeys.push(pId);
-            rowKeys.current.push(pId);
-            setExpandedRowKeys(expandedRowKeys);
-          }
-          if (type) {
-            actionRef.current?.reload();
-          }
-          State.current = {};
-          State.visible = false;
-        }}
-        data={State.current}
-        visible={State.visible}
-        schema={schema}
-      />
+      <Card className={'department'} style={{ minHeight }}>
+        <div className={'department-warp'}>
+          <div className={'department-left'}>
+            <Tree onSelect={setParentId} />
+          </div>
+          <div className={'department-right'}>
+            <Assets parentId={parentId} />
+          </div>
+        </div>
+      </Card>
+      {/*<SearchComponent<DepartmentItem>*/}
+      {/*  field={columns}*/}
+      {/*  defaultParam={[{ column: 'typeId', value: 'org', termType: 'eq' }]}*/}
+      {/*  onSearch={async (data) => {*/}
+      {/*    // 重置分页数据*/}
+      {/*    actionRef.current?.reset?.();*/}
+      {/*    setParam(data);*/}
+      {/*  }}*/}
+      {/*  // onReset={() => {*/}
+      {/*  //   // 重置分页及搜索参数*/}
+      {/*  //   actionRef.current?.reset?.();*/}
+      {/*  //   setParam({});*/}
+      {/*  // }}*/}
+      {/*  target="department"*/}
+      {/*/>*/}
+      {/*<ProTable<DepartmentItem>*/}
+      {/*  columns={columns}*/}
+      {/*  actionRef={actionRef}*/}
+      {/*  request={async (params) => {*/}
+      {/*    const response = await service.queryOrgThree({*/}
+      {/*      paging: false,*/}
+      {/*      sorts: [sortParam],*/}
+      {/*      ...params,*/}
+      {/*    });*/}
+      {/*    setTreeData(response.result);*/}
+      {/*    return {*/}
+      {/*      code: response.message,*/}
+      {/*      result: {*/}
+      {/*        data: response.result,*/}
+      {/*        pageIndex: 0,*/}
+      {/*        pageSize: 0,*/}
+      {/*        total: 0,*/}
+      {/*      },*/}
+      {/*      status: response.status,*/}
+      {/*    };*/}
+      {/*  }}*/}
+      {/*  onChange={(_, f, sorter: any) => {*/}
+      {/*    if (sorter.order) {*/}
+      {/*      setSortParam({ name: sorter.columnKey, order: sorter.order.replace('end', '') });*/}
+      {/*    } else {*/}
+      {/*      setSortParam({ name: 'sortIndex', value: 'asc' });*/}
+      {/*    }*/}
+      {/*  }}*/}
+      {/*  rowKey="id"*/}
+      {/*  expandable={{*/}
+      {/*    expandedRowKeys: [...rowKeys.current],*/}
+      {/*    onExpandedRowsChange: (keys) => {*/}
+      {/*      rowKeys.current = keys as React.Key[];*/}
+      {/*      setExpandedRowKeys(keys as React.Key[]);*/}
+      {/*    },*/}
+      {/*  }}*/}
+      {/*  pagination={false}*/}
+      {/*  search={false}*/}
+      {/*  params={param}*/}
+      {/*  headerTitle={*/}
+      {/*    <PermissionButton*/}
+      {/*      isPermission={permission.add}*/}
+      {/*      onClick={() => {*/}
+      {/*        State.visible = true;*/}
+      {/*      }}*/}
+      {/*      key="button"*/}
+      {/*      icon={<PlusOutlined />}*/}
+      {/*      type="primary"*/}
+      {/*    >*/}
+      {/*      {intl.formatMessage({*/}
+      {/*        id: 'pages.data.option.add',*/}
+      {/*        defaultMessage: '新增',*/}
+      {/*      })}*/}
+      {/*    </PermissionButton>*/}
+      {/*  }*/}
+      {/*/>*/}
+      {/*<Save<DepartmentItem>*/}
+      {/*  parentChange={(pId) => {*/}
+      {/*    return getSortIndex(treeData, pId);*/}
+      {/*  }}*/}
+      {/*  title={*/}
+      {/*    State.current.parentId*/}
+      {/*      ? intl.formatMessage({*/}
+      {/*          id: 'pages.system.department.option.add',*/}
+      {/*          defaultMessage: '新增子部门',*/}
+      {/*        })*/}
+      {/*      : undefined*/}
+      {/*  }*/}
+      {/*  service={service}*/}
+      {/*  onCancel={(type, pId) => {*/}
+      {/*    if (pId) {*/}
+      {/*      expandedRowKeys.push(pId);*/}
+      {/*      rowKeys.current.push(pId);*/}
+      {/*      setExpandedRowKeys(expandedRowKeys);*/}
+      {/*    }*/}
+      {/*    if (type) {*/}
+      {/*      actionRef.current?.reload();*/}
+      {/*    }*/}
+      {/*    State.current = {};*/}
+      {/*    State.visible = false;*/}
+      {/*  }}*/}
+      {/*  data={State.current}*/}
+      {/*  visible={State.visible}*/}
+      {/*  schema={schema}*/}
+      {/*/>*/}
     </PageContainer>
   );
 });

+ 5 - 13
src/pages/system/Department/save.tsx

@@ -1,7 +1,6 @@
 // Modal 弹窗,用于新增、修改数据
 import React from 'react';
-import type { Field } from '@formily/core';
-import { createForm, onFieldReact } from '@formily/core';
+import { createForm } from '@formily/core';
 import { createSchemaField } from '@formily/react';
 import {
   ArrayTable,
@@ -30,14 +29,13 @@ import type BaseService from '@/utils/BaseService';
 export interface SaveModalProps<T> extends Omit<ModalProps, 'onOk' | 'onCancel'> {
   service: BaseService<T>;
   data?: Partial<T>;
-  reload?: () => void;
+  reload?: (pId: string) => void;
   /**
    * Model关闭事件
    * @param type 是否为请求接口后关闭,用于外部table刷新数据
    */
   onCancel?: (type: boolean, id?: React.Key) => void;
   schema: ISchema;
-  parentChange: (value?: string) => number;
 }
 
 const Save = <T extends object>(props: SaveModalProps<T>) => {
@@ -71,15 +69,6 @@ const Save = <T extends object>(props: SaveModalProps<T>) => {
   const form = createForm({
     validateFirst: true,
     initialValues: data || {},
-    effects: () => {
-      onFieldReact('sortIndex', (field) => {
-        const value = (field as Field).value;
-        if (props.parentChange && !value) {
-          const sortIndex = props.parentChange(field.query('parentId').value());
-          (field as Field).value = !!sortIndex ? sortIndex : sortIndex + 1;
-        }
-      });
-    },
   });
 
   /**
@@ -105,6 +94,9 @@ const Save = <T extends object>(props: SaveModalProps<T>) => {
     if (response.status === 200) {
       message.success('操作成功!');
       modalClose(true, response.result.parentId);
+      if (props.reload) {
+        props.reload(response.result.parentId);
+      }
       if ((window as any).onTabSaveSuccess) {
         (window as any).onTabSaveSuccess(response.result);
         setTimeout(() => window.close(), 300);

+ 1 - 0
src/pages/system/Department/style.ts

@@ -0,0 +1 @@
+import './index.less';

+ 3 - 1
src/pages/system/Department/typings.d.ts

@@ -27,6 +27,7 @@ export type ProductItem = {
   id: string;
   name: string;
   description: string;
+  grantedPermissions?: string[];
 };
 
 // 产品分类
@@ -37,6 +38,7 @@ export type DeviceItem = {
   id: string;
   name: string;
   productName: string;
-  createTime: string;
+  createTime: number;
   state: State;
+  grantedPermissions?: string[];
 };