-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(a-button):
DeleteLink
改为函数组件
- Loading branch information
Showing
1 changed file
with
30 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,52 +1,38 @@ | ||
import { Component } from 'react'; | ||
import $ from 'miaoxing'; | ||
import PropTypes from 'prop-types'; | ||
import {Typography} from 'antd'; | ||
|
||
class DeleteLink extends Component { | ||
static propTypes = { | ||
message: PropTypes.string, | ||
href: PropTypes.string, | ||
onDelete: PropTypes.func, | ||
} | ||
|
||
static defaultProps = { | ||
message: '删除后将无法还原,确定删除?', | ||
} | ||
|
||
constructor(props) { | ||
super(props); | ||
|
||
this.handleDelete = this.handleDelete.bind(this); | ||
} | ||
|
||
handleDelete(e) { | ||
e.preventDefault(); | ||
|
||
$.confirm(this.props.message, (result) => { | ||
if (!result) { | ||
return; | ||
const handleDelete = (message, href, onDelete, e) => { | ||
e.preventDefault(); | ||
|
||
$.confirm(message, (result) => { | ||
if (!result) { | ||
return; | ||
} | ||
|
||
$.delete({ | ||
url: href, | ||
loading: true, | ||
dataType: 'json', | ||
}).then(({ret}) => { | ||
$.ret(ret); | ||
if (ret.isSuc()) { | ||
onDelete && onDelete(); | ||
} | ||
|
||
$.delete({ | ||
url: this.props.href, | ||
loading: true, | ||
dataType: 'json', | ||
}).then(({ret}) => { | ||
$.ret(ret); | ||
if (ret.isSuc()) { | ||
this.props.onDelete && this.props.onDelete(); | ||
} | ||
}); | ||
}); | ||
} | ||
|
||
render() { | ||
const {message, href, onDelete, ...rest} = this.props; | ||
return <Typography.Link type="danger" href="#" onClick={this.handleDelete} {...rest}> | ||
删除 | ||
</Typography.Link>; | ||
} | ||
} | ||
}); | ||
}; | ||
|
||
const DeleteLink = ({message = '删除后将无法还原,确定删除?', href, onDelete, ...rest}) => { | ||
return <Typography.Link type="danger" href="#" onClick={handleDelete.bind(this, message, href, onDelete)} {...rest}> | ||
删除 | ||
</Typography.Link>; | ||
}; | ||
|
||
DeleteLink.propTypes = { | ||
message: PropTypes.string, | ||
href: PropTypes.string, | ||
onDelete: PropTypes.func, | ||
}; | ||
|
||
export default DeleteLink; |