<template>
|
<el-dialog
|
v-model="dialogVisible"
|
:title="computedTitle"
|
:width="width"
|
@close="handleClose"
|
>
|
<slot></slot>
|
<template #footer>
|
<div class="dialog-footer">
|
<el-button type="primary" @click="handleConfirm">确认</el-button>
|
<el-button @click="handleCancel">取消</el-button>
|
</div>
|
</template>
|
</el-dialog>
|
</template>
|
|
<script setup>
|
import { computed } from 'vue'
|
|
const props = defineProps({
|
modelValue: {
|
type: Boolean,
|
default: false
|
},
|
title: {
|
type: [String, Function],
|
default: ''
|
},
|
operationType: {
|
type: String,
|
default: ''
|
},
|
width: {
|
type: String,
|
default: '70%'
|
}
|
})
|
|
const emit = defineEmits(['update:modelValue', 'close', 'confirm', 'cancel'])
|
|
const dialogVisible = computed({
|
get: () => props.modelValue,
|
set: (val) => emit('update:modelValue', val)
|
})
|
|
const computedTitle = computed(() => {
|
if (typeof props.title === 'function') {
|
return props.title(props.operationType)
|
}
|
return props.title
|
})
|
|
const handleClose = () => {
|
emit('close')
|
}
|
|
const handleConfirm = () => {
|
emit('confirm')
|
}
|
|
const handleCancel = () => {
|
emit('cancel')
|
dialogVisible.value = false
|
}
|
</script>
|
|
<style scoped>
|
.dialog-footer {
|
text-align: center;
|
}
|
</style>
|