commonModal.vue 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. <template>
  2. <u-mask class="commonModal" :show="isShow" :mask-click-able="false">
  3. <view class="modal-con">
  4. <u-icon v-if="isClose" @click="isShow=false" class="close-icon" name="close-circle" size="40" color="#999"></u-icon>
  5. <view class="modal-title">{{title}}</view>
  6. <view class="modal-main">{{content}}</view>
  7. <view class="modal-footer">
  8. <view class="button-cancel" v-if="isCancel" @click="handleCancel">{{cancelText}}</view>
  9. <view class="button-confirm" @click="handleConfirm">{{confirmText}}</view>
  10. </view>
  11. </view>
  12. </u-mask>
  13. </template>
  14. <script>
  15. export default {
  16. props: {
  17. openModal: { // 弹框显示状态
  18. type: Boolean,
  19. default: false
  20. },
  21. title: { // 标题
  22. type: String,
  23. default: '提示'
  24. },
  25. content: { // 内容
  26. type: String,
  27. default: ''
  28. },
  29. isCancel: { // 是否有取消按钮
  30. type: Boolean,
  31. default: true
  32. },
  33. isClose: { // 是否有关闭按钮
  34. type: Boolean,
  35. default: false
  36. },
  37. confirmText: { // 确认按钮内容
  38. type: String,
  39. default: '确认'
  40. },
  41. cancelText: { // 取消按钮内容
  42. type: String,
  43. default: '取消'
  44. }
  45. },
  46. data() {
  47. return {
  48. isShow: this.openModal, // 是否打开弹框
  49. }
  50. },
  51. methods: {
  52. // 确认
  53. handleConfirm(){
  54. this.$emit('confirm')
  55. },
  56. // 取消
  57. handleCancel(){
  58. this.isShow = false
  59. this.$emit('cancel')
  60. }
  61. },
  62. watch: {
  63. // 父页面传过来的弹框状态
  64. openModal (newValue, oldValue) {
  65. this.isShow = newValue
  66. },
  67. // 重定义的弹框状态
  68. isShow (newValue, oldValue) {
  69. if (!newValue) {
  70. this.$emit('close')
  71. }
  72. }
  73. }
  74. }
  75. </script>
  76. <style lang="scss">
  77. .commonModal{
  78. width: 100%;
  79. height: 100vh;
  80. position: absolute;
  81. left: 0;
  82. top: 0;
  83. z-index: 10000;
  84. .modal-con{
  85. width: 70%;
  86. margin: 40vh auto 0;
  87. background-color: #fff;
  88. border-radius: 24upx;
  89. position: relative;
  90. .close-icon{
  91. position: absolute;
  92. right: 6upx;
  93. top: 6upx;
  94. }
  95. .modal-title{
  96. text-align: center;
  97. font-size: 30upx;
  98. color: #000;
  99. padding: 30upx 30upx 0;
  100. }
  101. .modal-main{
  102. text-align: center;
  103. font-size: 28upx;
  104. color: #222;
  105. line-height: 1.5em;
  106. padding: 30upx 30upx 40upx;
  107. }
  108. .modal-footer{
  109. font-size: 30upx;
  110. display: flex;
  111. justify-content: space-between;
  112. align-items: center;
  113. text-align: center;
  114. border-top: 1upx solid #E5E5E5;
  115. .button-cancel{
  116. color: #999;
  117. border-right: 1upx solid #E5E5E5;
  118. flex-grow: 1;
  119. padding: 20upx 0;
  120. width: 50%;
  121. }
  122. .button-confirm{
  123. color: #2A86F4;
  124. flex-grow: 1;
  125. padding: 20upx 0;
  126. width: 50%;
  127. }
  128. }
  129. }
  130. }
  131. </style>