tabs.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. // pages/tabbar/message/modules/tabs.js
  2. Component({
  3. /**
  4. * 组件的属性列表
  5. */
  6. properties: {
  7. list: {
  8. type: Array,
  9. value: [{
  10. label: '系统消息',
  11. nubmer: "9"
  12. }, {
  13. label: '应用消息',
  14. nubmer: "15"
  15. }]
  16. },
  17. onChange: {
  18. type: Function
  19. }
  20. },
  21. lifetimes: {
  22. ready() {
  23. this.setBorBotLeft()
  24. }
  25. },
  26. /**
  27. * 组件的初始数据
  28. */
  29. data: {
  30. animationData: {}, //横线平移动画
  31. acIndex: 0,
  32. },
  33. /**
  34. * 组件的方法列表
  35. */
  36. methods: {
  37. /* 改变选中 */
  38. changeTab(e) {
  39. if (this.data.acIndex == e.currentTarget.dataset.index) return;
  40. this.setData({
  41. acIndex: e.currentTarget.dataset.index
  42. })
  43. this.triggerEvent("onChange", e.currentTarget.dataset.item)
  44. this.setBorBotLeft()
  45. },
  46. //更改横线位置
  47. setBorBotLeft() {
  48. let animation = wx.createAnimation({
  49. duration: 1000,
  50. timingFunction: 'ease',
  51. })
  52. let that = this;
  53. let query = wx.createSelectorQuery().in(this)
  54. query.select('.acTitle').boundingClientRect();
  55. query.exec(function (res) {
  56. animation.translate(res[0].left).step({
  57. duration: 300
  58. })
  59. that.setData({
  60. animationData: animation.export()
  61. })
  62. })
  63. },
  64. }
  65. })