index.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. import { $wuxIndex } from '../../dist/index'
  2. import ad from '../index/ad'
  3. const NAMES = ['Aaron', 'Alden', 'Austin', 'Baldwin', 'Braden', 'Carl', 'Chandler', 'Clyde', 'David', 'Edgar', 'Elton', 'Floyd', 'Freeman', 'Gavin', 'Hector', 'Henry', 'Ian', 'Jason', 'Joshua', 'Kane', 'Lambert', 'Matthew', 'Morgan', 'Neville', 'Oliver', 'Oscar', 'Perry', 'Quinn', 'Ramsey', 'Scott', 'Seth', 'Spencer', 'Timothy', 'Todd', 'Trevor', 'Udolf', 'Victor', 'Vincent', 'Walton', 'Willis', 'Xavier', 'Yvonne', 'Zack', 'Zane']
  4. ad({
  5. data: {
  6. alphabet: [],
  7. indicatorPosition: 'center',
  8. },
  9. onLoad() {
  10. const alphabet = []
  11. 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'.split('').forEach((initial, i) => {
  12. const cells = NAMES.filter((name) => name.charAt(0) === initial)
  13. alphabet.push({
  14. initial,
  15. cells,
  16. })
  17. })
  18. this.setData({
  19. alphabet,
  20. })
  21. },
  22. onChange(e) {
  23. console.log('onChange', e.detail)
  24. },
  25. setIndicator() {
  26. this.setData({
  27. indicatorPosition:
  28. this.data.indicatorPosition === 'center'
  29. ? 'right'
  30. : 'center',
  31. })
  32. },
  33. scrollToH() {
  34. const { scrollTo } = $wuxIndex()
  35. scrollTo(this.data.alphabet.findIndex((v) => v.initial === 'H'))
  36. },
  37. scrollToZ() {
  38. const { scrollTo } = $wuxIndex()
  39. scrollTo('Z')
  40. },
  41. })