ソースを参照

feat(部门管理): 替换搜索组件

xieyonghong 3 年 前
コミット
9b0e869eaf

+ 1 - 0
src/locales/zh-CN/pages.ts

@@ -124,6 +124,7 @@ export default {
   'pages.system.org.option.add': '添加下级',
   // 系统设置-部门管理
   'pages.system.department.user': '用户',
+  'pages.system.department.option.add': '新增子部门',
   // 系统设置-第三方平台
   'pages.system.openApi': '第三方平台',
   'pages.system.openApi.username': '用户名',

+ 78 - 20
src/pages/system/Department/Assets/deivce/index.tsx

@@ -3,7 +3,7 @@ import ProTable from '@jetlinks/pro-table';
 import type { ActionType, ProColumns } from '@jetlinks/pro-table';
 import { useIntl } from '@@/plugin-locale/localeExports';
 import { Button, message, Popconfirm, Tooltip, Badge } from 'antd';
-import { useRef } from 'react';
+import { useRef, useState } from 'react';
 import { useParams } from 'umi';
 import { observer } from '@formily/react';
 import type { DeviceItem } from '@/pages/system/Department/typings';
@@ -11,6 +11,7 @@ import { DisconnectOutlined, PlusOutlined } from '@ant-design/icons';
 import Models from './model';
 import Service from '@/pages/system/Department/Assets/service';
 import Bind from './bind';
+import SearchComponent from '@/components/SearchComponent';
 
 export const service = new Service<DeviceItem>();
 
@@ -32,7 +33,23 @@ export default observer(() => {
   const actionRef = useRef<ActionType>();
 
   const param = useParams<{ id: string }>();
-
+  const [searchParam, setSearchParam] = useState({
+    terms: [
+      {
+        column: 'id',
+        termType: 'dim-assets',
+        value: {
+          assetType: 'device',
+          targets: [
+            {
+              type: 'org',
+              id: param.id,
+            },
+          ],
+        },
+      },
+    ],
+  });
   /**
    * 解除资产绑定
    */
@@ -102,6 +119,39 @@ export default observer(() => {
         defaultMessage: '状态',
       }),
       dataIndex: 'state',
+      filters: true,
+      onFilter: true,
+      valueType: 'select',
+      valueEnum: {
+        all: {
+          text: intl.formatMessage({
+            id: 'pages.searchTable.titleStatus.all',
+            defaultMessage: '全部',
+          }),
+          status: 'Default',
+        },
+        onLine: {
+          text: intl.formatMessage({
+            id: 'pages.device.instance.status.onLine',
+            defaultMessage: '在线',
+          }),
+          status: 'onLine',
+        },
+        offLine: {
+          text: intl.formatMessage({
+            id: 'pages.device.instance.status.offLine',
+            defaultMessage: '离线',
+          }),
+          status: 'offLine',
+        },
+        notActive: {
+          text: intl.formatMessage({
+            id: 'pages.device.instance.status.notActive',
+            defaultMessage: '未启用',
+          }),
+          status: 'notActive',
+        },
+      },
       render: (_, row) => <DeviceBadge type={row.state.value} text={row.state.text} />,
       search: false,
     },
@@ -151,28 +201,36 @@ export default observer(() => {
         onCancel={closeModal}
         reload={() => actionRef.current?.reload()}
       />
+      <SearchComponent<DeviceItem>
+        field={columns}
+        onSearch={async (data) => {
+          setSearchParam({
+            terms: [
+              ...data,
+              {
+                column: 'id',
+                termType: 'dim-assets',
+                value: {
+                  assetType: 'device',
+                  targets: [
+                    {
+                      type: 'org',
+                      id: param.id,
+                    },
+                  ],
+                },
+              },
+            ],
+          });
+        }}
+        target="department-assets-device"
+      />
       <ProTable<DeviceItem>
         actionRef={actionRef}
         columns={columns}
-        // schema={schema}
         rowKey="id"
-        params={{
-          terms: [
-            {
-              column: 'id',
-              termType: 'dim-assets',
-              value: {
-                assetType: 'device',
-                targets: [
-                  {
-                    type: 'org',
-                    id: param.id,
-                  },
-                ],
-              },
-            },
-          ],
-        }}
+        search={false}
+        params={searchParam}
         request={(params) => service.queryDeviceList(params)}
         rowSelection={{
           selectedRowKeys: Models.unBindKeys,

+ 45 - 19
src/pages/system/Department/Assets/product/index.tsx

@@ -3,7 +3,7 @@ import ProTable from '@jetlinks/pro-table';
 import type { ActionType, ProColumns } from '@jetlinks/pro-table';
 import { useIntl } from '@@/plugin-locale/localeExports';
 import { Button, message, Popconfirm, Tooltip } from 'antd';
-import { useRef } from 'react';
+import { useRef, useState } from 'react';
 import { useParams } from 'umi';
 import { observer } from '@formily/react';
 import type { ProductItem } from '@/pages/system/Department/typings';
@@ -11,6 +11,7 @@ import { DisconnectOutlined, PlusOutlined } from '@ant-design/icons';
 import Service from '@/pages/system/Department/Assets/service';
 import Models from './model';
 import Bind from './bind';
+import SearchComponent from '@/components/SearchComponent';
 
 export const service = new Service<ProductItem>();
 
@@ -19,6 +20,23 @@ export default observer(() => {
   const actionRef = useRef<ActionType>();
 
   const param = useParams<{ id: string }>();
+  const [searchParam, setSearchParam] = useState({
+    terms: [
+      {
+        column: 'id',
+        termType: 'dim-assets',
+        value: {
+          assetType: 'product',
+          targets: [
+            {
+              type: 'org',
+              id: param.id,
+            },
+          ],
+        },
+      },
+    ],
+  });
 
   /**
    * 解除资产绑定
@@ -119,28 +137,36 @@ export default observer(() => {
         onCancel={closeModal}
         reload={() => actionRef.current?.reload()}
       />
+      <SearchComponent<ProductItem>
+        field={columns}
+        onSearch={async (data) => {
+          setSearchParam({
+            terms: [
+              ...data,
+              {
+                column: 'id',
+                termType: 'dim-assets',
+                value: {
+                  assetType: 'product',
+                  targets: [
+                    {
+                      type: 'org',
+                      id: param.id,
+                    },
+                  ],
+                },
+              },
+            ],
+          });
+        }}
+        target="department-assets-product"
+      />
       <ProTable<ProductItem>
         actionRef={actionRef}
         columns={columns}
-        // schema={schema}
         rowKey="id"
-        params={{
-          terms: [
-            {
-              column: 'id',
-              termType: 'dim-assets',
-              value: {
-                assetType: 'product',
-                targets: [
-                  {
-                    type: 'org',
-                    id: param.id,
-                  },
-                ],
-              },
-            },
-          ],
-        }}
+        search={false}
+        params={searchParam}
         request={(params) => service.queryProductList(params)}
         rowSelection={{
           selectedRowKeys: Models.unBindKeys,

+ 45 - 19
src/pages/system/Department/Assets/productCategory/index.tsx

@@ -3,7 +3,7 @@ import ProTable from '@jetlinks/pro-table';
 import type { ActionType, ProColumns } from '@jetlinks/pro-table';
 import { useIntl } from '@@/plugin-locale/localeExports';
 import { Button, Popconfirm, Tooltip, message } from 'antd';
-import { useRef } from 'react';
+import { useRef, useState } from 'react';
 import { useParams } from 'umi';
 import { observer } from '@formily/react';
 import type { ProductCategoryItem } from '@/pages/system/Department/typings';
@@ -11,6 +11,7 @@ import { DisconnectOutlined, PlusOutlined } from '@ant-design/icons';
 import Models from '@/pages/system/Department/Assets/productCategory/model';
 import Service from '@/pages/system/Department/Assets/service';
 import Bind from './bind';
+import SearchComponent from '@/components/SearchComponent';
 
 export const service = new Service<ProductCategoryItem>('assets');
 
@@ -30,6 +31,23 @@ export default observer(() => {
   const intl = useIntl();
   const actionRef = useRef<ActionType>();
   const param = useParams<{ id: string }>();
+  const [searchParam, setSearchParam] = useState({
+    terms: [
+      {
+        column: 'id',
+        termType: 'dim-assets',
+        value: {
+          assetType: 'deviceCategory',
+          targets: [
+            {
+              type: 'org',
+              id: param.id,
+            },
+          ],
+        },
+      },
+    ],
+  });
 
   /**
    * 解除资产绑定
@@ -137,28 +155,36 @@ export default observer(() => {
         onCancel={closeModal}
         reload={() => actionRef.current?.reload()}
       />
+      <SearchComponent<ProductCategoryItem>
+        field={columns}
+        onSearch={async (data) => {
+          setSearchParam({
+            terms: [
+              ...data,
+              {
+                column: 'id',
+                termType: 'dim-assets',
+                value: {
+                  assetType: 'deviceCategory',
+                  targets: [
+                    {
+                      type: 'org',
+                      id: param.id,
+                    },
+                  ],
+                },
+              },
+            ],
+          });
+        }}
+        target="department-assets-category"
+      />
       <ProTable<ProductCategoryItem>
         actionRef={actionRef}
         columns={columns}
-        // schema={schema}
+        params={searchParam}
+        search={false}
         rowKey="id"
-        params={{
-          terms: [
-            {
-              column: 'id',
-              termType: 'dim-assets',
-              value: {
-                assetType: 'deviceCategory',
-                targets: [
-                  {
-                    type: 'org',
-                    id: param.id,
-                  },
-                ],
-              },
-            },
-          ],
-        }}
         request={async (params) => {
           const response = await service.queryProductCategoryList(params);
           return {

+ 65 - 11
src/pages/system/Department/Member/index.tsx

@@ -3,8 +3,8 @@ import { PageContainer } from '@ant-design/pro-layout';
 import ProTable from '@jetlinks/pro-table';
 import type { ActionType, ProColumns } from '@jetlinks/pro-table';
 import { useIntl } from '@@/plugin-locale/localeExports';
-import { Button, message, Popconfirm, Tooltip } from 'antd';
-import { useRef } from 'react';
+import { Badge, Button, Card, Divider, message, Popconfirm, Tooltip } from 'antd';
+import { useRef, useState } from 'react';
 import { useParams } from 'umi';
 import { observer } from '@formily/react';
 import MemberModel from '@/pages/system/Department/Member/model';
@@ -12,6 +12,7 @@ import type { MemberItem } from '@/pages/system/Department/typings';
 import Service from '@/pages/system/Department/Member/service';
 import { PlusOutlined, DisconnectOutlined } from '@ant-design/icons';
 import Bind from './bind';
+import SearchComponent from '@/components/SearchComponent';
 
 export const service = new Service('tenant');
 
@@ -20,6 +21,9 @@ const Member = observer(() => {
   const actionRef = useRef<ActionType>();
 
   const param = useParams<{ id: string }>();
+  const [searchParam, setSearchParam] = useState({
+    terms: [{ column: 'id$in-dimension$org', value: param.id }],
+  });
 
   const handleUnBind = () => {
     service.handleUser(param.id, MemberModel.unBindUsers, 'unbind').subscribe({
@@ -55,12 +59,52 @@ const Member = observer(() => {
     },
     {
       title: intl.formatMessage({
-        id: 'pages.system.tenant.memberManagement.administrators',
-        defaultMessage: '管理员',
+        id: 'pages.searchTable.titleStatus',
+        defaultMessage: '状态',
       }),
-      dataIndex: 'adminMember',
-      renderText: (text) => (text ? '是' : '否'),
-      search: false,
+      dataIndex: 'status',
+      filters: true,
+      onFilter: true,
+      valueType: 'select',
+      valueEnum: {
+        all: {
+          text: intl.formatMessage({
+            id: 'pages.searchTable.titleStatus.all',
+            defaultMessage: '全部',
+          }),
+          status: 'Default',
+        },
+        1: {
+          text: intl.formatMessage({
+            id: 'pages.searchTable.titleStatus.normal',
+            defaultMessage: '正常',
+          }),
+          status: 1,
+        },
+        0: {
+          text: intl.formatMessage({
+            id: 'pages.searchTable.titleStatus.disable',
+            defaultMessage: '禁用',
+          }),
+          status: 0,
+        },
+      },
+      render: (value) => (
+        <Badge
+          status={value === 1 ? 'success' : 'error'}
+          text={
+            value === 1
+              ? intl.formatMessage({
+                  id: 'pages.searchTable.titleStatus.normal',
+                  defaultMessage: '正常',
+                })
+              : intl.formatMessage({
+                  id: 'pages.searchTable.titleStatus.disable',
+                  defaultMessage: '禁用',
+                })
+          }
+        />
+      ),
     },
     {
       title: intl.formatMessage({
@@ -107,10 +151,22 @@ const Member = observer(() => {
         onCancel={closeModal}
         reload={() => actionRef.current?.reload()}
       />
+      <Card>
+        <SearchComponent<MemberItem>
+          field={columns}
+          onSearch={async (data) => {
+            setSearchParam({
+              terms: [...data, { column: 'id$in-dimension$org', value: param.id }],
+            });
+          }}
+          target="department-user"
+        />
+      </Card>
+      <Divider />
       <ProTable<MemberItem>
         actionRef={actionRef}
         columns={columns}
-        // schema={schema}
+        search={false}
         rowKey="id"
         request={(params) => service.queryUser(params)}
         rowSelection={{
@@ -119,9 +175,7 @@ const Member = observer(() => {
             MemberModel.unBindUsers = selectedRows.map((item) => item.id);
           },
         }}
-        defaultParams={{
-          'id$in-dimension$org': param.id,
-        }}
+        params={searchParam}
         toolBarRender={() => [
           <Button
             onClick={() => {

+ 2 - 2
src/pages/system/Department/Member/service.ts

@@ -8,8 +8,8 @@ import { filter, map } from 'rxjs/operators';
 class Service extends BaseService<MemberItem> {
   queryUser = (params: Record<string, unknown>) =>
     request(`/${SystemConst.API_BASE}/user/_query`, {
-      method: 'GET',
-      params,
+      method: 'POST',
+      data: params,
     });
 
   handleUser = (id: string, data: Record<string, unknown>[] | string[], type: 'bind' | 'unbind') =>

+ 22 - 7
src/pages/system/Department/index.tsx

@@ -2,9 +2,9 @@
 import { PageContainer } from '@ant-design/pro-layout';
 import ProTable from '@jetlinks/pro-table';
 import type { ActionType, ProColumns } from '@jetlinks/pro-table';
-import { useRef } from 'react';
+import { useRef, useState } from 'react';
 import { useIntl } from '@@/plugin-locale/localeExports';
-import { Button, message, Popconfirm, Tooltip } from 'antd';
+import { Button, message, Popconfirm, Tooltip, Card, Divider } from 'antd';
 import {
   EditOutlined,
   PlusOutlined,
@@ -20,6 +20,7 @@ import { observer } from '@formily/react';
 import { model } from '@formily/reactive';
 import { Link } from 'umi';
 import Save from './save';
+import SearchComponent from '@/components/SearchComponent';
 
 export const service = new Service('organization');
 
@@ -37,6 +38,9 @@ export const State = model<ModelType>({
 export default observer(() => {
   const actionRef = useRef<ActionType>();
   const intl = useIntl();
+  const [param, setParam] = useState({
+    terms: [{ column: 'typeId', value: 'org' }],
+  });
 
   /**
    * 根据部门ID删除数据
@@ -68,6 +72,7 @@ export default observer(() => {
         id: 'pages.device.instanceDetail.detail.sort',
         defaultMessage: '排序',
       }),
+      search: false,
       dataIndex: 'sortIndex',
     },
     {
@@ -106,7 +111,7 @@ export default observer(() => {
         >
           <Tooltip
             title={intl.formatMessage({
-              id: 'pages.data.option.edit',
+              id: 'pages.system.department.option.add',
               defaultMessage: '新增子部门',
             })}
           >
@@ -179,16 +184,25 @@ export default observer(() => {
 
   return (
     <PageContainer>
-      <ProTable<any>
+      <Card>
+        <SearchComponent<DepartmentItem>
+          field={columns}
+          onSearch={async (data) => {
+            setParam({ terms: [...data, { column: 'typeId', value: 'org' }] });
+          }}
+          target="department"
+        />
+      </Card>
+      <Divider />
+      <ProTable<DepartmentItem>
         columns={columns}
         actionRef={actionRef}
         request={async (params) => {
-          delete params.pageIndex;
           const response = await service.queryOrgThree({ paging: false, ...params });
           return {
             code: response.message,
             result: {
-              data: response.result as CategoryItem[],
+              data: response.result,
               pageIndex: 0,
               pageSize: 0,
               total: 0,
@@ -198,6 +212,8 @@ export default observer(() => {
         }}
         rowKey="id"
         pagination={false}
+        search={false}
+        params={param}
         toolBarRender={() => [
           <Button
             onClick={() => (State.visible = true)}
@@ -215,7 +231,6 @@ export default observer(() => {
           id: 'pages.system.department',
           defaultMessage: '部门列表',
         })}
-        defaultParams={{ typeId: 'org' }}
       />
       <Save<DepartmentItem>
         service={service}