gui-top-message.vue 2.4 KB

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