@@ -5,11 +5,12 @@ import type { DSelectItem } from '@react-devui/ui/components/select';
55import { isUndefined } from 'lodash' ;
66import React , { useImperativeHandle , useState } from 'react' ;
77
8- import { useAsync , useEventCallback } from '@react-devui/hooks' ;
8+ import { useEventCallback } from '@react-devui/hooks' ;
99import { FormControl , FormGroup , useForm , Validators } from '@react-devui/ui' ;
1010import { DForm , DInput , DModal , DSelect } from '@react-devui/ui' ;
1111
1212import { AppResponsiveForm } from '../../../components' ;
13+ import { useHttp } from '../../../core' ;
1314import { useAPI } from '../../../hooks' ;
1415
1516export interface AppDeviceModalProps {
@@ -19,8 +20,10 @@ export interface AppDeviceModalProps {
1920function DeviceModal ( props : AppDeviceModalProps , ref : React . ForwardedRef < OpenSettingFn < DeviceData > > ) : JSX . Element | null {
2021 const { onSuccess } = props ;
2122
22- const modelApi = useAPI ( '/device/model' ) ;
23- const async = useAsync ( ) ;
23+ const http = useHttp ( ) ;
24+ const httpOfInit = useHttp ( ) ;
25+ const modelApi = useAPI ( http , '/device/model' ) ;
26+ const modelApiOfInit = useAPI ( httpOfInit , '/device/model' ) ;
2427
2528 const [ visible , setVisible ] = useState ( false ) ;
2629 const [ device , setDevice ] = useState < DeviceData > ( ) ;
@@ -42,7 +45,7 @@ function DeviceModal(props: AppDeviceModalProps, ref: React.ForwardedRef<OpenSet
4245 updateForm ( ) ;
4346
4447 setModelList ( undefined ) ;
45- modelApi . list ( ) . subscribe ( {
48+ modelApiOfInit . list ( ) . subscribe ( {
4649 next : ( res ) => {
4750 setModelList (
4851 res . resources . map ( ( model ) => ( {
@@ -70,16 +73,19 @@ function DeviceModal(props: AppDeviceModalProps, ref: React.ForwardedRef<OpenSet
7073 dOkProps = { { disabled : ! form . valid } }
7174 onOkClick = { ( ) =>
7275 new Promise ( ( r ) => {
73- async . setTimeout ( ( ) => {
74- onSuccess ( ) ;
75- r ( true ) ;
76- } , 500 ) ;
76+ modelApi . list ( ) . subscribe ( {
77+ next : ( ) => {
78+ onSuccess ( ) ;
79+ r ( true ) ;
80+ } ,
81+ } ) ;
7782 } )
7883 }
7984 > </ DModal . Footer >
8085 }
8186 dMaskClosable = { false }
8287 onClose = { ( ) => {
88+ httpOfInit . abortAll ( ) ;
8389 setVisible ( false ) ;
8490 } }
8591 >
0 commit comments