gui-popup-menu.vue 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. <template>
  2. <view class="gui-relative" v-if="showIn">
  3. <view class="grace-popup-mask"
  4. :class="[showIn?'grace-shade-in':'', outting ? 'grace-shade-out' : '']"
  5. @tap.stop="close" @touchmove.stop.prevent="stopfun"
  6. :style="{backgroundColor:background, zIndex:zIndex}"
  7. v-if="showIn"></view>
  8. <view class="grace-popup-menu"
  9. v-if="showIn" ref="guipopupmenu"
  10. :class="[showIn?'grace-shade-in':'', outting ? 'grace-shade-out' : '']"
  11. :style="{
  12. top:top+'px', right:right+'px', width:menuWidth,
  13. zIndex:zIndex+1, height:showIn?'':'0rpx'
  14. }">
  15. <!-- #ifndef APP-NVUE -->
  16. <view :class="['gui-flex', 'gui-rows', 'arrow-d-'+arrowDirection]"
  17. v-if="isArrow">
  18. <view class="arrow-up" :style="{margin:arrowMargin}"></view>
  19. </view>
  20. <!-- #endif -->
  21. <view :style="{width:menuWidth}">
  22. <slot></slot>
  23. </view>
  24. </view>
  25. </view>
  26. </template>
  27. <script>
  28. // #ifdef APP-NVUE
  29. const animation = weex.requireModule('animation');
  30. // #endif
  31. var graceJS = require('@/GraceUI5/js/grace.js');
  32. export default {
  33. name : "gui-popup-menu",
  34. props : {
  35. menuWidth : { type : String, default : '258rpx' },
  36. background : { type : String, default : 'rgba(0,0,0, 0.3)' },
  37. zIndex : { type : Number, default : 99 },
  38. isArrow : { type : Boolean, default : true},
  39. arrowDirection : {type : String, default : "right"},
  40. arrowMargin : { type : String, default : "0 15rpx"}
  41. },
  42. data() {
  43. return {
  44. showIn : false,
  45. top : 0,
  46. right : 0,
  47. outting : false
  48. }
  49. },
  50. methods: {
  51. stopfun : function(e){e.stopPropagation(); return null;},
  52. open : function(){
  53. this.outting = false;
  54. this.showIn = true;
  55. // #ifdef APP-NVUE
  56. graceJS.getRefs('guipopupmenu', this, 0, (guipopupref)=>{
  57. animation.transition(guipopupref, {
  58. styles: {opacity:1, transform:'scale(1)'},
  59. duration: 200, //ms
  60. timingFunction: 'ease',
  61. delay: 0 //ms
  62. });
  63. });
  64. // #endif
  65. },
  66. close : function(){
  67. this.outting = true;
  68. setTimeout(()=>{
  69. this.showIn = false;
  70. },200);
  71. // #ifdef APP-NVUE
  72. graceJS.getRefs('guipopupmenu', this, 0, (guipopupref)=>{
  73. animation.transition(guipopupref, {
  74. styles: {opacity:0, transform:'scale(0.5)'},
  75. duration: 200, //ms
  76. timingFunction: 'ease',
  77. delay: 0 //ms
  78. });
  79. });
  80. // #endif
  81. },
  82. setTop : function (top) {
  83. this.top = top;
  84. },
  85. setRight : function (right) {
  86. this.right = right;
  87. }
  88. }
  89. }
  90. </script>
  91. <style scoped>
  92. .grace-popup-menu{width:258rpx; padding:10rpx; right:0; top:0; position:absolute; opacity:0; transform:scale(0.1);}
  93. /* #ifdef APP-NVUE */
  94. .grace-popup-menu{padding:0rpx 10rpx;}
  95. /* #endif */
  96. .grace-popup-mask{width:750rpx; position:fixed; left:0; top:0px; bottom:0; flex:1;}
  97. /* #ifndef APP-NVUE */
  98. .grace-popup-mask{height:100%;}
  99. .arrow-up{width:0; height:0; border-left:18rpx solid transparent; border-right:18rpx solid transparent; border-bottom:18rpx solid #FFFFFF;}
  100. .arrow-d-right{justify-content:flex-end;}
  101. .arrow-d-center{justify-content:center;}
  102. .arrow-d-left{justify-content:flex-start;}
  103. .grace-shade-in{animation:grace-shade-in-a 150ms ease-in forwards;}
  104. @keyframes grace-shade-in-a{0%{transform:scale(0.1); opacity:0;} 100%{transform: scale(1); opacity:1;}}
  105. .grace-shade-out{animation:grace-shade-out-a 150ms ease-out forwards;}
  106. @keyframes grace-shade-out-a{0%{transform:scale(1); opacity:1;} 100%{transform: scale(0.5); opacity:0;}}
  107. /* #endif */
  108. /* #ifdef APP-NVUE */
  109. .grace-popup-menu{position:fixed;}
  110. /* #endif */
  111. </style>