index.vue 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. <template>
  2. <u-popup v-model="show" mode="center"
  3. bgColor="transparent"
  4. :customStyle="{ width: '100%' }"
  5. :mask-close-able="closeOnClickOverlay"
  6. :closeOnClickOverlay="closeOnClickOverlay"
  7. @close="onCancel">
  8. <view class="modal-box" :class="[type]">
  9. <view class="modal-header" v-if="!!title">
  10. <text>{{ title }}</text>
  11. </view>
  12. <view class="modal-content">
  13. <slot v-if="$slots.content" name="content"></slot>
  14. <text v-else>{{ content }}</text>
  15. </view>
  16. <view class="modal-footer">
  17. <template v-if="$slots.buttons">
  18. <slot name="buttons"></slot>
  19. </template>
  20. <template v-else>
  21. <button class="btn cancel"
  22. v-if="showCancelButton"
  23. @click="onCancel()"
  24. >{{ cancelText }}</button>
  25. <button class="btn submit"
  26. v-if="showConfirmButton"
  27. @click="onSubmit()"
  28. >{{ confirmText }}</button>
  29. </template>
  30. </view>
  31. </view>
  32. </u-popup>
  33. </template>
  34. <script>
  35. export default {
  36. name: "",
  37. props: {
  38. title: {
  39. default: '',
  40. type: String
  41. },
  42. // success, warning
  43. type: {
  44. default: '',
  45. type: String
  46. },
  47. content: {
  48. default: '',
  49. type: String
  50. },
  51. cancelText: {
  52. default: '取消',
  53. type: String
  54. },
  55. confirmText: {
  56. default: '确认',
  57. type: String
  58. },
  59. showCancelButton: {
  60. default: true,
  61. type: Boolean
  62. },
  63. showConfirmButton: {
  64. default: true,
  65. type: Boolean
  66. },
  67. // 点击遮罩是否关闭弹窗
  68. closeOnClickOverlay: {
  69. type: Boolean,
  70. default: false
  71. },
  72. },
  73. data() {
  74. return {
  75. show: false,
  76. timer: null
  77. };
  78. },
  79. mounted() {
  80. },
  81. methods: {
  82. onOpen(duration = 0, callback) {
  83. this.show = true;
  84. if (duration > 0) {
  85. // 清除之前的定时器(防止多次调用)
  86. if (this.timer) clearTimeout(this.timer);
  87. this.timer = setTimeout(() => {
  88. this.show = false;
  89. callback && callback();
  90. }, duration);
  91. }
  92. },
  93. onCancel() {
  94. this.$emit('cancel');
  95. this.show = false;
  96. },
  97. onSubmit() {
  98. this.$emit('confirm');
  99. this.show = false;
  100. },
  101. }
  102. }
  103. </script>
  104. <style lang="scss" scoped>
  105. ::v-deep .u-popup {
  106. flex: initial;
  107. }
  108. ::v-deep .u-mode-center-box {
  109. background: transparent;
  110. }
  111. .modal-box {
  112. width: calc(100vw - 150rpx);
  113. // margin: 0 75rpx;
  114. border-radius: 16rpx;
  115. background: #fff;
  116. .modal-header {
  117. margin: 0 24rpx;
  118. padding: 18rpx 0;
  119. text-align: center;
  120. border-bottom: 1rpx solid #EEEEEE;
  121. text {
  122. font-weight: 500;
  123. font-size: 34rpx;
  124. color: #333333;
  125. }
  126. }
  127. .modal-content {
  128. // min-height: 164rpx;
  129. padding: 42rpx 40rpx;
  130. text-align: center;
  131. text {
  132. font-weight: 400;
  133. font-size: 28rpx;
  134. color: #232832;
  135. }
  136. }
  137. .modal-footer {
  138. padding: 16rpx 24rpx;
  139. border-top: 1rpx solid #EEEEEE;
  140. gap: 20rpx;
  141. display: flex;
  142. align-items: center;
  143. justify-content: space-between;
  144. .btn {
  145. width: 100%;
  146. font-weight: 400;
  147. font-size: 28rpx;
  148. line-height: 68rpx;
  149. border-radius: 54rpx;
  150. &::after {
  151. border: none;
  152. }
  153. }
  154. .cancel {
  155. color: #999999;
  156. border: 1rpx solid #CCCCCC;
  157. background: #FFFFFF;
  158. }
  159. .submit {
  160. color: #FFFFFF;
  161. border: 1rpx solid #449AFF;
  162. background: #449AFF;
  163. }
  164. }
  165. &.success {
  166. background: linear-gradient(180deg, #E0F8E3 0%, #FFFFFF 25%);
  167. }
  168. &.warning {
  169. background: linear-gradient( 180deg, #FFEFE2 0%, #FFFFFF 35%);
  170. }
  171. }
  172. </style>