gui-popup-menu.vue 3.5 KB

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