@@ -2,12 +2,13 @@ import { PlusOutlined } from '@ant-design/icons';
22import { FormInstance , ModalForm , ProFormDependency , ProFormSelect , ProFormText } from '@ant-design/pro-form' ;
33import { PageContainer } from '@ant-design/pro-layout' ;
44import ProTable , { ActionType , ProColumns } from '@ant-design/pro-table' ;
5- import { Button , message } from 'antd' ;
5+ import { Button , message , Modal } from 'antd' ;
66import React , { useRef , useState } from 'react' ;
77import { getIntl , getLocale } from 'umi' ;
88import { ServiceItem } from './data' ;
9- import { addService , queryService } from './service' ;
9+ import { addService , queryService , removeService } from './service' ;
1010import styles from './index.less' ;
11+ const { confirm } = Modal ;
1112
1213const handleAdd = async ( fields : ServiceItem ) => {
1314 const intl = getIntl ( getLocale ( ) ) ;
@@ -34,6 +35,25 @@ const handleAdd = async (fields: ServiceItem) => {
3435 return false ;
3536 }
3637} ;
38+ const handleDelSome = async ( service : ServiceItem ) :Promise < boolean > => {
39+ const intl = getIntl ( getLocale ( ) ) ;
40+ const hide = message . loading ( intl . formatMessage ( { id :'deleting' } ) ) ;
41+ try {
42+ const result = await removeService ( service ) ;
43+ hide ( ) ;
44+ const success = result . success ;
45+ if ( success ) {
46+ message . success ( intl . formatMessage ( { id :'delete_success' } ) ) ;
47+ } else {
48+ message . error ( intl . formatMessage ( { id :'delete_fail' } ) ) ;
49+ }
50+ return success ;
51+ } catch ( error ) {
52+ hide ( ) ;
53+ message . error ( intl . formatMessage ( { id :'delete_fail' } ) ) ;
54+ return false ;
55+ }
56+ } ;
3757
3858const services : React . FC = ( ) => {
3959 const actionRef = useRef < ActionType > ( ) ;
@@ -114,7 +134,21 @@ const services: React.FC = () => {
114134 title : '操作' ,
115135 valueType : 'option' ,
116136 render : ( text , record , _ , action ) => [
117- < a className = { styles . linkDanger } >
137+ < a className = { styles . linkDanger }
138+ onClick = {
139+ ( ) => {
140+ confirm ( {
141+ content :`确定删除选中的服务吗?` ,
142+ onOk : async ( ) => {
143+ const result = await handleDelSome ( record )
144+ if ( result ) {
145+ actionRef . current ?. reload ( ) ;
146+ }
147+ }
148+ } )
149+ }
150+ }
151+ >
118152 删除
119153 </ a >
120154 ]
0 commit comments