graceActionSheet.vue 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <template>
  2. <view class="graceActionSheet" @tap.stop="closeByShade" @touchmove.stop="stopFun"
  3. :style="{backgroundColor:background, zIndex:zIndex, width:realShow ? '750rpx' : '0rpx'}">
  4. <view :class="['graceActionSheetBody', isIpx ? 'grace-ipx-bottom' : '']"
  5. :style="{width:realShow ? width : '0rpx',left:left,borderTopLeftRadius:borderRadius,borderTopRightRadius:borderRadius, zIndex:zIndex+1}"
  6. @tap.stop="stopFun">
  7. <view class="graceActionSheetTitle" :style="{color:titleColor}">{{title}}</view>
  8. <view class="graceActionSheetList" v-for="(item, index) in items" :key="index" @tap.stop="selected" :data-index="index"
  9. :style="{color:listColor, lineHeight:listLineHeight, fontSize:listFontSize}">{{item}}</view>
  10. <view class="graceActionSheetList" :style="{border:'none', color:cancelBtnColor}" @tap.stop="cancel">{{cancelBtnName}}</view>
  11. </view>
  12. </view>
  13. </template>
  14. <script>
  15. export default {
  16. props: {
  17. width:{type:String,default:'720rpx'},
  18. left:{type:String,default:'15rpx'},
  19. background:{type : String,default : 'rgba(0, 0, 0, 0.3)'},
  20. borderRadius : {type : String,default : '10rpx'},
  21. zIndex:{type : Number,default : 99},
  22. title:{type:String,default:''},
  23. titleColor:{type:String, default:'#323232'},
  24. items:{type:Array, default:function(){return [];}},
  25. listColor:{type:String, default:'#3688FF'},
  26. listLineHeight:{type:String, default:'100rpx'},
  27. listFontSize:{type:String, default:'30rpx'},
  28. cancelBtnName:{type:String,default:'取消'},
  29. cancelBtnColor:{type:String, default:'#999999'}
  30. },
  31. data() {
  32. return {
  33. realShow : false,
  34. isIpx:false
  35. }
  36. },
  37. created : function(){
  38. // #ifndef APP-PLUS
  39. try {
  40. var res = uni.getSystemInfoSync();
  41. res.model = res.model.replace(' ', '');
  42. res.model = res.model.toLowerCase();
  43. if(res.model.indexOf('iphonex') != -1 || res.model.indexOf('iphone11') != -1){
  44. this.isIpx = true;
  45. }
  46. } catch (e){return null;}
  47. // #endif
  48. },
  49. methods:{
  50. cancel:function(){
  51. this.realShow = false;
  52. this.$emit('cancel')
  53. },
  54. closeByShade: function(){this.cancel();},
  55. stopFun : function(){},
  56. selected:function (e) {
  57. this.$emit('selected', e.currentTarget.dataset.index);
  58. this.close();
  59. },
  60. close:function(){this.realShow = false;},
  61. show:function(){this.realShow = true;}
  62. }
  63. }
  64. </script>
  65. <style scoped>
  66. .graceActionSheet{position:fixed; width:100%; height:100%; left:0; top:0;}
  67. .graceActionSheetBody{background:#FFFFFF; position:absolute; bottom:0; left:0; overflow:hidden;}
  68. .graceActionSheetTitle{text-align:center; font-size:26rpx; line-height:120rpx; height:120rpx; font-weight:bold; border-bottom:1px solid #F8F8F8;}
  69. .grace-ipx-bottom{padding-bottom:50rpx !important;}
  70. .graceActionSheetList{line-height:120rpx; font-weight:600; overflow:hidden; text-align:center; margin:0 30rpx; border-bottom:1px solid #F8F8F8;}
  71. </style>