tui-actionsheet.vue 3.9 KB

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