admin
2020-12-08 7f2d1daf6af6ecebad84d80de46a0e5024bbf5da
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
import fmtUnit from '../_util/fmtUnit';
Component({
  data: {
    getColumnBorderIndex: 0,
    iconSize: fmtUnit(28)
  },
  props: {
    columnNum: 3,
    circular: false,
    list: [],
    onGridItemClick: function onGridItemClick() {},
    hasLine: true,
    infinite: false,
    multiLine: false,
    infiniteHeight: fmtUnit('90px'),
    gridName: ''
  },
  didMount: function didMount() {
    this.clearBorder();
    this.createGridName();
  },
  didUpdate: function didUpdate() {
    this.clearBorder();
    this.createGridName();
  },
  methods: {
    onGridItemClick: function onGridItemClick(e) {
      this.props.onGridItemClick({
        detail: {
          index: e.target.dataset.index
        }
      });
    },
    clearBorder: function clearBorder() {
      var _this$props = this.props,
          list = _this$props.list,
          columnNum = _this$props.columnNum;
 
      if (columnNum === 3) {
        var rows = list.length % columnNum;
        this.setData({
          getColumnBorderIndex: rows === 0 ? 3 : rows
        });
      }
    },
    createGridName: function createGridName() {
      var _this$props2 = this.props,
          infinite = _this$props2.infinite,
          gridName = _this$props2.gridName;
 
      if (infinite) {
        if (gridName === '' && !gridName) {
          this.props.gridName = "grid" + Math.floor(Math.random() * 100000);
          this.setData({
            gridName: this.props.gridName
          });
        }
      }
    }
  }
});