gracePopupMenu.vue 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <template name="gracePopupMenu">
  2. <view>
  3. <view class="grace-popup-mask" @tap.stop="hideMenu" @touchmove.stop.prevent=""
  4. :style="{background:background, zIndex:zIndex, top:showIn?'0px':'-3000px'}"></view>
  5. <view class="grace-popup-menu"
  6. :class="[showIn?'grace-shade-in':'grace-shade-out']"
  7. :style="{top:top+'px', width:menuWidth, zIndex:zIndex+1, height:showIn?'':'0rpx'}">
  8. <view :class="['grace-rows', 'arrow-d-'+arrowDirection]" v-if="isArrow">
  9. <view class="arrow-up" :style="{borderBottomColor:bgColor, margin:arrowMargin}"></view>
  10. </view>
  11. <view :style="{background:bgColor, width:menuWidth, borderRadius:borderRadius}"><slot></slot></view>
  12. </view>
  13. </view>
  14. </template>
  15. <script>
  16. export default {
  17. name: "gracePopupMenu",
  18. props: {
  19. show:{
  20. type : Boolean,
  21. default : false
  22. },
  23. top:{
  24. type : Number,
  25. default : 0
  26. },
  27. bgColor:{
  28. type : String,
  29. default :'#FFFFFF'
  30. },
  31. menuWidth :{
  32. type : String,
  33. default : '258rpx'
  34. },
  35. background : {
  36. type : String,
  37. default : 'rgba(0,0,0, 0.3)'
  38. },
  39. borderRadius:{
  40. type : String,
  41. default:'0rpx'
  42. },
  43. zIndex : {type:Number, default:3},
  44. isArrow:{type:Boolean, default:true},
  45. arrowDirection:{type:String, default:"right"},
  46. arrowMargin:{type:String, default:"0 12rpx"}
  47. },
  48. data() {
  49. return {
  50. showIn : false
  51. }
  52. },
  53. created:function(){
  54. if(this.show){this.open();}else{this.hide();}
  55. },
  56. watch:{
  57. show : function(val,oval){
  58. this.showIn = val;
  59. }
  60. },
  61. methods: {
  62. hideMenu : function() {
  63. this.$emit('hideMenu');
  64. },
  65. open : function(){
  66. this.showIn = true;
  67. },
  68. hide:function(){
  69. this.showIn = false;
  70. }
  71. }
  72. }
  73. </script>
  74. <style scoped>
  75. .grace-popup-menu{width:258rpx; padding:10rpx; right:0px; overflow:hidden; top:0px; position:absolute; z-index:3; opacity:0;}
  76. .grace-popup-mask{background:rgba(0,0,0, 0.3); width:100%; height:100%; position:fixed; left:0; top:-3000px; z-index:4;}
  77. .arrow-up{width:0; height:0; border-left:18rpx solid transparent; border-right:18rpx solid transparent; border-bottom:18rpx solid #FFFFFF;}
  78. .arrow-d-right{justify-content:flex-end;}
  79. .arrow-d-center{justify-content:center;}
  80. .arrow-d-left{justify-content:flex-start;}
  81. .grace-shade-in{animation:grace-shade-in-a 150ms ease-in forwards;}
  82. @keyframes grace-shade-in-a{0%{transform: scale(0.1); opacity:0;} 100%{transform: scale(1); opacity:1;}}
  83. .grace-shade-out{animation:grace-shade-out-a 150ms ease-out forwards;}
  84. @keyframes grace-shade-out-a{0%{opacity:1; height:'';} 100%{ opacity:0; height:0;}}
  85. </style>