commonModal.vue 2.2 KB

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