tabs.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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. isShow: {
  21. type: Boolean
  22. }
  23. },
  24. lifetimes: {
  25. ready() {
  26. this.setBorBotLeft()
  27. }
  28. },
  29. /**
  30. * 组件的初始数据
  31. */
  32. data: {
  33. animationData: {}, //横线平移动画
  34. acIndex: 0,
  35. },
  36. /**
  37. * 组件的方法列表
  38. */
  39. methods: {
  40. /* 改变选中 */
  41. changeTab(e) {
  42. if (this.data.acIndex == e.currentTarget.dataset.index) return;
  43. this.setData({
  44. acIndex: e.currentTarget.dataset.index
  45. })
  46. this.triggerEvent("onChange", e.currentTarget.dataset.item)
  47. this.setBorBotLeft()
  48. },
  49. //更改横线位置
  50. setBorBotLeft() {
  51. if (this.data.isShow) return;
  52. let animation = wx.createAnimation({
  53. duration: 1000,
  54. timingFunction: 'ease',
  55. })
  56. let that = this;
  57. let query = wx.createSelectorQuery().in(this)
  58. query.select('.acTitle').boundingClientRect();
  59. query.exec(function (res) {
  60. animation.translate(res[0].left).step({
  61. duration: 300
  62. })
  63. that.setData({
  64. animationData: animation.export()
  65. })
  66. })
  67. },
  68. }
  69. })