gui-top-message.vue 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <template>
  2. <view class="gui-top-message"
  3. ref="guipopupfortopmsg"
  4. v-if="show"
  5. :style="{top : navHeight+'px'}"
  6. :class="[out ? 'gui-top-message-out' : 'gui-top-message-in']">
  7. <slot></slot>
  8. </view>
  9. </template>
  10. <script>
  11. // #ifdef APP-NVUE
  12. const animation = weex.requireModule('animation');
  13. // #endif
  14. var graceJS = require('@/GraceUI5/js/grace.js');
  15. export default{
  16. name : "gui-top-message",
  17. props : {
  18. duration : {type:Number, default:2000},
  19. customNav : {type:Boolean, default:false }
  20. },
  21. data() {
  22. return {
  23. show : false,
  24. out : false,
  25. navHeight : 0
  26. }
  27. },
  28. created : function (){
  29. this.customNavSet();
  30. },
  31. methods:{
  32. customNavSet : function () {
  33. if(!this.customNav){
  34. // #ifdef H5
  35. this.navHeight = 44;
  36. // #endif
  37. // #ifndef H5
  38. this.navHeight = 0;
  39. // #endif
  40. }else{
  41. var system = graceJS.system();
  42. this.navHeight = system.statusBarHeight;
  43. }
  44. },
  45. open : function(){
  46. this.out = false;
  47. this.show = true;
  48. // #ifdef APP-NVUE
  49. this.weexAnimateIn();
  50. // #endif
  51. setTimeout(()=>{this.close();}, this.duration);
  52. },
  53. close : function(){
  54. this.out = true;
  55. // #ifdef APP-NVUE
  56. this.weexAnimateOut();
  57. // #endif
  58. setTimeout(()=>{this.show = false;},350);
  59. },
  60. // #ifdef APP-NVUE
  61. weexAnimateIn : function(){
  62. graceJS.getRefs('guipopupfortopmsg', this, 0, (guipopupref)=>{
  63. animation.transition(guipopupref, {
  64. styles: {transform:'translateY(0px)', opacity:1},
  65. duration: 350, //ms
  66. timingFunction: 'ease',
  67. delay: 0 //ms
  68. });
  69. });
  70. },
  71. weexAnimateOut : function(){
  72. graceJS.getRefs('guipopupfortopmsg', this, 0, (guipopupref)=>{
  73. animation.transition(guipopupref, {
  74. styles: {transform:'translateY(-200px)', opacity:0},
  75. duration: 350, //ms
  76. timingFunction: 'ease',
  77. delay: 0 //ms
  78. });
  79. });
  80. },
  81. // #endif
  82. }
  83. }
  84. </script>
  85. <style scoped>
  86. .gui-top-message{position:fixed; left:0; top:0; width:750rpx; z-index:900; transform:translateY(-200px); opacity:0.1;}
  87. /* #ifdef H5 */
  88. .gui-top-message{top:44px;}
  89. /* #endif */
  90. /* #ifndef APP-NVUE */
  91. @keyframes gui-top-message-in{0%{transform:translateY(-200px); opacity:0.1;} 100%{transform:translateY(0px); opacity:1;}}
  92. .gui-top-message-in{animation:gui-top-message-in 350ms linear forwards;}
  93. @keyframes gui-top-message-out{0%{transform:translateY(0px); opacity:1;} 100%{transform:translateY(-200px); opacity:1;}}
  94. .gui-top-message-out{animation:gui-top-message-out 350ms linear forwards;}
  95. /* #endif */
  96. </style>