SmModal.vue 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. <template>
  2. <!-- 过渡动画 -->
  3. <transition name="modal-fade">
  4. <!-- 关闭模态框事件 和 控制模态框是否显示 -->
  5. <div class="modal-backdrop" @click="$emit('closeModal')" v-show="show">
  6. <div class="modal" @click.stop>
  7. <div class="modal-body" id="modalDescription">
  8. <!-- 状态提示文字的插槽 -->
  9. <slot name="status">{{statusText}}</slot>
  10. <slot name="body">
  11. </slot>
  12. <el-button class="icon-btn_style fr" @click="$emit('closeModal')">×</el-button>
  13. </div>
  14. <!-- 模态框内容文字 可有可无 -->
  15. <div class="modal-content" v-if="contentText">
  16. <slot>this is Modal-content</slot>
  17. </div>
  18. <ul>
  19. <!-- 模态框按钮 可选单个确定按钮 和 两个确定、取消按钮 -->
  20. <!-- 单个确定按钮 -->
  21. <li v-if="alert" :class="buttonBackground" @click.stop="$emit('button')">确定</li>
  22. <!-- 确定和取消按钮 -->
  23. <li v-else class="confirm">
  24. <div>取消</div>
  25. <div :class="buttonBackground" @click.stop="$emit('confirm')">{{sure}}</div>
  26. </li>
  27. </ul>
  28. </div>
  29. </div>
  30. </transition>
  31. </template>
  32. <script>
  33. export default {
  34. name: "modal",
  35. // 通过 props 传值
  36. props: {
  37. imgadress: String,
  38. title: String, //标题文字
  39. show: {
  40. //显示取消
  41. type: Boolean,
  42. default: false
  43. },
  44. statusText: String, //状态文字
  45. contentText: String, //描述文字
  46. IDList: Array, //ID 列表
  47. payMoney: Number,
  48. yuan: String,
  49. buttonBackground: String, //按钮背景色
  50. alert: String, //判断一个还是两个按钮
  51. sure: String //第二个按钮的提示文字
  52. },
  53. data() {
  54. return {
  55. closemodal: "close",
  56. // isModalVisible:false,
  57. // 确定和取消按钮的两种颜色
  58. // red: "redBackground",
  59. // blue: "blueBackground"
  60. };
  61. },
  62. components: {
  63. },
  64. methods: {
  65. // 关闭模态框事件
  66. close() {
  67. this.$emit("close");
  68. }
  69. }
  70. };
  71. </script>
  72. <style lang="scss" scoped>
  73. .modal-backdrop {
  74. position: fixed;
  75. top: 0;
  76. right: 0;
  77. bottom: 0;
  78. left: 0;
  79. background-color: rgba(0, 0, 0, 0.3);
  80. display: flex;
  81. justify-content: center;
  82. align-items: center;
  83. z-index: 12;
  84. .modal {
  85. width: 50%;
  86. padding-bottom:10px;
  87. top:50px;
  88. background-color: #fff;
  89. box-shadow: 2px 2px 20px rgba(0, 0, 0, 0.3);
  90. overflow-x: auto;
  91. display: flex;
  92. flex-direction: column;
  93. // width: 11.8rem;
  94. position: relative;
  95. border-radius: 0.2rem;
  96. .img {
  97. width: 3.6rem;
  98. height: 3.6rem;
  99. margin: 0.8rem 4.1rem;
  100. }
  101. .modal-header {
  102. padding: 0.6rem 4.1rem;
  103. width: 3.6rem;
  104. height: 3.6rem;
  105. box-sizing: border-box;
  106. .img {
  107. width: 100%;
  108. height: 100%;
  109. }
  110. div {
  111. width: 100%;
  112. height: 100%;
  113. background: #000;
  114. }
  115. }
  116. .modal-body {
  117. width: 100%;
  118. padding:1.6rem;
  119. margin-bottom: 0.8rem;
  120. box-sizing: border-box;
  121. display: flex;
  122. justify-content: space-between;
  123. align-items: center;
  124. li {
  125. width: 2rem;
  126. height: 0.04rem;
  127. background: #eeeee5;
  128. }
  129. }
  130. .modal-content {
  131. width: 100%;
  132. // height: 0.6rem;
  133. max-height: 61vh;
  134. overflow: auto;
  135. margin-bottom: 0.8rem;
  136. text-align: center;
  137. color: #34304b;
  138. span {
  139. color: #32b8b9;
  140. i {
  141. color: #4f4f4f;
  142. }
  143. }
  144. }
  145. ul {
  146. li {
  147. width: 100%;
  148. height: 1.52rem;
  149. line-height: 1.52rem;
  150. text-align: center;
  151. color: #fff;
  152. font-size: 0.56rem;
  153. letter-spacing: 0.4rem;
  154. }
  155. .confirm {
  156. display: flex;
  157. div:nth-child(1) {
  158. flex: 1;
  159. background: #dedede;
  160. color: #bcbbbf;
  161. }
  162. div:nth-child(2) {
  163. flex: 1;
  164. color: #fff;
  165. }
  166. }
  167. }
  168. }
  169. }
  170. /* 动画 */
  171. .modal-fade-enter,
  172. .modal-fade-leave-active {
  173. opacity: 0;
  174. }
  175. .modal-fade-enter-active,
  176. .modal-fade-leave-active {
  177. transition: opacity 0.5s ease;
  178. }
  179. </style>