tui-actionsheet.vue 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. <template>
  2. <view @touchmove.stop.prevent>
  3. <view class="tui-actionsheet" :class="{'tui-actionsheet-show':show,'tui-actionsheet-radius':radius}">
  4. <view class="tui-actionsheet-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="{'tui-btn-last':!isCancel && index==itemList.length-1}"
  10. hover-class="tui-actionsheet-hover" :hover-stay-time="150" :data-index="index" :style="{color:item.color || '#2B2B2B'}"
  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="{'tui-mask-show':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: '#2B2B2B'
  41. }]
  42. }
  43. },
  44. //提示文字
  45. tips: {
  46. type: String,
  47. default: ''
  48. },
  49. //提示文字颜色
  50. color: {
  51. type: String,
  52. default: '#808080'
  53. },
  54. //提示文字大小 rpx
  55. size: {
  56. type: Number,
  57. default: 26
  58. },
  59. //是否需要圆角
  60. radius: {
  61. type: Boolean,
  62. default: true
  63. },
  64. //是否需要取消按钮
  65. isCancel: {
  66. type: Boolean,
  67. default: true
  68. }
  69. },
  70. methods: {
  71. handleClickMask() {
  72. if (!this.maskClosable) return
  73. this.handleClickCancel()
  74. },
  75. handleClickItem(e) {
  76. if (!this.show) return
  77. const dataset = e.currentTarget.dataset
  78. this.$emit('click', {
  79. index: Number(dataset.index)
  80. })
  81. },
  82. handleClickCancel() {
  83. this.$emit('cancel')
  84. }
  85. }
  86. }
  87. </script>
  88. <style scoped>
  89. .tui-actionsheet {
  90. width: 100%;
  91. position: fixed;
  92. left: 0;
  93. right: 0;
  94. bottom: 0;
  95. z-index: 9999;
  96. visibility: hidden;
  97. transform: translate3d(0, 100%, 0);
  98. transform-origin: center;
  99. transition: all 0.25s ease-in-out;
  100. background-color: #F7F7F7;
  101. min-height: 100rpx;
  102. }
  103. .tui-actionsheet-radius {
  104. border-top-left-radius: 20rpx;
  105. border-top-right-radius: 20rpx;
  106. overflow: hidden;
  107. }
  108. .tui-actionsheet-show {
  109. transform: translate3d(0, 0, 0);
  110. visibility: visible;
  111. }
  112. .tui-actionsheet-tips {
  113. width: 100%;
  114. padding: 40rpx 60rpx;
  115. box-sizing: border-box;
  116. text-align: center;
  117. background-color: #fff;
  118. display: flex;
  119. align-items: center;
  120. justify-content: center;
  121. }
  122. .tui-operate-box {
  123. padding-bottom: 12rpx;
  124. }
  125. .tui-actionsheet-btn {
  126. width: 100%;
  127. height: 100rpx;
  128. background-color: #fff;
  129. display: flex;
  130. align-items: center;
  131. justify-content: center;
  132. text-align: center;
  133. font-size: 34rpx;
  134. position: relative;
  135. box-sizing: content-box;
  136. }
  137. .tui-btn-last {
  138. padding-bottom: env(safe-area-inset-bottom);
  139. }
  140. .tui-actionsheet-divider::before {
  141. content: '';
  142. width: 100%;
  143. border-top: 1rpx solid #E7E7E7;
  144. position: absolute;
  145. top: 0;
  146. left: 0;
  147. -webkit-transform: scaleY(0.5);
  148. transform: scaleY(0.5);
  149. }
  150. .tui-actionsheet-cancel {
  151. color: #1a1a1a;
  152. padding-bottom: env(safe-area-inset-bottom);
  153. }
  154. .tui-actionsheet-hover {
  155. background-color: #f7f7f9;
  156. }
  157. .tui-actionsheet-mask {
  158. position: fixed;
  159. top: 0;
  160. left: 0;
  161. right: 0;
  162. bottom: 0;
  163. background-color: rgba(0, 0, 0, 0.6);
  164. z-index: 9996;
  165. transition: all 0.3s ease-in-out;
  166. opacity: 0;
  167. visibility: hidden;
  168. }
  169. .tui-mask-show {
  170. opacity: 1;
  171. visibility: visible;
  172. }
  173. </style>