alert.vue 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. <template>
  2. <view>
  3. <view class="tui-alert-class tui-alert-box" :class="[show?'tui-alert-show':'']">
  4. <view class="tui-alert-content" :style="{fontSize:size+'rpx',color:color, padding: padding}">
  5. <slot></slot>
  6. </view>
  7. <view class="tui-alert-btn" :style="{color:btnColor}" hover-class="tui-alert-btn-hover" :hover-stay-time="150"
  8. @tap.stop="handleClick">{{btnText}}</view>
  9. </view>
  10. <view class="tui-alert-mask" :class="[show?'tui-alert-mask-show':'']" @tap.stop="handleClickCancel"></view>
  11. </view>
  12. </template>
  13. <script>
  14. export default {
  15. name: 'tuiAlert',
  16. props: {
  17. // 控制显示
  18. show: {
  19. type: Boolean,
  20. default: false
  21. },
  22. // 提示信息字体大小
  23. size: {
  24. type: Number,
  25. default: 28
  26. },
  27. // 提示信息字体颜色
  28. color: {
  29. type: String,
  30. default: '#333'
  31. },
  32. // 按钮字体颜色
  33. btnColor: {
  34. type: String,
  35. default: '#666'
  36. },
  37. btnText: {
  38. type: String,
  39. default: '知道了'
  40. },
  41. // content padding
  42. padding: {
  43. type: String,
  44. default: '98rpx 48rpx 92rpx 48rpx'
  45. },
  46. // 点击遮罩 是否可关闭
  47. maskClosable: {
  48. type: Boolean,
  49. default: false
  50. }
  51. },
  52. methods: {
  53. handleClick(e) {
  54. if (!this.show) return
  55. this.$emit('click', {})
  56. },
  57. handleClickCancel() {
  58. if (!this.maskClosable) return
  59. this.$emit('cancel')
  60. }
  61. }
  62. }
  63. </script>
  64. <style>
  65. .tui-alert-box {
  66. position: fixed;
  67. width: 560rpx;
  68. left: 50%;
  69. top: 50%;
  70. background: #fff;
  71. transition: all 0.3s ease-in-out;
  72. transform: translate(-50%, -50%) scale(0);
  73. opacity: 0;
  74. border-radius: 20px;
  75. overflow: hidden;
  76. z-index: 9998;
  77. }
  78. .tui-alert-show {
  79. transform: translate(-50%, -50%) scale(1);
  80. opacity: 1;
  81. }
  82. .tui-alert-mask {
  83. position: fixed;
  84. top: 0;
  85. left: 0;
  86. right: 0;
  87. bottom: 0;
  88. background: rgba(0, 0, 0, 0.5);
  89. z-index: 9996;
  90. transition: all 0.3s ease-in-out;
  91. opacity: 0;
  92. visibility: hidden;
  93. }
  94. .tui-alert-mask-show {
  95. visibility: visible;
  96. opacity: 1;
  97. }
  98. .tui-alert-content {
  99. text-align: center;
  100. color: #333333;
  101. /* padding: 98rpx 48rpx 92rpx 48rpx; */
  102. box-sizing: border-box;
  103. word-break: break-all;
  104. }
  105. .tui-alert-btn {
  106. width: 100%;
  107. height: 90rpx;
  108. display: flex;
  109. align-items: center;
  110. justify-content: center;
  111. background: #fff;
  112. box-sizing: border-box;
  113. position: relative;
  114. font-size: 32rpx;
  115. line-height: 32rpx;
  116. }
  117. .tui-alert-btn-hover {
  118. background: #f7f7f7;
  119. }
  120. .tui-alert-btn::before {
  121. width: 100%;
  122. content: "";
  123. position: absolute;
  124. border-top: 1rpx solid #E0E0E0;
  125. -webkit-transform: scaleY(0.5);
  126. transform: scaleY(0.5);
  127. left: 0;
  128. top: 0;
  129. }
  130. </style>