12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394 |
- // components/dotLine/index.js
- Component({
- options: {
- observers: true
- },
- /**
- * 组件的属性列表
- */
- properties: {
- list: {
- type: Array,
- value: [
- {
- name: "步骤1"
- },
- {
- name: "步骤2"
- },
- {
- name: "步骤3"
- }
- ]
- },
- currentIndex: {
- type: Number,
- value: 0
- },
- swiperDx: {
- type: Number,
- value: 0
- },
- width: {
- type: Number,
- value: 140
- },
- language: {
- type: String
- }
- },
- /**
- * 组件的初始数据
- */
- data: {
- tabList: []
- },
- /**
- * 组件的方法列表
- */
- methods: {},
- observers: {
- swiperDx: function(swiperDx) {
- const { currentIndex } = this.data;
- this.data.list.forEach((item, index) => {
- item.isPass = index <= currentIndex;
- if (swiperDx > 0 && swiperDx < 375) {
- if (index < currentIndex + 1) {
- item.width = this.data.width;
- } else if (index == currentIndex + 1) {
- item.width = (swiperDx / 375) * this.data.width;
- } else if (index > currentIndex + 1) {
- item.width = 0;
- }
- } else if (swiperDx < 0 && swiperDx > -375) {
- if (index < currentIndex) {
- item.width = this.data.width;
- } else if (index == currentIndex) {
- item.width = (1 + swiperDx / 375) * this.data.width;
- } else if (index > currentIndex) {
- item.width = 0;
- }
- }
- });
- this.setData({
- tabList: this.data.list
- });
- },
- currentIndex: function(currentIndex) {
- const { swiperDx } = this.data;
- this.data.list.forEach((item, index) => {
- item.isPass = index <= currentIndex;
- if (swiperDx == 0 || swiperDx >= 375 || swiperDx <= -375) {
- if (index <= currentIndex) {
- item.width = this.data.width;
- } else if (index > currentIndex) {
- item.width = 0;
- }
- }
- });
- this.setData({
- tabList: this.data.list
- });
- }
- }
- });
|