smd-code.js 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. const smdCodeCalculator = require('../../../tools/smd-code/index.js')
  2. const handlers = {
  3. setSmdCodeState(changedData) {
  4. this.setData(smdCodeCalculator.updateState(this.data, changedData))
  5. },
  6. onSmdKindTap(event) {
  7. const kind = event.currentTarget.dataset.kind
  8. const kindIndex = (this.data.smdKindOptions || []).findIndex((item) => item.key === kind)
  9. if (kindIndex < 0) return
  10. this.setSmdCodeState({
  11. smdFormatIndex: 0,
  12. smdFormatKey: '',
  13. smdKindIndex: kindIndex
  14. })
  15. },
  16. onSmdFormatTap(event) {
  17. const format = event.currentTarget.dataset.format
  18. const formatIndex = (this.data.smdFormatOptions || []).findIndex((item) => item.key === format)
  19. if (formatIndex < 0) return
  20. this.setSmdCodeState({
  21. smdFormatIndex: formatIndex,
  22. smdFormatKey: format
  23. })
  24. },
  25. onSmdCodeInput(event) {
  26. this.setSmdCodeState({
  27. smdCodeText: event.detail.value
  28. })
  29. },
  30. clearSmdCodeInput() {
  31. this.setSmdCodeState({
  32. smdCodeText: ''
  33. })
  34. }
  35. }
  36. module.exports = {
  37. handlers
  38. }