新增PersonnelSelect组件
parent
1fb5df105d
commit
70e11b921e
|
|
@ -1,12 +1,14 @@
|
||||||
import type { FC } from "react";
|
import type { FC } from "react";
|
||||||
import type { BasicLeftTreeProps } from "../../Basic";
|
import type { BasicLeftTreeProps } from "../../Basic";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 请求参数
|
||||||
|
*/
|
||||||
export interface Params {
|
export interface Params {
|
||||||
/** 企业id */
|
/** 企业id */
|
||||||
eqCorpinfoId?: string;
|
eqCorpinfoId?: string;
|
||||||
/** 父级部门id */
|
/** 父级部门id */
|
||||||
eqParentId?: string;
|
eqParentId?: string;
|
||||||
[key: string]: any;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -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;
|
||||||
|
|
@ -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;
|
||||||
|
|
@ -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;
|
||||||
|
|
@ -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;
|
||||||
|
|
@ -15,6 +15,8 @@ export interface BasicSelectTreeProps extends TreeSelectProps {
|
||||||
onGetNodePathsIsIncludeOneself?: boolean;
|
onGetNodePathsIsIncludeOneself?: boolean;
|
||||||
/** 获取父级节点 */
|
/** 获取父级节点 */
|
||||||
onGetNodePaths?: (nodes: Record<string, any>[]) => void;
|
onGetNodePaths?: (nodes: Record<string, any>[]) => void;
|
||||||
|
/** 占位符 */
|
||||||
|
placeholder?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -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;
|
params?: Params;
|
||||||
|
/** 占位符,默认"部门“ */
|
||||||
|
placeholder?: string;
|
||||||
|
/** 是否需要企业id,默认 false */
|
||||||
|
isNeedCorpInfoId?: boolean;
|
||||||
|
/** 是否需要父级部门id,默认 false */
|
||||||
|
isNeedParentId?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 部门下拉树组件(港务局版本)
|
* 基础下拉树组件(港务局版本)
|
||||||
*/
|
*/
|
||||||
declare const DepartmentSelectTree: FC<DepartmentSelectTreeProps>;
|
declare const DepartmentSelectTree: FC<DepartmentSelectTreeProps>;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,27 +3,38 @@ import { useEffect, useState } from "react";
|
||||||
import BasicLeftTree from "../../Basic";
|
import BasicLeftTree from "../../Basic";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 部门左侧树组件(港务局版本)
|
* 基础下拉树组件(港务局版本)
|
||||||
*/
|
*/
|
||||||
function DepartmentSelectTree(props) {
|
function DepartmentSelectTree(props) {
|
||||||
const {
|
const {
|
||||||
params = {},
|
params = {},
|
||||||
|
placeholder = "部门",
|
||||||
|
isNeedCorpInfoId = false,
|
||||||
|
isNeedParentId = false,
|
||||||
...restProps
|
...restProps
|
||||||
} = props;
|
} = props;
|
||||||
|
|
||||||
const [treeData, setTreeData] = useState([]);
|
const [treeData, setTreeData] = useState([]);
|
||||||
|
|
||||||
const getData = async () => {
|
const getData = async () => {
|
||||||
|
setTreeData([]);
|
||||||
|
|
||||||
|
// 根据参数决定是否发送请求
|
||||||
|
if (isNeedCorpInfoId && !params.eqCorpinfoId)
|
||||||
|
return;
|
||||||
|
if (isNeedParentId && !params.eqParentId)
|
||||||
|
return;
|
||||||
|
|
||||||
const { data } = await request("/basic-info/department/listTree", "post", params);
|
const { data } = await request("/basic-info/department/listTree", "post", params);
|
||||||
setTreeData(data);
|
setTreeData(data);
|
||||||
};
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
getData();
|
getData();
|
||||||
}, []);
|
}, [JSON.stringify(params), isNeedCorpInfoId, isNeedParentId]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<BasicLeftTree treeData={treeData} placeholder="部门" {...restProps} />
|
<BasicLeftTree treeData={treeData} placeholder={placeholder} {...restProps} />
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue