|
@@ -1,5 +1,5 @@
|
|
|
<template>
|
|
|
- <el-dialog v-bind="megeProps" :fullscreen="fullscreen" class="com-dialog">
|
|
|
+ <el-dialog v-bind="megeProps" :fullscreen="fullscreen" :class="['com-dialog',customClass]">
|
|
|
<template #header v-if="props.header !== false">
|
|
|
<el-row>
|
|
|
<div class="el-dialog__title zt-dialog__title">
|
|
@@ -12,10 +12,20 @@
|
|
|
/>
|
|
|
</div>
|
|
|
<el-space size="default">
|
|
|
- <button type="button" class="el-dialog__headerbtn" @click="fullscreen = !fullscreen" v-if="props.showFullscreen">
|
|
|
+ <button
|
|
|
+ type="button"
|
|
|
+ class="el-dialog__headerbtn"
|
|
|
+ @click="fullscreen = !fullscreen"
|
|
|
+ v-if="props.showFullscreen"
|
|
|
+ >
|
|
|
<el-icon class="el-dialog__close"><FullScreen /></el-icon>
|
|
|
</button>
|
|
|
- <button type="button" class="el-dialog__headerbtn" @click="dialogVisible = false" v-if="props.showClose">
|
|
|
+ <button
|
|
|
+ type="button"
|
|
|
+ class="el-dialog__headerbtn"
|
|
|
+ @click="dialogVisible = false"
|
|
|
+ v-if="props.showClose"
|
|
|
+ >
|
|
|
<el-icon class="el-dialog__close"><Close /></el-icon>
|
|
|
</button>
|
|
|
</el-space>
|
|
@@ -49,31 +59,42 @@
|
|
|
</el-dialog>
|
|
|
</template>
|
|
|
<script setup lang="ts">
|
|
|
-import { defineProps, defineSlots, computed, ref, type VNode, useAttrs,watch,nextTick } from 'vue'
|
|
|
-import type { ButtonProps } from 'element-plus'
|
|
|
-import { DialogModalProps } from './props'
|
|
|
-import { Close, FullScreen } from '@element-plus/icons-vue'
|
|
|
-import { BasicHelp } from '@/components/helpMessage'
|
|
|
-import { isNumber } from '@/utils/is'
|
|
|
+import {
|
|
|
+ defineProps,
|
|
|
+ defineSlots,
|
|
|
+ computed,
|
|
|
+ ref,
|
|
|
+ type VNode,
|
|
|
+ useAttrs,
|
|
|
+ watch,
|
|
|
+ nextTick,
|
|
|
+ unref
|
|
|
+} from 'vue';
|
|
|
+import type { ButtonProps } from 'element-plus';
|
|
|
+import { DialogModalProps } from './props';
|
|
|
+import { Close, FullScreen } from '@element-plus/icons-vue';
|
|
|
+import { BasicHelp } from '@/components/helpMessage';
|
|
|
+import { isNumber } from '@/utils/is';
|
|
|
|
|
|
defineOptions({
|
|
|
- name: 'Dialog'
|
|
|
-})
|
|
|
+ name: 'Dialog',
|
|
|
+});
|
|
|
|
|
|
interface Props extends DialogModalProps {
|
|
|
- footer?: boolean | (() => VNode)
|
|
|
- okText?: string
|
|
|
- cancelText?: string
|
|
|
- okButtonProps?: Partial<ButtonProps>
|
|
|
- cancelButtonProps?: Partial<ButtonProps>
|
|
|
- onOk?: () => void
|
|
|
- onBeforeOk?: () => Promise<boolean>
|
|
|
- onCancel?: () => void
|
|
|
- lockScroll?: boolean
|
|
|
- closeOnClickModal?: boolean
|
|
|
- closeOnPressEscape?: boolean
|
|
|
- modal?: boolean
|
|
|
- showFullscreen?: boolean
|
|
|
+ footer?: boolean | (() => VNode);
|
|
|
+ okText?: string;
|
|
|
+ cancelText?: string;
|
|
|
+ okButtonProps?: Partial<ButtonProps>;
|
|
|
+ cancelButtonProps?: Partial<ButtonProps>;
|
|
|
+ onOk?: () => void;
|
|
|
+ onBeforeOk?: () => Promise<boolean>;
|
|
|
+ onCancel?: () => void;
|
|
|
+ lockScroll?: boolean;
|
|
|
+ closeOnClickModal?: boolean;
|
|
|
+ closeOnPressEscape?: boolean;
|
|
|
+ modal?: boolean;
|
|
|
+ showFullscreen?: boolean;
|
|
|
+ customClass?: string;
|
|
|
}
|
|
|
|
|
|
const props = withDefaults(defineProps<Props>(), {
|
|
@@ -85,80 +106,89 @@ const props = withDefaults(defineProps<Props>(), {
|
|
|
closeOnClickModal: true,
|
|
|
closeOnPressEscape: true,
|
|
|
modal: true,
|
|
|
- showFullscreen: true
|
|
|
-})
|
|
|
+ showFullscreen: true,
|
|
|
+ customClass: '', // 默认为空
|
|
|
+});
|
|
|
+
|
|
|
+setTimeout(() => {
|
|
|
+ console.log(props.modalClass);
|
|
|
+}, 1000);
|
|
|
|
|
|
-const attrs = useAttrs()
|
|
|
+const attrs = useAttrs();
|
|
|
|
|
|
const megeProps = computed(() => {
|
|
|
return {
|
|
|
...props,
|
|
|
- ...attrs
|
|
|
- }
|
|
|
-})
|
|
|
+ ...attrs,
|
|
|
+ };
|
|
|
+});
|
|
|
|
|
|
defineSlots<{
|
|
|
- title: () => VNode
|
|
|
- footer: () => VNode
|
|
|
- default: () => VNode
|
|
|
-}>()
|
|
|
+ title: () => VNode;
|
|
|
+ footer: () => VNode;
|
|
|
+ default: () => VNode;
|
|
|
+}>();
|
|
|
|
|
|
-const okLoading = ref(false)
|
|
|
-const fullscreen = ref(false)
|
|
|
+const okLoading = ref(false);
|
|
|
+const fullscreen = ref(false);
|
|
|
|
|
|
-const dialogHeight = ref(isNumber(props.maxHeight) ? `${props.maxHeight}px` : props.maxHeight)
|
|
|
+const dialogHeight = ref(
|
|
|
+ isNumber(props.maxHeight) ? `${props.maxHeight}px` : props.maxHeight,
|
|
|
+);
|
|
|
|
|
|
watch(
|
|
|
() => fullscreen.value,
|
|
|
async (val: boolean) => {
|
|
|
- await nextTick()
|
|
|
+ await nextTick();
|
|
|
if (val) {
|
|
|
- const windowHeight = document.documentElement.offsetHeight
|
|
|
- dialogHeight.value = `${windowHeight - 55 - 60 - (props.footer ? 63 : 0)}px`
|
|
|
+ const windowHeight = document.documentElement.offsetHeight;
|
|
|
+ dialogHeight.value = `${windowHeight - 55 - 60 - (props.footer ? 63 : 0)}px`;
|
|
|
} else {
|
|
|
- dialogHeight.value = isNumber(props.maxHeight) ? `${props.maxHeight}px` : props.maxHeight
|
|
|
+ dialogHeight.value = isNumber(props.maxHeight)
|
|
|
+ ? `${props.maxHeight}px`
|
|
|
+ : props.maxHeight;
|
|
|
}
|
|
|
},
|
|
|
{
|
|
|
- immediate: true
|
|
|
- }
|
|
|
-)
|
|
|
+ immediate: true,
|
|
|
+ },
|
|
|
+);
|
|
|
|
|
|
const dialogStyle = computed(() => {
|
|
|
return {
|
|
|
- height: unref(dialogHeight)
|
|
|
- }
|
|
|
-})
|
|
|
+ height: unref(dialogHeight),
|
|
|
+ };
|
|
|
+});
|
|
|
|
|
|
-const emit = defineEmits(['update:modelValue'])
|
|
|
+const emit = defineEmits(['update:modelValue']);
|
|
|
|
|
|
const dialogVisible = defineModel('modelValue', {
|
|
|
type: Boolean,
|
|
|
- default: false
|
|
|
-})
|
|
|
+ default: false,
|
|
|
+});
|
|
|
|
|
|
const handleOk = async () => {
|
|
|
if (props.onBeforeOk) {
|
|
|
try {
|
|
|
- okLoading.value = true
|
|
|
- const flag = await props.onBeforeOk()
|
|
|
+ okLoading.value = true;
|
|
|
+ const flag = await props.onBeforeOk();
|
|
|
if (flag) {
|
|
|
- okLoading.value = false
|
|
|
- dialogVisible.value = false
|
|
|
+ okLoading.value = false;
|
|
|
+ dialogVisible.value = false;
|
|
|
}
|
|
|
} catch (error) {
|
|
|
- okLoading.value = false
|
|
|
+ okLoading.value = false;
|
|
|
}
|
|
|
} else {
|
|
|
- props.onOk?.()
|
|
|
- dialogVisible.value = false
|
|
|
+ props.onOk?.();
|
|
|
+ dialogVisible.value = false;
|
|
|
}
|
|
|
-}
|
|
|
+};
|
|
|
|
|
|
const handleCancel = () => {
|
|
|
- props.onCancel?.()
|
|
|
- dialogVisible.value = false
|
|
|
-}
|
|
|
+ props.onCancel?.();
|
|
|
+ dialogVisible.value = false;
|
|
|
+};
|
|
|
</script>
|
|
|
<style lang="scss" scoped>
|
|
|
:deep(.el-dialog__headerbtn) {
|
|
@@ -168,6 +198,7 @@ const handleCancel = () => {
|
|
|
}
|
|
|
|
|
|
.com-dialog {
|
|
|
+
|
|
|
.#{$elNamespace}-overlay-dialog {
|
|
|
display: flex;
|
|
|
justify-content: center;
|