tui-alert.vue 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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}">
  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: 30
  26. },
  27. //提示信息字体颜色
  28. color: {
  29. type: String,
  30. default: "#333"
  31. },
  32. //按钮字体颜色
  33. btnColor: {
  34. type: String,
  35. default: "#EB0909"
  36. },
  37. btnText:{
  38. type: String,
  39. default: "确定"
  40. },
  41. //点击遮罩 是否可关闭
  42. maskClosable: {
  43. type: Boolean,
  44. default: false
  45. }
  46. },
  47. methods: {
  48. handleClick(e) {
  49. if (!this.show) return;
  50. this.$emit('click', {});
  51. },
  52. handleClickCancel() {
  53. if (!this.maskClosable) return;
  54. this.$emit('cancel');
  55. }
  56. }
  57. }
  58. </script>
  59. <style scoped>
  60. .tui-alert-box {
  61. position: fixed;
  62. width: 560rpx;
  63. left: 50%;
  64. top: 50%;
  65. background-color: #fff;
  66. transition: all 0.3s ease-in-out;
  67. transform: translate(-50%, -50%) scale(0);
  68. opacity: 0;
  69. border-radius: 6rpx;
  70. overflow: hidden;
  71. z-index: 99998;
  72. }
  73. .tui-alert-show {
  74. transform: translate(-50%, -50%) scale(1);
  75. opacity: 1;
  76. }
  77. .tui-alert-mask {
  78. position: fixed;
  79. top: 0;
  80. left: 0;
  81. right: 0;
  82. bottom: 0;
  83. background-color: rgba(0, 0, 0, 0.5);
  84. z-index: 99996;
  85. transition: all 0.3s ease-in-out;
  86. opacity: 0;
  87. visibility: hidden;
  88. }
  89. .tui-alert-mask-show {
  90. visibility: visible;
  91. opacity: 1;
  92. }
  93. .tui-alert-content {
  94. text-align: center;
  95. color: #333333;
  96. padding: 98rpx 48rpx 92rpx 48rpx;
  97. box-sizing: border-box;
  98. word-break: break-all;
  99. }
  100. .tui-alert-btn {
  101. width: 100%;
  102. height: 90rpx;
  103. display: flex;
  104. align-items: center;
  105. justify-content: center;
  106. background-color: #fff;
  107. box-sizing: border-box;
  108. position: relative;
  109. font-size: 32rpx;
  110. line-height: 32rpx;
  111. }
  112. .tui-alert-btn-hover {
  113. background-color: #f7f7f7;
  114. }
  115. .tui-alert-btn::before {
  116. width: 100%;
  117. content: "";
  118. position: absolute;
  119. border-top: 1rpx solid #E0E0E0;
  120. -webkit-transform: scaleY(0.5);
  121. transform: scaleY(0.5);
  122. left: 0;
  123. top: 0;
  124. }
  125. </style>