graceDrawer.nvue 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <template>
  2. <view>
  3. <view class="grace-drawer-shade" v-if="show" @click.stop="closeDrawer" @touchmove.stop="" :style="{backgroundColor:background}"></view>
  4. <view ref="graceDrawerMenu" v-if="show" class="grace-drawer-nav" @tap.stop="stopFun"
  5. :style="{width:width+'rpx', left : direction == 'left' ? (width*-1)+'rpx' : 'none',
  6. right : direction == 'right' ? (width*-1)+'rpx' : 'none',
  7. padding:padding, backgroundColor:slotBg}">
  8. <view class="grace-drawer-main"><slot name="links"></slot></view>
  9. </view>
  10. </view>
  11. </template>
  12. <script>
  13. export default {
  14. name: "graceDrawer",
  15. props: {
  16. width : {
  17. type : Number,
  18. default : 500
  19. },
  20. show : {
  21. type : Boolean,
  22. default : true
  23. },
  24. direction : {
  25. type : String,
  26. default : 'left'
  27. },
  28. background:{
  29. type : String,
  30. default : 'rgba(0, 0, 0, 0.5)'
  31. },
  32. slotBg:{
  33. type : String,
  34. default : 'rgba(255, 255, 255, 1)'
  35. },
  36. padding : {
  37. type : String,
  38. default : '30rpx'
  39. }
  40. },
  41. updated:function(){
  42. if(this.show){
  43. setTimeout(()=>{
  44. var moveX = this.direction == 'left' ? uni.upx2px(this.width) + 'px' : (uni.upx2px(this.width) * -1) + 'px';
  45. var animation = weex.requireModule('animation');
  46. animation.transition(this.$refs.graceDrawerMenu, {
  47. styles: {transform:'translate('+moveX+', 0)'},
  48. duration:200,
  49. timingFunction: 'linear',
  50. needLayout:false,
  51. delay: 0
  52. }, function (){}
  53. );
  54. }, 100);
  55. }
  56. },
  57. methods:{
  58. closeDrawer : function(){
  59. this.$emit('closeDrawer');
  60. },
  61. stopFun : function(){}
  62. }
  63. }
  64. </script>
  65. <style scoped>
  66. .grace-drawer-shade{position:fixed; width:750rpx; bottom:0; top:0; left:0; background-color:rgba(0, 0, 0, 0.5);}
  67. .grace-drawer-nav{background-color:#FFFFFF; position:fixed; bottom:0; top:0;}
  68. .grace-drawer-main{}
  69. </style>