index.vue 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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. v-if="props.otherBtnText"
  47. color="primary"
  48. text
  49. @click="handleOtherBtn"
  50. >
  51. {{ otherBtnText }}
  52. </v-btn>
  53. <v-btn
  54. color="primary"
  55. text
  56. @click="handleSave"
  57. >
  58. {{ props.submitText }}
  59. </v-btn>
  60. </v-card-actions>
  61. </template>
  62. <template v-else>
  63. <slot name="footer"></slot>
  64. </template>
  65. </v-card>
  66. </v-dialog>
  67. </template>
  68. <script setup>
  69. import { ref, computed, watch } from 'vue'
  70. defineOptions({ name: 'components-ct-dialog' })
  71. const emits = defineEmits(['update:visible', 'close', 'other', 'submit'])
  72. const props = defineProps({
  73. titleClass: {
  74. type: String,
  75. default: 'text-h5'
  76. },
  77. bodyStyle: {
  78. type: String,
  79. default: ''
  80. },
  81. widthType: {
  82. type: [Number, String],
  83. default: 0
  84. },
  85. title: {
  86. type: String,
  87. default: '提示'
  88. },
  89. submitText: {
  90. type: String,
  91. default: '提交'
  92. },
  93. visible: {
  94. type: Boolean,
  95. default: false
  96. },
  97. footer: {
  98. type: Boolean,
  99. default: true
  100. },
  101. showDrawer: {
  102. type: Boolean,
  103. default: false
  104. },
  105. flexBox: {
  106. type: Boolean,
  107. default: false
  108. },
  109. otherBtnText: {
  110. type: String,
  111. default: ''
  112. },
  113. closeable: {
  114. type: Boolean,
  115. default: true
  116. },
  117. closeText: {
  118. type: String,
  119. default: '取消'
  120. }
  121. })
  122. const show = ref(false)
  123. watch(() => props.visible, (newVal) => {
  124. show.value = newVal
  125. })
  126. const dialogWidth = computed(() => {
  127. const arr = ['900px', '1200px', '400px', '600px', '500px', '96%', '90%']
  128. return arr[+props.widthType]
  129. })
  130. const handleClose = () => {
  131. // emits('update:visible', false)
  132. emits('close', false)
  133. }
  134. const handleOtherBtn = () => {
  135. emits('other', false)
  136. }
  137. const handleSave = () => {
  138. emits('submit', false)
  139. }
  140. </script>
  141. <style lang="scss" scoped>
  142. .drawer{
  143. color: #fff;
  144. background-color: #1976d2;
  145. }
  146. // ::v-deep .v-dialog:not(.v-dialog--fullscreen) {
  147. // overflow: visible !important;
  148. // }
  149. </style>