|
@@ -1,9 +1,7 @@
|
|
|
import {useState} from 'react';
|
|
|
import {context, pageContext} from '../context';
|
|
|
import {exportDepartment} from '@apis';
|
|
|
-import {useContextSection, usePage} from '@hooks';
|
|
|
-import {EXPORT_ERROR_TIPS, exportFile} from '@utils';
|
|
|
-import {message} from 'antd';
|
|
|
+import {useContextSection, useExportFile, usePage} from '@hooks';
|
|
|
|
|
|
export function useField() {
|
|
|
const [state, setState] = useState({name: '', code: ''});
|
|
@@ -17,29 +15,31 @@ export function useField() {
|
|
|
return [state, onChange] as const;
|
|
|
}
|
|
|
|
|
|
-export function useHandle(name: string, code: string) {
|
|
|
+export function useSearch(name: string, code: string) {
|
|
|
const dispatch = useContextSection(context, state => state[1]);
|
|
|
- const [{page, pageSize}, {onCurrentPageChange}] = usePage(pageContext);
|
|
|
+ const [, {onCurrentPageChange}] = usePage(pageContext);
|
|
|
|
|
|
function onSearch() {
|
|
|
onCurrentPageChange(1);
|
|
|
dispatch({type: 'SEARCH', payload: {name, code}});
|
|
|
}
|
|
|
|
|
|
+ return onSearch;
|
|
|
+}
|
|
|
+
|
|
|
+export function useExport() {
|
|
|
+ const [{page, pageSize}] = usePage(pageContext);
|
|
|
+ const [isExporting, mutate] = useExportFile(exportDepartment);
|
|
|
+ const {code, name} = useContextSection(context, state => state[0]);
|
|
|
+
|
|
|
function onExport() {
|
|
|
- exportDepartment({
|
|
|
+ mutate({
|
|
|
page: page.toString(),
|
|
|
limit: pageSize.toString(),
|
|
|
code,
|
|
|
departmentName: name,
|
|
|
- })
|
|
|
- .then(function(res: Blob) {
|
|
|
- exportFile(res);
|
|
|
- })
|
|
|
- .catch(function() {
|
|
|
- message.error(EXPORT_ERROR_TIPS);
|
|
|
- });
|
|
|
+ });
|
|
|
}
|
|
|
|
|
|
- return {onSearch, onExport};
|
|
|
+ return [isExporting, onExport] as const;
|
|
|
}
|