graceNvueNumberKeyboard.vue 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <template>
  2. <view>
  3. <view class="grace-mask" @tap.stop="done" @touchmove.stop="" v-if="show"></view>
  4. <view class="grace-keyboard" v-if="show">
  5. <text class="grace-keyboard-res" v-if="showInputRes">{{resVal}}</text>
  6. <view class="grace-keyboard-body">
  7. <view class="grace-keyboard-left">
  8. <text v-for="(item, index) in [1,2,3,4,5,6,7,8,9]" :key="index" class="grace-keyboard-keys" :class="[tapIndex == item ? 'keydown' : '']" :data-keynumber="item" @tap.stop="inputNow">{{item}}</text>
  9. <text class="grace-keyboard-keys" :class="[tapIndex == 0 ? 'keydown' : '']"
  10. :style="{width: isPoint ? '259rpx':'538rpx'}" data-keynumber="0" @tap.stop="inputNow">0</text>
  11. <text v-if="isPoint" class="grace-keyboard-keys" style="width:259rpx;" :class="[tapIndex == '.' ? 'keydown' : '']" data-keynumber="." @tap.stop="inputNow">.</text>
  12. </view>
  13. <view class="grace-keyboard-right">
  14. <text class="grace-keyboard-keys grace-icons" :class="[tapIndex == -3 ? 'keydown' : '']" :data-keynumber="-3" @tap.stop="deleteNow">&#xe623;</text>
  15. <text class="grace-keyboard-keys grace-keyboard-done" @tap.stop="done">{{doneBtnName}}</text>
  16. </view>
  17. </view>
  18. </view>
  19. </view>
  20. </template>
  21. <script>
  22. export default {
  23. props: {
  24. show : { type : Boolean, default : false },
  25. doneBtnName : { type : String, default : "完成" },
  26. isPoint : { type : Boolean, default : true },
  27. showInputRes:{type : Boolean, default : true},
  28. value:{type:String, default:''}
  29. },
  30. data() {
  31. return {
  32. resVal: '',
  33. tapIndex : -1
  34. }
  35. },
  36. created:function(){
  37. this.resVal = this.value;
  38. },
  39. methods: {
  40. inputNow : function (e){
  41. var k = e.currentTarget.dataset.keynumber;
  42. this.resVal += k+'';
  43. this.tapIndex = k;
  44. this.$emit('keyboardInput', k);
  45. this.removeClass();
  46. },
  47. deleteNow : function (e){
  48. var k = e.currentTarget.dataset.keynumber;
  49. this.tapIndex = k;
  50. this.resVal = this.resVal.substring(0, this.resVal.length - 1);
  51. this.$emit('keyboardDelete');
  52. this.removeClass();
  53. },
  54. done : function(e){
  55. var k = e.currentTarget.dataset.keynumber;
  56. this.tapIndex = k;
  57. this.$emit('keyboardDone');
  58. this.removeClass();
  59. },
  60. setVal : function (val) {
  61. this.resVal = val;
  62. },
  63. removeClass : function () {
  64. setTimeout(()=>{this.tapIndex = -1;}, 200);
  65. }
  66. }
  67. }
  68. </script>
  69. <style scoped>
  70. .grace-mask{background-color:rgba(255, 255, 255, 0); position:fixed; width:750rpx; flex:1; left:0; top:0; bottom:0;}
  71. .grace-keyboard{background-color:#F4F5F6; position:fixed; width:750rpx; left:0; bottom:0;}
  72. .grace-keyboard-body{flex-direction:row; justify-content:space-between; padding:10px 0;}
  73. .grace-keyboard-left{width:560rpx; flex-direction:row; flex-wrap:wrap; justify-content:space-between;}
  74. .grace-keyboard-right{width:188rpx; flex-direction:column; justify-content:space-between;}
  75. .grace-keyboard-keys{width:166rpx; height:100rpx; margin:10rpx; background-color:#FFFFFF; text-align:center; line-height:100rpx; border-radius:8rpx; font-weight:700; font-size:50rpx;}
  76. .grace-keyboard-done{height:340rpx; line-height:340rpx; font-size:36rpx; font-weight:400; background-color:#3688FF; color:#FFFFFF;}
  77. .grace-keyboard-res{line-height:60rpx; text-align:center; font-size:32rpx; font-weight:bold; padding-top:20rpx;}
  78. .keydown{background-color:#3688FF; color:#FFFFFF;}
  79. </style>