123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142 |
- export function jsonToArray(nodes) {
- let pid = -1;
- const toArray = (nodes) => {
- let r = [];
- if (Array.isArray(nodes)) {
- for (let i = 0, l = nodes.length; i < l; i++) {
- nodes[i].pid = pid;
- r.push(nodes[i]);
- if (
- Array.isArray(nodes[i]["children"]) &&
- nodes[i]["children"].length > 0
- ) {
-
- pid = nodes[i].id;
- r = r.concat(toArray(nodes[i]["children"]));
- delete nodes[i]["children"];
- }
- }
- }
- return r;
- };
- return toArray(nodes);
- }
- export function arrayToJson(treeArray) {
- var r = [];
- var tmpMap = {};
- for (var i = 0, l = treeArray.length; i < l; i++) {
-
- tmpMap[treeArray[i]["id"]] = treeArray[i];
- }
- for (i = 0, l = treeArray.length; i < l; i++) {
- var key = tmpMap[treeArray[i]["pid"]];
-
-
- if (key) {
-
- if (!key["children"]) {
- key["children"] = [];
- key["children"].push(treeArray[i]);
-
- } else {
- key["children"].push(treeArray[i]);
- }
- } else {
-
- r.push(treeArray[i]);
- }
- }
- return r;
- }
- export const treeFindPath = (tree, func, name = "id", path = []) => {
- if (!tree) return [];
- for (const data of tree) {
-
- path.push(data[name]);
- if (func(data)) return path;
- if (data.children) {
- const findChildren = treeFindPath(data.children, func, name, path);
- if (findChildren.length) return findChildren;
- }
- path.pop();
- }
- return [];
- };
- export const unwarp = (obj) => obj && (obj.__v_raw || obj.valueOf() || obj);
- export const icons = () => {
- const components = require("@element-plus/icons-vue");
- console.log("🚀 ~ file: map.js ~ line 107 ~ icons ~ e", components);
- const names = [];
- for (const key in components) {
- names.push(components[key].name);
- }
- return names;
- };
- export function exportExcel(tableData, fieldLabels, fieldKeys, fileName) {
- let dataStr = fieldLabels.toString() + '\r\n';
- tableData.forEach(item => {
- fieldKeys.forEach(key => {
-
- dataStr += `"${item[key]}"\t,`;
- });
- dataStr += '\r\n';
- });
-
- const url = "data:text/xls;charset=utf-8,\ufeff" + encodeURIComponent(dataStr);
- const link = document.createElement("a");
- link.href = url;
- link.download = fileName + ".xls";
- link.style.display = 'none';
- document.body.appendChild(link);
- link.click();
- document.body.removeChild(link);
- }
|