Skip to content

Commit 5cb78ef

Browse files
committed
feat(Lov): 支持动态参数以及Lov覆写
1 parent d75e198 commit 5cb78ef

File tree

3 files changed

+10
-5
lines changed

3 files changed

+10
-5
lines changed

src/components/Lov/Lov.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ for (let i = 0; i < keys.length; i += 1) {
1616
}
1717

1818
const Lov: React.FC<LovProps> = (props) => {
19-
const config = cache[props.keyword];
20-
const { value, onChange } = props;
19+
const { value, onChange, keyword, overwriteConfig } = props;
20+
const config = { ...cache[keyword], ...overwriteConfig };
2121
const [show, setShow] = useState<boolean>(false);
2222
const [lovValue, setLovValue] = useState<any>();
2323
const [modalKey, setModalKey] = useState<number>(1);

src/components/Lov/LovModal.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,8 @@ function getRet(row: any, config: LovConfig<any>) {
108108
const LovModal: React.FC<LovModalProps & LovConfig<any> & ModalProps> = (props) => {
109109
const config: LovConfig<any> = props;
110110

111-
const { value, setValue, title, show, setShow, modalStyle, modalProperties } = props;
111+
const { value, setValue, title, show, setShow, modalStyle, modalProperties, dynamicParams } =
112+
props;
112113

113114
const tableRef = useRef<ActionType>();
114115

@@ -257,7 +258,7 @@ const LovModal: React.FC<LovModalProps & LovConfig<any> & ModalProps> = (props)
257258
method: config.method,
258259
sendMessage: false,
259260
};
260-
option[config.position.toLowerCase()] = { ...p, ...config.fixedParams };
261+
option[config.position.toLowerCase()] = { ...p, ...config.fixedParams, ...dynamicParams };
261262

262263
return request<R<PageResult<any>>>(config.url, option);
263264
}}

src/components/Lov/typing.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import type React from 'react';
22

33
export type LovProps = {
44
keyword: string;
5+
// 覆写配置
6+
overwriteConfig?: Partial<LovConfig<any>>;
57
} & LovModalProps;
68

79
export type LovConfig<T> = {
@@ -17,7 +19,7 @@ export type LovConfig<T> = {
1719
method: 'GET' | 'POST' | 'HEAD' | 'PUT' | 'PATCH' | 'DELETE' | 'OPTIONS' | 'TRACE';
1820
// 参数位置
1921
position: 'DATA' | 'PARAMS';
20-
// 固定请求参数
22+
// 固定请求参数, 该参数值会覆盖搜索栏中同名的参数值
2123
fixedParams?: Record<string, any>;
2224
// 是否多选
2325
multiple: boolean;
@@ -72,4 +74,6 @@ export type LovModalProps = {
7274
value?: any;
7375
// 参数为新值
7476
onChange?: (val: any) => void;
77+
// 动态参数. 该参数值会覆盖 固定参数以及搜索栏中同名的参数值
78+
dynamicParams?: Record<string, any>;
7579
};

0 commit comments

Comments
 (0)