ConfirmDialog.vue 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <template>
  2. <el-dialog
  3. :title="title"
  4. v-model="visible"
  5. width="30%"
  6. :before-close="handleClose"
  7. >
  8. <p>{{ message }}</p>
  9. <template #footer>
  10. <span class="dialog-footer">
  11. <el-button @click="handleCancel">取 消</el-button>
  12. <el-button type="primary" @click="handleConfirm">确 定</el-button>
  13. </span>
  14. </template>
  15. </el-dialog>
  16. </template>
  17. <script setup>
  18. import { ref, watch, toRefs } from 'vue';
  19. import { ElMessage } from 'element-plus';
  20. const props = defineProps({
  21. modelValue: {
  22. type: Boolean,
  23. default: false
  24. },
  25. title: {
  26. type: String,
  27. default: '确认操作'
  28. },
  29. objId: {
  30. type: String,
  31. default: 0
  32. },
  33. message: {
  34. type: String,
  35. default: '您确定要执行此操作吗?'
  36. }
  37. });
  38. const emit = defineEmits(['update:modelValue', 'confirm', 'cancel']);
  39. const visible = ref(props.modelValue);
  40. watch(() => props.modelValue, (newValue) => {
  41. visible.value = newValue;
  42. });
  43. const handleClose = (done) => {
  44. emit('update:modelValue', false);
  45. done();
  46. };
  47. const handleConfirm = () => {
  48. emit('confirm');
  49. emit('update:modelValue', false);
  50. };
  51. const handleCancel = () => {
  52. emit('cancel');
  53. emit('update:modelValue', false);
  54. };
  55. </script>
  56. <style scoped>
  57. /* 添加样式 */
  58. </style>