alertModal.vue 6.4 KB

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