Skip to content

Commit 5091a87

Browse files
committed
feat(modal): add minHeight and height prop #156
1 parent 5c27353 commit 5091a87

File tree

6 files changed

+21
-13
lines changed

6 files changed

+21
-13
lines changed

src/components/Form/src/BasicForm.vue

+1-11
Original file line numberDiff line numberDiff line change
@@ -31,17 +31,7 @@
3131
import type { AdvanceState } from './types/hooks';
3232
import type { CSSProperties, Ref, WatchStopHandle } from 'vue';
3333
34-
import {
35-
defineComponent,
36-
reactive,
37-
ref,
38-
computed,
39-
unref,
40-
onMounted,
41-
watch,
42-
toRefs,
43-
toRaw,
44-
} from 'vue';
34+
import { defineComponent, reactive, ref, computed, unref, onMounted, watch, toRefs } from 'vue';
4535
import { Form, Row } from 'ant-design-vue';
4636
import FormItem from './components/FormItem';
4737
import FormAction from './components/FormAction.vue';

src/components/Form/src/hooks/useFormValues.ts

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import { isArray, isFunction, isObject, isString } from '/@/utils/is';
22
import moment from 'moment';
3-
import { unref } from 'vue';
3+
import { unref, nextTick } from 'vue';
44
import type { Ref, ComputedRef } from 'vue';
55
import type { FieldMapToTime, FormSchema } from '../types/form';
6+
import { useModalContext } from '/@/components/Modal';
67

78
interface UseFormValuesContext {
89
transformDateFuncRef: Ref<Fn>;
@@ -18,6 +19,7 @@ export function useFormValues({
1819
getSchema,
1920
formModel,
2021
}: UseFormValuesContext) {
22+
const modalFn = useModalContext();
2123
// Processing form values
2224
function handleFormValues(values: Recordable) {
2325
if (!isObject(values)) {
@@ -81,6 +83,10 @@ export function useFormValues({
8183
}
8284
});
8385
defaultValueRef.value = obj;
86+
nextTick(() => {
87+
// Solve the problem of modal adaptive height calculation when the form is placed in the modal
88+
modalFn?.redoModalHeight?.();
89+
});
8490
}
8591

8692
return { handleFormValues, initDefault };

src/components/Modal/src/BasicModal.vue

+2
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
:fullScreen="fullScreenRef"
2424
ref="modalWrapperRef"
2525
:loading="getProps.loading"
26+
:minHeight="getProps.minHeight"
27+
:height="getProps.height"
2628
:visible="visibleRef"
2729
:modalFooterHeight="footer !== undefined && !footer ? 0 : undefined"
2830
v-bind="omit(getProps.wrapperProps, 'visible')"

src/components/Modal/src/components/ModalWrapper.vue

+6-1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
modalHeaderHeight: propTypes.number.def(50),
3939
modalFooterHeight: propTypes.number.def(54),
4040
minHeight: propTypes.number.def(200),
41+
height: propTypes.number,
4142
footerOffset: propTypes.number.def(0),
4243
visible: propTypes.bool,
4344
fullScreen: propTypes.bool,
@@ -142,7 +143,11 @@
142143
realHeightRef.value =
143144
window.innerHeight - props.modalFooterHeight - props.modalHeaderHeight;
144145
} else {
145-
realHeightRef.value = realHeight > maxHeight ? maxHeight : realHeight + 16 + 30;
146+
realHeightRef.value = props.height
147+
? props.height
148+
: realHeight > maxHeight
149+
? maxHeight
150+
: realHeight + 16 + 30;
146151
}
147152
emit('height-change', unref(realHeightRef));
148153
} catch (error) {

src/components/Modal/src/props.ts

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ const { t } = useI18n();
88

99
export const modalProps = {
1010
visible: propTypes.bool,
11+
height: propTypes.number,
12+
minHeight: propTypes.number,
1113
// open drag
1214
draggable: propTypes.bool.def(true),
1315
centered: propTypes.bool,

src/components/Modal/src/types.ts

+3
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ export interface ReturnInnerMethods extends ModalMethods {
2727
export type UseModalInnerReturnType = [RegisterFn, ReturnInnerMethods];
2828

2929
export interface ModalProps {
30+
minHeight?: number;
31+
height?: number;
3032
// 启用wrapper后 底部可以适当增加高度
3133
wrapperFooterOffset?: number;
3234
draggable?: boolean;
@@ -195,6 +197,7 @@ export interface ModalWrapperProps {
195197
modalHeaderHeight: number;
196198
modalFooterHeight: number;
197199
minHeight: number;
200+
height: number;
198201
visible: boolean;
199202
fullScreen: boolean;
200203
useWrapper: boolean;

0 commit comments

Comments
 (0)