xm-keyboard-v2.vue 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. <template>
  2. <view class="xm-keyboard-v2">
  3. <xm-popup :show="isShow" @close="toCancel" background="#d4d5d9" :showContent="showContent" :anim="anim">
  4. <view style="background-color: #FFF;">
  5. <view class="xm-flex xm-title" v-if="title">
  6. {{ title }}
  7. </view>
  8. <view style="padding: 10px;">
  9. <xm-keyboard-input ref="keyboardInput" @change="inputChange" :cursor="cursor"
  10. :show-pointer="type == 'plate'" :max="max"></xm-keyboard-input>
  11. </view>
  12. </view>
  13. <xm-keyboard-box ref="keyboardBox" :show-change-btn="type == 'plate'" :show-cancel-btn="!showContent"
  14. :vibration="vibration" :disable="disable" @add="inputAdd" @del="inputDel" @clear="inputClear"
  15. @cancel="toCancel" @confirm="toConfirm"></xm-keyboard-box>
  16. </xm-popup>
  17. </view>
  18. </template>
  19. <script>
  20. export default {
  21. name: 'xm-keyboard-v2',
  22. emits: ['confirm', 'cancel'],
  23. props: {
  24. title: {
  25. type: String,
  26. default: ''
  27. },
  28. cursor: {
  29. type: Boolean,
  30. default: false
  31. },
  32. vibration: {
  33. type: Boolean,
  34. default: false
  35. },
  36. type: {
  37. type: String,
  38. default: 'plate'
  39. },
  40. max: {
  41. type: Number,
  42. default: 8,
  43. },
  44. showContent: {
  45. type: Boolean,
  46. default: false
  47. },
  48. // 是否加入动画效果
  49. anim: {
  50. type: Boolean,
  51. default: true
  52. },
  53. // 禁用某些按钮
  54. disable: {
  55. required: false,
  56. default: () => ('')
  57. },
  58. },
  59. data() {
  60. return {
  61. isShow: false,
  62. value: '',
  63. }
  64. },
  65. methods: {
  66. toShow(value) {
  67. this.value = value || '';
  68. this.isShow = true;
  69. this.$refs.keyboardInput.changeValue(this.value);
  70. },
  71. toConfirm() {
  72. this.isShow = false;
  73. let value = this.$refs.keyboardInput.values.join('')
  74. this.$emit('confirm', value);
  75. },
  76. toCancel() {
  77. this.isShow = false;
  78. this.$emit('cancel');
  79. },
  80. inputChange(index) {
  81. if (this.type == 'plate') {
  82. this.$refs.keyboardBox.changeMode(index == 0 ? 0 : 1);
  83. } else {
  84. this.$refs.keyboardBox.changeMode(1);
  85. }
  86. },
  87. inputAdd(v) {
  88. this.$refs.keyboardInput.toAdd(v);
  89. },
  90. inputDel() {
  91. this.$refs.keyboardInput.toDel();
  92. },
  93. inputClear() {
  94. this.$refs.keyboardInput.toClear();
  95. }
  96. },
  97. }
  98. </script>
  99. <style lang="scss" scoped>
  100. .xm-keyboard-v2 {
  101. .xm-flex {
  102. display: flex;
  103. align-items: center;
  104. justify-content: center;
  105. }
  106. .xm-title {
  107. padding: 20px 0 10px 0;
  108. font-weight: bold;
  109. }
  110. }
  111. </style>