index.vue 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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. icon
  19. elevation="0"
  20. @click="handleClose"
  21. >
  22. <v-icon :color="props.showDrawer ? '#fff' : '#000'">
  23. mdi-close
  24. </v-icon>
  25. </v-btn>
  26. </span>
  27. </v-card-title>
  28. <v-divider></v-divider>
  29. <v-card-text class="flex-grow-1 overflow-y-auto" :class="{ 'd-flex': props.flexBox }" :style="props.bodyStyle">
  30. <slot></slot>
  31. </v-card-text>
  32. <template v-if="props.footer">
  33. <v-divider></v-divider>
  34. <v-card-actions>
  35. <v-spacer></v-spacer>
  36. <v-btn
  37. color="primary"
  38. text
  39. @click="handleClose"
  40. >
  41. 取消
  42. </v-btn>
  43. <v-btn
  44. color="primary"
  45. text
  46. @click="handleSave"
  47. >
  48. 提交
  49. </v-btn>
  50. </v-card-actions>
  51. </template>
  52. <template v-else>
  53. <slot name="footer"></slot>
  54. </template>
  55. </v-card>
  56. </v-dialog>
  57. </template>
  58. <script setup>
  59. import { ref, defineEmits, computed, watch } from 'vue'
  60. defineOptions({ name: 'components-ct-dialog' })
  61. const emits = defineEmits(['update:visible', 'close', 'submit'])
  62. const props = defineProps({
  63. titleClass: {
  64. type: String,
  65. default: 'text-h5'
  66. },
  67. bodyStyle: {
  68. type: String,
  69. default: ''
  70. },
  71. widthType: {
  72. type: [Number, String],
  73. default: 0
  74. },
  75. title: {
  76. type: String,
  77. default: '提示'
  78. },
  79. visible: {
  80. type: Boolean,
  81. default: false
  82. },
  83. footer: {
  84. type: Boolean,
  85. default: true
  86. },
  87. showDrawer: {
  88. type: Boolean,
  89. default: false
  90. },
  91. flexBox: {
  92. type: Boolean,
  93. default: false
  94. }
  95. })
  96. const show = ref(false)
  97. watch(() => props.visible, (newVal) => {
  98. show.value = newVal
  99. })
  100. const dialogWidth = computed(() => {
  101. const arr = ['900px', '1200px', '400px', '600px']
  102. return arr[+props.widthType]
  103. })
  104. const handleClose = () => {
  105. // emits('update:visible', false)
  106. emits('close', false)
  107. }
  108. const handleSave = () => {
  109. emits('submit', false)
  110. }
  111. </script>
  112. <style lang="scss" scoped>
  113. .drawer{
  114. color: #fff;
  115. background-color: #1976d2;
  116. }
  117. // ::v-deep .v-dialog:not(.v-dialog--fullscreen) {
  118. // overflow: visible !important;
  119. // }
  120. </style>