新增PersonnelSelect组件

master
LiuJiaNan 2025-11-06 09:38:23 +08:00
parent 1fb5df105d
commit 70e11b921e
8 changed files with 164 additions and 6 deletions

View File

@ -1,12 +1,14 @@
import type { FC } from "react";
import type { BasicLeftTreeProps } from "../../Basic";
/**
*
*/
export interface Params {
/** 企业id */
eqCorpinfoId?: string;
/** 父级部门id */
eqParentId?: string;
[key: string]: any;
}
/**

23
components/Select/Basic/index.d.ts vendored Normal file
View File

@ -0,0 +1,23 @@
import type { SelectProps } from "antd/es/select";
import type { FC } from "react";
/**
*
*/
export interface BasicSelectProps extends SelectProps {
/** 数据源 */
data: Record<string, any>[];
/** 数据 label 字段,默认 name */
nameKey?: string;
/** 数据 value 字段,默认 id */
idKey?: string;
/** 占位符 */
placeholder?: string;
}
/**
* 使使
*/
declare const BasicSelectTree: FC<BasicSelectProps>;
export default BasicSelectTree;

View File

@ -0,0 +1,32 @@
import { Select } from "antd";
/**
* 基础下拉组件不建议直接使用此组件二次继承使用
*/
function BasicSelect(props) {
const {
placeholder = "",
data = [],
nameKey = "name",
idKey = "id",
...restProps
} = props;
return (
<Select placeholder={`请选择${placeholder}`} showSearch allowClear {...restProps}>
{data.map((item) => {
const value = item[idKey];
const label = item[nameKey];
return (
<Select.Option key={value} value={value}>
{label}
</Select.Option>
);
})}
</Select>
);
}
BasicSelect.displayName = "BasicSelect";
export default BasicSelect;

View File

@ -0,0 +1,37 @@
import type { FC } from "react";
import type { BasicSelectProps } from "../../Basic";
/**
*
*/
export interface Params {
/** 企业id */
corpinfoId?: string;
/** 岗位id */
postId?: string;
/** 部门id */
departmentId?: string;
}
/**
*
*/
export interface DepartmentSelectProps extends Omit<BasicSelectProps, "data"> {
/** 请求参数 */
params?: Params;
/** 占位符,默认"人员" */
placeholder?: string;
/** 是否需要企业id默认 false */
isNeedCorpInfoId?: boolean;
/** 是否需要岗位id默认 false */
isNeedPostId?: boolean;
/** 是否需要部门id默认 true */
isNeedDepartmentId?: boolean;
}
/**
*
*/
declare const DepartmentSelect: FC<DepartmentSelectProps>;
export default DepartmentSelect;

View File

@ -0,0 +1,45 @@
import { request } from "@cqsjjb/jjb-common-lib/http";
import { useEffect, useState } from "react";
import BasicSelect from "~/components/Select/Basic";
/**
* 基础下拉组件港务局版本
*/
function PersonnelSelect(props) {
const {
params = {},
placeholder = "人员",
isNeedCorpInfoId = false,
isNeedDepartmentId = true,
isNeedPostId = false,
...restProps
} = props;
const [data, setData] = useState([]);
const getData = async () => {
setData([]);
// 根据参数决定是否发送请求
if (isNeedCorpInfoId && !params.corpinfoId)
return;
if (isNeedDepartmentId && !params.departmentId)
return;
if (isNeedPostId && !params.postId)
return;
const { data } = await request("/basic-info/user/listAll", "get", params);
setData(data);
};
useEffect(() => {
getData();
}, [JSON.stringify(params), isNeedCorpInfoId, isNeedDepartmentId, isNeedPostId]);
return (
<BasicSelect data={data} placeholder={placeholder} {...restProps} />
);
}
PersonnelSelect.displayName = "PersonnelSelect";
export default PersonnelSelect;

View File

@ -15,6 +15,8 @@ export interface BasicSelectTreeProps extends TreeSelectProps {
onGetNodePathsIsIncludeOneself?: boolean;
/** 获取父级节点 */
onGetNodePaths?: (nodes: Record<string, any>[]) => void;
/** 占位符 */
placeholder?: string;
}
/**

View File

@ -5,13 +5,19 @@ import { Params } from "../../../LeftTree/Department/Gwj";
/**
*
*/
export interface DepartmentSelectTreeProps extends Omit<BasicSelectTreeProps, "treeData" | "placeholder"> {
export interface DepartmentSelectTreeProps extends Omit<BasicSelectTreeProps, "treeData"> {
/** 请求参数 */
params?: Params;
/** 占位符,默认"部门“ */
placeholder?: string;
/** 是否需要企业id默认 false */
isNeedCorpInfoId?: boolean;
/** 是否需要父级部门id默认 false */
isNeedParentId?: boolean;
}
/**
*
*
*/
declare const DepartmentSelectTree: FC<DepartmentSelectTreeProps>;

View File

@ -3,27 +3,38 @@ import { useEffect, useState } from "react";
import BasicLeftTree from "../../Basic";
/**
* 部门左侧树组件港务局版本
* 基础下拉树组件港务局版本
*/
function DepartmentSelectTree(props) {
const {
params = {},
placeholder = "部门",
isNeedCorpInfoId = false,
isNeedParentId = false,
...restProps
} = props;
const [treeData, setTreeData] = useState([]);
const getData = async () => {
setTreeData([]);
// 根据参数决定是否发送请求
if (isNeedCorpInfoId && !params.eqCorpinfoId)
return;
if (isNeedParentId && !params.eqParentId)
return;
const { data } = await request("/basic-info/department/listTree", "post", params);
setTreeData(data);
};
useEffect(() => {
getData();
}, []);
}, [JSON.stringify(params), isNeedCorpInfoId, isNeedParentId]);
return (
<BasicLeftTree treeData={treeData} placeholder="部门" {...restProps} />
<BasicLeftTree treeData={treeData} placeholder={placeholder} {...restProps} />
);
}