沙盘演示系统应用的微信小程序
zuoxiao
2024-08-28 eb3dbfdcb126beeb1d08f3306ac8f5bbc466e133
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
var getBadgeValue = function (props) {
  if (props.dot) {
    return '';
  }
  if (isNaN(props.count) || isNaN(props.maxCount)) {
    return props.count;
  }
  return parseInt(props.count) > props.maxCount ? props.maxCount + '+' : props.count;
};
 
var hasUnit = function (unit) {
  return (
    unit.indexOf('px') > 0 ||
    unit.indexOf('rpx') > 0 ||
    unit.indexOf('em') > 0 ||
    unit.indexOf('rem') > 0 ||
    unit.indexOf('%') > 0 ||
    unit.indexOf('vh') > 0 ||
    unit.indexOf('vm') > 0
  );
};
 
var getBadgeStyles = function (props) {
  var styleStr = '';
  if (props.color) {
    styleStr += 'background:' + props.color + ';';
  }
  if (props.offset[0]) {
    styleStr += 'left: calc(100% + ' + (hasUnit(props.offset[0].toString()) ? props.offset[0] : props.offset[0] + 'px') + ');';
  }
  if (props.offset[1]) {
    styleStr += 'top:' + (hasUnit(props.offset[1].toString()) ? props.offset[1] : props.offset[1] + 'px') + ';';
  }
  return styleStr;
};
 
var getBadgeOuterClass = function (props) {
  var baseClass = 't-badge';
  var classNames = [baseClass, props.shape === 'ribbon' ? baseClass + '__ribbon-outer' : ''];
  return classNames.join(' ');
};
 
var getBadgeInnerClass = function (props) {
  var baseClass = 't-badge';
  var classNames = [
    baseClass + '--basic',
    props.dot ? baseClass + '--dot' : '',
    baseClass + '--' + props.size,
    baseClass + '--' + props.shape,
    !props.dot && props.count ? baseClass + '--count' : '',
  ];
  return classNames.join(' ');
};
 
var isShowBadge = function (props) {
  if (props.dot) {
    return true;
  }
  if (!props.showZero && !isNaN(props.count) && parseInt(props.count) === 0) {
    return false;
  }
  if (props.count == null) return false;
  return true;
};
 
module.exports.getBadgeValue = getBadgeValue;
module.exports.getBadgeStyles = getBadgeStyles;
module.exports.getBadgeOuterClass = getBadgeOuterClass;
module.exports.getBadgeInnerClass = getBadgeInnerClass;
module.exports.isShowBadge = isShowBadge;