|
@@ -7,7 +7,7 @@
|
|
|
<transition name="bounceModalFrame" @afterLeave="unmount">
|
|
|
<div v-show="show" class="modalFrame" :class="props.className" @click="handleMaskClose">
|
|
|
<div class="animationBox">
|
|
|
- <div class="modalFrameBox" :style="modalFrameStyle" @click.stop>
|
|
|
+ <div ref="modalFrameBoxDom" class="modalFrameBox" :style="modalFrameStyle" @click.stop>
|
|
|
<div ref="modalFrameTitleDom" class="modalFrameTitle" :class="{ noMove: !props.draggable }">
|
|
|
<span>{{ props.title }}</span>
|
|
|
<el-icon class="icon" @click="close"><Close /></el-icon>
|
|
@@ -33,7 +33,7 @@
|
|
|
<script setup lang="ts">
|
|
|
import { Close } from "@element-plus/icons-vue"
|
|
|
import { addClass, removeClass } from "@/libs/tools"
|
|
|
-import { ref, computed, onMounted, nextTick, DefineComponent, ComponentPublicInstance, App } from "vue"
|
|
|
+import { ref, computed, onMounted, DefineComponent, ComponentPublicInstance, App } from "vue"
|
|
|
|
|
|
interface modalFrameDataType {
|
|
|
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
@@ -71,6 +71,7 @@ const show = ref(false) //控制动画显示隐藏
|
|
|
const vm = ref<ComponentPublicInstance>()
|
|
|
const vmApp = ref<App<Element>>()
|
|
|
const modalFrameTitleDom = ref<HTMLDivElement>()
|
|
|
+const modalFrameBoxDom = ref<HTMLDivElement>()
|
|
|
const templateModal = ref<ComponentPublicInstance>()
|
|
|
//计算按钮是否显示
|
|
|
const filterBtnShow = computed(() => {
|
|
@@ -111,14 +112,12 @@ function computePos(type: "width" | "height", value: number | string) {
|
|
|
}
|
|
|
onMounted(() => {
|
|
|
addClass(bodyDom, name)
|
|
|
- props.draggable &&
|
|
|
- nextTick(() => {
|
|
|
- drag(modalFrameTitleDom.value!)
|
|
|
- })
|
|
|
+ props.draggable && drag(modalFrameTitleDom.value!)
|
|
|
+ window.addEventListener("resize", refreshPos)
|
|
|
})
|
|
|
function drag(el: HTMLElement) {
|
|
|
function mousedown(e: MouseEvent) {
|
|
|
- const parentElement = el.parentElement!
|
|
|
+ const parentElement = modalFrameBoxDom.value!
|
|
|
const parentElementRect = parentElement.getBoundingClientRect()
|
|
|
const downX = e.clientX
|
|
|
const downY = e.clientY
|
|
@@ -144,6 +143,14 @@ function drag(el: HTMLElement) {
|
|
|
}
|
|
|
el.addEventListener("mousedown", mousedown)
|
|
|
}
|
|
|
+//重新计算位置 居中
|
|
|
+function refreshPos() {
|
|
|
+ const posWidth = computePos("width", props.width)
|
|
|
+ const posHeight = computePos("height", props.height)
|
|
|
+ if (modalFrameBoxDom.value) {
|
|
|
+ modalFrameBoxDom.value.style.transform = `translate(${posWidth.pos}px, ${posHeight.pos}px)`
|
|
|
+ }
|
|
|
+}
|
|
|
//取消按钮
|
|
|
function cancel() {
|
|
|
if (props.onCancel) {
|
|
@@ -179,6 +186,7 @@ function remove() {
|
|
|
show.value = false
|
|
|
}
|
|
|
function unmount() {
|
|
|
+ window.removeEventListener("resize", refreshPos)
|
|
|
vm.value && bodyDom!.removeChild(vm.value.$el)
|
|
|
vmApp.value?.unmount()
|
|
|
removeClass(bodyDom, name)
|