|
@@ -1,20 +1,19 @@
|
|
|
import type { ModalProps, ModalMethods } from './types';
|
|
|
|
|
|
+import { defineComponent, computed, ref, watch, unref, watchEffect } from 'vue';
|
|
|
+
|
|
|
import Modal from './Modal';
|
|
|
-import { Button } from 'ant-design-vue';
|
|
|
+import Button from '/@/components/Button/index.vue';
|
|
|
import ModalWrapper from './ModalWrapper';
|
|
|
import { BasicTitle } from '/@/components/Basic';
|
|
|
-import { defineComponent, computed, ref, watch, unref, watchEffect } from 'vue';
|
|
|
-
|
|
|
import { FullscreenExitOutlined, FullscreenOutlined, CloseOutlined } from '@ant-design/icons-vue';
|
|
|
|
|
|
-import { basicProps } from './props';
|
|
|
-
|
|
|
import { getSlot, extendSlots } from '/@/utils/helper/tsxHelper';
|
|
|
import { isFunction } from '/@/utils/is';
|
|
|
import { deepMerge } from '/@/utils';
|
|
|
import { buildUUID } from '/@/utils/uuid';
|
|
|
|
|
|
+import { basicProps } from './props';
|
|
|
// import { triggerWindowResize } from '@/utils/event/triggerWindowResizeEvent';
|
|
|
export default defineComponent({
|
|
|
name: 'BasicModal',
|
|
@@ -22,18 +21,14 @@ export default defineComponent({
|
|
|
emits: ['visible-change', 'height-change', 'cancel', 'ok', 'register'],
|
|
|
setup(props, { slots, emit, attrs }) {
|
|
|
const visibleRef = ref(false);
|
|
|
-
|
|
|
const propsRef = ref<Partial<ModalProps> | null>(null);
|
|
|
-
|
|
|
const modalWrapperRef = ref<any>(null);
|
|
|
-
|
|
|
// modal Bottom and top height
|
|
|
const extHeightRef = ref(0);
|
|
|
-
|
|
|
// Unexpanded height of the popup
|
|
|
const formerHeightRef = ref(0);
|
|
|
-
|
|
|
const fullScreenRef = ref(false);
|
|
|
+
|
|
|
// Custom title component: get title
|
|
|
const getMergeProps = computed(() => {
|
|
|
return {
|
|
@@ -41,6 +36,7 @@ export default defineComponent({
|
|
|
...(unref(propsRef) as any),
|
|
|
};
|
|
|
});
|
|
|
+
|
|
|
// modal component does not need title
|
|
|
const getProps = computed((): any => {
|
|
|
const opt = {
|
|
@@ -56,9 +52,11 @@ export default defineComponent({
|
|
|
wrapClassName: className,
|
|
|
};
|
|
|
});
|
|
|
+
|
|
|
watchEffect(() => {
|
|
|
visibleRef.value = !!props.visible;
|
|
|
});
|
|
|
+
|
|
|
watch(
|
|
|
() => unref(visibleRef),
|
|
|
(v) => {
|
|
@@ -68,6 +66,7 @@ export default defineComponent({
|
|
|
immediate: false,
|
|
|
}
|
|
|
);
|
|
|
+
|
|
|
/**
|
|
|
* @description: 渲染标题
|
|
|
*/
|
|
@@ -83,13 +82,17 @@ export default defineComponent({
|
|
|
|
|
|
function renderContent() {
|
|
|
const { useWrapper, loading, wrapperProps } = unref(getProps);
|
|
|
- return useWrapper ? (
|
|
|
+ if (!useWrapper) return getSlot(slots);
|
|
|
+
|
|
|
+ const showFooter = props.footer !== undefined && !props.footer ? 0 : undefined;
|
|
|
+ return (
|
|
|
<ModalWrapper
|
|
|
footerOffset={props.wrapperFooterOffset}
|
|
|
fullScreen={unref(fullScreenRef)}
|
|
|
ref={modalWrapperRef}
|
|
|
loading={loading}
|
|
|
visible={unref(visibleRef)}
|
|
|
+ modalFooterHeight={showFooter}
|
|
|
{...wrapperProps}
|
|
|
onGetExtHeight={(height: number) => {
|
|
|
extHeightRef.value = height;
|
|
@@ -100,13 +103,12 @@ export default defineComponent({
|
|
|
>
|
|
|
{() => getSlot(slots)}
|
|
|
</ModalWrapper>
|
|
|
- ) : (
|
|
|
- getSlot(slots)
|
|
|
);
|
|
|
}
|
|
|
+
|
|
|
// 取消事件
|
|
|
async function handleCancel(e: Event) {
|
|
|
- e.stopPropagation();
|
|
|
+ e && e.stopPropagation();
|
|
|
if (props.closeFunc && isFunction(props.closeFunc)) {
|
|
|
const isClose: boolean = await props.closeFunc();
|
|
|
visibleRef.value = !isClose;
|
|
@@ -115,6 +117,7 @@ export default defineComponent({
|
|
|
visibleRef.value = false;
|
|
|
emit('cancel');
|
|
|
}
|
|
|
+
|
|
|
// 底部按钮自定义实现,
|
|
|
function renderFooter() {
|
|
|
const {
|
|
@@ -131,7 +134,6 @@ export default defineComponent({
|
|
|
return (
|
|
|
<>
|
|
|
{getSlot(slots, 'insertFooter')}
|
|
|
-
|
|
|
{showCancelBtn && (
|
|
|
<Button {...cancelButtonProps} onClick={handleCancel}>
|
|
|
{() => cancelText}
|
|
@@ -150,11 +152,11 @@ export default defineComponent({
|
|
|
{() => okText}
|
|
|
</Button>
|
|
|
)}
|
|
|
-
|
|
|
{getSlot(slots, 'appendFooter')}
|
|
|
</>
|
|
|
);
|
|
|
}
|
|
|
+
|
|
|
/**
|
|
|
* @description: 关闭按钮
|
|
|
*/
|
|
@@ -176,27 +178,26 @@ export default defineComponent({
|
|
|
}
|
|
|
|
|
|
function handleFullScreen(e: Event) {
|
|
|
- e.stopPropagation();
|
|
|
+ e && e.stopPropagation();
|
|
|
fullScreenRef.value = !unref(fullScreenRef);
|
|
|
|
|
|
const modalWrapper = unref(modalWrapperRef);
|
|
|
- if (modalWrapper) {
|
|
|
- const modalWrapSpinEl = (modalWrapper.$el as HTMLElement).querySelector(
|
|
|
- '.ant-spin-nested-loading'
|
|
|
- );
|
|
|
- if (modalWrapSpinEl) {
|
|
|
- if (!unref(formerHeightRef) && unref(fullScreenRef)) {
|
|
|
- formerHeightRef.value = (modalWrapSpinEl as HTMLElement).offsetHeight;
|
|
|
- console.log(formerHeightRef);
|
|
|
- }
|
|
|
- if (unref(fullScreenRef)) {
|
|
|
- (modalWrapSpinEl as HTMLElement).style.height = `${
|
|
|
- window.innerHeight - unref(extHeightRef)
|
|
|
- }px`;
|
|
|
- } else {
|
|
|
- (modalWrapSpinEl as HTMLElement).style.height = `${unref(formerHeightRef)}px`;
|
|
|
- }
|
|
|
- }
|
|
|
+ if (!modalWrapper) return;
|
|
|
+
|
|
|
+ const wrapperEl = modalWrapper.$el as HTMLElement;
|
|
|
+ if (!wrapperEl) return;
|
|
|
+
|
|
|
+ const modalWrapSpinEl = wrapperEl.querySelector('.ant-spin-nested-loading') as HTMLElement;
|
|
|
+ if (!modalWrapSpinEl) return;
|
|
|
+
|
|
|
+ if (!unref(formerHeightRef) && unref(fullScreenRef)) {
|
|
|
+ formerHeightRef.value = modalWrapSpinEl.offsetHeight;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (unref(fullScreenRef)) {
|
|
|
+ modalWrapSpinEl.style.height = `${window.innerHeight - unref(extHeightRef)}px`;
|
|
|
+ } else {
|
|
|
+ modalWrapSpinEl.style.height = `${unref(formerHeightRef)}px`;
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -206,21 +207,22 @@ export default defineComponent({
|
|
|
function setModalProps(props: Partial<ModalProps>): void {
|
|
|
// Keep the last setModalProps
|
|
|
propsRef.value = deepMerge(unref(propsRef) || {}, props);
|
|
|
- if (Reflect.has(props, 'visible')) {
|
|
|
- visibleRef.value = !!props.visible;
|
|
|
- }
|
|
|
+ if (!Reflect.has(props, 'visible')) return;
|
|
|
+ visibleRef.value = !!props.visible;
|
|
|
}
|
|
|
|
|
|
const modalMethods: ModalMethods = {
|
|
|
setModalProps,
|
|
|
};
|
|
|
+
|
|
|
const uuid = buildUUID();
|
|
|
emit('register', modalMethods, uuid);
|
|
|
+
|
|
|
return () => (
|
|
|
<Modal
|
|
|
onCancel={handleCancel}
|
|
|
- {...{ ...attrs, ...props, ...unref(getProps) }}
|
|
|
getContainer={() => document.querySelector('.default-layout__main')}
|
|
|
+ {...{ ...attrs, ...props, ...unref(getProps) }}
|
|
|
>
|
|
|
{{
|
|
|
...extendSlots(slots, ['default']),
|