|
|
@@ -1,4 +1,4 @@
|
|
1
|
|
-/**
|
|
|
1
|
+/**
|
|
2
|
2
|
* 通用js方法封装处理
|
|
3
|
3
|
* Copyright (c) 2019 ruoyi
|
|
4
|
4
|
*/
|
|
|
@@ -58,7 +58,7 @@ export function addDateRange(params, dateRange, propName) {
|
|
58
|
58
|
var search = params;
|
|
59
|
59
|
search.params = {};
|
|
60
|
60
|
if (null != dateRange && '' != dateRange) {
|
|
61
|
|
- if (typeof(propName) === "undefined") {
|
|
|
61
|
+ if (typeof (propName) === "undefined") {
|
|
62
|
62
|
search.params["beginTime"] = dateRange[0];
|
|
63
|
63
|
search.params["endTime"] = dateRange[1];
|
|
64
|
64
|
} else {
|
|
|
@@ -87,8 +87,8 @@ export function selectDictLabels(datas, value, separator) {
|
|
87
|
87
|
var currentSeparator = undefined === separator ? "," : separator;
|
|
88
|
88
|
var temp = value.split(currentSeparator);
|
|
89
|
89
|
Object.keys(value.split(currentSeparator)).some((val) => {
|
|
90
|
|
- Object.keys(datas).some((key) => {
|
|
91
|
|
- if (datas[key].dictValue == ('' + temp[val])) {
|
|
|
90
|
+ Object.keys(datas).some((key) => {
|
|
|
91
|
+ if (datas[key].dictValue == ('' + temp[val])) {
|
|
92
|
92
|
actions.push(datas[key].dictLabel + currentSeparator);
|
|
93
|
93
|
}
|
|
94
|
94
|
})
|
|
|
@@ -129,38 +129,47 @@ export function praseStrEmpty(str) {
|
|
129
|
129
|
* @param {*} id id字段 默认 'id'
|
|
130
|
130
|
* @param {*} parentId 父节点字段 默认 'parentId'
|
|
131
|
131
|
* @param {*} children 孩子节点字段 默认 'children'
|
|
132
|
|
- * @param {*} rootId 根Id 默认 0
|
|
133
|
132
|
*/
|
|
134
|
|
-export function handleTree(data, id, parentId, children, rootId) {
|
|
135
|
|
- id = id || 'id'
|
|
136
|
|
- parentId = parentId || 'parentId'
|
|
137
|
|
- children = children || 'children'
|
|
138
|
|
- rootId = rootId || Math.min.apply(Math, data.map(item => { return item[parentId] })) || 0
|
|
139
|
|
- //对源数据深度克隆
|
|
140
|
|
- const cloneData = JSON.parse(JSON.stringify(data))
|
|
141
|
|
- //循环所有项
|
|
142
|
|
- const treeData = cloneData.filter(father => {
|
|
143
|
|
- let branchArr = cloneData.filter(child => {
|
|
144
|
|
- //返回每一项的子级数组
|
|
145
|
|
- return father[id] === child[parentId]
|
|
146
|
|
- });
|
|
147
|
|
- branchArr.length > 0 ? father.children = branchArr : '';
|
|
148
|
|
- //返回第一层
|
|
149
|
|
- return father[parentId] === rootId;
|
|
150
|
|
- });
|
|
151
|
|
- return treeData != '' ? treeData : data;
|
|
152
|
|
-}
|
|
|
133
|
+export function handleTree(data, id, parentId, children) {
|
|
|
134
|
+ let config = {
|
|
|
135
|
+ id: id || 'id',
|
|
|
136
|
+ parentId: parentId || 'parentId',
|
|
|
137
|
+ childrenList: children || 'children'
|
|
|
138
|
+ };
|
|
|
139
|
+
|
|
|
140
|
+ var childrenListMap = {};
|
|
|
141
|
+ var nodeIds = {};
|
|
|
142
|
+ var tree = [];
|
|
153
|
143
|
|
|
154
|
|
- /**
|
|
155
|
|
- * 参数处理
|
|
156
|
|
- * @param {*} params 参数
|
|
157
|
|
- */
|
|
158
|
|
-export function tansParams(params) {
|
|
159
|
|
- let result = ''
|
|
160
|
|
- Object.keys(params).forEach((key) => {
|
|
161
|
|
- if (!Object.is(params[key], undefined) && !Object.is(params[key], null) && !Object.is(JSON.stringify(params[key]), '{}')) {
|
|
162
|
|
- result += encodeURIComponent(key) + '=' + encodeURIComponent(params[key]) + '&'
|
|
|
144
|
+ for (let d of data) {
|
|
|
145
|
+ let parentId = d[config.parentId];
|
|
|
146
|
+ if (childrenListMap[parentId] == null) {
|
|
|
147
|
+ childrenListMap[parentId] = [];
|
|
163
|
148
|
}
|
|
164
|
|
- })
|
|
165
|
|
- return result
|
|
|
149
|
+ nodeIds[d[config.id]] = d;
|
|
|
150
|
+ childrenListMap[parentId].push(d);
|
|
|
151
|
+ }
|
|
|
152
|
+
|
|
|
153
|
+ for (let d of data) {
|
|
|
154
|
+ let parentId = d[config.parentId];
|
|
|
155
|
+ if (nodeIds[parentId] == null) {
|
|
|
156
|
+ tree.push(d);
|
|
|
157
|
+ }
|
|
|
158
|
+ }
|
|
|
159
|
+
|
|
|
160
|
+ for (let t of tree) {
|
|
|
161
|
+ adaptToChildrenList(t);
|
|
|
162
|
+ }
|
|
|
163
|
+
|
|
|
164
|
+ function adaptToChildrenList(o) {
|
|
|
165
|
+ if (childrenListMap[o[config.id]] !== null) {
|
|
|
166
|
+ o[config.childrenList] = childrenListMap[o[config.id]];
|
|
|
167
|
+ }
|
|
|
168
|
+ if (o[config.childrenList]) {
|
|
|
169
|
+ for (let c of o[config.childrenList]) {
|
|
|
170
|
+ adaptToChildrenList(c);
|
|
|
171
|
+ }
|
|
|
172
|
+ }
|
|
|
173
|
+ }
|
|
|
174
|
+ return tree;
|
|
166
|
175
|
}
|