graceHeaderAlert.nvue 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <template>
  2. <view class="grace-alert" v-if="showIn" :style="{top : topReal + 'px'}">
  3. <view class="grace-alert-body" ref="gracealert"
  4. :style="{'background-color':background, width:width+'rpx'}">
  5. <slot></slot>
  6. </view>
  7. </view>
  8. </template>
  9. <script>
  10. export default {
  11. name: "graceHeaderAlert",
  12. props: {
  13. show : { type : Boolean, default : false },
  14. background : { type : String, default : '#F1F2F3' },
  15. top : { type : Number, default : 20 },
  16. width : { type : Number, default : 580},
  17. duration : { type : Number, default : 2500}
  18. },
  19. data() {
  20. return {
  21. showIn : false,
  22. topReal : 0
  23. }
  24. },
  25. created:function(){
  26. this.topReal = this.top;
  27. this.showIn = this.show;
  28. },
  29. watch: {
  30. show : function(n , o){
  31. if(n){
  32. this.showIn = n;
  33. this.animation();
  34. }
  35. }
  36. },
  37. methods:{
  38. open:function(){
  39. this.showIn = true;
  40. this.animation();
  41. },
  42. close:function(){
  43. this.showIn = false;
  44. },
  45. animation : function(){
  46. setTimeout(()=>{
  47. var animation = weex.requireModule('animation');
  48. animation.transition(this.$refs.gracealert, {
  49. styles : {opacity:0, transform:'scale(0.1,0.1)'},
  50. duration : 1,
  51. timingFunction : 'linear',
  52. needLayout : false,
  53. delay : 0 ,
  54. }, ()=>{
  55. animation.transition(this.$refs.gracealert, {
  56. styles : {opacity:1, transform:'scale(1,1)'},
  57. duration : 150,
  58. timingFunction : 'linear',
  59. needLayout : false,
  60. delay : 0 ,
  61. });
  62. });
  63. }, 200);
  64. setTimeout(()=>{this.showIn = false;}, this.duration);
  65. }
  66. }
  67. }
  68. </script>
  69. <style scoped>
  70. .grace-alert{width:750rpx; flex-direction:row; flex-wrap:nowrap; justify-content:center; align-items:center; position:fixed; left:0rpx; top:20rpx;}
  71. .grace-alert-body{padding:25rpx; border-radius:10rpx; flex-direction:row; flex-wrap:nowrap; justify-content:center; align-items:center; opacity:0;}
  72. </style>