codecook-keyboard.vue 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. <template>
  2. <view class="car-keyboard">
  3. <view class="status-bar">
  4. <view class="close" @click="hideHandler"> 关闭 </view>
  5. </view>
  6. <view class="keys-container">
  7. <view class="row" v-for="(row, index) in keys" :key="index">
  8. <view
  9. :class="[
  10. 'key',
  11. { last: j === row.length - 1 },
  12. { 'is-delete': deleteKeys.includes(key) },
  13. ]"
  14. v-for="(key, j) in row"
  15. :key="key"
  16. @click="keyTapHandler(key)"
  17. >
  18. <view class="txt" v-if="!deleteKeys.includes(key)">
  19. {{ key }}
  20. </view>
  21. <view class="delete" v-else></view>
  22. </view>
  23. </view>
  24. </view>
  25. </view>
  26. </template>
  27. <script>
  28. export default {
  29. name: "KeyBoard",
  30. components: {},
  31. props: {
  32. value: {
  33. type: Boolean,
  34. default: false,
  35. },
  36. type: {
  37. type: String,
  38. default: "provinces",
  39. validator: (value) => {
  40. return ["provinces", "areas"].indexOf(value) !== -1;
  41. },
  42. },
  43. },
  44. data() {
  45. return {
  46. deleteKeys: ["-", "="], // 避免2个删除按钮key冲突
  47. provinces: [
  48. ["京", "津", "沪", "渝", "川", "新", "藏", "宁", "桂", "贵"],
  49. ["云", "黑", "吉", "辽", "晋", "冀", "青", "鲁", "豫", "苏"],
  50. ["皖", "浙", "闽", "赣", "湘", "鄂", "粤", "琼", "甘", "陕"],
  51. ["蒙", "港", "澳", "台", "使", "领", "警", "学", "="],
  52. ],
  53. areas: [
  54. ["1", "2", "3", "4", "5", "6", "7", "8", "9", "0"],
  55. ["Q", "W", "E", "R", "T", "Y", "U", "I", "O", "P"],
  56. ["A", "S", "D", "F", "G", "H", "J", "K", "L"],
  57. ["Z", "X", "C", "V", "B", "N", "M", "-"],
  58. ],
  59. };
  60. },
  61. watch: {},
  62. computed: {
  63. keys() {
  64. return this[this.type];
  65. },
  66. },
  67. methods: {
  68. keyTapHandler(key) {
  69. if (this.deleteKeys.includes(key)) {
  70. this.$emit("on-delete");
  71. return;
  72. }
  73. this.$emit("on-input", key);
  74. },
  75. hideHandler() {
  76. this.$emit("on-hide");
  77. },
  78. },
  79. beforeMount() {},
  80. mounted() {},
  81. };
  82. </script>
  83. <style scoped lang="less">
  84. .car-keyboard {
  85. position: fixed;
  86. bottom: 0;
  87. left: 0;
  88. width: 100%;
  89. background-color: #f5f5f5;
  90. z-index: 999;
  91. }
  92. .status-bar {
  93. height: 80rpx;
  94. background: #dfe8e7;
  95. color: #323330;
  96. display: flex;
  97. flex-direction: row-reverse;
  98. }
  99. .close {
  100. font-size: 30rpx;
  101. height: 100%;
  102. padding: 0 20rpx;
  103. display: flex;
  104. align-items: center;
  105. }
  106. .keys-container {
  107. padding: 23rpx 13rpx 30rpx 13rpx;
  108. }
  109. .row {
  110. display: flex;
  111. flex-wrap: wrap;
  112. justify-content: center;
  113. margin-bottom: 14rpx;
  114. }
  115. .key {
  116. width: 60rpx;
  117. height: 72rpx;
  118. background: #ffffff;
  119. border: 1rpx solid #e6e6e6;
  120. box-sizing: border-box;
  121. border-radius: 4rpx;
  122. color: #323330;
  123. font-size: 36rpx;
  124. display: flex;
  125. align-items: center;
  126. justify-content: center;
  127. margin-right: 14rpx;
  128. .delete {
  129. width: 66rpx;
  130. height: 40rpx;
  131. background: url(../../static/codecook-keyboard/icon_delete.png) no-repeat;
  132. background-size: 100% 100%;
  133. }
  134. &.is-delete {
  135. width: 134rpx;
  136. }
  137. &.last {
  138. margin-right: 0;
  139. }
  140. }
  141. </style>