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 };
|
})
|