index.vue 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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. v-bind="$attrs"
  11. v-on="$listeners"
  12. >
  13. <slot></slot>
  14. <span slot="footer">
  15. <m-button @click="show = false">{{ option?.textCancel ?? '取 消'}}</m-button>
  16. <m-button type="primary" @click="sure">{{ option?.textSure ?? '确 定'}}</m-button>
  17. </span>
  18. </el-dialog>
  19. </template>
  20. <script>
  21. export default {
  22. name: 'm-dialog',
  23. props: {
  24. title: String,
  25. width: String,
  26. option: {
  27. type: Object,
  28. default: () => ({
  29. textCancel: '取 消',
  30. textSure: '确 定'
  31. })
  32. }
  33. },
  34. data () {
  35. return {
  36. show: false
  37. }
  38. },
  39. // directives: {
  40. // 'drag-dialog': {
  41. // bind (el, binding, vnode) {
  42. // if (!binding.value) return
  43. // const dialogHeaderEl = el.querySelector('.el-dialog__header')
  44. // const dragDom = el.querySelector('.el-dialog')
  45. // console.log(dragDom)
  46. // dialogHeaderEl.style.cursor = 'move'
  47. // dragDom.style.position = 'fixed'
  48. // dragDom.style.marginLeft = (document.clientWidth - dragDom.clientWidth) / 2 + 'px'
  49. // let isDragging = false
  50. // // let offsetX = 0
  51. // // let offsetY = 0
  52. // dialogHeaderEl.onmousedown = (e) => {
  53. // isDragging = true
  54. // // 计算鼠标按下时相对于对话框左上角的偏移量
  55. // // const rect = dragDom.getBoundingClientRect()
  56. // const clientX = e.clientX
  57. // const clientY = e.clientY
  58. // document.onmousemove = (e) => {
  59. // if (!isDragging) return
  60. // // 计算新的对话框位置
  61. // let left = e.clientX - clientX
  62. // let top = e.clientY - clientY
  63. // // 限制拖拽范围
  64. // const screenWidth = document.body.clientWidth
  65. // const screenHeight = document.body.clientHeight
  66. // const dragDomWidth = dragDom.offsetWidth
  67. // const dragDomHeight = dragDom.offsetHeight
  68. // if (left < 0) left = 0
  69. // if (left > screenWidth - dragDomWidth) left = screenWidth - dragDomWidth
  70. // if (top < 0) top = 0
  71. // if (top > screenHeight - dragDomHeight) top = screenHeight - dragDomHeight
  72. // // 更新对话框位置
  73. // dragDom.style.left = `${left}px`
  74. // dragDom.style.top = `${top}px`
  75. // }
  76. // document.onmouseup = () => {
  77. // isDragging = false
  78. // document.onmousemove = null
  79. // document.onmouseup = null
  80. // }
  81. // }
  82. // }
  83. // }
  84. // },
  85. methods: {
  86. open () {
  87. this.show = true
  88. },
  89. close () {
  90. this.show = false
  91. },
  92. sure () {
  93. this.$emit('sure')
  94. if (!this.$listeners.sure) {
  95. this.show = false
  96. }
  97. }
  98. }
  99. }
  100. </script>
  101. <style lang="scss" scoped>
  102. </style>