action-sheet.vue 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. <template name="simpleActionSheet">
  2. <view class="simple-action-sheet" v-if="show" @touchmove.stop.prevent="moveHandleStop">
  3. <view class="simple-actionsheet-mask" v-if="overlay" v-bind:style="{ zIndex: zIndex-1 }" @click="ActionCloseOverlay"></view>
  4. <view class="simple-actionsheet" v-bind:style="{ zIndex: zIndex }" :class="[show ? 'simple-actionsheet-animate-show' : '']">
  5. <view class="simple-actionsheet-content">
  6. <view class="simple-actionsheet_item" hover-class="simple-actionsheet_item_hover" v-for="(item,index) in actions" :key="index" @click="ActionClick(index)">{{item.name}}</view>
  7. <view class="simple-actionsheet_item simple-actionsheet_item-cancel" hover-class="simple-actionsheet_item_hover" @click="ActionCancelClick">{{cancelText}}</view>
  8. </view>
  9. </view>
  10. </view>
  11. </template>
  12. <script>
  13. export default {
  14. name: "simpleActionSheet",
  15. props: {
  16. show:{
  17. type : Boolean,
  18. default:false, // 是否展示
  19. },
  20. actions:{
  21. type : Array,
  22. default : [], // 菜单选项
  23. },
  24. title: {
  25. type: String,
  26. default: "" // 标题
  27. },
  28. zIndex:{
  29. type : Number,
  30. default : 100 // z-index 层级
  31. },
  32. cancelText:{
  33. type: String,
  34. default: "取消" //取消按钮文字
  35. },
  36. overlay:{
  37. type : Boolean,
  38. default:true, // 是否显示遮罩层
  39. },
  40. closeOverlay:{
  41. type : Boolean,
  42. default:true, // 是否点击遮罩层关闭
  43. }
  44. },
  45. methods:{
  46. ActionClick:function(index){
  47. var action = this.actions[index];
  48. this.$emit('select',action); // 选中
  49. },
  50. ActionCancelClick:function(){
  51. this.$emit('cancel'); // 点击了取消按钮
  52. },
  53. ActionCloseOverlay:function(){
  54. this.$emit('close'); // 点击了遮罩层
  55. },
  56. moveHandleStop:function(){
  57. }
  58. }
  59. }
  60. </script>
  61. <style>
  62. .simple-action-sheet .simple-actionsheet{
  63. position: fixed;
  64. left: 0;
  65. right: 0;
  66. bottom: 0;
  67. color: #323233;
  68. max-height: 90%;
  69. overflow-y: auto;
  70. -webkit-overflow-scrolling: touch;
  71. background-color: #f8f8f8;
  72. -webkit-transform: translateY(100%);
  73. transform: translateY(100%);
  74. -webkit-backface-visibility: hidden;
  75. backface-visibility: hidden;
  76. z-index: 5000;
  77. width: 100%;
  78. background-color: #efeff4;
  79. -webkit-transition: -webkit-transform .3s;
  80. transition: -webkit-transform .3s;
  81. transition: transform .3s;
  82. transition: transform .3s,-webkit-transform .3s;
  83. }
  84. .simple-action-sheet .simple-actionsheet.simple-actionsheet-animate-show{
  85. -webkit-transform: translate(0);
  86. transform: translate(0);
  87. }
  88. .simple-action-sheet .simple-actionsheet-mask{
  89. position: fixed;
  90. top: 0;
  91. left: 0;
  92. width: 100%;
  93. height: 100%;
  94. background-color: rgba(0, 0, 0, 0.7);
  95. }
  96. .simple-action-sheet .simple-actionsheet .simple-actionsheet_item{
  97. height: 100rpx;
  98. line-height: 100rpx;
  99. font-size: 32rpx;
  100. text-align: center;
  101. background-color: #fff;
  102. border-bottom: 1rpx solid #ebedf0;
  103. }
  104. .simple-action-sheet .simple-actionsheet .simple-actionsheet_item_hover{
  105. background-color: #e8e8e8;
  106. }
  107. .simple-actionsheet_item-cancel{
  108. margin-top: 10rpx;
  109. }
  110. </style>