index.wxs 2.21 KB
Newer Older
李嘉林 committed
1
/* eslint-disable */
程默 committed
2 3 4
var utils = require('../wxs/utils.wxs');
var style = require('../wxs/style.wxs');

李嘉林 committed
5 6 7 8 9 10 11 12 13 14 15 16 17 18
function tabClass(active, ellipsis) {
  var classes = ['tab-class'];

  if (active) {
    classes.push('tab-active-class');
  }

  if (ellipsis) {
    classes.push('van-ellipsis');
  }

  return classes.join(' ');
}

程默 committed
19 20 21 22
function tabStyle(data) {
  var titleColor = data.active
    ? data.titleActiveColor
    : data.titleInactiveColor;
李嘉林 committed
23

程默 committed
24
  var ellipsis = data.scrollable && data.ellipsis;
李嘉林 committed
25

程默 committed
26 27 28 29 30 31 32 33
  // card theme color
  if (data.type === 'card') {
    return style({
      'border-color': data.color,
      'background-color': !data.disabled && data.active ? data.color : null,
      color: titleColor || (!data.disabled && !data.active ? data.color : null),
      'flex-basis': ellipsis ? 88 / data.swipeThreshold + '%' : null,
    });
李嘉林 committed
34 35
  }

程默 committed
36 37 38 39 40
  return style({
    color: titleColor,
    'flex-basis': ellipsis ? 88 / data.swipeThreshold + '%' : null,
  });
}
李嘉林 committed
41

程默 committed
42 43 44 45
function navStyle(color, type) {
  return style({
    'border-color': type === 'card' && color ? color : null,
  });
李嘉林 committed
46 47 48 49 50 51 52
}

function trackStyle(data) {
  if (!data.animated) {
    return '';
  }

程默 committed
53 54 55 56 57 58 59
  return style({
    left: -100 * data.currentIndex + '%',
    'transition-duration': data.duration + 's',
    '-webkit-transition-duration': data.duration + 's',
  });
}

60 61 62 63
function lineStyle(linePosition,data) {
  // 横向标签平铺模式缩短宽度
  var lineWidth = linePosition == 3?(data.lineWidth - 32):data.lineWidth
  var lineOffsetLeft = linePosition == 3 ? (data.lineOffsetLeft + 16) : data.lineOffsetLeft
程默 committed
64
  return style({
65 66 67
    width: utils.addUnit(lineWidth),
    transform: 'translateX(' + lineOffsetLeft + 'px)',
    '-webkit-transform': 'translateX(' + lineOffsetLeft + 'px)',
程默 committed
68 69 70 71 72 73 74 75 76
    'background-color': data.color,
    height: data.lineHeight !== -1 ? utils.addUnit(data.lineHeight) : null,
    'border-radius':
      data.lineHeight !== -1 ? utils.addUnit(data.lineHeight) : null,
    'transition-duration': !data.skipTransition ? data.duration + 's' : null,
    '-webkit-transition-duration': !data.skipTransition
      ? data.duration + 's'
      : null,
  });
李嘉林 committed
77 78
}

程默 committed
79 80 81 82 83 84 85
module.exports = {
  tabClass: tabClass,
  tabStyle: tabStyle,
  trackStyle: trackStyle,
  lineStyle: lineStyle,
  navStyle: navStyle,
};