XKModal.vue 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. /*
  2. * @Author: wf
  3. * @Date: 2021-09-Tu 05:49:30
  4. * @Last Modified by: wf
  5. * @Last Modified time: 2021-09-Tu 05:49:30
  6. */
  7. <template>
  8. <!-- <transition name="el-zoom-in-center"> -->
  9. <el-dialog
  10. v-if="modal.show"
  11. :visible.sync="modal.show"
  12. class="xk-modal"
  13. :width="modal.width"
  14. :fullscreen="modal.fullscreen"
  15. :custom-class="modal.customClass || 'xk-el-modal'"
  16. :class="{ 'is-modal': !modal.fullscreen,'newpop':modal.class }"
  17. :append-to-body="true"
  18. :lock-scroll="true"
  19. @closed="close"
  20. ref="xkModal"
  21. top="0"
  22. :close-on-click-modal="false"
  23. :close-on-press-escape="false"
  24. >
  25. <div slot="title">
  26. <span class="title">{{ modal.title }}</span>
  27. <span v-if="modal.title && !modal.notip">
  28. (
  29. <span class="color-danger">*为必填项</span>)
  30. </span>
  31. </div>
  32. <component
  33. :id="modal.id"
  34. :is="modal.component"
  35. :params="modal.props"
  36. :ref="modal.id"
  37. @close="$store.dispatch('closeModal')"
  38. ></component>
  39. <span slot="footer" class="dialog-footer" v-if="!modal.fullscreen||showFooter">
  40. <el-button @click="close()" v-if="!modal.showCancelButton">{{ modal.cancelButtonText || '取消' }}</el-button>
  41. <el-button type="primary" v-if="!modal.showConfirmButton" @click="submit(modal.id)">{{ modal.confirmButtonText || '确认' }}</el-button>
  42. </span>
  43. </el-dialog>
  44. <!-- </transition> -->
  45. </template>
  46. <script>
  47. const preventBrowserBack = () => {
  48. history.pushState(null, null, document.URL);
  49. };
  50. /*
  51. 使用vuex this.$store.dispatch("openModal", {})打开弹窗,具体参数去store查看
  52. */
  53. export default {
  54. name: 'xk-modal',
  55. props: {
  56. params: {
  57. type: Object,
  58. default() {
  59. return {};
  60. }
  61. }
  62. },
  63. data() {
  64. return {};
  65. },
  66. computed: {
  67. modal() {
  68. const obj = this.$store.getters['getModalParams'];
  69. if (obj && obj.height) {
  70. this.$nextTick(() => {
  71. if (this.$refs.xkModal && this.$refs.xkModal.$el && this.$refs.xkModal.$el.childNodes) {
  72. this.$refs.xkModal.$el.childNodes[0].style.height = obj.height;
  73. }
  74. });
  75. }
  76. if (obj.show) {
  77. history.pushState(null, null, document.URL);
  78. window.addEventListener('popstate', preventBrowserBack, false);
  79. } else {
  80. window.removeEventListener('popstate', preventBrowserBack);
  81. }
  82. return obj;
  83. }
  84. },
  85. methods: {
  86. close() {
  87. this.$store.dispatch('closeModal');
  88. },
  89. submit(id) {
  90. const component = this.$refs[id];
  91. component.submit && component.submit();
  92. }
  93. }
  94. };
  95. </script>
  96. <style lang="scss">
  97. .xk-modal {
  98. overflow: hidden;
  99. .el-dialog {
  100. .el-dialog__header {
  101. height: 54px;
  102. border-radius: 6px 6px 0 0;
  103. border-bottom: 1px solid #eaedf3;
  104. padding: 0 25px;
  105. display: flex;
  106. align-items: center;
  107. justify-content: space-between;
  108. font-size: 16px;
  109. background: #F7FBFF;
  110. }
  111. .el-dialog__body {
  112. padding: 20px;
  113. overflow: auto;
  114. .el-form {
  115. .el-select,
  116. .el-cascader {
  117. width: 100%;
  118. }
  119. }
  120. &::-webkit-scrollbar{
  121. display: none;
  122. }
  123. }
  124. .el-dialog__footer {
  125. border-top: 1px solid #eaedf3;
  126. }
  127. &.is-fullscreen {
  128. height: 100% !important;
  129. border-radius: 0;
  130. .el-dialog__body {
  131. position: absolute;
  132. left: 0;
  133. bottom: 0;
  134. top: 54px;
  135. right: 0;
  136. display: flex;
  137. justify-content: center;
  138. }
  139. }
  140. }
  141. }
  142. .is-modal {
  143. .el-dialog {
  144. border-radius: 8px;
  145. width: auto;
  146. max-height: 80%;
  147. min-height: 210px;
  148. position: absolute;
  149. top: 50%;
  150. left: 50%;
  151. transform: translate(-50%, -50%);
  152. background: #fff;
  153. .el-dialog__body {
  154. height: calc(100% - 110px);
  155. }
  156. }
  157. }
  158. .newpop .el-dialog {
  159. background:transparent;
  160. }
  161. .newpop .el-dialog .el-dialog__header {
  162. height: 50px;
  163. background:rgba(13, 21, 41, 0.3);
  164. }
  165. .newpop .el-dialog .el-dialog__body {
  166. height: 100%;
  167. padding:0;
  168. }
  169. .newpop .el-dialog .el-dialog__footer {
  170. display: none;
  171. }
  172. .newpop .title{
  173. color:#fff;
  174. }
  175. .color-danger{
  176. color: red;
  177. }
  178. </style>