yModal.vue 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. <template>
  2. <view class="yModal-container" :class="show ? 'show' : ''">
  3. <!-- 提示 -->
  4. <view class="yModal">
  5. <view class="yModal-content">
  6. <view class="yModal-title">
  7. {{title}}
  8. </view>
  9. <slot></slot>
  10. </view>
  11. <view class="yModal-bottom">
  12. <view class="yModal-bottom-item">
  13. <button plain class="yModal-bottom-btn cancel-btn" hover-class="active" @click="cancel">
  14. {{cancelTxt}}
  15. </button>
  16. </view>
  17. <view class="yModal-bottom-item">
  18. <button plain class="yModal-bottom-btn confirm-btn" hover-class="active" @click="confirm">
  19. {{confirmTxt}}
  20. </button>
  21. </view>
  22. </view>
  23. </view>
  24. <view v-if="show" class="yModal-mask"></view>
  25. </view>
  26. </template>
  27. <script>
  28. export default {
  29. props: {
  30. title: {
  31. type: String,
  32. required: true,
  33. },
  34. show: {
  35. type: Boolean,
  36. default: false
  37. },
  38. cancelTxt: {
  39. type: String,
  40. default: '取消'
  41. },
  42. confirmTxt: {
  43. type: String,
  44. default: '确认'
  45. }
  46. },
  47. methods: {
  48. // 取消
  49. cancel() {
  50. this.$emit('onCancel');
  51. },
  52. // 确认
  53. confirm() {
  54. this.$emit('onConfirm');
  55. }
  56. }
  57. }
  58. </script>
  59. <style lang="scss">
  60. .yModal-container {
  61. width: 100%;
  62. height: 100%;
  63. position: fixed;
  64. top: 0;
  65. left: 0;
  66. z-index: -1;
  67. display: none;
  68. &.show {
  69. z-index: 900;
  70. display: block;
  71. }
  72. }
  73. .yModal {
  74. position: absolute;
  75. width: 622rpx;
  76. background-color: #fff;
  77. top: 50%;
  78. left: 50%;
  79. transform: translate3d(-50%, -50%, 0);
  80. border-radius: 30rpx;
  81. font-size: 32rpx;
  82. color: #323233;
  83. z-index: 902;
  84. .yModal-content {
  85. padding: 40rpx 30rpx;
  86. }
  87. .yModal-title {
  88. text-align: center;
  89. }
  90. .yModal-bottom {
  91. display: flex;
  92. .yModal-bottom-item {
  93. flex: 1;
  94. &:last-of-type {
  95. .yModal-bottom-btn {
  96. border-left: 1px solid #EBEDF0;
  97. border-bottom-left-radius: 0;
  98. }
  99. }
  100. }
  101. .yModal-bottom-btn {
  102. border: 0;
  103. border-top: 1px solid #EBEDF0;
  104. border-top-left-radius: 0;
  105. border-top-right-radius: 0;
  106. &.active {
  107. opacity: 0.6;
  108. }
  109. }
  110. // 确认按钮
  111. .confirm-btn {
  112. color: $uni-primary;
  113. }
  114. }
  115. }
  116. .yModal-mask {
  117. background-color: rgba(0, 0, 0, .3);
  118. z-index: 901;
  119. width: 100%;
  120. height: 100%;
  121. position: fixed;
  122. }
  123. </style>