index.vue 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. <template>
  2. <!-- 对话框共用组件 -->
  3. <v-dialog
  4. style="z-index: var(--zIndex-dialog)"
  5. v-model="show"
  6. persistent
  7. v-bind="$attrs"
  8. :fullscreen="props.showDrawer"
  9. :max-width="dialogWidth"
  10. :width="dialogWidth"
  11. >
  12. <v-card max-height="90vh" class="d-flex flex-column">
  13. <v-card-title :class="{'drawer': props.showDrawer}">
  14. <!-- text-h6 h5 -->
  15. <span class="d-flex align-center justify-space-between" :class="[props.titleClass]">
  16. {{ props.title }}
  17. <v-btn
  18. v-if="props.closeable"
  19. icon
  20. elevation="0"
  21. @click="handleClose"
  22. >
  23. <v-icon :color="props.showDrawer ? '#fff' : '#000'">
  24. mdi-close
  25. </v-icon>
  26. </v-btn>
  27. </span>
  28. </v-card-title>
  29. <v-divider></v-divider>
  30. <v-card-text class="flex-grow-1 overflow-y-auto" :class="{ 'd-flex': props.flexBox }" :style="props.bodyStyle">
  31. <slot></slot>
  32. </v-card-text>
  33. <template v-if="props.footer">
  34. <v-divider></v-divider>
  35. <v-card-actions>
  36. <v-spacer></v-spacer>
  37. <v-btn
  38. v-if="props.closeable"
  39. color="primary"
  40. text
  41. @click="handleClose"
  42. >
  43. {{ closeText }}
  44. </v-btn>
  45. <v-btn
  46. color="primary"
  47. text
  48. @click="handleSave"
  49. >
  50. {{ props.submitText }}
  51. </v-btn>
  52. </v-card-actions>
  53. </template>
  54. <template v-else>
  55. <slot name="footer"></slot>
  56. </template>
  57. </v-card>
  58. </v-dialog>
  59. </template>
  60. <script setup>
  61. import { ref, computed, watch } from 'vue'
  62. defineOptions({ name: 'components-ct-dialog' })
  63. const emits = defineEmits(['update:visible', 'close', 'submit'])
  64. const props = defineProps({
  65. titleClass: {
  66. type: String,
  67. default: 'text-h5'
  68. },
  69. bodyStyle: {
  70. type: String,
  71. default: ''
  72. },
  73. widthType: {
  74. type: [Number, String],
  75. default: 0
  76. },
  77. title: {
  78. type: String,
  79. default: '提示'
  80. },
  81. submitText: {
  82. type: String,
  83. default: '提交'
  84. },
  85. visible: {
  86. type: Boolean,
  87. default: false
  88. },
  89. footer: {
  90. type: Boolean,
  91. default: true
  92. },
  93. showDrawer: {
  94. type: Boolean,
  95. default: false
  96. },
  97. flexBox: {
  98. type: Boolean,
  99. default: false
  100. },
  101. closeable: {
  102. type: Boolean,
  103. default: true
  104. },
  105. closeText: {
  106. type: String,
  107. default: '取消'
  108. }
  109. })
  110. const show = ref(false)
  111. watch(() => props.visible, (newVal) => {
  112. show.value = newVal
  113. })
  114. const dialogWidth = computed(() => {
  115. const arr = ['900px', '1200px', '400px', '600px', '500px', '96%']
  116. return arr[+props.widthType]
  117. })
  118. const handleClose = () => {
  119. // emits('update:visible', false)
  120. emits('close', false)
  121. }
  122. const handleSave = () => {
  123. emits('submit', false)
  124. }
  125. </script>
  126. <style lang="scss" scoped>
  127. .drawer{
  128. color: #fff;
  129. background-color: #1976d2;
  130. }
  131. // ::v-deep .v-dialog:not(.v-dialog--fullscreen) {
  132. // overflow: visible !important;
  133. // }
  134. </style>