tui-keyboard.vue 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. <template>
  2. <view>
  3. <view class="tui-keyboard-mask" :class="[show?'tui-mask-show':'']" v-if="mask" @tap="handleClose"></view>
  4. <view class="tui-keyboard" :class="{'tui-keyboard-radius':radius,'tui-keyboard-action':action,'tui-keyboard-show':show}">
  5. <slot></slot>
  6. <view class="tui-keyboard-grids">
  7. <!--{{(index==9 || index==10 || index==11)?'tui-grid-bottom':''}}-->
  8. <view class="tui-keyboard-grid" :class="{'tui-bg-gray':index==9 || index==11}" v-for="(item,index) in itemList"
  9. :key="index" hover-class="tui-keyboard-hover" :hover-stay-time="150" @tap="handleClick" :data-index="index">
  10. <view v-if="index<11" class="tui-keyboard-item" :class="{'tui-fontsize-32':index==9}">{{getKeyBoard(index,action)}}</view>
  11. <view v-else class="tui-keyboard-item">
  12. <view class="tui-icon tui-keyboard-delete"></view>
  13. </view>
  14. </view>
  15. </view>
  16. </view>
  17. </view>
  18. </template>
  19. <script>
  20. export default {
  21. name: "tuiKeyboard",
  22. props: {
  23. //是否需要mask
  24. mask: {
  25. type: Boolean,
  26. default: true
  27. },
  28. //控制键盘显示
  29. show: {
  30. type: Boolean,
  31. default: false
  32. },
  33. //是否直接显示,不需要动画,一般使用在锁屏密码
  34. action: {
  35. type: Boolean,
  36. default: true
  37. },
  38. //是否带圆角
  39. radius: {
  40. type: Boolean,
  41. default: false
  42. }
  43. },
  44. data() {
  45. return {
  46. itemList: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
  47. };
  48. },
  49. methods: {
  50. getKeyBoard: function(index, action) {
  51. var content = index + 1;
  52. if (index == 9) {
  53. content = action ? "取消" : "清除";
  54. } else if (index == 10) {
  55. content = 0;
  56. }
  57. return content;
  58. },
  59. //关闭
  60. handleClose() {
  61. if (!this.show) {
  62. return;
  63. }
  64. this.$emit('close', {});
  65. },
  66. handleClick(e) {
  67. if (!this.show) {
  68. return;
  69. }
  70. const dataset = e.currentTarget.dataset;
  71. this.$emit('click', {
  72. index: Number(dataset.index)
  73. })
  74. }
  75. }
  76. }
  77. </script>
  78. <style scoped>
  79. @font-face {
  80. font-family: 'keyboardFont';
  81. src: url(data:application/font-woff;charset=utf-8;base64,d09GRgABAAAAAASgAA0AAAAABugAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABGRlRNAAAEhAAAABoAAAAch/nJvUdERUYAAARkAAAAHgAAAB4AKQAKT1MvMgAAAZwAAABDAAAAVj4mSapjbWFwAAAB8AAAAD4AAAFCAA/rY2dhc3AAAARcAAAACAAAAAj//wADZ2x5ZgAAAjwAAACsAAAA0BLVU2FoZWFkAAABMAAAAC0AAAA2FXPmsWhoZWEAAAFgAAAAHAAAACQH3gOFaG10eAAAAeAAAAAOAAAAEAwAAABsb2NhAAACMAAAAAoAAAAKAGgAAG1heHAAAAF8AAAAHwAAACABEQBLbmFtZQAAAugAAAFJAAACiCnmEVVwb3N0AAAENAAAACgAAAA6nLlLs3jaY2BkYGAAYukqK754fpuvDNwsDCBwU+tiFBKtwMLA9ABIczAwgUQB4ccH+gAAAHjaY2BkYGBu+N/AEMPCAAJAkpEBFbAAAEcKAm142mNgZGBgYGGwZ2BmAAEmIOYCQgaG/2A+AwAPIgFdAHjaY2BkYWCcwMDKwMDUyXSGgYGhH0IzvmYwYuQAijKwMjNgBQFprikMDs93PN/B3PC/gSGGuYGhASjMCJIDAPenDU0AeNpjYYAAFigGAACAAA0AAHjaY2BgYGaAYBkGRgYQsAHyGMF8FgYFIM0ChED+8x3//0NICW+oSgZGNgYYk4GRCUgwMaACRoZhDwAItAhZAAAAAAAAAAAAAABoAAB42l3MTQqCUBSG4fNpqBxECS/+YFTXRGcFKteZjW0nuoqWVtOgPbgKZ1cqaBDN3snzkklE+xUZEwUkqSOCzGx4EGGEsJYd2vURgQdbomhayC0iu8h8lEVmiR1sS4TVGVFYqeaEVjXmVT8TsWjf83yYIjFq1QM9I0/1c9HMMI06zfHgmMeRY8HDwOKnjSlYZvdQ5u4yB+gVbqrX97cAOxsHn9GF/9G3iV4WbSWBeNp9kD1OAzEQhZ/zByQSQiCoXVEA2vyUKRMp9Ailo0g23pBo1155nUg5AS0VB6DlGByAGyDRcgpelkmTImvt6PObmeexAZzjGwr/3yXuhBWO8ShcwREy4Sr1F+Ea+V24jhY+hRvUf4SbuFUD4RYu1BsdVO2Eu5vSbcsKZxgIV3CKJ+Eq9ZVwjfwqXMcVPoQb1L+EmxjjV7iFa2WpDOFhMEFgnEFjig3jAjEcLJIyBtahOfRmEsxMTzd6ETubOBso71dilwMeaDnngCntPbdmvkon/mDLgdSYbh4FS7YpjS4idCgbXyyc1d2oc7D9nu22tNi/a4E1x+xRDWzU/D3bM9JIbAyvkJI18jK3pBJTj2hrrPG7ZynW814IiU68y/SIx5o0dTr3bmniwOLn8owcfbS5kj33qBw+Y1kIeb/dTsQgil2GP5PYcRkAAAB42mNgYoAALjDJyIAOWMCiTIxM/FmZiXkFiXnxxRmJeckZpQA1nQZRAAAAAf//AAIAAQAAAAwAAAAWAAAAAgABAAMAAwABAAQAAAACAAAAAHjaY2BgYGQAgqtL1DlA9E2ti1EwGgA9dwYGAAA=) format('woff');
  82. font-weight: normal;
  83. font-style: normal;
  84. }
  85. .tui-icon {
  86. font-family: "keyboardFont" !important;
  87. font-size: 22px;
  88. font-style: normal;
  89. -webkit-font-smoothing: antialiased;
  90. -moz-osx-font-smoothing: grayscale;
  91. line-height: 1;
  92. color: #333;
  93. }
  94. .tui-keyboard-delete:before {
  95. content: "\e7b8";
  96. }
  97. .tui-keyboard-mask {
  98. position: fixed;
  99. top: 0;
  100. left: 0;
  101. right: 0;
  102. bottom: 0;
  103. background-color: rgba(0, 0, 0, 0.6);
  104. z-index: 998;
  105. transition: all 0.3s ease-in-out;
  106. opacity: 0;
  107. visibility: hidden;
  108. }
  109. .tui-mask-show {
  110. opacity: 1;
  111. visibility: visible;
  112. }
  113. .tui-keyboard {
  114. width: 100%;
  115. position: fixed;
  116. left: 0;
  117. right: 0;
  118. bottom: 0;
  119. z-index: 999;
  120. padding-bottom: env(safe-area-inset-bottom);
  121. background-color: #fff;
  122. }
  123. .tui-keyboard-radius {
  124. border-top-left-radius: 16rpx;
  125. border-top-right-radius: 16rpx;
  126. overflow: hidden;
  127. }
  128. .tui-keyboard-action {
  129. visibility: hidden;
  130. transform: translate3d(0, 100%, 0);
  131. transform-origin: center;
  132. transition: all 0.3s ease-in-out;
  133. }
  134. .tui-keyboard-show {
  135. transform: translate3d(0, 0, 0);
  136. visibility: visible;
  137. }
  138. .tui-bg-gray {
  139. background-color: #e7e6eb !important;
  140. }
  141. .tui-keyboard-grids {
  142. width: 100%;
  143. position: relative;
  144. overflow: hidden;
  145. display: flex;
  146. display: -webkit-flex;
  147. flex-direction: row;
  148. flex-wrap: wrap;
  149. }
  150. .tui-keyboard-grids::after {
  151. content: " ";
  152. position: absolute;
  153. left: 0;
  154. top: 0;
  155. width: 100%;
  156. height: 1px;
  157. border-top: 1px solid #eaeef1;
  158. -webkit-transform-origin: 0 0;
  159. transform-origin: 0 0;
  160. -webkit-transform: scaleY(0.5);
  161. transform: scaleY(0.5);
  162. }
  163. .tui-keyboard-grid {
  164. position: relative;
  165. padding: 24rpx 20rpx;
  166. box-sizing: border-box;
  167. background-color: #fff;
  168. width: 33.33333333%;
  169. }
  170. .tui-keyboard-grid:nth-of-type(3n)::before {
  171. width: 0;
  172. border-right: 0;
  173. }
  174. .tui-keyboard-grid::before {
  175. content: " ";
  176. position: absolute;
  177. right: 0;
  178. top: 0;
  179. width: 1px;
  180. bottom: 0;
  181. border-right: 1px solid #eaeef1;
  182. -webkit-transform-origin: 100% 0;
  183. transform-origin: 100% 0;
  184. -webkit-transform: scaleX(0.5);
  185. transform: scaleX(0.5);
  186. }
  187. .tui-keyboard-grid::after {
  188. content: " ";
  189. position: absolute;
  190. left: 0;
  191. bottom: 0;
  192. right: 0;
  193. height: 1px;
  194. border-bottom: 1px solid #eaeef1;
  195. -webkit-transform-origin: 0 100%;
  196. transform-origin: 0 100%;
  197. -webkit-transform: scaleY(0.5);
  198. transform: scaleY(0.5);
  199. }
  200. .tui-grid-bottom::after {
  201. height: 0 !important;
  202. border-bottom: 0 !important;
  203. }
  204. .tui-keyboard-hover {
  205. background-color: #f7f7f9 !important;
  206. }
  207. .tui-keyboard-item {
  208. display: flex;
  209. align-items: center;
  210. justify-content: center;
  211. font-size: 48rpx;
  212. height: 60rpx;
  213. color: #000;
  214. }
  215. .tui-fontsize-32 {
  216. font-size: 32rpx;
  217. color: #333 !important;
  218. }
  219. </style>