index.vue 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  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. callback: null
  78. };
  79. },
  80. mounted() {
  81. },
  82. methods: {
  83. onOpen(duration = 0, callback) {
  84. this.show = true;
  85. if (duration > 0) {
  86. // 清除之前的定时器(防止多次调用)
  87. if (this.timer) clearTimeout(this.timer);
  88. this.timer = setTimeout(() => {
  89. this.show = false;
  90. callback && callback();
  91. }, duration);
  92. }
  93. if (!duration && callback) {
  94. this.callback = callback;
  95. }
  96. },
  97. onCancel() {
  98. this.$emit('cancel');
  99. this.show = false;
  100. },
  101. onSubmit() {
  102. this.callback && this.callback();
  103. this.$emit('confirm');
  104. this.show = false;
  105. },
  106. }
  107. }
  108. </script>
  109. <style lang="scss" scoped>
  110. ::v-deep .u-popup {
  111. flex: initial;
  112. }
  113. ::v-deep .u-mode-center-box {
  114. background: transparent;
  115. }
  116. .modal-box {
  117. width: calc(100vw - 150rpx);
  118. // margin: 0 75rpx;
  119. border-radius: 16rpx;
  120. background: #fff;
  121. .modal-header {
  122. margin: 0 24rpx;
  123. padding: 18rpx 0;
  124. text-align: center;
  125. border-bottom: 1rpx solid #EEEEEE;
  126. text {
  127. font-weight: 500;
  128. font-size: 34rpx;
  129. color: #333333;
  130. }
  131. }
  132. .modal-content {
  133. // min-height: 164rpx;
  134. padding: 42rpx 40rpx;
  135. text-align: center;
  136. text {
  137. font-weight: 400;
  138. font-size: 28rpx;
  139. color: #232832;
  140. }
  141. }
  142. .modal-footer {
  143. padding: 16rpx 24rpx;
  144. border-top: 1rpx solid #EEEEEE;
  145. gap: 20rpx;
  146. display: flex;
  147. align-items: center;
  148. justify-content: space-between;
  149. .btn {
  150. width: 100%;
  151. font-weight: 400;
  152. font-size: 28rpx;
  153. line-height: 68rpx;
  154. border-radius: 54rpx;
  155. &::after {
  156. border: none;
  157. }
  158. }
  159. .cancel {
  160. color: #999999;
  161. border: 1rpx solid #CCCCCC;
  162. background: #FFFFFF;
  163. }
  164. .submit {
  165. color: #FFFFFF;
  166. border: 1rpx solid #449AFF;
  167. background: #449AFF;
  168. }
  169. }
  170. &.success {
  171. background: linear-gradient(180deg, #E0F8E3 0%, #FFFFFF 25%);
  172. }
  173. &.warning {
  174. background: linear-gradient( 180deg, #FFEFE2 0%, #FFFFFF 35%);
  175. }
  176. }
  177. </style>