CompanyTree.js 884 B

12345678910111213141516171819202122232425
  1. import companyInfoApi from "@/api/base/companyInfo";
  2. export default {
  3. install(Vue) {
  4. Vue.prototype.$cloneData = (title, content, callback) => {
  5. var companyResult = "";
  6. companyInfoApi.list().then(function (response) {
  7. var jsonData = response.data;
  8. if (jsonData.result) {
  9. companyResult = jsonData.data;
  10. }
  11. });
  12. let cloneData = JSON.parse(JSON.stringify(companyResult)); // 对源数据深度克隆
  13. cloneData.filter(father => {
  14. // 循环所有项,并添加children属性
  15. let branchArr = cloneData.filter(child => father.id == child.parentId); // 返回每一项的子级数组
  16. branchArr.length > 0 ? (father.children = branchArr) : ""; //给父级添加一个children属性,并赋值
  17. return father.parentId == null; //返回第一层
  18. });
  19. return cloneData;
  20. };
  21. }
  22. }