keyCode.vue 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. <template>
  2. <view class="keyCode flex">
  3. <!-- section -->
  4. <view id="input" @click="show=true" class="left flex">
  5. <view v-for="(item,index) of copy" :key="index" class="text-black margin-right-xs flex justify-center align-center">{{item}}</view>
  6. </view>
  7. <view @click="changefunc" class="right padding-xs text-blue">新</view>
  8. <!-- footer -->
  9. <!-- 键盘 -->
  10. <view v-if="show" class="key bg-grey">
  11. <!-- 工具栏 -->
  12. <view class="tool bg-gray flex justify-between padding-sm">
  13. <view @click="concalfunc">取消</view>
  14. <view :class="copy[copy.length-1] ? '' : 'text-grey' ">完成</view>
  15. </view>
  16. <!-- 键值 0-->
  17. <view v-show="key==0" class="codeA padding-lr-xs padding-bottom-sm">
  18. <!-- 第一行 -->
  19. <view class="one flex justify-around">
  20. <button @click="handlerfunc(item)" v-for="(item,index) of codes[0][0]" :key="index" class="item cu-btn padding-sm ">{{item}}</button>
  21. </view>
  22. <!-- 第二行 -->
  23. <view class="two flex justify-around">
  24. <button @click="handlerfunc(item)" v-for="(item,index) of codes[0][1]" :key="index" class="item cu-btn padding-sm ">{{item}}</button>
  25. </view>
  26. <!-- 第三行 -->
  27. <view class="one flex justify-around">
  28. <button @click="handlerfunc(item)" v-for="(item,index) of codes[0][2]" :key="index" class="item cu-btn padding-sm ">{{item}}</button>
  29. </view>
  30. <!-- 第四行 -->
  31. <view class="four flex justify-around">
  32. <button class="item cu-btn padding-sm bg-black padding-lr-lg">字</button>
  33. <button @click="handlerfunc(item)" v-for="(item,index) of codes[0][3]" :key="index" class="item cu-btn padding-sm ">{{item}}</button>
  34. <button @click="deletefunc" class="item cu-btn padding-sm bg-black padding-lr-lg"><van-icon name="clear" /></button>
  35. </view>
  36. </view>
  37. <!-- 键值 1 -->
  38. <view v-show="key!=0" class="codeB padding-lr-xs padding-bottom-sm">
  39. <!-- 第一行 -->
  40. <view class="one flex justify-around">
  41. <button @click="handlerfunc(item)" v-for="(item,index) of codes[1][0]" :key="index" class="item cu-btn ">{{item}}</button>
  42. </view>
  43. <!-- 第二行 -->
  44. <view class="two flex justify-around">
  45. <button @click="handlerfunc(item)" v-for="(item,index) of codes[1][1]" :key="index" class="item cu-btn ">{{item}}</button>
  46. </view>
  47. <!-- 第三行 -->
  48. <view class="one flex justify-around">
  49. <button @click="handlerfunc(item)" v-for="(item,index) of codes[1][2]" :key="index" class="item cu-btn ">{{item}}</button>
  50. </view>
  51. <!-- 第四行 -->
  52. <view class="four flex justify-around">
  53. <button class="item cu-btn padding-sm bg-black padding-lr-lg">ABC</button>
  54. <button @click="handlerfunc(item)" v-for="(item,index) of codes[1][3]" :key="index" class="item cu-btn padding-sm ">{{item}}</button>
  55. <button @click="deletefunc" class="item cu-btn padding-sm bg-black padding-lr-lg"><van-icon name="clear" /></button>
  56. </view>
  57. </view>
  58. </view>
  59. <!-- 图层蒙版 -->
  60. <!-- <view v-if="show" @click="show=false" class="mask"></view> -->
  61. </view>
  62. </template>
  63. <script>
  64. export default{
  65. props:{
  66. value:{type:String,default:()=>""}
  67. },
  68. data(){
  69. return {
  70. // copy:['豫','H','1','2','3','4','5','6']
  71. copy:['','','','','','',''],
  72. show:false,
  73. key:0,
  74. codes:[
  75. [["京","沪","辽","苏","闽","豫","粤","贵","甘","桂"],["津","冀","吉","浙","赣","鄂","琼","云","青","宁"],["渝","晋","黑","皖","鲁","湘","川","陕","蒙","新"],["藏","使","领","警","学","港","澳"]],
  76. [[1,2,3,4,5,6,7,8,9,0],["Q","W","R","T","Y","U","I","O","P"],["A","S","D","F","G","H","J","K","L"],["Z","X","C","V","B","N","M"]]
  77. ]
  78. }
  79. },
  80. methods:{
  81. // 输入
  82. handlerfunc(item){
  83. var key=this.key;
  84. var copy=JSON.parse(JSON.stringify(this.copy));
  85. copy[key]=item;
  86. this.key=key+1;
  87. this.copy=copy;
  88. if(key===copy.length-1) {
  89. this.show=false;
  90. return
  91. };
  92. },
  93. // 删除键
  94. deletefunc(){
  95. var key=this.key;
  96. var copy=this.copy;
  97. copy[key-1]='';
  98. if(key>0) this.key=key-1;
  99. this.copy=copy;
  100. },
  101. // 取消
  102. concalfunc(){
  103. this.key=0;
  104. this.show=false;
  105. this.copy=['','','','','','',''];
  106. },
  107. // 新
  108. changefunc(){
  109. var copy=this.copy
  110. if(copy.length>=8) {
  111. copy.splice(-1,1)
  112. }else{
  113. copy.push("")
  114. }
  115. this.copy=copy;
  116. }
  117. },
  118. watch:{
  119. show:{
  120. handler(newVal){
  121. if(newVal) {
  122. // const query=uni.createSelectorQuery().in(this);
  123. // query.select("#input").boundingClientRect();
  124. // query.selectViewport().scrollOffset();
  125. // query.exec(res=>{
  126. // uni.pageScrollTo({ scrollTop: res[0].top || 0, duration: 300 })
  127. // })
  128. this.copy=this.copy.map(item=>'');
  129. this.key=0;
  130. };
  131. }
  132. },
  133. copy:{
  134. handler(newVal){
  135. var value="";
  136. newVal.forEach(item=>value+=item);
  137. value=value.trim();
  138. if(newVal.length==value.length || this.key==0) this.$emit("update:value",value)
  139. }
  140. }
  141. }
  142. }
  143. </script>
  144. <style lang="scss" scoped>
  145. .keyCode{
  146. .left{
  147. flex: auto;
  148. >view{
  149. border: 1rpx solid #999;
  150. width: 40rpx;height: 58rpx;
  151. box-sizing: border-box;
  152. }
  153. }
  154. .right{
  155. border: 1rpx dashed #999;
  156. }
  157. .key{
  158. position: fixed;
  159. bottom: 0;left: 0;
  160. z-index: 10000;
  161. width: 100%;
  162. .codeA{
  163. min-height: 300rpx;
  164. .item{
  165. margin-top: 10rpx;
  166. }
  167. }
  168. .codeB{
  169. min-height: 300rpx;
  170. .item{
  171. margin-top: 10rpx;
  172. padding-left: 28rpx;
  173. padding-right: 28rpx;
  174. }
  175. }
  176. }
  177. }
  178. </style>