From f1ae3d5b2a9c3aac1825ea8416ef1039f3ac2fa9 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E8=87=AA=E5=B8=A6=E5=A4=A7=E4=BD=AC=E6=B0=94=E5=9C=BA?=
<188633308@qq.com>
Date: Mon, 28 Jun 2021 13:47:59 +0800
Subject: [PATCH] =?UTF-8?q?fix=20=E8=8F=9C=E5=8D=95=E6=8E=88=E6=9D=83?=
=?UTF-8?q?=E9=80=89=E6=8B=A9=E9=97=AE=E9=A2=98?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../src/components/authority-view/index.jsx | 99 ++++++++++---------
1 file changed, 53 insertions(+), 46 deletions(-)
diff --git a/web-react/src/components/authority-view/index.jsx b/web-react/src/components/authority-view/index.jsx
index adabbe9..e6c220f 100644
--- a/web-react/src/components/authority-view/index.jsx
+++ b/web-react/src/components/authority-view/index.jsx
@@ -17,11 +17,11 @@ function getVisible() {
const caseChildren = checked.filter(item => item.visibleParent || item.type != 2)
const visibleParents = []
// 递归寻找父级
- const findVisibleParents = (children) => {
+ const findVisibleParents = children => {
const parents = []
children.forEach(item => {
if (item.parentId) {
- const parent = this.list.find(item => item.id === item.parentId)
+ const parent = this.list.find(p => p.id === item.parentId)
if (parent) {
parents.push(parent)
visibleParents.push(parent)
@@ -50,7 +50,9 @@ function getVisible() {
function renderDescriptions(data) {
return data.map(item => {
- return item.children && item.children.length ? renderItem.call(this, item) : renderCheckbox.call(this, item)
+ return item.children && item.children.length
+ ? renderItem.call(this, item)
+ : renderCheckbox.call(this, item)
})
}
@@ -63,8 +65,10 @@ function renderItem(data) {
value={data.id}
checked={data.checked}
indeterminate={data.indeterminate}
- onChange={(e) => this.onChange(e, data)}
- >{data.title}
+ onChange={e => this.onChange(e, data)}
+ >
+ {data.title}
+
}
>
{renderDescriptions.call(this, data.children)}
@@ -76,26 +80,22 @@ function renderItem(data) {
function renderCheckbox(data) {
return (
-
this.onChange(e, data)}
- >{data.title}
- {
- data.visibleParent && data.type == 2 &&
+
this.onChange(e, data)}>
+ {data.title}
+
+ {data.visibleParent && data.type == 2 && (
- }
+ )}
)
}
export default class AuthorityView extends Component {
-
state = {
loading: false,
- dataSource: []
+ dataSource: [],
}
list = []
@@ -104,7 +104,8 @@ export default class AuthorityView extends Component {
super(props)
this.autoLoad = typeof this.props.autoLoad === 'boolean' ? this.props.autoLoad : true
- this.loadData = typeof this.props.loadData === 'function' ? this.props.loadData : async () => { }
+ this.loadData =
+ typeof this.props.loadData === 'function' ? this.props.loadData : async () => {}
}
/**
@@ -126,7 +127,10 @@ export default class AuthorityView extends Component {
if (this.props.defaultSelectedKeys) {
this.list.map(item => {
- if (this.props.defaultSelectedKeys.includes(item.id) && (!item.children || !item.children.length)) {
+ if (
+ this.props.defaultSelectedKeys.includes(item.id) &&
+ (!item.children || !item.children.length)
+ ) {
this.onSelect(true, item)
}
})
@@ -134,8 +138,10 @@ export default class AuthorityView extends Component {
this.setState({
dataSource: res,
- loading: false
+ loading: false,
})
+
+ this.onChange()
}
onReloadData = () => {
@@ -143,16 +149,18 @@ export default class AuthorityView extends Component {
}
onChange = (e, item) => {
- this.onSelect(e.target.checked, item)
+ if (e && item) {
+ this.onSelect(e.target.checked, item)
+ }
const visible = getVisible.call(this)
if (this.props.onSelect) {
this.props.onSelect(
// 返回所有选中
- this.list.filter(item => item.checked).map(item => item.id),
+ this.list.filter(p => p.checked).map(p => p.id),
// 返回所有选中和半选
- this.list.filter(item => item.checked || item.indeterminate).map(item => item.id),
+ this.list.filter(p => p.checked || p.indeterminate).map(p => p.id),
// 返回所有选中和半选,但是不返回没有子级选中visibleParent的半选
visible
)
@@ -170,7 +178,7 @@ export default class AuthorityView extends Component {
}
this.setState({
- dataSource: this.list.filter(item => item.parentId === EMPTY_ID)
+ dataSource: this.list.filter(p => p.parentId === EMPTY_ID),
})
}
@@ -210,31 +218,30 @@ export default class AuthorityView extends Component {
return (
}>
- {
- !this.state.loading ?
-
- {
- this.state.dataSource.map(item => {
- return (
- this.onChange(e, item)}
- >{item.title}
- }
+ {!this.state.loading ? (
+
+ {this.state.dataSource.map(item => {
+ return (
+ this.onChange(e, item)}
>
- {renderDescriptions.call(this, item.children)}
-
- )
- })
- }
-
- :
-
- }
+ {item.title}
+
+ }
+ >
+ {renderDescriptions.call(this, item.children)}
+
+ )
+ })}
+
+ ) : (
+
+ )}
)