index.ts 971 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. // components/dateselect/index.ts
  2. Component({
  3. /**
  4. * 组件的属性列表
  5. */
  6. properties: {
  7. g_cdn: String
  8. },
  9. /**
  10. * 组件的初始数据
  11. */
  12. data: {
  13. current: 0,
  14. date: [{
  15. key: 7,
  16. name: '最近7天'
  17. },
  18. {
  19. key: 14,
  20. name: '最近14天'
  21. },
  22. {
  23. key: 30,
  24. name: '最近30天'
  25. }]
  26. },
  27. /**
  28. * 组件的方法列表
  29. */
  30. methods: {
  31. swiperChange(e:any) {
  32. this.triggerEvent('dateselect',{current:this.data.date[e.detail.current]}, { bubbles: true, composed: true })
  33. },
  34. tabSwitch(e: any) {
  35. let idx = this.data.current
  36. let { oper } = e.currentTarget.dataset
  37. if (oper == 'prev') {
  38. idx -= 1
  39. if (idx < 0) {
  40. idx = this.data.date.length - 1
  41. }
  42. } else {
  43. idx += 1
  44. if (idx > this.data.date.length - 1) {
  45. idx = 0
  46. }
  47. }
  48. this.setData({
  49. current: idx
  50. })
  51. }
  52. }
  53. })