actionsheet.vue 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. <template>
  2. <view>
  3. <view class="tui-actionsheet-class tui-actionsheet" :class="[show?'tui-actionsheet-show':'']">
  4. <view class="tui-tips" :style="{fontSize:size+'rpx',color:color}" v-if="tips">
  5. {{tips}}
  6. </view>
  7. <view :class="[isCancel?'tui-operate-box':'']">
  8. <block v-for="(item,index) in itemList" :key="index">
  9. <view class="tui-actionsheet-btn tui-actionsheet-divider" :class="[(!isCancel && index==itemList.length-1)?'tui-btn-last':'']"
  10. hover-class="tui-actionsheet-hover" :hover-stay-time="150" :data-index="index" :style="{color:item.color || '#1a1a1a'}"
  11. @tap="handleClickItem">{{item.text}}</view>
  12. </block>
  13. </view>
  14. <view class="tui-actionsheet-btn tui-actionsheet-cancel" hover-class="tui-actionsheet-hover" :hover-stay-time="150"
  15. v-if="isCancel" @tap="handleClickCancel">取消</view>
  16. </view>
  17. <view class="tui-actionsheet-mask" :class="[show?'tui-mask-show':'']" @tap="handleClickMask"></view>
  18. </view>
  19. </template>
  20. <script>
  21. export default {
  22. name: "tuiActionsheet",
  23. props: {
  24. //点击遮罩 是否可关闭
  25. maskClosable: {
  26. type: Boolean,
  27. default: true
  28. },
  29. //显示操作菜单
  30. show: {
  31. type: Boolean,
  32. default: false
  33. },
  34. //菜单按钮数组,自定义文本颜色,红色参考色:#e53a37
  35. itemList: {
  36. type: Array,
  37. default: function() {
  38. return [{
  39. text: "确定",
  40. color: "#1a1a1a"
  41. }]
  42. }
  43. },
  44. //提示文字
  45. tips: {
  46. type: String,
  47. default: ""
  48. },
  49. //提示文字颜色
  50. color: {
  51. type: String,
  52. default: "#9a9a9a"
  53. },
  54. //提示文字大小 rpx
  55. size: {
  56. type: Number,
  57. default: 26
  58. },
  59. //是否需要取消按钮
  60. isCancel: {
  61. type: Boolean,
  62. default: true
  63. }
  64. },
  65. methods: {
  66. handleClickMask() {
  67. if (!this.maskClosable) return;
  68. this.handleClickCancel();
  69. },
  70. handleClickItem(e) {
  71. if (!this.show) return;
  72. const dataset = e.currentTarget.dataset;
  73. this.$emit('click', {
  74. index: dataset.index
  75. });
  76. },
  77. handleClickCancel() {
  78. this.$emit('cancel');
  79. }
  80. }
  81. }
  82. </script>
  83. <style>
  84. .tui-actionsheet {
  85. width: 100%;
  86. position: fixed;
  87. left: 0;
  88. right: 0;
  89. bottom: 0;
  90. z-index: 9999;
  91. visibility: hidden;
  92. transform: translate3d(0, 100%, 0);
  93. transform-origin: center;
  94. transition: all 0.3s ease-in-out;
  95. background: #eaeaec;
  96. min-height: 100rpx;
  97. }
  98. .tui-actionsheet-show {
  99. transform: translate3d(0, 0, 0);
  100. visibility: visible;
  101. }
  102. .tui-tips {
  103. width: 100%;
  104. padding: 30rpx 60rpx;
  105. box-sizing: border-box;
  106. text-align: center;
  107. background: #fff;
  108. display: flex;
  109. align-items: center;
  110. justify-content: center;
  111. }
  112. .tui-operate-box {
  113. padding-bottom: 12rpx;
  114. }
  115. .tui-actionsheet-btn {
  116. width: 100%;
  117. height: 100rpx;
  118. background: #fff;
  119. display: flex;
  120. align-items: center;
  121. justify-content: center;
  122. text-align: center;
  123. font-size: 36rpx;
  124. position: relative;
  125. }
  126. .tui-btn-last {
  127. padding-bottom: env(safe-area-inset-bottom);
  128. }
  129. .tui-actionsheet-divider::before {
  130. content: '';
  131. width: 100%;
  132. border-top: 1rpx solid #d9d9d9;
  133. position: absolute;
  134. top: 0;
  135. left: 0;
  136. -webkit-transform: scaleY(0.5);
  137. transform: scaleY(0.5);
  138. }
  139. .tui-actionsheet-cancel {
  140. color: #1a1a1a;
  141. padding-bottom: env(safe-area-inset-bottom);
  142. }
  143. .tui-actionsheet-hover {
  144. background: #f7f7f9;
  145. }
  146. .tui-actionsheet-mask {
  147. position: fixed;
  148. top: 0;
  149. left: 0;
  150. right: 0;
  151. bottom: 0;
  152. background: rgba(0, 0, 0, 0.6);
  153. z-index: 9996;
  154. transition: all 0.3s ease-in-out;
  155. opacity: 0;
  156. visibility: hidden;
  157. }
  158. .tui-mask-show {
  159. opacity: 1;
  160. visibility: visible;
  161. }
  162. </style>