|
|
@ -1,4 +1,4 @@
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* 通用js方法封装处理
|
|
|
|
* 通用js方法封装处理
|
|
|
|
* Copyright (c) 2019 ruoyi
|
|
|
|
* Copyright (c) 2019 ruoyi
|
|
|
|
*/
|
|
|
|
*/
|
|
|
@ -58,7 +58,7 @@ export function addDateRange(params, dateRange, propName) {
|
|
|
|
var search = params;
|
|
|
|
var search = params;
|
|
|
|
search.params = {};
|
|
|
|
search.params = {};
|
|
|
|
if (null != dateRange && '' != dateRange) {
|
|
|
|
if (null != dateRange && '' != dateRange) {
|
|
|
|
if (typeof(propName) === "undefined") {
|
|
|
|
if (typeof (propName) === "undefined") {
|
|
|
|
search.params["beginTime"] = dateRange[0];
|
|
|
|
search.params["beginTime"] = dateRange[0];
|
|
|
|
search.params["endTime"] = dateRange[1];
|
|
|
|
search.params["endTime"] = dateRange[1];
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
@ -129,38 +129,47 @@ export function praseStrEmpty(str) {
|
|
|
|
* @param {*} id id字段 默认 'id'
|
|
|
|
* @param {*} id id字段 默认 'id'
|
|
|
|
* @param {*} parentId 父节点字段 默认 'parentId'
|
|
|
|
* @param {*} parentId 父节点字段 默认 'parentId'
|
|
|
|
* @param {*} children 孩子节点字段 默认 'children'
|
|
|
|
* @param {*} children 孩子节点字段 默认 'children'
|
|
|
|
* @param {*} rootId 根Id 默认 0
|
|
|
|
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
export function handleTree(data, id, parentId, children, rootId) {
|
|
|
|
export function handleTree(data, id, parentId, children) {
|
|
|
|
id = id || 'id'
|
|
|
|
let config = {
|
|
|
|
parentId = parentId || 'parentId'
|
|
|
|
id: id || 'id',
|
|
|
|
children = children || 'children'
|
|
|
|
parentId: parentId || 'parentId',
|
|
|
|
rootId = rootId || Math.min.apply(Math, data.map(item => { return item[parentId] })) || 0
|
|
|
|
childrenList: children || 'children'
|
|
|
|
//对源数据深度克隆
|
|
|
|
};
|
|
|
|
const cloneData = JSON.parse(JSON.stringify(data))
|
|
|
|
|
|
|
|
//循环所有项
|
|
|
|
|
|
|
|
const treeData = cloneData.filter(father => {
|
|
|
|
|
|
|
|
let branchArr = cloneData.filter(child => {
|
|
|
|
|
|
|
|
//返回每一项的子级数组
|
|
|
|
|
|
|
|
return father[id] === child[parentId]
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
branchArr.length > 0 ? father.children = branchArr : '';
|
|
|
|
|
|
|
|
//返回第一层
|
|
|
|
|
|
|
|
return father[parentId] === rootId;
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
return treeData != '' ? treeData : data;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
var childrenListMap = {};
|
|
|
|
* 参数处理
|
|
|
|
var nodeIds = {};
|
|
|
|
* @param {*} params 参数
|
|
|
|
var tree = [];
|
|
|
|
*/
|
|
|
|
|
|
|
|
export function tansParams(params) {
|
|
|
|
for (let d of data) {
|
|
|
|
let result = ''
|
|
|
|
let parentId = d[config.parentId];
|
|
|
|
Object.keys(params).forEach((key) => {
|
|
|
|
if (childrenListMap[parentId] == null) {
|
|
|
|
if (!Object.is(params[key], undefined) && !Object.is(params[key], null) && !Object.is(JSON.stringify(params[key]), '{}')) {
|
|
|
|
childrenListMap[parentId] = [];
|
|
|
|
result += encodeURIComponent(key) + '=' + encodeURIComponent(params[key]) + '&'
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
nodeIds[d[config.id]] = d;
|
|
|
|
return result
|
|
|
|
childrenListMap[parentId].push(d);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (let d of data) {
|
|
|
|
|
|
|
|
let parentId = d[config.parentId];
|
|
|
|
|
|
|
|
if (nodeIds[parentId] == null) {
|
|
|
|
|
|
|
|
tree.push(d);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (let t of tree) {
|
|
|
|
|
|
|
|
adaptToChildrenList(t);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function adaptToChildrenList(o) {
|
|
|
|
|
|
|
|
if (childrenListMap[o[config.id]] !== null) {
|
|
|
|
|
|
|
|
o[config.childrenList] = childrenListMap[o[config.id]];
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (o[config.childrenList]) {
|
|
|
|
|
|
|
|
for (let c of o[config.childrenList]) {
|
|
|
|
|
|
|
|
adaptToChildrenList(c);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return tree;
|
|
|
|
}
|
|
|
|
}
|
|
|
|