z-message.vue 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. <template>
  2. <view class="message-content flex-n fjc" :class="show?'animate_show':'animate_hide'">
  3. <view class="text" :class="type">{{text}}</view>
  4. </view>
  5. </template>
  6. <script>
  7. export default {
  8. name: 'z-message',
  9. props: {
  10. // type: {
  11. // type: String,
  12. // default: ''
  13. // },
  14. // text: {
  15. // type: String | Object,
  16. // default: ''
  17. // },
  18. // show: {
  19. // type: Boolean,
  20. // default: false
  21. // }
  22. },
  23. data() {
  24. return {
  25. show:false,
  26. type:'',
  27. text:''
  28. }
  29. },
  30. methods:{
  31. success(text){
  32. this.show=true;
  33. this.type='success';
  34. this.text=text;
  35. setTimeout(() => {this.show=false},2000) //显示后2秒就消失
  36. },
  37. error(text){
  38. this.show=true;
  39. this.type='error';
  40. this.text=text;
  41. setTimeout(() => {this.show=false},2000) //显示后2秒就消失
  42. }
  43. }
  44. }
  45. </script>
  46. <style lang="scss" scoped>
  47. @keyframes hide{
  48. 0%{
  49. top: 110rpx;
  50. opacity: 1;
  51. }
  52. 50%{
  53. top:10rpx;
  54. opacity: 0;
  55. }
  56. 100%{
  57. top:-90rpx;
  58. opacity: 0;
  59. }
  60. }
  61. @keyframes show{
  62. 0%{
  63. top:-90rpx;
  64. opacity: 0;
  65. }
  66. 50%{
  67. top:10rpx;
  68. opacity: 0;
  69. }
  70. 100%{
  71. top: 110rpx;
  72. opacity: 1;
  73. }
  74. }
  75. .animate_hide{
  76. animation: hide 1s;
  77. animation-fill-mode: forwards;
  78. }
  79. .animate_show{
  80. animation: show .5s;
  81. animation-fill-mode: forwards;
  82. }
  83. .message-content {
  84. position: fixed;
  85. top: 110rpx;
  86. width: 100%;
  87. left: 0;
  88. z-index: 1600;
  89. height: fit-content;
  90. .text {
  91. width: fit-content;
  92. max-width: 550rpx;
  93. text-align: center;
  94. font-size: 34rpx;
  95. padding: 20rpx 40rpx;
  96. }
  97. .success {
  98. background-color: #f0f9eb;
  99. border-color: #e1f3d8;
  100. color: #67C23A;
  101. }
  102. .error {
  103. background-color: #fef0f0;
  104. border-color: #fde2e2;
  105. color: #F56C6C;
  106. }
  107. .info {
  108. background-color: #f9fafc;
  109. border: 1px solid #eaeefb;
  110. color: #5e6d82;
  111. }
  112. }
  113. </style>