forked from nsjcy/frontEnd/nsjcy

Mr Ke
2020-05-27 942cb64adf9f3f8113549ffc9f64e6861d556064
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
import fetch from './_fetch';
 
function typeToIcon(type) {
  switch (type) {
    case 'offline':
      return 'cloud-download-o'
    case 'online':
      return 'file-text';
    case 'image':
      return 'picture';
    default:
      return 'file-unknown';
  }
}
export default (busId, attachmentId) => fetch(`api/businessAggr/findAllAtt?entityId=${busId}`)
  .then(json => json.data)
  .then(({result:data, size}) => {
    let item = null;
    const flatList = [];
    const walk = (list, name) => {
      list.forEach(node => {
        if (node.children) {
          node.icon = 'folder';
          walk(node.children, node.name);
        } else {
          node.icon = typeToIcon(node.type);
          if (!item && attachmentId && node.path.indexOf(attachmentId) > -1) {
            item = node;
          }
          flatList.push(node);
        }
      });
    };
    walk(data);
    const max = flatList.map(e => e.step).reduce((max, num) => Math.max(max, num || 0), 0);
    if (max > 1) flatList.forEach(node => {
      if (node.step === max) {
        node.latest = true;
      }
    });
    if (!item) item = data[0].children[0];
    // 防止底部被遮住的垫片
    data.push({ size : size , path: 'path#1' });
    data.push({ path: 'path#2' });
    return { data, item };
  })