This commit is contained in:
孙景学
2025-07-11 08:33:29 +08:00
parent 7049687456
commit 2457dfb6f3
6 changed files with 78 additions and 42 deletions

View File

@ -136,27 +136,27 @@ const CategoryAddModal: React.FC<Props> = ({ visible, onCancel, onSuccess }) =>
const handleTreeCheck = (checkedKeysValue: any) => {
const onlyOneEachLevel = checkedKeysValue;
console.log(onlyOneEachLevel,'onlyOneEachLevel');
console.log(onlyOneEachLevel, 'onlyOneEachLevel');
setCheckedKeys(onlyOneEachLevel);
form.setFieldsValue({ categoryKeys: onlyOneEachLevel });
};
// 从树中获取所有选中节点及其父级节点
const collectCheckedWithParents = (nodes: TreeNodeType[], checked: string[]): string[] => {
const result = new Set<string>();
const collectCheckedWithParents = (nodes: TreeNodeType[], checked: string[]): string[] => {
const result = new Set<string>();
const dfs = (node: TreeNodeType, parents: string[]) => {
if (checked.includes(node.key)) {
result.add(node.key);
parents.forEach(pid => result.add(pid)); // 加入所有父级
}
node.children?.forEach(child => dfs(child, [...parents, node.key]));
const dfs = (node: TreeNodeType, parents: string[]) => {
if (checked.includes(node.key)) {
result.add(node.key);
parents.forEach(pid => result.add(pid)); // 加入所有父级
}
node.children?.forEach(child => dfs(child, [...parents, node.key]));
};
nodes.forEach(root => dfs(root, []));
return Array.from(result);
};
nodes.forEach(root => dfs(root, []));
return Array.from(result);
};
// 提交校验
const handleOk = async () => {
try {
@ -248,15 +248,17 @@ const collectCheckedWithParents = (nodes: TreeNodeType[], checked: string[]): st
required
rules={[{ required: true, message: '请选择品类' }]}
>
<Tree
checkable
selectable={false}
treeData={treeData}
checkedKeys={checkedKeys}
expandedKeys={expandedKeys}
onExpand={setExpandedKeys as any}
onCheck={handleTreeCheck}
/>
<div style={{ maxHeight: 200, overflow: 'auto', border: '1px solid #f0f0f0', borderRadius: 4, padding: 8 }}>
<Tree
checkable
selectable={false}
treeData={treeData}
checkedKeys={checkedKeys}
expandedKeys={expandedKeys}
onExpand={setExpandedKeys as any}
onCheck={handleTreeCheck}
/>
</div>
<span style={{ color: '#888', marginLeft: 4, fontWeight: 400, fontSize: 12 }}>
</span>

View File

@ -229,11 +229,11 @@ const CategoryLibraryManage: React.FC = () => {
<Button className="buttonReset" icon={<DeleteOutlined />} onClick={handleReset} ></Button>
</Form.Item>
<Form.Item style={{ marginLeft: 'auto' }}>
{/* <Form.Item style={{ marginLeft: 'auto' }}>
<Button className="buttonFunctionBlock" type="primary" onClick={() => setAddVisible(true)} >
新增
</Button>
</Form.Item>
</Form.Item> */}
</Form>
</div>