大空间消毒机
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

63 lines
1.3 KiB

2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
  1. <template>
  2. <div :class="keyboardClass" id="keyboard"></div>
  3. </template>
  4. <script>
  5. import Keyboard from 'simple-keyboard'
  6. import 'simple-keyboard/build/css/index.css'
  7. export default {
  8. name: 'SimpleKeyboard',
  9. props: {
  10. keyboardClass: {
  11. default: 'simple-keyboard',
  12. type: String,
  13. },
  14. input: {
  15. type: String,
  16. },
  17. hideKeyBoard: {
  18. type: Function,
  19. default: () => {},
  20. },
  21. },
  22. data: () => ({
  23. keyboard: null,
  24. }),
  25. mounted() {
  26. this.keyboard = new Keyboard(this.keyboardClass, {
  27. onChange: this.onChange,
  28. onKeyPress: this.onKeyPress,
  29. })
  30. },
  31. methods: {
  32. onChange(input) {
  33. this.$emit('onChange', input)
  34. },
  35. onKeyPress(button) {
  36. this.$emit('onKeyPress', button)
  37. /**
  38. * If you want to handle the shift and caps lock buttons
  39. */
  40. if (button === '{shift}' || button === '{lock}') this.handleShift()
  41. },
  42. handleShift() {
  43. let currentLayout = this.keyboard.options.layoutName
  44. let shiftToggle = currentLayout === 'default' ? 'shift' : 'default'
  45. this.keyboard.setOptions({
  46. layoutName: shiftToggle,
  47. })
  48. },
  49. },
  50. watch: {
  51. input(input) {
  52. this.keyboard.setInput(input)
  53. },
  54. },
  55. }
  56. </script>
  57. <!-- Add "scoped" attribute to limit CSS to this component only -->
  58. <style lang="scss" scoped></style>