Bladeren bron

chore: 抽取公共条件字段

xyh 2 jaren geleden
bovenliggende
commit
b5f5782373

+ 0 - 17
packages/app/src/pages/container/filter/hooks.ts

@@ -1,24 +1,7 @@
 import {exportContainer} from '@apis';
 import {useContextSection, useExportFile, usePage} from '@hooks';
-import {useState} from 'react';
 import {context, pageContext} from '../context';
 
-export function useField() {
-  const [field, setField] = useState({
-    department: '',
-    type: '',
-    name: '',
-  });
-
-  function onChange(key: keyof typeof field) {
-    return function(value: string) {
-      setField(prev => ({...prev, [key]: value}));
-    };
-  }
-
-  return [field, onChange] as const;
-}
-
 export function useSearch(
   {name, type, department}: {name: string, type: string, department: string},
 ) {

+ 7 - 3
packages/app/src/pages/container/filter/index.tsx

@@ -1,12 +1,16 @@
 import {FilterButtonGroup, FilterField, FilterSelect} from '@components';
 import {Card, Row} from 'antd';
 import {FC} from 'react';
-import {useExport, useField, useSearch} from './hooks';
-import {useDepartmentOptions, useTableSearch} from '@hooks';
+import {useExport, useSearch} from './hooks';
+import {useDepartmentOptions, useFilterField, useTableSearch} from '@hooks';
 import {searchContext} from '../context';
 
 const Filter: FC = function() {
-  const [{name, department, type}, onChange] = useField();
+  const [{name, department, type}, onChange] = useFilterField({
+    department: '',
+    type: '',
+    name: '',
+  });
   const options = useDepartmentOptions(true);
   const onSearch = useSearch({name, department, type});
   const [isSearching] = useTableSearch(searchContext);

+ 0 - 13
packages/app/src/pages/department/filter/hooks.ts

@@ -1,20 +1,7 @@
-import {useState} from 'react';
 import {context, pageContext} from '../context';
 import {exportDepartment} from '@apis';
 import {useContextSection, useExportFile, usePage} from '@hooks';
 
-export function useField() {
-  const [state, setState] = useState({name: '', code: ''});
-
-  function onChange(key: 'name' | 'code') {
-    return function(val: string) {
-      setState(prev => ({...prev, [key]: val}));
-    };
-  }
-
-  return [state, onChange] as const;
-}
-
 export function useSearch(name: string, code: string) {
   const dispatch = useContextSection(context, state => state[1]);
 

+ 3 - 3
packages/app/src/pages/department/filter/index.tsx

@@ -1,12 +1,12 @@
 import {FilterButtonGroup, FilterField} from '@components';
 import {Card, Row} from 'antd';
 import {FC} from 'react';
-import {useExport, useField, useSearch} from './hooks';
-import {useTableSearch} from '@hooks';
+import {useExport, useSearch} from './hooks';
+import {useFilterField, useTableSearch} from '@hooks';
 import {searchContext} from '../context';
 
 const Filter: FC = function() {
-  const [{name, code}, onChange] = useField();
+  const [{name, code}, onChange] = useFilterField({name: '', code: ''});
   const onSearch = useSearch(name, code);
   const [isExporting, onExport] = useExport();
   const [isSearching] = useTableSearch(searchContext);

+ 0 - 16
packages/app/src/pages/menu-id/filter/hooks.ts

@@ -1,22 +1,6 @@
-import {useEffect, useState} from 'react';
 import {context} from '../context';
 import {useContextSection} from '@hooks';
 
-export function useField() {
-  const name = useContextSection(context, state => state[0].name);
-  const [state, setState] = useState(name);
-
-  useEffect(function() {
-    setState(name);
-  }, [name]);
-
-  function onChange(val: string) {
-    setState(val);
-  }
-
-  return [state, onChange] as const;
-}
-
 export function useHandle(value: string) {
   const dispatch = useContextSection(context, state => state[1]);
 

+ 3 - 3
packages/app/src/pages/menu-id/filter/index.tsx

@@ -1,12 +1,12 @@
 import {FilterButtonGroup, FilterField} from '@components';
 import {Card, Row} from 'antd';
-import {FC} from 'react';
-import {useField, useHandle} from './hooks';
+import {FC, useState} from 'react';
+import {useHandle} from './hooks';
 import {useTableSearch} from '@hooks';
 import {searchContext} from '../context';
 
 const Filter: FC = function() {
-  const [value, onChange] = useField();
+  const [value, onChange] = useState('');
   const {onSearch} = useHandle(value);
   const [isSearching] = useTableSearch(searchContext);
 

+ 0 - 16
packages/app/src/pages/menu/filter/hooks.ts

@@ -1,22 +1,6 @@
-import {useEffect, useState} from 'react';
 import {context} from '../context';
 import {useContextSection} from '@hooks';
 
-export function useField() {
-  const name = useContextSection(context, state => state[0].name);
-  const [state, setState] = useState(name);
-
-  useEffect(function() {
-    setState(name);
-  }, [name]);
-
-  function onChange(val: string) {
-    setState(val);
-  }
-
-  return [state, onChange] as const;
-}
-
 export function useHandle(value: string) {
   const dispatch = useContextSection(context, state => state[1]);
 

+ 3 - 3
packages/app/src/pages/menu/filter/index.tsx

@@ -1,12 +1,12 @@
 import {FilterButtonGroup, FilterField} from '@components';
 import {Card, Row} from 'antd';
-import {FC} from 'react';
-import {useField, useHandle} from './hooks';
+import {FC, useState} from 'react';
+import {useHandle} from './hooks';
 import {useTableSearch} from '@hooks';
 import {searchContext} from '../context';
 
 const Filter: FC = function() {
-  const [value, onChange] = useField();
+  const [value, onChange] = useState('');
   const {onSearch} = useHandle(value);
   const [isSearching] = useTableSearch(searchContext);
 

+ 0 - 16
packages/app/src/pages/pda-menu/filter/hooks.ts

@@ -1,22 +1,6 @@
-import {useEffect, useState} from 'react';
 import {context} from '../context';
 import {useContextSection} from '@hooks';
 
-export function useField() {
-  const name = useContextSection(context, state => state[0].name);
-  const [state, setState] = useState(name);
-
-  useEffect(function() {
-    setState(name);
-  }, [name]);
-
-  function onChange(val: string) {
-    setState(val);
-  }
-
-  return [state, onChange] as const;
-}
-
 export function useHandle(value: string) {
   const dispatch = useContextSection(context, state => state[1]);
 

+ 3 - 3
packages/app/src/pages/pda-menu/filter/index.tsx

@@ -1,12 +1,12 @@
 import {FilterButtonGroup, FilterField} from '@components';
 import {Card, Row} from 'antd';
-import {FC} from 'react';
-import {useField, useHandle} from './hooks';
+import {FC, useState} from 'react';
+import {useHandle} from './hooks';
 import {useTableSearch} from '@hooks';
 import {searchContext} from '../context';
 
 const Filter: FC = function() {
-  const [value, onChange] = useField();
+  const [value, onChange] = useState('');
   const {onSearch} = useHandle(value);
   const [isSearching] = useTableSearch(searchContext);
 

+ 0 - 11
packages/app/src/pages/role/filter/hooks.ts

@@ -1,18 +1,7 @@
-import {useState} from 'react';
 import {useContext, useContextSection, useExportFile, usePage} from '@hooks';
 import {context, pageContext} from '../context';
 import {exportRole} from '@apis';
 
-export function useField() {
-  const [state, setState] = useState('');
-
-  function onChange(val: string) {
-    setState(val);
-  }
-
-  return [state, onChange] as const;
-}
-
 export function useSearch(value: string) {
   const [, dispatch] = useContext(context);
 

+ 3 - 3
packages/app/src/pages/role/filter/index.tsx

@@ -1,12 +1,12 @@
 import {FilterButtonGroup, FilterField} from '@components';
 import {Card, Row} from 'antd';
-import {FC} from 'react';
-import {useExport, useField, useSearch} from './hooks';
+import {FC, useState} from 'react';
+import {useExport, useSearch} from './hooks';
 import {useTableSearch} from '@hooks';
 import {searchContext} from '../context';
 
 const Filter: FC = function() {
-  const [value, onChange] = useField();
+  const [value, onChange] = useState('');
   const onSearch = useSearch(value);
   const [isExporting, onExport] = useExport();
   const [isSearching] = useTableSearch(searchContext);

+ 0 - 18
packages/app/src/pages/storage/filter/hooks.ts

@@ -1,26 +1,8 @@
-import {useState} from 'react';
 import {useContextSelector} from 'use-context-selector';
 import {context, pageContext} from '../context';
 import {useExportFile, usePage} from '@hooks';
 import {exportStorage} from '@apis';
 
-export function useField() {
-  const [fields, setFields] = useState({
-    name: '',
-    code: '',
-    type: '',
-    isNotDisable: '',
-  });
-
-  function onChange(key: keyof typeof fields) {
-    return function(value: string) {
-      setFields(prev => ({...prev, [key]: value}));
-    };
-  }
-
-  return [fields, onChange] as const;
-}
-
 export function useSearch(state: {
   name: string,
   code: string,

+ 8 - 3
packages/app/src/pages/storage/filter/index.tsx

@@ -1,8 +1,8 @@
 import {FilterField, FilterButtonGroup, FilterSelect} from '@components';
 import {Card, Row, Space} from 'antd';
 import {FC} from 'react';
-import {useExport, useField, useSearch} from './hooks';
-import {useDictionaryOptions, useTableSearch} from '@hooks';
+import {useExport, useSearch} from './hooks';
+import {useDictionaryOptions, useFilterField, useTableSearch} from '@hooks';
 import {searchContext} from '../context';
 
 const disableOptions = [
@@ -12,7 +12,12 @@ const disableOptions = [
 ];
 
 const Filter: FC = function() {
-  const [fields, onChange] = useField();
+  const [fields, onChange] = useFilterField({
+    name: '',
+    code: '',
+    type: '',
+    isNotDisable: '',
+  });
   const {code, name, type, isNotDisable} = fields;
   const onSearch = useSearch(fields);
   const [isExporting, onExport] = useExport();

+ 0 - 13
packages/app/src/pages/user/filter/hooks.ts

@@ -1,20 +1,7 @@
 import {useContextSection, useExportFile, usePage} from '@hooks';
-import {useState} from 'react';
 import {context, pageContext} from '../context';
 import {exportUser} from '@apis';
 
-export function useField() {
-  const [state, setState] = useState({name: '', code: ''});
-
-  function onChange(key: 'name' | 'code') {
-    return function(value: string) {
-      setState(prev => ({...prev, [key]: value}));
-    };
-  }
-
-  return [state, onChange] as const;
-}
-
 export function useSearch(name: string, code: string) {
   const dispatch = useContextSection(context, ([,dispatch]) => dispatch);
 

+ 3 - 3
packages/app/src/pages/user/filter/index.tsx

@@ -1,12 +1,12 @@
 import {FilterButtonGroup, FilterField} from '@components';
 import {Card, Row} from 'antd';
 import {FC} from 'react';
-import {useSearch, useField, useExport} from './hooks';
-import {useTableSearch} from '@hooks';
+import {useSearch, useExport} from './hooks';
+import {useFilterField, useTableSearch} from '@hooks';
 import {searchContext} from '../context';
 
 const Filter: FC = function() {
-  const [{name, code}, onChange] = useField();
+  const [{name, code}, onChange] = useFilterField({name: '', code: ''});
   const onSearch = useSearch(name, code);
   const [isExporting, onExport] = useExport();
   const [isSearching] = useTableSearch(searchContext);