84 lines
1.7 KiB
Vue
Raw Normal View History

2025-10-31 16:16:56 +08:00
<template>
2025-11-03 17:56:26 +08:00
<el-dialog
:visible.sync="visible"
:title="title"
:width="width"
destroy-on-close
>
<component
v-if="dynamicComponent"
:is="dynamicComponent"
ref="dynamicComponentRef"
v-bind="componentProps"
/>
2025-11-13 17:03:24 +08:00
<slot></slot>
2025-10-31 16:16:56 +08:00
<template #footer>
<div class="dialog-footer">
2025-11-14 14:58:33 +08:00
<el-button class="button" size="large" type="primary" @click="onConfirm"> {{ onConfirmName }} </el-button>
<el-button class="button" size="large" @click="onCancel"> {{ onCancelName }} </el-button>
2025-10-31 16:16:56 +08:00
</div>
</template>
</el-dialog>
</template>
<script setup>
2025-11-03 17:56:26 +08:00
import { computed, ref, } from "vue";
const dynamicComponentRef = ref(null);
defineExpose({
dynamicComponentRef // 暴露给父组件
});
2025-10-31 16:16:56 +08:00
const props = defineProps({
visible: {
type: Boolean,
default: false,
},
width: {
type: String,
default: "50%",
},
title: {
type: String,
default: "",
},
2025-11-03 17:56:26 +08:00
dynamicComponent: {
type: [Object, Function],
default: null,
},
componentProps: {
type: Object,
default: () => ({}),
},
2025-10-31 16:16:56 +08:00
onConfirm: {
type: Function,
default: () => {},
},
onCancel: {
type: Function,
default: () => {},
},
onConfirmName: {
type: String,
2025-11-14 14:58:33 +08:00
default: "保存",
},
onCancelName: {
type: String,
default: "取消",
}
2025-10-31 16:16:56 +08:00
});
2025-11-03 17:56:26 +08:00
const normalizedComponent = computed(() =>
props.dynamicComponent ? markRaw(props.dynamicComponent) : null
);
2025-10-31 16:16:56 +08:00
</script>
2025-11-14 14:58:33 +08:00
<style lang="scss" scoped>
.dialog-footer {
display: flex;
justify-content: center;
.button {
width: 150px;
}
}
2025-10-31 16:16:56 +08:00
</style>