master
LiuJiaNan 2025-11-11 14:40:56 +08:00
parent 6f87ced6f1
commit 6cd0ad0182
7 changed files with 65 additions and 11 deletions

View File

@ -57,7 +57,7 @@ const FormBuilder = (props) => {
</Button> </Button>
)} )}
{showCancelButton && ( {showCancelButton && (
<Button onClick={handleCancel} style={{ marginRight: 8 }}> <Button onClick={handleCancel}>
{cancelButtonText} {cancelButtonText}
</Button> </Button>
)} )}

View File

@ -90,15 +90,17 @@ function HiddenInfo(props) {
{ label: "隐患状态", children: getLabelName({ list: HIDDEN_STATE_ENUM, status: info.state }) }, { label: "隐患状态", children: getLabelName({ list: HIDDEN_STATE_ENUM, status: info.state }) },
{ label: "隐患描述", children: info.hiddenDesc }, { label: "隐患描述", children: info.hiddenDesc },
{ label: "隐患部位", children: info.hiddenPart }, { label: "隐患部位", children: info.hiddenPart },
...(info.source === 2 || info.source === 3 ...(
(info.source === 2 || info.source === 3) && (info.hiddenCheckListCO && Object.keys(info.hiddenCheckListCO).length > 0)
? [ ? [
{ label: "风险点(单元)", children: "todo" }, { label: "风险点(单元)", children: info.hiddenCheckListCO.listRiskPoints },
{ label: "辨识部位", children: "todo" }, { label: "辨识部位", children: info.hiddenCheckListCO.identifiedLocations },
{ label: "存在风险", children: "todo" }, { label: "存在风险", children: info.hiddenCheckListCO.existingRisks },
{ label: "风险分级", children: "todo" }, { label: "风险分级", children: info.hiddenCheckListCO.riskLevel },
{ label: "隐患清单", children: "todo" }, { label: "隐患清单", children: info.hiddenCheckListCO.listName },
] ]
: []), : []
),
{ {
label: "隐患上报位置(经纬度)", label: "隐患上报位置(经纬度)",
children: [info.longitude && `经度:${info.longitude}`, info.latitude && `纬度:${info.latitude}`].filter(Boolean).join(" "), children: [info.longitude && `经度:${info.longitude}`, info.latitude && `纬度:${info.latitude}`].filter(Boolean).join(" "),

View File

@ -23,6 +23,8 @@ export interface BasicSelectTreeProps extends Omit<TreeSelectProps, "fieldNames"
onGetLabel?: (label: string) => void; onGetLabel?: (label: string) => void;
/** 获取数据 */ /** 获取数据 */
onGetData?: (data: Record<string, any>[], processedData: Record<string, any>[]) => void; onGetData?: (data: Record<string, any>[], processedData: Record<string, any>[]) => void;
/** 是否只允许选择最后一级,默认 false */
onlyLastLevel?: boolean;
} }
/** /**

View File

@ -1,6 +1,6 @@
import { TreeSelect } from "antd"; import { TreeSelect } from "antd";
import { useEffect } from "react"; import { useEffect } from "react";
import { getTreeNodePaths, processTreeDataByLevel } from "../../../utils"; import { getTreeNodePaths, processTreeDataByLevel, processTreeDataForOnlyLastLevel } from "../../../utils";
/** /**
* 基础下拉树组件不建议直接使用此组件二次继承使用 * 基础下拉树组件不建议直接使用此组件二次继承使用
@ -18,11 +18,12 @@ function BasicSelectTree(props) {
idKey = "id", idKey = "id",
childrenKey = "children", childrenKey = "children",
level, level,
onlyLastLevel = false,
...restProps ...restProps
} = props; } = props;
// 根据 level 处理树数据 // 根据 level 处理树数据
const processedTreeData = level let processedTreeData = level
? processTreeDataByLevel({ ? processTreeDataByLevel({
data: treeData, data: treeData,
level, level,
@ -31,6 +32,9 @@ function BasicSelectTree(props) {
}) })
: treeData; : treeData;
// 根据 onlyLastLevel 处理树数据
processedTreeData = processTreeDataForOnlyLastLevel({ data: processedTreeData, childrenKey, onlyLastLevel });
const handleChange = (value, label, extra) => { const handleChange = (value, label, extra) => {
if (value) { if (value) {
const parentNodes = getTreeNodePaths({ const parentNodes = getTreeNodePaths({

View File

@ -115,7 +115,7 @@ function useTable(service, options) {
usePagination = true, usePagination = true,
defaultType = "advance", defaultType = "advance",
defaultCurrent = 1, defaultCurrent = 1,
defaultPageSize = 10, defaultPageSize = 20,
defaultPagination = { current: defaultCurrent, pageSize: defaultPageSize }, defaultPagination = { current: defaultCurrent, pageSize: defaultPageSize },
...restRestOptions ...restRestOptions
} = restOptions; } = restOptions;

19
utils/index.d.ts vendored
View File

@ -301,3 +301,22 @@ export function processTreeDataByLevel(
/** 子节点 */ /** 子节点 */
[key: string]: any; [key: string]: any;
}[]; }[];
/**
* onlyLastLevel selectable
*/
export function processTreeDataForOnlyLastLevel(
options: {
/** 树形数据 */
data: any[];
/** 子节点字段名 */
childrenKey: string;
/** 是否只允许选择最后一级 */
onlyLastLevel?: boolean;
},
): {
/** 是否允许选择 */
selectable: boolean;
/** 子节点 */
[key: string]: any;
}[];

View File

@ -462,6 +462,33 @@ export const processTreeDataByLevel = (options) => {
}); });
}; };
/**
* 根据 onlyLastLevel 属性处理树数据添加 selectable 属性控制节点是否可选择
*/
export const processTreeDataForOnlyLastLevel = (options) => {
const { data, childrenKey, onlyLastLevel = false } = options;
if (!onlyLastLevel)
return data;
return data.map((item) => {
// 检查是否有子节点
const hasChildren = item[childrenKey] && item[childrenKey].length > 0;
// 如果有子节点,则不可选择
const processedItem = {
...item,
selectable: !hasChildren,
};
// 递归处理子节点
if (hasChildren) {
processedItem[childrenKey] = processTreeDataForOnlyLastLevel({ data: item[childrenKey], childrenKey, onlyLastLevel });
}
return processedItem;
});
};
/** /**
* 获取文件url * 获取文件url
*/ */