gui-number-keyboard.vue 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. <template>
  2. <gui-popup ref="guipopupfornk"
  3. position="bottom" :canCloseByShade="canCloseByShade">
  4. <view style="background-color:#F6F7F8;"
  5. @tap.stop.prevent="stopfun">
  6. <text class="gui-keyboard-res gui-block-text" v-if="showInputRes"
  7. :style="{color:resultColor, fontSize:resultSize}">{{resVal}}</text>
  8. <view class="gui-keyboard gui-flex gui-rows gui-space-between">
  9. <view class="gui-keyboard-left gui-flex gui-rows gui-wrap gui-space-between">
  10. <text v-for="(item, index) in [1,2,3,4,5,6,7,8,9]" :key="index"
  11. class="gui-keyboard-keys gui-block-text"
  12. :data-keynumber="item"
  13. :style="{
  14. backgroundColor:tapIndex == item ? tapBgColor : '#FFFFFF',
  15. color : tapIndex == item ? '#FFFFFF' : '#2B2E3D'
  16. }"
  17. @tap.stop="inputNow">{{item}}</text>
  18. <text class="gui-keyboard-keys gui-block-text"
  19. :style="{
  20. width: isPoint ? '259rpx':'538rpx',
  21. backgroundColor:tapIndex == 0 ? tapBgColor : '#FFFFFF',
  22. color : tapIndex == 0 ? '#FFFFFF' : '#2B2E3D'
  23. }"
  24. data-keynumber="0" @tap.stop="inputNow">0</text>
  25. <text v-if="isPoint" class="gui-keyboard-keys"
  26. :style="{
  27. width:'259rpx',
  28. backgroundColor:tapIndex == '.' ? tapBgColor : '#FFFFFF',
  29. color : tapIndex == '.' ? '#FFFFFF' : '#2B2E3D'
  30. }"
  31. data-keynumber="." @tap.stop="inputNow">.</text>
  32. </view>
  33. <view class="gui-keyboard-right gui-flex gui-columns gui-align-items-center">
  34. <text class="gui-keyboard-keys gui-icons gui-block-text"
  35. :style="{
  36. backgroundColor : tapIndex == -3 ? tapBgColor : '#FFFFFF',
  37. color : tapIndex == -3 ? '#FFFFFF' : '#2B2E3D'
  38. }"
  39. :data-keynumber="-3" @tap.stop="deleteNow">&#xe623;</text>
  40. <text class="gui-keyboard-keys gui-keyboard-done gui-block-text"
  41. :style="{backgroundColor:tapBgColor}" @tap.stop="done">{{doneBtnName}}</text>
  42. </view>
  43. </view>
  44. </view>
  45. </gui-popup>
  46. </template>
  47. <script>
  48. export default{
  49. name : "gui-number-keyboard",
  50. props : {
  51. canCloseByShade : { type : Boolean, default : false},
  52. doneBtnName : { type : String, default : "完成" },
  53. isPoint : { type : Boolean, default : true },
  54. value : { type : String, default : ''},
  55. showInputRes : { type : Boolean, default : true},
  56. resultColor : { type : String, default : '#2B2E3D'},
  57. resultSize : { type : String, default : '32rpx'},
  58. tapBgColor : { type : String, default : '#008AFF'},
  59. },
  60. methods:{
  61. open : function(){
  62. this.$refs.guipopupfornk.open();
  63. },
  64. close : function(){
  65. this.$refs.guipopupfornk.close();
  66. },
  67. stopfun : function(e){
  68. e.stopPropagation();
  69. return ;
  70. },
  71. inputNow : function (e){
  72. var k = e.currentTarget.dataset.keynumber;
  73. this.resVal += k+'';
  74. this.tapIndex = k;
  75. this.$emit('keyboardInput', k);
  76. this.removeClass();
  77. },
  78. deleteNow : function (e){
  79. var k = e.currentTarget.dataset.keynumber;
  80. this.tapIndex = k;
  81. this.resVal = this.resVal.substring(0, this.resVal.length - 1);
  82. this.$emit('keyboardDelete');
  83. this.removeClass();
  84. },
  85. done : function(){
  86. this.$emit('keyboardDone');
  87. },
  88. setVal : function (val) {
  89. this.resVal = val;
  90. },
  91. removeClass : function () {
  92. setTimeout(()=>{this.tapIndex = -1;}, 100);
  93. },
  94. },
  95. data() {
  96. return {
  97. resVal : '',
  98. tapIndex : -1
  99. }
  100. },
  101. created:function(){
  102. this.resVal = this.value+'';
  103. },
  104. watch:{
  105. value : function (val) {
  106. this.resVal = val+'';
  107. }
  108. }
  109. }
  110. </script>
  111. <style>
  112. .gui-keyboard{background-color:#F6F7F8; width:750rpx; padding:20rpx 0;}
  113. .gui-keyboard-body{flex-direction:row; justify-content:space-between; padding:10px 0;}
  114. .gui-keyboard-left{width:560rpx;}
  115. .gui-keyboard-right{width:188rpx;}
  116. .gui-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;}
  117. .gui-keyboard-done{height:340rpx; line-height:340rpx; font-size:36rpx; font-weight:400; color:#FFFFFF;}
  118. .gui-keyboard-res{line-height:60rpx; text-align:center; font-size:32rpx; font-weight:bold; padding-top:20rpx;}
  119. .keydown{background-color:#3688FF; color:#FFFFFF;}
  120. </style>