feature/2.15.1.2407.01-权限
This commit is contained in:
parent
b0d790f988
commit
b91f35418e
|
|
@ -140,6 +140,10 @@ export const syncAuthData = (params) => {
|
|||
export const syncAuthMember = (params) => {
|
||||
return postFetch("/api/bs/hrmsalary/auth/member/sync", params);
|
||||
};
|
||||
//保存权限
|
||||
export const saveAuthOpt = (params) => {
|
||||
return postFetch("/api/bs/hrmsalary/auth/opt/save", params);
|
||||
};
|
||||
//权限项
|
||||
export const getAuthOptTree = (params) => {
|
||||
return WeaTools.callApi("/api/bs/hrmsalary/auth/opt/tree", "GET", params);
|
||||
|
|
|
|||
|
|
@ -10,28 +10,79 @@
|
|||
import React, { Component } from "react";
|
||||
import * as API from "../../../../apis/taxAgent";
|
||||
import { Row } from "antd";
|
||||
import { WeaLocaleProvider } from "ecCom";
|
||||
import { WeaLocaleProvider, WeaTree } from "ecCom";
|
||||
|
||||
const getLabel = WeaLocaleProvider.getLabel;
|
||||
|
||||
class AuthTree extends Component {
|
||||
constructor(props) {
|
||||
super(props);
|
||||
this.state = {};
|
||||
this.state = {
|
||||
checkedKeys: [], expandedKeys: [], datas: {}
|
||||
};
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
const { roleId } = this.props;
|
||||
API.getAuthOptTree({ roleId }).then(({ status, data }) => {
|
||||
if (status) {
|
||||
console.log(data);
|
||||
this.setState({
|
||||
datas: {
|
||||
canClick: true, id: data.key, nodeid: data.key, isParent: true, name: data.name,
|
||||
subs: _.map(data.modules, item => ({
|
||||
...item, canClick: true, id: item.key, nodeid: item.key, pid: data.key, isParent: !_.isEmpty(item.pages),
|
||||
subs: _.map(item.pages, o => ({
|
||||
...o, canClick: true, id: `${item.key}-${o.key}`, nodeid: `${item.key}-${o.key}`,
|
||||
pid: item.key, isParent: !_.isEmpty(o.opts),
|
||||
subs: _.map(o.opts, k => ({
|
||||
canClick: true, id: `${o.key}-${k.key}`, name: k.name, nodeid: `${o.key}-${k.key}`,
|
||||
pid: `${item.key}-${o.key}`, isParent: false, able: k.able
|
||||
}))
|
||||
}))
|
||||
}))
|
||||
}
|
||||
}, () => this.setState({ expandedKeys: this.initExpandKeys(), checkedKeys: this.initCheckedKeys() }));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
initExpandKeys = () => {
|
||||
const { datas } = this.state;
|
||||
const parentIds = [];
|
||||
const findParent = (node) => {
|
||||
if (node.subs && node.subs.length > 0) {
|
||||
parentIds.push(node.id);
|
||||
node.subs.forEach(child => findParent(child));
|
||||
}
|
||||
};
|
||||
findParent(datas);
|
||||
return parentIds;
|
||||
};
|
||||
initCheckedKeys = () => {
|
||||
const { datas } = this.state;
|
||||
const checkedIds = [];
|
||||
const findCheckedId = (node) => {
|
||||
if (node.subs && node.subs.length > 0) {
|
||||
node.subs.forEach(child => {
|
||||
if (!!child.able) checkedIds.push(child.id);
|
||||
findCheckedId(child);
|
||||
});
|
||||
}
|
||||
};
|
||||
findCheckedId(datas);
|
||||
return checkedIds;
|
||||
};
|
||||
|
||||
render() {
|
||||
const { checkedKeys, expandedKeys, datas } = this.state;
|
||||
return (
|
||||
<Row className="tax_role_auth_tree">权限</Row>
|
||||
<Row className="tax_role_auth_tree">
|
||||
<WeaTree
|
||||
checkable onCheck={checkedKeys => this.setState({ checkedKeys })} checkedKeys={checkedKeys}
|
||||
expandedKeys={expandedKeys} onExpand={expandedKeys => this.setState({ expandedKeys })}
|
||||
datas={datas}
|
||||
/>
|
||||
</Row>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -146,6 +146,28 @@ class Index extends Component {
|
|||
}
|
||||
});
|
||||
};
|
||||
saveAuthOpt = () => {
|
||||
const { roleId } = this.props;
|
||||
const { state: { checkedKeys } } = this.authTreeRef;
|
||||
const payload = {
|
||||
roleId, opts: _.reduce(checkedKeys, (pre, cur) => {
|
||||
if (cur.indexOf("query") !== -1 || cur.indexOf("admin") !== -1) {
|
||||
const [page, opt] = cur.split("-");
|
||||
return [...pre, { page, opt }];
|
||||
}
|
||||
return pre;
|
||||
}, [])
|
||||
};
|
||||
this.setState({ loading: { ...this.state.loading, set: true } });
|
||||
API.saveAuthOpt(payload).then(({ status, errormsg }) => {
|
||||
this.setState({ loading: { ...this.state.loading, set: false } });
|
||||
if (status) {
|
||||
message.success(getLabel(111, "操作成功!"));
|
||||
} else {
|
||||
message.error(errormsg);
|
||||
}
|
||||
});
|
||||
};
|
||||
syncAuthData = () => {
|
||||
const { roleId } = this.props, { selectedKey } = this.state;
|
||||
this.setState({ async: true });
|
||||
|
|
@ -199,7 +221,7 @@ class Index extends Component {
|
|||
onChange={(__, ___, replaceDatas) => this.setState({ replaceDatas })}/>
|
||||
</Row>);
|
||||
} else {
|
||||
return (<AuthTree roleId={roleId}/>);
|
||||
return (<AuthTree roleId={roleId} ref={dom => this.authTreeRef = dom}/>);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
@ -233,16 +255,19 @@ class Index extends Component {
|
|||
const rowSelection = {
|
||||
selectedRowKeys, onChange: (selectedRowKeys) => this.setState({ selectedRowKeys })
|
||||
};
|
||||
const buttons = [
|
||||
<Button type="primary" onClick={this.syncAuthData} loading={loading.async}>{getLabel(111, "同步")}</Button>,
|
||||
<Button type="ghost" loading={loading.set} onClick={this.saveAuthOpt}>{getLabel(111, "保存")}</Button>
|
||||
];
|
||||
selectedKey === "auth.AuthTargetTypeEnum" && buttons.shift();
|
||||
selectedKey !== "auth.AuthTargetTypeEnum" && buttons.pop();
|
||||
return (
|
||||
<WeaDialog
|
||||
{...this.props} hasScroll className="tax_role_set_dialog" initLoadCss title={getLabel(111, "编辑角色")}
|
||||
buttons={[
|
||||
<Button type="primary" onClick={this.syncAuthData} loading={loading.async}>{getLabel(111, "同步")}</Button>
|
||||
]}
|
||||
style={{
|
||||
width: 960, height: 606.6, minHeight: 200, minWidth: 380,
|
||||
maxHeight: "90%", maxWidth: "90%", overflow: "hidden", transform: "translate(0px, 0px)"
|
||||
}}
|
||||
buttons={buttons} style={{
|
||||
width: 960, height: 606.6, minHeight: 200, minWidth: 380,
|
||||
maxHeight: "90%", maxWidth: "90%", overflow: "hidden", transform: "translate(0px, 0px)"
|
||||
}}
|
||||
>
|
||||
<div className="tax_role_set_container">
|
||||
<Row className="tax_role_row_groupname">
|
||||
|
|
|
|||
Loading…
Reference in New Issue