SubDialog.vue 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. <template>
  2. <el-dialog
  3. :model-value="modelValue"
  4. @update:model-value="$emit('update:modelValue', $event)"
  5. align-center
  6. :modal="false"
  7. :close-on-click-modal="false"
  8. :append-to-body="true"
  9. draggable
  10. :fullscreen="false"
  11. :modal-append-to-body="false"
  12. :modal-class="modalClass"
  13. :width="width"
  14. :class="dialogClass"
  15. :style="{ height: height }"
  16. :before-close="handleBeforeClose"
  17. >
  18. <template #header="{ titleId, titleClass }">
  19. <div class="my-header">
  20. <h4 :id="titleId" :class="titleClass">{{ title }}</h4>
  21. </div>
  22. </template>
  23. <!-- 内容插槽 -->
  24. <div class="dialog-content" :style="{ height: contentHeight }">
  25. <slot></slot>
  26. </div>
  27. <template #footer>
  28. <span class="dialog-footer">
  29. <el-button @click="handleCancel">取消</el-button>
  30. <el-button type="primary" @click="handleConfirm">
  31. 确认
  32. </el-button>
  33. </span>
  34. </template>
  35. </el-dialog>
  36. </template>
  37. <script setup>
  38. import { defineProps, defineEmits } from 'vue'
  39. const props = defineProps({
  40. modelValue: {
  41. type: Boolean,
  42. default: false
  43. },
  44. title: {
  45. type: String,
  46. default: '弹窗标题'
  47. },
  48. width: {
  49. type: String,
  50. default: '450'
  51. },
  52. height: {
  53. type: String,
  54. default: 'auto'
  55. },
  56. contentHeight: {
  57. type: String,
  58. default: 'calc(100% - 110px)'
  59. },
  60. modalClass: {
  61. type: String,
  62. default: 'summary-dlg'
  63. },
  64. dialogClass: {
  65. type: String,
  66. default: 'dialog_class bgcolor tianjia'
  67. }
  68. })
  69. const emit = defineEmits(['update:modelValue', 'confirm', 'cancel'])
  70. const handleBeforeClose = (done) => {
  71. emit('cancel')
  72. done()
  73. }
  74. const handleCancel = () => {
  75. emit('update:modelValue', false)
  76. emit('cancel')
  77. }
  78. const handleConfirm = () => {
  79. emit('confirm')
  80. emit('update:modelValue', false)
  81. }
  82. </script>
  83. <style scoped>
  84. .dialog-content {
  85. overflow-y: auto; /* 只允许垂直滚动 */
  86. overflow-x: hidden; /* 禁止水平滚动 */
  87. padding: 10px 0;
  88. width: 100%;
  89. box-sizing: border-box; /* 确保padding不增加总宽度 */
  90. }
  91. </style>