tui-toast.vue 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. <template>
  2. <view class="tui-toast" :class="[visible?'tui-toast-show':'',content?'tui-toast-padding':'',icon?'':'tui-unicon-padding']" :style="{width:getWidth(icon,content),zIndex:zIndex}">
  3. <image :src="imgUrl" class="tui-toast-img" v-if="icon"></image>
  4. <view class="tui-toast-text" :class="[icon?'':'tui-unicon']">{{title}}</view>
  5. <view class="tui-toast-text tui-content-ptop" v-if="content && icon">{{content}}</view>
  6. </view>
  7. </template>
  8. <script>
  9. export default {
  10. name: "tuiToast",
  11. props: {
  12. zIndex:{
  13. type:Number,
  14. default:99999
  15. }
  16. },
  17. data() {
  18. return {
  19. timer: null,
  20. //是否显示
  21. visible: false,
  22. //显示标题
  23. title: "操作成功",
  24. //显示内容
  25. content: "",
  26. //是否有icon
  27. icon:false,
  28. imgUrl:""
  29. };
  30. },
  31. methods: {
  32. show: function(options) {
  33. let {
  34. duration = 2000,
  35. icon=false
  36. } = options;
  37. clearTimeout(this.timer);
  38. this.visible = true;
  39. this.title = options.title || "";
  40. this.content = options.content || "";
  41. this.icon=icon;
  42. if(icon && options.imgUrl){
  43. this.imgUrl=options.imgUrl
  44. }
  45. this.timer = setTimeout(() => {
  46. this.visible = false;
  47. clearTimeout(this.timer);
  48. this.timer = null;
  49. }, duration);
  50. },
  51. getWidth(icon,content){
  52. let width="auto";
  53. if(icon){
  54. width=content?'420rpx':'360rpx'
  55. }
  56. return width
  57. }
  58. }
  59. }
  60. </script>
  61. <style scoped>
  62. .tui-toast {
  63. background-color: rgba(0, 0, 0, 0.75);
  64. border-radius: 10rpx;
  65. position: fixed;
  66. visibility: hidden;
  67. opacity: 0;
  68. left: 50%;
  69. top: 48%;
  70. -webkit-transform: translate(-50%, -50%);
  71. transform: translate(-50%, -50%);
  72. transition: 0.3s ease-in-out;
  73. transition-property:opacity,visibility;
  74. display: flex;
  75. align-items: center;
  76. justify-content: center;
  77. flex-direction: column;
  78. padding: 60rpx 20rpx 54rpx 20rpx;
  79. box-sizing: border-box;
  80. }
  81. .tui-toast-padding {
  82. padding-top: 50rpx !important;
  83. padding-bottom: 50rpx !important;
  84. }
  85. .tui-unicon-padding {
  86. padding: 24rpx 40rpx !important;
  87. word-break: break-all;
  88. }
  89. .tui-toast-show {
  90. visibility: visible;
  91. opacity: 1;
  92. }
  93. .tui-toast-img {
  94. width: 120rpx;
  95. height: 120rpx;
  96. display: block;
  97. margin-bottom: 28rpx;
  98. }
  99. .tui-toast-text {
  100. font-size: 30rpx;
  101. line-height: 30rpx;
  102. font-weight: 400;
  103. color: #fff;
  104. text-align: center;
  105. }
  106. .tui-unicon{
  107. line-height: 40rpx !important;
  108. font-size: 32rpx !important;
  109. }
  110. .tui-content-ptop {
  111. padding-top: 10rpx;
  112. font-size: 26rpx !important;
  113. }
  114. </style>