tui-alert.vue 2.5 KB

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