You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

number-keyboard.vue 6.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  1. <template>
  2. <view :class="['KeyboarBody','bottomMove', 'bodMove', bodMove]" v-if="KeyboarHid">
  3. <view @click="close" class="dowmImgBx">
  4. <view class="dowmImg"></view>
  5. <view v-if="confirmBtn" class="complete" @click.stop="complete">完成</view>
  6. </view>
  7. <view class="KeyboarBx">
  8. <view v-for="(num , index) in keyboardNum " :key='index' @click="clickBoard(num)" hover-class="hover"
  9. :hover-stay-time='20' class="keyboar">
  10. {{num}}
  11. </view>
  12. <view @click="clickBoard(otherNum)" :class="['keyboar',otherNum==''?'empty':'']" :hover-stay-time='20'
  13. hover-class="hover">{{otherNum}}</view>
  14. <view @click="clickBoard('0')" hover-class="hover" :hover-stay-time='20' class="keyboar">0</view>
  15. <view @click="deleteKeyboar()" class="keyboar keyboarflex" :hover-stay-time='20' hover-class="hover">
  16. <view class="keyboarDel"></view>
  17. </view>
  18. </view>
  19. </view>
  20. </template>
  21. <script>
  22. export default {
  23. props: {
  24. //限制输入框的长度 空值不限制
  25. psdLength: {
  26. type: [Number, String],
  27. default: ''
  28. },
  29. //键盘码
  30. keyboardNum: {
  31. type: [Array, Object],
  32. default: () => {
  33. return [1, 2, 3, 4, 5, 6, 7, 8, 9]
  34. }
  35. },
  36. //特殊键盘码 .或者X 默空
  37. otherNum: {
  38. type: String,
  39. default: ''
  40. },
  41. //是否显示完成按钮
  42. confirmBtn:{
  43. type: Boolean,
  44. default: false
  45. },
  46. //是否在需要打开键盘时隐藏底部tabBar关闭键盘展示tabBar功能
  47. tabBar: {
  48. type: Boolean,
  49. default: false
  50. },
  51. value: {
  52. type: String,
  53. default: ''
  54. }
  55. },
  56. data() {
  57. return {
  58. bodMove: '',
  59. password: '', //要返回的结果
  60. iptNum: [], //输入的内容
  61. KeyboarHid: false, //键盘影藏和显示
  62. }
  63. },
  64. watch: {
  65. iptNum(newVal, oldVal) {
  66. this.$emit('input', newVal.join(''))
  67. },
  68. value(newVal, oldVal) {
  69. this.iptNum = newVal.split('')
  70. }
  71. },
  72. created() {
  73. },
  74. methods: {
  75. open() {
  76. this.KeyboarHid = true;
  77. if (this.tabBar) {
  78. uni.hideTabBar()
  79. }
  80. this.$nextTick(() => {
  81. setTimeout(() => {
  82. this.bodMove = 'moveShow'
  83. }, 30)
  84. })
  85. },
  86. close() {
  87. if (this.tabBar) {
  88. uni.showTabBar()
  89. }
  90. this.bodMove = '';
  91. this.$nextTick(() => {
  92. setTimeout(() => {
  93. this.KeyboarHid = false
  94. }, 300)
  95. })
  96. },
  97. // 密码框
  98. clickBoard(num) {
  99. if (num == '') return;
  100. let iptNum = this.iptNum.filter(item => item != '');
  101. //判断是否限制长度
  102. if (this.psdLength != '') {
  103. if (iptNum.length >= this.psdLength) {
  104. return
  105. };
  106. this.iptNum.push(num);
  107. } else {
  108. this.iptNum.push(num);
  109. }
  110. },
  111. //完成
  112. complete(){
  113. this.$emit('confirm', this.iptNum.join(''))
  114. },
  115. //重置 清空
  116. reset() {
  117. this.iptNum = [];
  118. },
  119. //删除
  120. deleteKeyboar() {
  121. this.iptNum.pop();
  122. }
  123. }
  124. }
  125. </script>
  126. <style scoped>
  127. .bodMove {
  128. transition: all .3s
  129. }
  130. .bottomMove {
  131. bottom: 0;
  132. left: 0;
  133. width: 100%;
  134. transform: translateY(100%)
  135. }
  136. .moveShow {
  137. transform: translateY(0)
  138. }
  139. .KeyboarBody {
  140. position: fixed;
  141. bottom: 0;
  142. left: 0;
  143. right: 0;
  144. z-index: 99;
  145. background-color: #FFFFFF;
  146. }
  147. .KeyboarBx {
  148. display: flex;
  149. flex-wrap: wrap;
  150. text-align: center;
  151. background-color: rgba(3, 3, 3, 0.1);
  152. padding: 10rpx 6rpx 0rpx 6rpx;
  153. margin-left: -12rpx;
  154. }
  155. .keyboar {
  156. width: 20%;
  157. flex-grow: 1;
  158. padding: 3%;
  159. font-size: 40rpx;
  160. background-color: #FFFFFF;
  161. border-radius: 10rpx;
  162. margin-left: 12rpx;
  163. margin-bottom: 10rpx;
  164. }
  165. .dian {
  166. margin-top: -10rpx;
  167. }
  168. .keyboarBtn {
  169. background: linear-gradient(45deg, rgba(242, 131, 9, 1) 0%, rgba(230, 36, 15, 1) 100%);
  170. color: #fff;
  171. }
  172. .hover {
  173. background: #ebedf0;
  174. }
  175. .bot {
  176. bottom: 0;
  177. }
  178. .empty {
  179. background-color: #EEEEEE;
  180. }
  181. .dowmImgBx {
  182. display: flex;
  183. justify-content: center;
  184. align-items: center;
  185. width: 100%;
  186. position: relative;
  187. }
  188. .complete {
  189. position: absolute;
  190. right: 0rpx;
  191. bottom: 5rpx;
  192. font-size: 28rpx;
  193. padding-right: 30rpx;
  194. padding-left: 20rpx;
  195. }
  196. .dowmImg {
  197. width: 35rpx;
  198. height: 35rpx;
  199. margin-bottom: 10rpx;
  200. background: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAACT0lEQVRYR+2UPWgTYRjH/8/dpdZCpVhU/BoEB8FBEBFt7tJe7i5CbAXhrg6CQ8HBQXAQHBzq5CA4CA4OgoNgr0GQIhQTUkJqCPEDBEEQBAdBQSoVlIakXvLIofmopMnlizjkxuN9nt/v/b/v+xB6/FGP+egL9BPoJ/D/JLC8/Hp33sl9AXDOCMqRbsyH6NLzGwLR7BapuDMQCKy4jHICi5nMNinrpAk4DOC8EZQfdVKiBGemxyHNb5V6bziCaDRxSPT5bAaOCAJd0Cb8DzshUYIT4cnqit+anqZCTQH357NE+qDIhXmAjoJpxtD8D9qRqOwcT538DyscDuer+9W8hNFo8oDok2wGHxcIFzVVvt+KRAkOYDG3NmhNTR3L/ttn01eQTL7cv+6sz4NwkhmXQpp8rxmJ8s6B2NAATFmWf9aqr/sMY7HUHsEHmxkKGJcNTb7rRaKyc1rKZ4vW5KTyfbO6hnMgHo/vYmHQBjBBxFd0VblTT6IC56REjqmq6rd66xsKuMXx+ItRFn/ZYOhMfDWkKrdrNa068xQVJVPXT3xtlJgnAbdJIpEYcViyATpFoGt60H+runkVPCOwYGra2OdG8A2DyMvihYXU8NAwzQF8moDrelC+6daV4YRXcNg0DOWTl35NC7gF6XR661qu6N6JMwzMMrPgjlcw3hCzqevKR6/wlgTcokjk3cDI6KpNRGf/wt6yWDBD4+MfmoG3LPBHIiJu37F3jsH7JAgzqjr2vll4WwKtwJoeRJ2CtD0HuinieQ50S6Iv0E+g5wn8Bo+vyyFXaYw2AAAAAElFTkSuQmCC');
  201. background-repeat: no-repeat;
  202. background-position: center center;
  203. background-size: 100%;
  204. }
  205. .keyboarDel {
  206. width: 50rpx;
  207. height: 36rpx;
  208. margin-bottom: 10rpx;
  209. background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAABqUlEQVRYR+2WPUvEQBCGZze1/8DKUnsrEcVaLhvwCgULCy1sLGzFE8RKC0EsBLGwEBRuhmChlTb+hCu0vU4Ff4H3SkKCOS4fezHnNUkXQuZ58s7sbhSN+VJj5lMtUCdglYDrurNKqSMiWqpoaD+IaI6Z3woFjDErRHRJRBMVweMyz8y8mCsQwW8rBtsJjBgeSGQn8A/wbAFbOIBHpdQnEa2ltKijlHoBsJnTvsEEbOFR0SYz37mu21JK7SdAnV6v1wzutdYda4Eh4XHdDWa+Skgk4cHwzlgJlISHtQHsiMhpIAEgXDFa6yL47wx4njcJoPuXpQZgT0QOG43GtCW8fwiNMYFxsOGUucLYAXz7vv+aMhNZNfuHsKRECHcc5wvAAxFdM/OxpUTqKhgmifjLu47j3BPRfDQTWyJyYSGRvhHZJgHgQERanuf5AJaTOQNYFZEbY8wTES1k9CB3JxwmiTJzk78VB09tkyhLzz0L4qIjlig+jkechJ1AJHFGRNt/iHvgVQC7InJS+EeUaMc6gKkqJLTW7+12+zyoZS1QBTitRi1QJzD2BH4AtrHfITKVMwgAAAAASUVORK5CYII=');
  210. background-repeat: no-repeat;
  211. background-position: center center;
  212. background-size: 100%;
  213. margin-top: 11rpx;
  214. }
  215. .keyboarflex {
  216. display: flex;
  217. justify-content: center;
  218. align-items: center;
  219. }
  220. </style>