index.vue 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. <template>
  2. <el-dialog
  3. v-model="dialogVisible"
  4. :align-center="alignCenter"
  5. :append-to="appendTo"
  6. :append-to-body="appendToBody"
  7. :before-close="beforeClose"
  8. :center="center"
  9. :class="'vab-dialog-' + theme"
  10. :close-on-click-modal="closeOnClickModal"
  11. :close-on-press-escape="closeOnPressEscape"
  12. :destroy-on-close="destroyOnClose"
  13. :draggable="draggable"
  14. :fullscreen="isFullscreen"
  15. :lock-scroll="lockScroll"
  16. :modal="modal"
  17. :modal-class="modalClass"
  18. :open-delay="openDelay"
  19. :overflow="overflow"
  20. :show-close="showClose"
  21. :style="{
  22. transition: animated ? 'all 0.3s cubic-bezier(0.645, 0.045, 0.355, 1),transform 0s' : '',
  23. }"
  24. :top="top"
  25. :width="width"
  26. v-bind="$attrs"
  27. >
  28. <template #header>
  29. <slot name="header">
  30. <div class="el-dialog__title" @dblclick="setFullscreen">{{ title }}</div>
  31. </slot>
  32. <button v-if="showClose" class="el-dialog__headerbtn" type="button" @click="closeDialog">
  33. <el-icon class="el-dialog__close">
  34. <close />
  35. </el-icon>
  36. </button>
  37. <button v-if="showFullscreen" class="el-dialog__headerbtn" style="right: 51px" type="button" @click="setFullscreen">
  38. <vab-icon class="el-dialog__close el-dialog__fullscreen" :icon="isFullscreen ? 'fullscreen-exit-fill' : 'fullscreen-fill'" />
  39. </button>
  40. </template>
  41. <div v-loading="loading">
  42. <slot></slot>
  43. </div>
  44. <template #footer>
  45. <slot name="footer"></slot>
  46. </template>
  47. </el-dialog>
  48. </template>
  49. <script lang="ts" setup>
  50. import { Close } from '@element-plus/icons-vue'
  51. import { ElDialog } from 'element-plus'
  52. defineOptions({
  53. name: 'VabDialog',
  54. })
  55. const props = defineProps({
  56. ...ElDialog.props,
  57. modelValue: {
  58. type: Boolean,
  59. default: false,
  60. },
  61. showFullscreen: {
  62. type: Boolean,
  63. default: true,
  64. },
  65. fullscreen: {
  66. type: Boolean,
  67. default: false,
  68. },
  69. loading: {
  70. type: Boolean,
  71. default: false,
  72. },
  73. animated: {
  74. type: Boolean,
  75. default: true,
  76. },
  77. closeOnClickModal: {
  78. type: Boolean,
  79. default: false,
  80. },
  81. closeOnPressEscape: {
  82. type: Boolean,
  83. default: false,
  84. },
  85. theme: {
  86. type: String,
  87. default: 'default', //支持default、plain、primary三种
  88. },
  89. draggable: {
  90. type: Boolean,
  91. default: true,
  92. },
  93. })
  94. const emit = defineEmits(['update:modelValue'])
  95. const dialogVisible = useVModel(props, 'modelValue', emit)
  96. const isFullscreen = ref<any>(false)
  97. const closeDialog = () => {
  98. dialogVisible.value = false
  99. isFullscreen.value = false
  100. }
  101. const setFullscreen = () => {
  102. isFullscreen.value = !isFullscreen.value
  103. }
  104. watch(
  105. props,
  106. () => {
  107. isFullscreen.value = props.fullscreen
  108. },
  109. {
  110. immediate: true,
  111. }
  112. )
  113. </script>