index.vue 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. <template>
  2. <el-dialog
  3. :visible.sync="show"
  4. :title="title"
  5. :width="width ?? '800px'"
  6. lock-scroll
  7. :close-on-click-modal="false"
  8. :close-on-press-escape="false"
  9. destroy-on-close
  10. :class="{'el-dialog--hide-footer': hideFooter }"
  11. v-bind="$attrs"
  12. v-on="$listeners"
  13. >
  14. <slot></slot>
  15. <span slot="footer" v-if="!hideFooter">
  16. <m-button @click="show = false">{{ option?.textCancel ?? '取 消'}}</m-button>
  17. <m-button :type="option?.colorSure ?? 'orange'" @click="sure">{{ option?.textSure ?? '确 定'}}</m-button>
  18. <slot name="button-after"></slot>
  19. </span>
  20. </el-dialog>
  21. </template>
  22. <script>
  23. export default {
  24. name: 'm-dialog',
  25. props: {
  26. title: String,
  27. width: String,
  28. hideFooter: Boolean,
  29. option: {
  30. type: Object,
  31. default: () => ({
  32. textCancel: '取 消',
  33. textSure: '确 定'
  34. })
  35. }
  36. },
  37. data () {
  38. return {
  39. show: false
  40. }
  41. },
  42. // directives: {
  43. // 'drag-dialog': {
  44. // bind (el, binding, vnode) {
  45. // if (!binding.value) return
  46. // const dialogHeaderEl = el.querySelector('.el-dialog__header')
  47. // const dragDom = el.querySelector('.el-dialog')
  48. // console.log(dragDom)
  49. // dialogHeaderEl.style.cursor = 'move'
  50. // dragDom.style.position = 'fixed'
  51. // dragDom.style.marginLeft = (document.clientWidth - dragDom.clientWidth) / 2 + 'px'
  52. // let isDragging = false
  53. // // let offsetX = 0
  54. // // let offsetY = 0
  55. // dialogHeaderEl.onmousedown = (e) => {
  56. // isDragging = true
  57. // // 计算鼠标按下时相对于对话框左上角的偏移量
  58. // // const rect = dragDom.getBoundingClientRect()
  59. // const clientX = e.clientX
  60. // const clientY = e.clientY
  61. // document.onmousemove = (e) => {
  62. // if (!isDragging) return
  63. // // 计算新的对话框位置
  64. // let left = e.clientX - clientX
  65. // let top = e.clientY - clientY
  66. // // 限制拖拽范围
  67. // const screenWidth = document.body.clientWidth
  68. // const screenHeight = document.body.clientHeight
  69. // const dragDomWidth = dragDom.offsetWidth
  70. // const dragDomHeight = dragDom.offsetHeight
  71. // if (left < 0) left = 0
  72. // if (left > screenWidth - dragDomWidth) left = screenWidth - dragDomWidth
  73. // if (top < 0) top = 0
  74. // if (top > screenHeight - dragDomHeight) top = screenHeight - dragDomHeight
  75. // // 更新对话框位置
  76. // dragDom.style.left = `${left}px`
  77. // dragDom.style.top = `${top}px`
  78. // }
  79. // document.onmouseup = () => {
  80. // isDragging = false
  81. // document.onmousemove = null
  82. // document.onmouseup = null
  83. // }
  84. // }
  85. // }
  86. // }
  87. // },
  88. methods: {
  89. open () {
  90. this.show = true
  91. },
  92. close () {
  93. this.show = false
  94. },
  95. sure () {
  96. this.$emit('sure')
  97. if (!this.$listeners.sure) {
  98. this.show = false
  99. }
  100. }
  101. }
  102. }
  103. </script>
  104. <style lang="scss" scoped>
  105. .el-dialog--hide-footer {
  106. ::v-deep .el-dialog {
  107. &.is-fullscreen {
  108. &>.el-dialog__body {
  109. height: calc(100% - 55px);
  110. }
  111. }
  112. }
  113. }
  114. ::v-deep .el-dialog {
  115. &.is-fullscreen {
  116. height: 100vh;
  117. overflow: hidden;
  118. border-spacing: 0; /* 避免单元格间距影响 */
  119. // display: table;
  120. // &>.el-dialog__header, &>.el-dialog__footer {
  121. // display: table-cell; /* 固定高度的行 */
  122. // height: 1px; /* 最小高度,内容撑开 */
  123. // }
  124. &>.el-dialog__body {
  125. height: calc(100% - 55px - 70px); /* 减去头部和底部的高度 */
  126. box-sizing: border-box;
  127. // display: table-row; /* 自动填充剩余高度 */
  128. // height: 100%; /* 关键:占满剩余空间 */
  129. // padding: 0;
  130. // position: relative;
  131. // &>.el-dialog__body_content {
  132. // position: absolute;
  133. // width: 100%;
  134. // height: 100%;
  135. // }
  136. }
  137. }
  138. }
  139. </style>