alertModal.vue 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. <!--
  2. * @Author: wf
  3. * @Date: 2021-08-12 16:12:17
  4. * @LastEditors: D4THYL3
  5. * @LastEditTime: 2022-09-14 10:22:11
  6. * @Description: element-ui Dialog弹窗封装
  7. -->
  8. <template>
  9. <!-- <transition name="el-zoom-in-center"> -->
  10. <el-dialog
  11. v-if="modal.show"
  12. :visible.sync="modal.show"
  13. class="alert-modal"
  14. :width="modal.width"
  15. :fullscreen="modal.fullscreen"
  16. :custom-class="modal.customClass || 'alert-el-modal'"
  17. :class="{ 'is-modal': !modal.fullscreen, newpop: modal.class }"
  18. :append-to-body="true"
  19. :lock-scroll="true"
  20. @closed="close"
  21. ref="alertModal"
  22. top="0"
  23. :close-on-click-modal="false"
  24. :close-on-press-escape="false"
  25. >
  26. <div slot="title">
  27. <div class="title_row">
  28. <strong class="title">{{ modal.title }}</strong>
  29. {{ modal.star }}
  30. <span v-if="modal.hideStar"></span>
  31. <span v-else-if="modal.title && !modal.notip"> (<span class="color-danger">*为必填项</span>) </span>
  32. <!-- <i class="close" @click="close"></i> -->
  33. </div>
  34. </div>
  35. <!-- :style="`height:${modal.showFooter ? 'calc(100% - 50px)' : 'calc(100% - 54px)'}`" -->
  36. <!-- <div class="body_content"> -->
  37. <div
  38. class="content"
  39. v-scroll
  40. >
  41. <component
  42. :id="modal.id"
  43. :is="modal.component"
  44. :params="modal.props"
  45. :ref="modal.id"
  46. @close="close"
  47. ></component>
  48. </div>
  49. <!-- </div> -->
  50. <span
  51. slot="footer"
  52. class="dialog-footer"
  53. v-if="!modal.fullscreen || modal.showFooter"
  54. >
  55. <el-button
  56. @click="alertReset(modal.id)"
  57. class="reset"
  58. v-if="modal.showResetButton"
  59. >重置</el-button>
  60. <el-button
  61. @click="close"
  62. class="reset"
  63. v-if="!modal.showCancelButton"
  64. >{{ modal.cancelButtonText || '取消' }}</el-button>
  65. <el-button
  66. type="primary"
  67. v-if="!modal.showConfirmButton"
  68. @click="submit(modal.id)"
  69. >{{
  70. modal.confirmButtonText || '保存'
  71. }}</el-button>
  72. </span>
  73. </el-dialog>
  74. <!-- </transition> -->
  75. </template>
  76. <script>
  77. const preventBrowserBack = () => {
  78. history.pushState(null, null, document.URL);
  79. };
  80. /*
  81. 使用vuex this.$store.dispatch("openModal", {})打开弹窗,具体参数去store查看
  82. */
  83. export default {
  84. name: 'alert-modal',
  85. props: {
  86. params: {
  87. type: Object,
  88. default () {
  89. return {};
  90. }
  91. }
  92. },
  93. data () {
  94. return {
  95. // modal:{}
  96. };
  97. },
  98. computed: {
  99. modal () {
  100. // const xx = this.$store.getters['getPopups'];
  101. let obj = this.params;
  102. if (obj && obj.height) {
  103. this.$nextTick(() => {
  104. if (this.$refs.alertModal && this.$refs.alertModal.$el && this.$refs.alertModal.$el.childNodes) {
  105. this.$refs.alertModal.$el.childNodes[0].style.height = obj.height;
  106. }
  107. });
  108. }
  109. if (obj.show) {
  110. history.pushState(null, null, document.URL);
  111. window.addEventListener('popstate', preventBrowserBack, false);
  112. } else {
  113. window.removeEventListener('popstate', preventBrowserBack);
  114. }
  115. return obj;
  116. }
  117. },
  118. watch: {},
  119. methods: {
  120. close () {
  121. this.$store.dispatch('delPopup', this.modal.id);
  122. },
  123. // 弹窗重置,执行弹出组件的reset方法
  124. alertReset (id) {
  125. const component = this.$refs[id];
  126. component.reset && component.reset();
  127. },
  128. submit (id) {
  129. const component = this.$refs[id];
  130. component.submit && component.submit();
  131. }
  132. },
  133. created () {
  134. // debugger
  135. // this.modal=this.params;
  136. }
  137. };
  138. </script>
  139. <style lang="scss" scoped>
  140. @import '@assets/css/public-style.scss';
  141. .alert-modal {
  142. overflow: hidden;
  143. /deep/.el-dialog {
  144. .el-dialog__header {
  145. height: 54px;
  146. border-radius: 6px 6px 0 0;
  147. background: rgba(248, 252, 255, 1);
  148. padding: 0 25px;
  149. display: flex;
  150. align-items: center;
  151. justify-content: space-between;
  152. font-size: 16px;
  153. }
  154. .el-dialog__body {
  155. padding: 20px;
  156. overflow: auto;
  157. .content {
  158. height: 100%;
  159. }
  160. // margin-bottom: 20px;
  161. .el-form {
  162. .el-select,
  163. .el-cascader {
  164. width: 100%;
  165. }
  166. }
  167. &::-webkit-scrollbar {
  168. display: none;
  169. }
  170. }
  171. .el-dialog__footer {
  172. border-top: none;
  173. position: relative;
  174. bottom: 10px;
  175. margin-top: 10px;
  176. .dialog-footer .reset {
  177. border: 1px solid #0eaeff;
  178. color: #0eaeff;
  179. }
  180. .el-button--primary {
  181. background-color: #0eaeff;
  182. // border-color: #0eaeff;
  183. }
  184. }
  185. &.is-fullscreen {
  186. height: 100% !important;
  187. border-radius: 0;
  188. .el-dialog__body {
  189. position: absolute;
  190. left: 0;
  191. bottom: 0;
  192. top: 54px;
  193. right: 0;
  194. display: flex;
  195. justify-content: center;
  196. }
  197. }
  198. }
  199. }
  200. .is-modal {
  201. .el-dialog {
  202. border-radius: 8px;
  203. width: auto;
  204. max-height: 80%;
  205. min-height: 210px;
  206. position: absolute;
  207. top: 50%;
  208. left: 50%;
  209. transform: translate(-50%, -50%);
  210. background: #fff;
  211. .el-dialog__body {
  212. /deep/ .content {
  213. height: 100% !important;
  214. }
  215. }
  216. }
  217. // .el-dialog__body::-webkit-scrollbar {
  218. // display: none;
  219. // }
  220. }
  221. .newpop .el-dialog {
  222. background: transparent;
  223. }
  224. .newpop .el-dialog .el-dialog__header {
  225. height: 50px;
  226. background: rgba(13, 21, 41, 0.3);
  227. }
  228. .newpop .el-dialog .el-dialog__body {
  229. height: 100%;
  230. padding: 0;
  231. }
  232. .newpop .el-dialog .el-dialog__footer {
  233. display: none;
  234. }
  235. .newpop .title {
  236. color: #fff;
  237. }
  238. .color-danger {
  239. color: red;
  240. }
  241. </style>