dialog_referrer_list.vue 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  1. <template>
  2. <div v-show="show" :transition="transition">
  3. <div class="modal" @click.self="clickMask">
  4. <div class="modal-dialog" :class="modalClass">
  5. <div class="image-border image-border1"></div>
  6. <div class="image-border image-border2"></div>
  7. <div class="image-border image-border3"></div>
  8. <div class="image-border image-border4"></div>
  9. <div class="modal-content">
  10. <!--Header-->
  11. <div class="modal-header">
  12. <slot name="header">
  13. <i class="el-icon-close" @click="cancel"></i>
  14. <h2 class="modal-title">
  15. <slot name="title">
  16. {{title}}
  17. </slot>
  18. </h2>
  19. </slot>
  20. </div>
  21. <!--Container-->
  22. <div class="modal-body">
  23. <slot></slot>
  24. </div>
  25. <!--Footer-->
  26. <div class="modal-footer">
  27. <slot name="footer">
  28. <el-button type="primary" :class="cancelClass" @click="cancel">{{cancelText}}</el-button>
  29. <el-button type="primary" @click="ok">{{okText}}</el-button>
  30. </slot>
  31. </div>
  32. </div>
  33. </div>
  34. </div>
  35. <div class="modal-backdrop in"></div>
  36. </div>
  37. </template>
  38. <script>
  39. export default {
  40. props: {
  41. show: {
  42. type: Boolean,
  43. twoWay: true,
  44. default: false
  45. },
  46. title: {
  47. type: String,
  48. default: 'Modal'
  49. },
  50. small: {
  51. type: Boolean,
  52. default: false
  53. },
  54. large: {
  55. type: Boolean,
  56. default: false
  57. },
  58. full: {
  59. type: Boolean,
  60. default: false
  61. },
  62. // 为true时无法通过点击遮罩层关闭modal
  63. force: {
  64. type: Boolean,
  65. default: false
  66. },
  67. // 自定义组件transition
  68. transition: {
  69. type: String,
  70. default: 'modal'
  71. },
  72. // 确认按钮text
  73. okText: {
  74. type: String,
  75. default: '确认'
  76. },
  77. // 取消按钮text
  78. cancelText: {
  79. type: String,
  80. default: '取消'
  81. },
  82. // 确认按钮className
  83. okClass: {
  84. type: String,
  85. default: 'btn blue'
  86. },
  87. // 取消按钮className
  88. cancelClass: {
  89. type: String,
  90. default: 'btn red btn-outline'
  91. },
  92. // 点击确定时关闭Modal
  93. // 默认为false,由父组件控制prop.show来关闭
  94. closeWhenOK: {
  95. type: Boolean,
  96. default: false
  97. }
  98. },
  99. data() {
  100. return {
  101. duration: null
  102. };
  103. },
  104. computed: {
  105. modalClass() {
  106. return {
  107. 'modal-lg': this.large,
  108. 'modal-sm': this.small,
  109. 'modal-full': this.full
  110. }
  111. }
  112. },
  113. mounted() {
  114. if (this.show) {
  115. document.body.className += ' modal-open';
  116. }
  117. },
  118. beforeDestroy() {
  119. document.body.className = document.body.className.replace(/\s?modal-open/, '');
  120. },
  121. watch: {
  122. show(value) {
  123. // 在显示时去掉body滚动条,防止出现双滚动条
  124. if (value) {
  125. document.body.className += ' modal-open';
  126. }
  127. // 在modal动画结束后再加上body滚动条
  128. else {
  129. if (!this.duration) {
  130. this.duration = window.getComputedStyle(this.$el)['transition-duration'].replace('s', '') * 1000;
  131. }
  132. window.setTimeout(() => {
  133. document.body.className = document.body.className.replace(/\s?modal-open/, '');
  134. }, this.duration || 0);
  135. }
  136. }
  137. },
  138. methods: {
  139. ok() {
  140. this.$emit('dialog_ok');
  141. },
  142. cancel() {
  143. this.$emit('dialog_cancel');
  144. },
  145. // 点击遮罩层
  146. clickMask() {
  147. if (!this.force) {
  148. this.cancel();
  149. }
  150. }
  151. }
  152. };
  153. </script>
  154. <style scoped>
  155. .modal {
  156. position: absolute;
  157. top: 0;
  158. left: 0;
  159. right: 0;
  160. bottom: 0;
  161. width: 100%;
  162. height: 100%;
  163. overflow: hidden;
  164. display: block;
  165. margin: 0 auto;
  166. background: rgba(0, 0, 0, 0.3);
  167. }
  168. .modal-dialog {
  169. position: absolute;
  170. left: 0;
  171. right: 0;
  172. width: 799px;
  173. min-height: 400px;
  174. display: block;
  175. border: 1px solid #005EA2;
  176. background: rgba(0, 23, 67, 0.8);
  177. margin: 0 auto;
  178. margin-top: 10%;
  179. }
  180. .modal-transition {
  181. transition: all .6s ease;
  182. }
  183. .modal-leave {
  184. /* 样式没什么用,但可以让根标签的transitionEnd生效,以去掉modal-leave */
  185. border-radius: 1px !important;
  186. }
  187. .modal-transition .modal-dialog, .modal-transition .modal-backdrop {
  188. transition: all .5s ease;
  189. }
  190. .modal-enter .modal-dialog, .modal-leave .modal-dialog {
  191. opacity: 0;
  192. transform: translateY(-30%);
  193. }
  194. .modal-enter .modal-backdrop, .modal-leave .modal-backdrop {
  195. opacity: 0;
  196. }
  197. .modal-header {
  198. padding: 7px 22px;
  199. }
  200. .modal-body {
  201. padding: 5px 20px;
  202. }
  203. .modal-title {
  204. width: 473px;
  205. margin: 0 auto;
  206. margin-top: 10px;
  207. text-align: center;
  208. font-size: 16px;
  209. cursor: pointer;
  210. color: #6DC1FF;
  211. font-weight: normal;
  212. padding-bottom: 10px;
  213. background: url("../assets/img/headbotter.png") bottom center no-repeat;
  214. background-size: 100%;
  215. }
  216. .modal-footer button {
  217. padding: 10px 20px;
  218. }
  219. .image-border {
  220. position: absolute;
  221. width: 20px;
  222. height: 20px;
  223. }
  224. .image-border1 {
  225. top: 0px;
  226. left: 0;
  227. border-left: 2px solid #6DC1FF;
  228. border-top: 2px solid #6DC1FF;
  229. }
  230. .image-border2 {
  231. top: 0;
  232. right: -2px;
  233. border-right: 2px solid #6DC1FF;
  234. border-top: 2px solid #6DC1FF;
  235. }
  236. .image-border3 {
  237. bottom: 0;
  238. left: 0;
  239. border-bottom: 2px solid #6DC1FF;
  240. border-left: 2px solid #6DC1FF;
  241. }
  242. .image-border4 {
  243. bottom: 0;
  244. right: -2px;
  245. border-right: 2px solid #6DC1FF;
  246. border-bottom: 2px solid #6DC1FF;
  247. }
  248. .el-icon-close {
  249. float: right;
  250. color: #6DC1FF;
  251. margin-top: 10px;
  252. font-size: 16px;
  253. }
  254. </style>