dialog.vue 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. <script setup>
  2. /**
  3. * element-plus组件
  4. */
  5. import { ElDialog } from 'element-plus';
  6. /**
  7. * element-plus字体
  8. */
  9. import { CircleCloseFilled, Warning } from '@element-plus/icons-vue';
  10. </script>
  11. <template>
  12. <div class="jt-dialog">
  13. <!--
  14. modal:是否需要遮罩层
  15. close-on-click-modal:是否可以通过点击 modal 关闭 Dialog
  16. -->
  17. <el-dialog
  18. :class="[animationClass]"
  19. draggable
  20. :modal="false"
  21. :destroy-on-close="false"
  22. v-model="dialogVisible"
  23. :title="title"
  24. :style="{ right: right, background: background, height: height, width: width, top: top }"
  25. @close="handleClose"
  26. >
  27. <template #header>
  28. <div slot="title" class="header-title">
  29. <span style="line-height:24px;font-size:18px;color:#fff;font-family: 'Alimama_ShuHeiTi_Bold'">{{ title }}</span>
  30. </div>
  31. </template>
  32. <template #default>
  33. <div class="odin-dialog__content"><slot></slot></div>
  34. </template>
  35. </el-dialog>
  36. </div>
  37. </template>
  38. <script>
  39. export default {
  40. name: '',
  41. props: {
  42. showDialog: {
  43. //接受父级组件的显示标记,用于被watch
  44. type: Boolean,
  45. default: false
  46. },
  47. title: {
  48. //Dialog 的标题
  49. type: String,
  50. default: 'jt-dialog'
  51. },
  52. width: {
  53. //Dialog 的宽度
  54. type: String,
  55. default: '300px'
  56. },
  57. top: {
  58. type: String,
  59. default: '0px'
  60. },
  61. right: {
  62. type: String,
  63. default: '0px'
  64. },
  65. direction: {
  66. type: String, //弹出方向
  67. default: 'rtl' //rtl 从右到左 / ltr 从左到右 / ttb 从上到下/ btt 从下到上
  68. },
  69. height: {
  70. //Dialog 的高度
  71. type: String,
  72. default: '100%'
  73. },
  74. background: {
  75. type: String,
  76. default: 'rgb(0 44 126 / 68%)'
  77. }
  78. },
  79. /**
  80. * computed的响应式依赖(缓存)
  81. **/
  82. computed: {
  83. //渐入动画
  84. animationClass() {
  85. if (this.direction === 'rtl') {
  86. return 'fadein-right';
  87. } else if (this.direction === 'ltr') {
  88. return 'fadein-left';
  89. } else if (this.direction === 'ttb') {
  90. return 'fadein-top';
  91. } else if (this.direction === 'btt') {
  92. return 'fadein-bottom';
  93. } else {
  94. return 'fadein-center';
  95. }
  96. }
  97. },
  98. /* 数据 */
  99. data() {
  100. return {
  101. dialogVisible: this.showDialog // 子组件自己的显示标记,用于真正切换dialog的显示/隐藏
  102. };
  103. },
  104. watch: {
  105. //观察父级组件的showDialog,并将showDialog的最新值设置给dialogVisible
  106. showDialog: function(newVal, oldVal) {
  107. this.dialogVisible = newVal;
  108. }
  109. },
  110. /* 方法 */
  111. methods: {
  112. /**
  113. * 关闭弹出框事件,触发父级组件的closeJTDialog方法
  114. */
  115. handleClose() {
  116. this.$emit('closeJTDialog');
  117. }
  118. },
  119. mounted() {}
  120. };
  121. </script>
  122. <style lang="scss">
  123. // el-dialog 加上scoped不起效果
  124. .jt-dialog {
  125. pointer-events: none; // ***覆盖层元素增加可穿透点击事件***
  126. .el-dialog {
  127. pointer-events: auto; // ***弹窗层元素不可穿透点击事件(不影响弹窗层元素的点击事件)***
  128. position: absolute !important; //将通知框的position改成absolute,可以在某个div进行显示
  129. background: rgb(5 45 155 / 70%);
  130. min-width: 300px;
  131. overflow: hidden;
  132. margin-top: 0px !important;
  133. .el-dialog__header {
  134. background: url('../../assets/image/backheader.png') no-repeat;
  135. margin-right: 0px;
  136. padding: 14px;
  137. }
  138. .el-dialog__body {
  139. padding: 10px;
  140. color: #fff;
  141. }
  142. }
  143. }
  144. </style>