| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980 |
- Component({
- options: {
- multipleSlots: true,
- addGlobalClass: true
- },
- properties: {
- list: {
- type: Array
- },
- active: {
- type: Number,
- value: 0
- },
- onChenge: {
- type: Function
- }
- },
- lifetimes: {
- attached() {
- getApp().globalData.Language.getLanguagePackage(this)
- }
- },
- data: {
- scrollLeft: 0,
- startPoint: 0, //记录滑动的初始位置
- slipFlag: false, //定义 滑动事件 节流阀, 防止一次滑动触发多次滑动事件
- },
- methods: {
- tabsChenge(e) {
- const {
- index
- } = e.currentTarget.dataset;
- if (this.data.active == index) return;
- this.setData({
- active: index
- });
- this.setActive();
- },
- setActive() {
- const that = this,
- active = this.data.active,
- query = wx.createSelectorQuery().in(this)
- query.select('#active' + active).boundingClientRect(function (res) {
- let index = res.dataset.index,
- scrollLeft = res.left;
- if (index >= 6) scrollLeft += ((index - 4) * res.width);
- if (that.data.scrollLeft > scrollLeft && index >= 4) scrollLeft += (2 * res.width)
- that.setData({
- scrollLeft
- })
- }).exec();
- this.triggerEvent("onChenge", active)
- },
- myTouchStart(e) {
- return;
- this.setData({
- slipFlag: true,
- startPoint: e.touches[0]
- })
- },
- myTouchMove(e) {
- return;
- let active = this.data.active;
- if (((this.data.startPoint.clientX - e.touches[e.touches.length - 1].clientX) > 80) && this.data.slipFlag) {
- if (active != this.data.list.length - 1) active++;
- this.setData({
- slipFlag: false,
- active
- })
- } else if (((this.data.startPoint.clientX - e.touches[e.touches.length - 1].clientX) < -80) && this.data.slipFlag) {
- if (active != 0) active--;
- this.setData({
- slipFlag: false,
- active
- })
- }
- this.setActive();
- },
- }
- })
|