centerPopup.vue 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. <template>
  2. <view :class="ani?'center-container':'center-container center-container2'" v-show="isShow" catchtouchmove>
  3. <view class="centerPopup" @touchmove.prevent>
  4. <view class="title" :style="{fontSize:fontSize}">{{title}}</view>
  5. <view class="subTitle">{{subTitle?subTitle:''}}</view>
  6. <view class="xzwButton">
  7. <view class="cancelButton" @click="leftClick" :style="{border:'1upx solid'+useColor,color:useColor,backgroundColor:'#fff'}">{{leftText}}</view>
  8. <view class="confirmButton" @click="rightClick" :style="{color:'#fff',backgroundColor:useColor}">{{rightText}}</view>
  9. </view>
  10. </view>
  11. <view class="mask" @click="close" v-show="isShow" @touchmove.prevent></view>
  12. </view>
  13. </template>
  14. <script>
  15. export default {
  16. props: {
  17. title: '', //标题
  18. subTitle: '', // 小标题
  19. leftText: { // 左侧文字
  20. type: String,
  21. default: '取消'
  22. },
  23. rightText: { // 右侧文字
  24. type: String,
  25. default: '确定'
  26. },
  27. color: { //弹窗颜色
  28. type: String,
  29. default: ''
  30. },
  31. default: { //左侧按钮是否默认点击
  32. type: Boolean,
  33. default: true
  34. },
  35. fontSize: { //字体大小
  36. type: String,
  37. default: '32upx'
  38. }
  39. },
  40. data() {
  41. return {
  42. isShow: false,
  43. ani: false,
  44. useColor: '#f00'
  45. }
  46. },
  47. methods: {
  48. leftClick() {
  49. if (this.default) {
  50. this.close()
  51. } else {
  52. this.$emit("leftClick")
  53. }
  54. },
  55. open() {
  56. this.$nextTick(function() {
  57. this.ani = true
  58. this.isShow = true
  59. if (this.color) {
  60. this.useColor = this.color
  61. } else {
  62. this.useColor = '#f00'
  63. }
  64. console.log(this.useColor)
  65. })
  66. },
  67. close() {
  68. this.ani = false
  69. // #ifndef MP-WEIXIN
  70. setTimeout(() => {
  71. this.isShow = false
  72. }, 180)
  73. // #endif
  74. // #ifdef MP-WEIXIN
  75. this.isShow = false
  76. // #endif
  77. },
  78. rightClick() {
  79. this.$emit('confirmClick')
  80. }
  81. }
  82. }
  83. </script>
  84. <style lang="scss">
  85. @keyframes in {
  86. 0% {
  87. opacity: 0;
  88. transform: scale(1.1, 1.1);
  89. }
  90. 100% {
  91. opacity: 1;
  92. transform: scale(1, 1);
  93. }
  94. }
  95. @keyframes out {
  96. 0% {
  97. opacity: 1;
  98. transform: scale(1, 1);
  99. }
  100. 100% {
  101. opacity: 0;
  102. transform: scale(1.2, 1.2);
  103. }
  104. }
  105. .center-container {
  106. z-index: 1000;
  107. position: fixed;
  108. top: 0;
  109. left: 0;
  110. bottom: 0;
  111. right: 0;
  112. animation: in 0.2s ease-in;
  113. .centerPopup {
  114. z-index: 1000;
  115. width: 586upx;
  116. background-color: #fff;
  117. border-radius: 20upx;
  118. position: absolute;
  119. left: 50%;
  120. top: 48%;
  121. transform: translate(-50%, -50%);
  122. .title {
  123. font-weight: bold;
  124. text-align: center;
  125. font-size: 32upx;
  126. padding: 74upx 20upx 20upx;
  127. }
  128. .subTitle {
  129. text-align: center;
  130. font-size: 24upx;
  131. padding: 0 20upx 20upx 20upx;
  132. }
  133. .xzwButton {
  134. display: flex;
  135. justify-content: space-between;
  136. padding: 20upx 70upx 54upx;
  137. view {
  138. width: 216upx;
  139. height: 60upx;
  140. display: flex;
  141. align-items: center;
  142. justify-content: center;
  143. border-radius: 44upx;
  144. font-size: 28upx;
  145. box-sizing: border-box;
  146. }
  147. }
  148. }
  149. .mask {
  150. z-index: 100;
  151. position: absolute;
  152. top: 0;
  153. left: 0;
  154. bottom: 0;
  155. right: 0;
  156. background: #000;
  157. opacity: 0.4;
  158. }
  159. }
  160. .center-container2 {
  161. animation: out 0.2s ease-in;
  162. }
  163. </style>