code: function tree(list) {
    const mapped = {}; // { id: name } 形式方便取值
  
    list.forEach((it) => {
      mapped[it.id] = it;
    });
  
    const result = [];
  
    list.forEach((it) => {
      if (it.pid === '') {
        result.push(it);
      } else {
        const parent = mapped[it.pid];
        if (parent) {
          if (!parent.children) {
            parent.children = [];
          }
          parent.children.push(it);
        }
      }
    });
  
    return result;
  }
docs: 生成树状结构
  
  @param {array} list
  @returns