mirror of
https://github.com/woodchen-ink/clash-and-dashboard.git
synced 2025-07-18 14:01:56 +08:00
Update: addrule & removerule
This commit is contained in:
parent
2be0eb448f
commit
0c3324e55a
@ -68,6 +68,27 @@ class Rules extends React.Component<I18nProps, RulesState> {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private addRule = () => {
|
||||||
|
const { rules } = this.state
|
||||||
|
const newRule = { type: RuleType['DOMAIN-SUFFIX'], payload: 'google.com.hk', proxy: 'DIRECT' }
|
||||||
|
const newRules = produce(rules, draftState => {
|
||||||
|
draftState.unshift(newRule)
|
||||||
|
})
|
||||||
|
|
||||||
|
this.setState({
|
||||||
|
rules: newRules,
|
||||||
|
modifiedIndex: 0
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
private removeRule = (index) => {
|
||||||
|
const { rules } = this.state
|
||||||
|
|
||||||
|
this.setState({
|
||||||
|
rules: rules.filter((r, idx) => idx !== index)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
onSortEnd = ({ oldIndex, newIndex }) => {
|
onSortEnd = ({ oldIndex, newIndex }) => {
|
||||||
this.setState({
|
this.setState({
|
||||||
rules: arrayMove(this.state.rules, oldIndex, newIndex)
|
rules: arrayMove(this.state.rules, oldIndex, newIndex)
|
||||||
@ -156,7 +177,7 @@ class Rules extends React.Component<I18nProps, RulesState> {
|
|||||||
</Select>
|
</Select>
|
||||||
</Col>
|
</Col>
|
||||||
<Col className="delete-btn" span={2} offset={3}>
|
<Col className="delete-btn" span={2} offset={3}>
|
||||||
{!isFinal && <span>删除</span>}
|
{!isFinal && <span onClick={() => this.removeRule(index)}>删除</span>}
|
||||||
</Col>
|
</Col>
|
||||||
</Row>
|
</Row>
|
||||||
</li>
|
</li>
|
||||||
@ -171,7 +192,7 @@ class Rules extends React.Component<I18nProps, RulesState> {
|
|||||||
return (
|
return (
|
||||||
<div className="page">
|
<div className="page">
|
||||||
<Header title={t('title')} >
|
<Header title={t('title')} >
|
||||||
<Icon type="plus" size={20} style={{ fontWeight: 'bold', cursor: 'pointer' }} />
|
<Icon type="plus" size={20} style={{ fontWeight: 'bold', cursor: 'pointer' }} onClick={this.addRule}/>
|
||||||
</Header>
|
</Header>
|
||||||
|
|
||||||
<Card className="rules-card">
|
<Card className="rules-card">
|
||||||
|
Loading…
x
Reference in New Issue
Block a user