actionsheet.vue 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. <template>
  2. <transition name="actionsheet-float">
  3. <div v-show="currentValue" class="mint-actionsheet">
  4. <ul class="mint-actionsheet-list" :style="{ 'margin-bottom': cancelText ? '5px' : '0' }">
  5. <li v-for="( item, index ) in actions" class="mint-actionsheet-listitem" @click.stop="itemClick(item, index)">{{ item.name }}</li>
  6. </ul>
  7. <a class="mint-actionsheet-button" @click.stop="currentValue = false" v-if="cancelText">{{ cancelText }}</a>
  8. </div>
  9. </transition>
  10. </template>
  11. <style>
  12. @component-namespace mint {
  13. @component actionsheet {
  14. position: fixed;
  15. background: #e0e0e0;
  16. width: 100%;
  17. text-align: center;
  18. bottom: 0;
  19. left: 50%;
  20. transform: translate3d(-50%, 0, 0);
  21. backface-visibility: hidden;
  22. transition: transform .3s ease-out;
  23. @descendent list {
  24. list-style: none;
  25. padding: 0;
  26. margin: 0;
  27. }
  28. @descendent listitem {
  29. border-bottom: solid 1px #e0e0e0;
  30. }
  31. @descendent listitem, button {
  32. display: block;
  33. width: 100%;
  34. height: 45px;
  35. line-height: 45px;
  36. font-size: 18px;
  37. color: #333;
  38. background-color: #fff;
  39. &:active {
  40. background-color: #f0f0f0;
  41. }
  42. }
  43. }
  44. }
  45. .actionsheet-float-enter,
  46. .actionsheet-float-leave-active {
  47. transform: translate3d(-50%, 100%, 0);
  48. }
  49. </style>
  50. <script type="text/babel">
  51. import Popup from 'mint-ui/src/utils/popup';
  52. import 'mint-ui/src/style/popup.css';
  53. export default {
  54. name: 'mt-actionsheet',
  55. mixins: [Popup],
  56. props: {
  57. modal: {
  58. default: true
  59. },
  60. modalFade: {
  61. default: false
  62. },
  63. lockScroll: {
  64. default: false
  65. },
  66. closeOnClickModal: {
  67. default: true
  68. },
  69. cancelText: {
  70. type: String,
  71. default: '取消'
  72. },
  73. actions: {
  74. type: Array,
  75. default: () => []
  76. }
  77. },
  78. data() {
  79. return {
  80. currentValue: false
  81. };
  82. },
  83. watch: {
  84. currentValue(val) {
  85. this.$emit('input', val);
  86. },
  87. value(val) {
  88. this.currentValue = val;
  89. }
  90. },
  91. methods: {
  92. itemClick(item, index) {
  93. if (item.method && typeof item.method === 'function') {
  94. item.method(item, index);
  95. }
  96. this.currentValue = false;
  97. }
  98. },
  99. mounted() {
  100. if (this.value) {
  101. this.rendered = true;
  102. this.currentValue = true;
  103. this.open();
  104. }
  105. }
  106. };
  107. </script>