index.js 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. // components/dotLine/index.js
  2. Component({
  3. /**
  4. * 组件的属性列表
  5. */
  6. properties: {
  7. list: {
  8. type: Array,
  9. value: [
  10. {name: '步骤1'},
  11. {name: '步骤2'},
  12. {name: '步骤3'},
  13. ]
  14. },
  15. currentIndex: {
  16. type: Number,
  17. value: 0
  18. },
  19. swiperDx: {
  20. type: Number,
  21. value: 0
  22. },
  23. width: {
  24. type: Number,
  25. value: 140
  26. },
  27. language:{
  28. type:String,
  29. }
  30. },
  31. /**
  32. * 组件的初始数据
  33. */
  34. data: {
  35. tabList: []
  36. },
  37. /**
  38. * 组件的方法列表
  39. */
  40. methods: {
  41. },
  42. observers: {
  43. 'swiperDx': function(swiperDx) {
  44. const { currentIndex } = this.data;
  45. this.data.list.forEach((item, index) => {
  46. item.isPass = (index <= currentIndex);
  47. if(swiperDx > 0 && swiperDx < 375) {
  48. if (index < currentIndex+1) {
  49. item.width = this.data.width
  50. } else if (index == currentIndex+1) {
  51. item.width = (swiperDx/375)*this.data.width
  52. } else if (index > currentIndex+1) {
  53. item.width = 0
  54. }
  55. } else if(swiperDx < 0 && swiperDx > -375) {
  56. if (index < currentIndex) {
  57. item.width = this.data.width
  58. } else if (index == currentIndex) {
  59. item.width = (1+(swiperDx/375))*this.data.width
  60. } else if (index > currentIndex) {
  61. item.width = 0
  62. }
  63. }
  64. });
  65. this.setData({
  66. tabList: this.data.list,
  67. });
  68. },
  69. 'currentIndex':function(currentIndex) {
  70. const { swiperDx } = this.data;
  71. this.data.list.forEach((item, index) => {
  72. item.isPass = (index <= currentIndex);
  73. if (swiperDx == 0 || swiperDx >= 375 || swiperDx <= -375) {
  74. if (index <= currentIndex) {
  75. item.width = this.data.width
  76. } else if (index > currentIndex) {
  77. item.width = 0
  78. }
  79. }
  80. });
  81. this.setData({
  82. tabList: this.data.list,
  83. });
  84. }
  85. }
  86. })