Commit 2c89cb28 authored by 卢均锐's avatar 卢均锐

Merge branch 'dev-srm' of http://10.0.0.22:3000/lingxi/lingxi-business-system into dev-srm

* 'dev-srm' of http://10.0.0.22:3000/lingxi/lingxi-business-system: chore: 添加父子不关联属性
parents 193a2661 e21752c4
import React, { useState, useRef } from 'react';
import { Row, Col, Modal } from 'antd';
import { useTreeTabs, FormState } from '@/hooks/useTreeTabs';
import MellowCard from '@/components/MellowCard';
import TabTree, { createTreeActions } from '@/components/TabTree';
import CheckboxTree from '@/components/CheckBoxTree';
import styles from './index.less';
const treeActions = createTreeActions();
const PowerInfo: React.FC<{}> = () => {
const [powerLoading, setPowerLoading] = useState(false);
const [buttonInfos, setButtonInfos] = useState<any>([]);
const actionRef = useRef<any>({});
// 获取左侧已选择的项
const getMenuSelectData = async () => {
setPowerLoading(true);
const res = await PublicApi.getMemberValidateTreeCheckids({
memberId: id,
validateId: validateId,
});
setPowerLoading(false);
if (res.code === 1000) {
const { checkIds } = res.data;
return { data: { ids: checkIds } };
}
return {
data: {
ids: [],
},
};
};
// 获取左边菜单
const fetchMenuData = async () => {
const res = await PublicApi.getMemberValidateTree({
memberId: id,
validateId: validateId,
});
return res;
};
// 点击左侧菜单获取右侧按钮菜单、及已勾选的信息
const handleFindDetail = menuId => {
PublicApi.getMemberValidateCommitGetbutton({
menuId: menuId,
memberId: id,
validateId: validateId,
}).then(res => {
const { data } = res;
let buttons = data.buttons.map(v => ({ id: v.id, buttonName: v.name }));
setButtonInfos(buttons || []);
if (actionRef.current.setSelected) {
actionRef.current.setSelected(data.checkIds);
}
});
};
const customSelect = (selectKey?, node?) => {
// 首次新增菜单的时候没有节点信息
if (!node) {
setNodeRecord(null);
setTreeStatus(FormState.ADD);
return;
}
// key相等时 不刷新右侧表单
if (nodeRecord && nodeRecord.key === selectKey) {
setNodeRecord(node);
setTreeStatus(FormState.EDIT);
} else {
if (isEditForm) {
// 有填写过表单
return new Promise((resolve, reject) => {
Modal.confirm({
content: '确认要离开当前页面吗,您提交的数据尚未保存',
onOk() {
// 确认离开当前页, 需改变node state
setNodeRecord(node);
setTreeStatus(FormState.EDIT);
// 点击菜单,请求数据重置
handleFindDetail(selectKey);
setIsEditForm(false);
resolve();
},
onCancel() {
reject();
},
});
});
} else {
// 编辑页, 需回显
handleFindDetail(selectKey);
setNodeRecord(node);
setTreeStatus(FormState.EDIT);
}
}
};
const {
treeData,
handleSelect,
nodeRecord,
setNodeRecord,
setTreeStatus,
setIsEditForm,
isEditForm,
} = useTreeTabs({
fetchMenuData,
selectCallback: customSelect,
});
// 更新右侧按钮
const handleSubmitAuth = async () => {
const buttonIds = [...actionRef.current.selected];
if (!nodeRecord) {
return;
}
if (isEditForm) {
// 更新右侧按钮
await PublicApi.postMemberValidateCommitUpdatebutton({
memberId: id,
validateId,
menuId: nodeRecord.id,
buttonIds: buttonIds,
});
}
setIsEditForm(false);
};
return (
<Row>
<Col span={15}>
<MellowCard>
<TabTree
title="菜单列表"
getMenuSelectData={getMenuSelectData}
customKey="id"
actions={treeActions}
treeData={treeData}
handleSelect={handleSelect}
disabled={true}
checkable
/>
</MellowCard>
</Col>
<Col span={8} offset={1}>
<MellowCard>
<CheckboxTree
actions={actionRef}
disabled={true}
handleChange={e => setIsEditForm(true)}
checkedNodes={buttonInfos}
title="菜单按钮访问权限"
handleSubmit={handleSubmitAuth}
showSave
/>
</MellowCard>
</Col>
</Row>
);
};
import React, { useState, useRef } from 'react';
import { Row, Col, Modal } from 'antd';
import { useTreeTabs, FormState } from '@/hooks/useTreeTabs';
import MellowCard from '@/components/MellowCard';
import TabTree, { createTreeActions } from '@/components/TabTree';
import CheckboxTree from '@/components/CheckBoxTree';
import styles from './index.less';
const treeActions = createTreeActions();
const PowerInfo: React.FC<{}> = () => {
const [powerLoading, setPowerLoading] = useState(false);
const [buttonInfos, setButtonInfos] = useState<any>([]);
const actionRef = useRef<any>({});
// 获取左侧已选择的项
const getMenuSelectData = async () => {
setPowerLoading(true);
const res = await PublicApi.getMemberValidateTreeCheckids({
memberId: id,
validateId: validateId,
});
setPowerLoading(false);
if (res.code === 1000) {
const { checkIds } = res.data;
return { data: { ids: checkIds } };
}
return {
data: {
ids: [],
},
};
};
// 获取左边菜单
const fetchMenuData = async () => {
const res = await PublicApi.getMemberValidateTree({
memberId: id,
validateId: validateId,
});
return res;
};
// 点击左侧菜单获取右侧按钮菜单、及已勾选的信息
const handleFindDetail = menuId => {
PublicApi.getMemberValidateCommitGetbutton({
menuId: menuId,
memberId: id,
validateId: validateId,
}).then(res => {
const { data } = res;
let buttons = data.buttons.map(v => ({ id: v.id, buttonName: v.name }));
setButtonInfos(buttons || []);
if (actionRef.current.setSelected) {
actionRef.current.setSelected(data.checkIds);
}
});
};
const customSelect = (selectKey?, node?) => {
// 首次新增菜单的时候没有节点信息
if (!node) {
setNodeRecord(null);
setTreeStatus(FormState.ADD);
return;
}
// key相等时 不刷新右侧表单
if (nodeRecord && nodeRecord.key === selectKey) {
setNodeRecord(node);
setTreeStatus(FormState.EDIT);
} else {
if (isEditForm) {
// 有填写过表单
return new Promise((resolve, reject) => {
Modal.confirm({
content: '确认要离开当前页面吗,您提交的数据尚未保存',
onOk() {
// 确认离开当前页, 需改变node state
setNodeRecord(node);
setTreeStatus(FormState.EDIT);
// 点击菜单,请求数据重置
handleFindDetail(selectKey);
setIsEditForm(false);
resolve();
},
onCancel() {
reject();
},
});
});
} else {
// 编辑页, 需回显
handleFindDetail(selectKey);
setNodeRecord(node);
setTreeStatus(FormState.EDIT);
}
}
};
const {
treeData,
handleSelect,
nodeRecord,
setNodeRecord,
setTreeStatus,
setIsEditForm,
isEditForm,
} = useTreeTabs({
fetchMenuData,
selectCallback: customSelect,
});
// 更新右侧按钮
const handleSubmitAuth = async () => {
const buttonIds = [...actionRef.current.selected];
if (!nodeRecord) {
return;
}
if (isEditForm) {
// 更新右侧按钮
await PublicApi.postMemberValidateCommitUpdatebutton({
memberId: id,
validateId,
menuId: nodeRecord.id,
buttonIds: buttonIds,
});
}
setIsEditForm(false);
};
return (
<Row>
<Col span={15}>
<MellowCard>
<TabTree
title="菜单列表"
getMenuSelectData={getMenuSelectData}
customKey="id"
actions={treeActions}
treeData={treeData}
handleSelect={handleSelect}
disabled={true}
checkStrictly
checkable
/>
</MellowCard>
</Col>
<Col span={8} offset={1}>
<MellowCard>
<CheckboxTree
actions={actionRef}
disabled={true}
handleChange={e => setIsEditForm(true)}
checkedNodes={buttonInfos}
title="菜单按钮访问权限"
handleSubmit={handleSubmitAuth}
showSave
/>
</MellowCard>
</Col>
</Row>
);
};
export default PowerInfo
\ No newline at end of file
This diff is collapsed.
......@@ -363,6 +363,7 @@ const DetailInfo: React.FC<DetailInfoProps> = ({
treeData={treeData}
handleSelect={handleSelect}
disabled={true}
checkStrictly
checkable
/>
</MellowCard>
......
......@@ -364,6 +364,7 @@ const DetailInfo: React.FC<DetailInfoProps> = ({
treeData={treeData}
handleSelect={handleSelect}
disabled={true}
checkStrictly
checkable
/>
</MellowCard>
......
......@@ -368,6 +368,7 @@ const DetailInfo: React.FC<DetailInfoProps> = ({
treeData={treeData}
handleSelect={handleSelect}
disabled={true}
checkStrictly
checkable
/>
</MellowCard>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment