index.js 2.6 KB

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