fix: 移除拖拽组件,全局注册ProModal替换默认AModal
This commit is contained in:
@@ -1,9 +1,10 @@
|
||||
<template>
|
||||
<a-modal
|
||||
<ProModal
|
||||
:drag="true"
|
||||
:destroyOnClose="true"
|
||||
:title="t('components.CronModal.title')"
|
||||
:visible="props.visible"
|
||||
:body-style="{ padding: '0 24px' }"
|
||||
:destroy-on-close="true"
|
||||
@cancel="fnCronModal(false)"
|
||||
@ok="fnCronModal(true)"
|
||||
>
|
||||
@@ -31,7 +32,7 @@
|
||||
v-model:value="cronStr"
|
||||
disabled
|
||||
/>
|
||||
</a-modal>
|
||||
</ProModal>
|
||||
</template>
|
||||
<script lang="ts" setup>
|
||||
import CronSecond from './components/Second.vue';
|
||||
|
||||
@@ -1,168 +0,0 @@
|
||||
<script setup lang="ts">
|
||||
import { ref, watch, watchEffect, CSSProperties, computed } from 'vue';
|
||||
import { useDraggable } from '@vueuse/core';
|
||||
const emit = defineEmits(['update:visible', 'ok', 'cancel']);
|
||||
/**于a-modal保持一致 */
|
||||
const props = defineProps({
|
||||
/**是否弹出显示,必传 */
|
||||
visible: {
|
||||
type: Boolean,
|
||||
required: true,
|
||||
},
|
||||
/**窗口标题 */
|
||||
title: {
|
||||
type: String,
|
||||
default: '',
|
||||
},
|
||||
/**窗口宽度 */
|
||||
width: {
|
||||
type: [String, Number],
|
||||
default: '520px',
|
||||
},
|
||||
bodyStyle: {
|
||||
type: Object,
|
||||
default: {},
|
||||
},
|
||||
keyboard: {
|
||||
type: Boolean,
|
||||
default: true,
|
||||
},
|
||||
mask: {
|
||||
type: Boolean,
|
||||
default: true,
|
||||
},
|
||||
maskClosable: {
|
||||
type: Boolean,
|
||||
default: true,
|
||||
},
|
||||
maskStyle: {
|
||||
type: Object,
|
||||
default: {},
|
||||
},
|
||||
destroyOnClose: {
|
||||
type: Boolean,
|
||||
default: false,
|
||||
},
|
||||
confirmLoading: {
|
||||
type: Boolean,
|
||||
default: false,
|
||||
},
|
||||
footer: {
|
||||
type: Object as any,
|
||||
},
|
||||
});
|
||||
|
||||
// 对标题进行监听
|
||||
const modalTitleRef = ref<HTMLElement | null>(null);
|
||||
const { x, y, isDragging } = useDraggable(modalTitleRef);
|
||||
|
||||
const startX = ref<number>(0);
|
||||
const startY = ref<number>(0);
|
||||
const startedDrag = ref(false);
|
||||
const transformX = ref(0);
|
||||
const transformY = ref(0);
|
||||
const preTransformX = ref(0);
|
||||
const preTransformY = ref(0);
|
||||
const dragRect = ref({ left: 0, right: 0, top: 0, bottom: 0 });
|
||||
|
||||
watch([x, y], () => {
|
||||
if (!startedDrag.value) {
|
||||
startX.value = x.value;
|
||||
startY.value = y.value;
|
||||
const bodyRect = document.body.getBoundingClientRect();
|
||||
const titleRectEl = modalTitleRef.value;
|
||||
if (titleRectEl) {
|
||||
const titleRect = titleRectEl.getBoundingClientRect();
|
||||
dragRect.value.right = bodyRect.width - (titleRect.width + 24);
|
||||
dragRect.value.bottom = bodyRect.height - (titleRect.height + 16);
|
||||
}
|
||||
preTransformX.value = transformX.value;
|
||||
preTransformY.value = transformY.value;
|
||||
}
|
||||
startedDrag.value = true;
|
||||
});
|
||||
|
||||
watchEffect(() => {
|
||||
if (!isDragging.value) {
|
||||
startedDrag.value = false;
|
||||
}
|
||||
if (startedDrag.value) {
|
||||
const dragRectX = Math.min(
|
||||
Math.max(dragRect.value.left + 24, x.value),
|
||||
dragRect.value.right
|
||||
);
|
||||
transformX.value = preTransformX.value + dragRectX - startX.value;
|
||||
|
||||
const dragRectY = Math.min(
|
||||
Math.max(dragRect.value.top + 16, y.value),
|
||||
dragRect.value.bottom
|
||||
);
|
||||
transformY.value = preTransformY.value + dragRectY - startY.value;
|
||||
}
|
||||
});
|
||||
|
||||
// 位移
|
||||
const transformStyle = computed<CSSProperties>(() => {
|
||||
return {
|
||||
transform: `translate(${transformX.value}px, ${transformY.value}px)`,
|
||||
};
|
||||
});
|
||||
|
||||
/**监听是否显示,位置还原 */
|
||||
watch(
|
||||
() => props.visible,
|
||||
val => {
|
||||
if (val) {
|
||||
transformX.value = 0;
|
||||
transformY.value = 0;
|
||||
}
|
||||
}
|
||||
);
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<a-modal
|
||||
wrapClassName="draggable-modal"
|
||||
:width="props.width"
|
||||
:keyboard="props.keyboard"
|
||||
:mask="props.mask"
|
||||
:mask-closable="props.maskClosable"
|
||||
:visible="props.visible"
|
||||
:confirm-loading="props.confirmLoading"
|
||||
:body-style="props.bodyStyle"
|
||||
:mask-style="props.maskStyle"
|
||||
:destroy-on-close="props.destroyOnClose"
|
||||
:footer="props.footer"
|
||||
@ok="(e:any) => emit('ok', e)"
|
||||
@cancel="(e:any) => emit('cancel', e)"
|
||||
>
|
||||
<template #title>
|
||||
<div
|
||||
ref="modalTitleRef"
|
||||
class="draggable-modal-title"
|
||||
v-text="title"
|
||||
></div>
|
||||
</template>
|
||||
<template #modalRender="{ originVNode }">
|
||||
<div :style="transformStyle">
|
||||
<component :is="originVNode" />
|
||||
</div>
|
||||
</template>
|
||||
<slot></slot>
|
||||
</a-modal>
|
||||
</template>
|
||||
|
||||
<style lang="less">
|
||||
.draggable-modal {
|
||||
// 穿透选择文字
|
||||
// 给a-modal设置 get-container=".ant-pro-page-container"
|
||||
// 防止跳转显示
|
||||
// &.ant-modal-wrap {
|
||||
// pointer-events: none;
|
||||
// }
|
||||
&-title {
|
||||
width: 100%;
|
||||
cursor: move;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -35,19 +35,22 @@ const props = defineProps({
|
||||
|
||||
/**弹框关闭事件 */
|
||||
function fnModalClose() {
|
||||
if(props.loading) return
|
||||
if (props.loading) return;
|
||||
emit('close');
|
||||
}
|
||||
|
||||
/**上传前检查或转换压缩 */
|
||||
function fnBeforeUpload(file: FileType) {
|
||||
if (props.loading) return false;
|
||||
// 检查文件大小
|
||||
if (props.size > 0) {
|
||||
// 检查文件大小
|
||||
if (props.size > 0) {
|
||||
const fileSize = file.size;
|
||||
const isLtM = fileSize / 1024 / 1024 < props.size;
|
||||
if (!isLtM) {
|
||||
message.error(`${t('components.UploadModal.allowFilter')} ${props.size}MB`, 3);
|
||||
message.error(
|
||||
`${t('components.UploadModal.allowFilter')} ${props.size}MB`,
|
||||
3
|
||||
);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -56,7 +59,10 @@ function fnBeforeUpload(file: FileType) {
|
||||
const fileName = file.name;
|
||||
const isAllowType = props.ext.some(v => fileName.endsWith(v));
|
||||
if (!isAllowType) {
|
||||
message.error(`${t('components.UploadModal.onlyAllow')} ${props.ext.join('、')}`, 3);
|
||||
message.error(
|
||||
`${t('components.UploadModal.onlyAllow')} ${props.ext.join('、')}`,
|
||||
3
|
||||
);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -65,13 +71,14 @@ function fnBeforeUpload(file: FileType) {
|
||||
|
||||
/**上传请求发出 */
|
||||
function fnUpload(up: UploadRequestOption) {
|
||||
emit('upload', up.file)
|
||||
emit('upload', up.file);
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<a-modal
|
||||
width="500px"
|
||||
<ProModal
|
||||
:drag="true"
|
||||
:destroyOnClose="true"
|
||||
:title="props.title"
|
||||
:visible="props.visible"
|
||||
:keyboard="false"
|
||||
@@ -93,20 +100,26 @@ function fnUpload(up: UploadRequestOption) {
|
||||
<p class="ant-upload-drag-icon">
|
||||
<inbox-outlined></inbox-outlined>
|
||||
</p>
|
||||
<p class="ant-upload-text">{{t('components.UploadModal.uploadTip')}}</p>
|
||||
<p class="ant-upload-text">
|
||||
{{ t('components.UploadModal.uploadTip') }}
|
||||
</p>
|
||||
<p class="ant-upload-hint">
|
||||
<div v-if="props.size > 0">
|
||||
{{t('components.UploadModal.allowSize')}} {{ props.size }} MB
|
||||
</div>
|
||||
<div v-if="props.ext.length > 0">
|
||||
{{t('components.UploadModal.allowFormat')}} {{ props.ext.join('、') }}
|
||||
|
||||
</div>
|
||||
<template v-if="props.size > 0">
|
||||
<div>
|
||||
{{ t('components.UploadModal.allowSize') }} {{ props.size }} MB
|
||||
</div>
|
||||
</template>
|
||||
<template v-if="props.ext.length > 0">
|
||||
<div>
|
||||
{{ t('components.UploadModal.allowFormat') }}
|
||||
{{ props.ext.join('、') }}
|
||||
</div>
|
||||
</template>
|
||||
</p>
|
||||
</a-upload-dragger>
|
||||
<slot></slot>
|
||||
</a-space>
|
||||
</a-modal>
|
||||
</ProModal>
|
||||
</template>
|
||||
|
||||
<style lang="less" scoped></style>
|
||||
|
||||
Reference in New Issue
Block a user