|
@@ -1,11 +1,19 @@
|
|
|
<template>
|
|
<template>
|
|
|
<a-modal
|
|
<a-modal
|
|
|
- :visible="true"
|
|
|
|
|
ref="modalRef"
|
|
ref="modalRef"
|
|
|
:wrap-style="{ overflow: 'hidden' }"
|
|
:wrap-style="{ overflow: 'hidden' }"
|
|
|
|
|
+ @ok="handleOk"
|
|
|
|
|
+ @cancel="close"
|
|
|
|
|
+ :closable="false"
|
|
|
|
|
+ :confirmLoading="state.confirmLoading"
|
|
|
|
|
+ v-bind="{
|
|
|
|
|
+ cancelText: '取消',
|
|
|
|
|
+ okText: '确定',
|
|
|
|
|
+ ...propsState
|
|
|
|
|
+ }"
|
|
|
>
|
|
>
|
|
|
<template #title>
|
|
<template #title>
|
|
|
- <div ref="modalTitleRef" style="width: 100%; cursor: move">{{title}}</div>
|
|
|
|
|
|
|
+ <div ref="modalTitleRef" style="width: 100%; cursor: move">{{propsState.label || 'model'}}</div>
|
|
|
</template>
|
|
</template>
|
|
|
<template #modalRender="{ originVNode }">
|
|
<template #modalRender="{ originVNode }">
|
|
|
<div :style="transformStyle">
|
|
<div :style="transformStyle">
|
|
@@ -17,17 +25,52 @@
|
|
|
|
|
|
|
|
<script lang="ts" setup >
|
|
<script lang="ts" setup >
|
|
|
import { useDraggable } from '@vueuse/core'
|
|
import { useDraggable } from '@vueuse/core'
|
|
|
-import { ref, watch, watchEffect, computed, CSSProperties } from 'vue'
|
|
|
|
|
|
|
+import { ModalProps } from 'ant-design-vue'
|
|
|
|
|
+import { ref, watch, watchEffect, computed, CSSProperties, reactive, onMounted } from 'vue'
|
|
|
|
|
|
|
|
-export interface ModalProPorps {
|
|
|
|
|
- visible: boolean,
|
|
|
|
|
- title: string
|
|
|
|
|
|
|
+export interface ModalProPorps extends ModalProps {
|
|
|
|
|
+ label: string
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-const emit = defineEmits(['close'])
|
|
|
|
|
|
|
+export interface ModalOkProps {
|
|
|
|
|
+ confirmed: () => void
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+const emit = defineEmits<{
|
|
|
|
|
+ (e: 'close'): void
|
|
|
|
|
+ (e: 'ok', arg: ModalOkProps): void
|
|
|
|
|
+}>()
|
|
|
|
|
|
|
|
const props = defineProps<ModalProPorps>()
|
|
const props = defineProps<ModalProPorps>()
|
|
|
|
|
|
|
|
|
|
+const propsState = reactive(props)
|
|
|
|
|
+
|
|
|
|
|
+watch(
|
|
|
|
|
+ () => props.title,
|
|
|
|
|
+ () => {
|
|
|
|
|
+ propsState.label = props.title
|
|
|
|
|
+ delete propsState.title
|
|
|
|
|
+ },
|
|
|
|
|
+ {
|
|
|
|
|
+ immediate: true
|
|
|
|
|
+ }
|
|
|
|
|
+)
|
|
|
|
|
+
|
|
|
|
|
+interface StateProps {
|
|
|
|
|
+ confirmLoading: boolean
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+const state = reactive<Partial<StateProps>>({})
|
|
|
|
|
+
|
|
|
|
|
+const close = () => emit('close')
|
|
|
|
|
+
|
|
|
|
|
+const handleOk = () => {
|
|
|
|
|
+ state.confirmLoading = true
|
|
|
|
|
+ emit('ok', {
|
|
|
|
|
+ confirmed: () => state.confirmLoading = false
|
|
|
|
|
+ })
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
// 拖拽相关的代码
|
|
// 拖拽相关的代码
|
|
|
const modalTitleRef = ref()
|
|
const modalTitleRef = ref()
|
|
|
|
|
|
|
@@ -41,6 +84,7 @@ const transformY = ref(0)
|
|
|
const preTransformX = ref(0)
|
|
const preTransformX = ref(0)
|
|
|
const preTransformY = ref(0)
|
|
const preTransformY = ref(0)
|
|
|
const dragRect = ref({ left: 0, right: 0, top: 0, bottom: 0 })
|
|
const dragRect = ref({ left: 0, right: 0, top: 0, bottom: 0 })
|
|
|
|
|
+
|
|
|
watch([x, y], () => {
|
|
watch([x, y], () => {
|
|
|
if (!startedDrag.value) {
|
|
if (!startedDrag.value) {
|
|
|
startX.value = x.value
|
|
startX.value = x.value
|
|
@@ -80,6 +124,7 @@ const transformStyle = computed<CSSProperties>(() => {
|
|
|
}
|
|
}
|
|
|
})
|
|
})
|
|
|
// 拖拽相关的代码
|
|
// 拖拽相关的代码
|
|
|
|
|
+
|
|
|
</script>
|
|
</script>
|
|
|
|
|
|
|
|
<style>
|
|
<style>
|