ConfirmDialog.vue 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. <template>
  2. <Modal
  3. :visible="visible"
  4. :width="width"
  5. :closeButton="false"
  6. :closeOnClickMask="closeOnClickMask"
  7. :closeOnEsc="closeOnEsc"
  8. @update:visible="handleVisibleChange"
  9. >
  10. <div class="confirm-dialog">
  11. <div class="confirm-dialog__title">{{ title }}</div>
  12. <div class="confirm-dialog__content">
  13. <slot>{{ content }}</slot>
  14. </div>
  15. <div class="confirm-dialog__footer">
  16. <Button type="default" @click="handleCancel">{{ cancelText }}</Button>
  17. <Button type="primary" @click="handleConfirm">{{ confirmText }}</Button>
  18. </div>
  19. </div>
  20. </Modal>
  21. </template>
  22. <script lang="ts" setup>
  23. import Modal from '@/components/Modal.vue'
  24. import Button from '@/components/Button.vue'
  25. const props = withDefaults(defineProps<{
  26. visible: boolean
  27. title?: string
  28. content?: string
  29. confirmText?: string
  30. cancelText?: string
  31. width?: number
  32. closeOnClickMask?: boolean
  33. closeOnEsc?: boolean
  34. }>(), {
  35. title: '提示',
  36. content: '',
  37. confirmText: '确认',
  38. cancelText: '取消',
  39. width: 420,
  40. closeOnClickMask: false,
  41. closeOnEsc: false,
  42. })
  43. const emit = defineEmits<{
  44. (event: 'update:visible', payload: boolean): void
  45. (event: 'confirm'): void
  46. (event: 'cancel'): void
  47. }>()
  48. const handleVisibleChange = (val: boolean) => {
  49. emit('update:visible', val)
  50. }
  51. const handleConfirm = () => {
  52. emit('confirm')
  53. emit('update:visible', false)
  54. }
  55. const handleCancel = () => {
  56. emit('cancel')
  57. emit('update:visible', false)
  58. }
  59. </script>
  60. <style lang="scss" scoped>
  61. .confirm-dialog {
  62. display: flex;
  63. flex-direction: column;
  64. gap: 16px;
  65. }
  66. .confirm-dialog__title {
  67. font-size: 16px;
  68. font-weight: 500;
  69. color: #333;
  70. }
  71. .confirm-dialog__content {
  72. font-size: 14px;
  73. color: #666;
  74. line-height: 1.5;
  75. }
  76. .confirm-dialog__footer {
  77. display: flex;
  78. justify-content: flex-end;
  79. gap: 12px;
  80. }
  81. </style>