keyboard.vue 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310
  1. <template>
  2. <view class="keyboard">
  3. <view class="number-board" v-if="isBoard">
  4. <view class="number-left">
  5. <view class="left-top">
  6. <view v-for="item in leftItems" :key="item" class="left-item"
  7. :class="item == '清空' ? 'empty' : ''" @click="singleWord(item)">{{ item }}</view>
  8. </view>
  9. </view>
  10. <view class="number-right">
  11. <view class="right-top" @click="deleteOneWord">
  12. <tui-icon name="deletekey" :size="30" color="#ACACAC"></tui-icon>
  13. </view>
  14. <view class="right-bottom" @click="setVerifica" :style="{ backgroundColor: iptValue == '' ? '#FFD2BE' : '' }">验劵</view>
  15. </view>
  16. </view>
  17. <view class="eng-board" v-else>
  18. <view class="eng-topOne">
  19. <view class="eng-box" v-for="item in engBoardList.one" :key="item" @click="singleWord(item)">{{ item }}
  20. </view>
  21. </view>
  22. <view class="eng-topTwo">
  23. <view class="eng-box" v-for="item in engBoardList.two" :key="item" @click="singleWord(item)">{{ item }}
  24. </view>
  25. </view>
  26. <view class="eng-topThree">
  27. <view class="eng-switch" @click="changeUpper">
  28. <template v-if="isUpper">
  29. <image class="" src="@/static/image/keyboard/shift-icon2.png" />
  30. </template>
  31. <template v-else>
  32. <image class="" src="@/static/image/keyboard/shift-icon.png" />
  33. </template>
  34. </view>
  35. <view class="box-list">
  36. <view class="eng-box" v-for="item in engBoardList.three" :key="item" @click="singleWord(item)">{{
  37. item }}</view>
  38. </view>
  39. <view class="delete" @click="deleteOneWord">
  40. <image class="" src="@/static/image/keyboard/delete.png" />
  41. </view>
  42. </view>
  43. <view class="eng-topFour">
  44. <view class="eng-number" @click="changeBoard">123</view>
  45. <view class="eng-coupons" @click="setVerifica" :style="{ backgroundColor: iptValue == '' ? '#FFD2BE' : '' }">验劵</view>
  46. <view class="eng-empty" @click="deleteAll">清空</view>
  47. </view>
  48. </view>
  49. </view>
  50. </template>
  51. <script>
  52. export default {
  53. props: {
  54. iptValue: {
  55. type: String,
  56. default: ''
  57. }
  58. },
  59. computed: {
  60. engBoardList() {
  61. let objBig = {
  62. one: ['Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', 'O', 'P'],
  63. two: ['A', 'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L'],
  64. three: ['Z', 'X', 'C', 'V', 'B', 'N', 'M']
  65. }
  66. let objSmall = {
  67. one: ['q', 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p'],
  68. two: ['a', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l'],
  69. three: ['z', 'x', 'c', 'v', 'b', 'n', 'm']
  70. }
  71. if (this.isUpper) {
  72. return objBig
  73. } else {
  74. return objSmall
  75. }
  76. }
  77. },
  78. data() {
  79. return {
  80. leftItems: [1, 2, 3, 4, 5, 6, 7, 8, 9, 'ABC', 0, '清空'],
  81. // 控制数字键盘以及英文键盘切换
  82. isBoard: true,
  83. // 控制切换大小写
  84. isUpper: true
  85. }
  86. },
  87. methods: {
  88. // 手机震动
  89. handleTouchEnd() {
  90. // #ifdef MP-WEIXIN
  91. wx.vibrateShort({ type: 'light' })
  92. // #endif
  93. },
  94. // 切换大小写
  95. changeUpper() {
  96. this.isUpper = !this.isUpper
  97. },
  98. // 数字键盘点击事件
  99. singleWord(val) {
  100. this.handleTouchEnd()
  101. if (val == 'ABC') {
  102. this.changeBoard()
  103. return
  104. } else if (val == '清空') {
  105. this.deleteAll()
  106. return
  107. }
  108. this.$emit('single', val)
  109. },
  110. // 删除单个字符
  111. deleteOneWord() {
  112. this.handleTouchEnd()
  113. this.$emit('deleteOne')
  114. },
  115. // 删除全部字符
  116. deleteAll() {
  117. this.handleTouchEnd()
  118. this.$emit('deleteAll')
  119. },
  120. // 验劵
  121. setVerifica(){
  122. this.$emit('setVerifica')
  123. },
  124. changeBoard() {
  125. this.isBoard = !this.isBoard
  126. }
  127. }
  128. }
  129. </script>
  130. <style lang="scss" scoped>
  131. .keyboard {
  132. .number-board {
  133. @include flex(center);
  134. .number-left {
  135. flex: 1;
  136. .left-top {
  137. @include flex(null, null, 6rpx);
  138. flex-wrap: wrap;
  139. }
  140. .left-item {
  141. width: 184rpx;
  142. height: 148rpx;
  143. background-color: #FFFFFF;
  144. color: #666666;
  145. font-weight: 700;
  146. font-size: 40rpx;
  147. @include flex(center);
  148. transition: all .1s ease;
  149. &:active {
  150. background-color: #cacaca;
  151. }
  152. /* &.active {
  153. background-image: linear-gradient(to bottom, #007AFF, #0F83FF);
  154. } */
  155. }
  156. .empty {
  157. color: #ACACAC;
  158. }
  159. }
  160. .number-right {
  161. width: 184rpx;
  162. height: 604rpx;
  163. box-sizing: border-box;
  164. @include flex(center, column, 6rpx);
  165. .right-top {
  166. width: 184rpx;
  167. height: 148rpx;
  168. background-color: #FFFFFF;
  169. @include flex(center);
  170. }
  171. .right-bottom {
  172. flex: 1;
  173. background-color: $primary-color;
  174. @include flex(center);
  175. width: 184rpx;
  176. color: #FFFFFF;
  177. }
  178. }
  179. }
  180. .eng-board {
  181. .eng-topOne {
  182. @include flex(space-between, null, 12rpx);
  183. }
  184. .eng-box {
  185. width: 64rpx;
  186. height: 84rpx;
  187. background-color: #FFFFFF;
  188. color: #333333;
  189. font-size: 30rpx;
  190. @include flex(center);
  191. border-radius: 16rpx;
  192. font-weight: 700;
  193. transition: all .1s ease;
  194. &:active {
  195. box-shadow: inset 0 0 10rpx rgba(0, 0, 0, 0.3);
  196. background-color: #cacaca;
  197. }
  198. }
  199. /* .eng-box {
  200. width: 64rpx;
  201. height: 84rpx;
  202. background-color: #FFFFFF;
  203. color: #333333;
  204. font-size: 30rpx;
  205. @include flex(center);
  206. border-radius: 16rpx;
  207. font-weight: 700;
  208. transition: all .1s ease;
  209. transform-origin: center;
  210. &:active {
  211. background-color: #cacaca;
  212. transform: scale(0.98);
  213. }
  214. } */
  215. .eng-topTwo {
  216. margin-top: 20rpx;
  217. @include flex(center, null, 12rpx);
  218. }
  219. .eng-topThree {
  220. margin-top: 20rpx;
  221. @include flex(space-between, null, 12rpx);
  222. .eng-switch {
  223. width: 84rpx;
  224. height: 84rpx;
  225. border-radius: 16rpx;
  226. background-color: #FFFFFF;
  227. @include flex(center);
  228. image {
  229. width: 42rpx;
  230. height: 34rpx;
  231. }
  232. }
  233. .box-list {
  234. @include flex(center, null, 12rpx);
  235. }
  236. .delete {
  237. width: 84rpx;
  238. height: 84rpx;
  239. border-radius: 16rpx;
  240. background-color: #FFFFFF;
  241. @include flex(center);
  242. image {
  243. width: 56rpx;
  244. height: 36rpx;
  245. }
  246. }
  247. }
  248. .eng-topFour {
  249. margin-top: 20rpx;
  250. @include flex(space-between);
  251. .eng-number {
  252. width: 190rpx;
  253. height: 84rpx;
  254. background-color: #FFFFFF;
  255. font-size: 28rpx;
  256. font-weight: 600;
  257. @include flex(center);
  258. border-radius: 16rpx;
  259. color: #333333;
  260. }
  261. .eng-coupons {
  262. width: 300rpx;
  263. height: 84rpx;
  264. @include flex(center);
  265. color: #FFFFFF;
  266. background-color: $primary-color;
  267. border-radius: 16rpx;
  268. }
  269. .eng-empty {
  270. width: 190rpx;
  271. height: 84rpx;
  272. background-color: #FFFFFF;
  273. font-size: 28rpx;
  274. font-weight: 600;
  275. @include flex(center);
  276. border-radius: 16rpx;
  277. color: #333333;
  278. }
  279. }
  280. }
  281. }
  282. </style>