瀏覽代碼

feat(department): add search defaultParams

Lind 4 年之前
父節點
當前提交
9a55899218

+ 2 - 2
src/components/SearchComponent/typings.d.ts

@@ -1,7 +1,7 @@
 type Term = {
   column: string | null;
-  value: string;
-  termType: string;
+  value: string | object;
+  termType?: string;
   type?: 'or' | 'and';
 };
 

+ 18 - 35
src/pages/system/Department/Assets/deivce/index.tsx

@@ -33,23 +33,7 @@ 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,
-            },
-          ],
-        },
-      },
-    ],
-  });
+  const [searchParam, setSearchParam] = useState({});
   /**
    * 解除资产绑定
    */
@@ -203,25 +187,24 @@ export default observer(() => {
       />
       <SearchComponent<DeviceItem>
         field={columns}
-        onSearch={async (data) => {
-          setSearchParam({
-            terms: [
-              ...data,
-              {
-                column: 'id',
-                termType: 'dim-assets',
-                value: {
-                  assetType: 'device',
-                  targets: [
-                    {
-                      type: 'org',
-                      id: param.id,
-                    },
-                  ],
+        defaultParam={[
+          {
+            column: 'id',
+            termType: 'dim-assets',
+            value: {
+              assetType: 'device',
+              targets: [
+                {
+                  type: 'org',
+                  id: param.id,
                 },
-              },
-            ],
-          });
+              ],
+            },
+          },
+        ]}
+        onSearch={async (data) => {
+          actionRef.current?.reset?.();
+          setSearchParam(data);
         }}
         target="department-assets-device"
       />

+ 18 - 35
src/pages/system/Department/Assets/product/index.tsx

@@ -20,23 +20,7 @@ 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,
-            },
-          ],
-        },
-      },
-    ],
-  });
+  const [searchParam, setSearchParam] = useState({});
 
   /**
    * 解除资产绑定
@@ -139,25 +123,24 @@ export default observer(() => {
       />
       <SearchComponent<ProductItem>
         field={columns}
-        onSearch={async (data) => {
-          setSearchParam({
-            terms: [
-              ...data,
-              {
-                column: 'id',
-                termType: 'dim-assets',
-                value: {
-                  assetType: 'product',
-                  targets: [
-                    {
-                      type: 'org',
-                      id: param.id,
-                    },
-                  ],
+        defaultParam={[
+          {
+            column: 'id',
+            termType: 'dim-assets',
+            value: {
+              assetType: 'product',
+              targets: [
+                {
+                  type: 'org',
+                  id: param.id,
                 },
-              },
-            ],
-          });
+              ],
+            },
+          },
+        ]}
+        onSearch={async (data) => {
+          actionRef.current?.reset?.();
+          setSearchParam(data);
         }}
         target="department-assets-product"
       />

+ 18 - 35
src/pages/system/Department/Assets/productCategory/index.tsx

@@ -31,23 +31,7 @@ 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,
-            },
-          ],
-        },
-      },
-    ],
-  });
+  const [searchParam, setSearchParam] = useState({});
 
   /**
    * 解除资产绑定
@@ -157,25 +141,24 @@ export default observer(() => {
       />
       <SearchComponent<ProductCategoryItem>
         field={columns}
-        onSearch={async (data) => {
-          setSearchParam({
-            terms: [
-              ...data,
-              {
-                column: 'id',
-                termType: 'dim-assets',
-                value: {
-                  assetType: 'deviceCategory',
-                  targets: [
-                    {
-                      type: 'org',
-                      id: param.id,
-                    },
-                  ],
+        defaultParam={[
+          {
+            column: 'id',
+            termType: 'dim-assets',
+            value: {
+              assetType: 'deviceCategory',
+              targets: [
+                {
+                  type: 'org',
+                  id: param.id,
                 },
-              },
-            ],
-          });
+              ],
+            },
+          },
+        ]}
+        onSearch={async (data) => {
+          actionRef.current?.reset?.();
+          setSearchParam(data);
         }}
         target="department-assets-category"
       />

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

@@ -82,10 +82,12 @@ const Bind = observer((props: Props) => {
           pageSize: 5,
         }}
         params={{
-          terms: [{
-            column: 'id$in-dimension$org$not',
-            value: param.id
-          }]
+          terms: [
+            {
+              column: 'id$in-dimension$org$not',
+              value: param.id,
+            },
+          ],
         }}
         rowSelection={{
           selectedRowKeys: MemberModel.bindUsers,

+ 4 - 6
src/pages/system/Department/Member/index.tsx

@@ -21,9 +21,7 @@ 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 [searchParam, setSearchParam] = useState({});
 
   const handleUnBind = () => {
     service.handleUser(param.id, MemberModel.unBindUsers, 'unbind').subscribe({
@@ -159,10 +157,10 @@ const Member = observer(() => {
       <Card>
         <SearchComponent<MemberItem>
           field={columns}
+          defaultParam={[{ column: 'id$in-dimension$org', value: param.id, termType: 'eq' }]}
           onSearch={async (data) => {
-            setSearchParam({
-              terms: [...data, { column: 'id$in-dimension$org', value: param.id }],
-            });
+            actionRef.current?.reset?.();
+            setSearchParam(data);
           }}
           target="department-user"
         />

+ 2 - 2
src/pages/system/Department/index.tsx

@@ -169,7 +169,7 @@ export default observer(() => {
         type: 'string',
         title: intl.formatMessage({
           id: 'pages.table.name',
-          defaultMessage: '名称'
+          defaultMessage: '名称',
         }),
         required: true,
         'x-decorator': 'FormItem',
@@ -189,7 +189,7 @@ export default observer(() => {
         type: 'string',
         title: intl.formatMessage({
           id: 'pages.device.instanceDetail.detail.sort',
-          defaultMessage: '排序'
+          defaultMessage: '排序',
         }),
         'x-decorator': 'FormItem',
         'x-component': 'NumberPicker',