明树Git Lab
Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
J
jt_backend
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
zengfanpei
jt_backend
Commits
d136765c
Commit
d136765c
authored
Dec 11, 2025
by
zfp1
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update
parent
aa5764b5
Pipeline
#104504
passed with stage
in 3 seconds
Changes
4
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
92 additions
and
55 deletions
+92
-55
projectController.js
controller/projectController.js
+15
-15
resourceController.js
controller/resourceController.js
+8
-5
projectModule.js
module/projectModule.js
+24
-18
index.js
utils/index.js
+45
-17
No files found.
controller/projectController.js
View file @
d136765c
...
@@ -120,13 +120,13 @@ async function createProject(req, res, next) {
...
@@ -120,13 +120,13 @@ async function createProject(req, res, next) {
// 处理 projectTzzjll-----
// 处理 projectTzzjll-----
// 立项资料
// 立项资料
let
lxzl
=
body
.
lxzl
||
[]
;
let
lxzl
=
_
.
compact
(
body
.
lxzl
||
[])
;
lxzl
=
lxzl
.
map
(
o
=>
{
return
{
fileId
:
o
.
id
,
projectId
:
project
.
id
,
proFieldKey
:
'lxzl'
}
});
lxzl
=
lxzl
.
map
(
o
=>
{
return
{
fileId
:
o
.
id
,
projectId
:
project
.
id
,
proFieldKey
:
'lxzl'
}
});
// 立项批复文件
// 立项批复文件
let
lxpfwj
=
body
.
lxpfwj
||
[]
;
let
lxpfwj
=
_
.
compact
(
body
.
lxpfwj
||
[])
;
lxpfwj
=
lxpfwj
.
map
(
o
=>
{
return
{
fileId
:
o
.
id
,
projectId
:
project
.
id
,
proFieldKey
:
'lxpfwj'
}
});
lxpfwj
=
lxpfwj
.
map
(
o
=>
{
return
{
fileId
:
o
.
id
,
projectId
:
project
.
id
,
proFieldKey
:
'lxpfwj'
}
});
// 相关上会材料
// 相关上会材料
let
xgshcl
=
body
.
xgshcl
||
[]
;
let
xgshcl
=
_
.
compact
(
body
.
xgshcl
||
[])
;
xgshcl
=
xgshcl
.
map
(
o
=>
{
return
{
fileId
:
o
.
id
,
projectId
:
project
.
id
,
proFieldKey
:
'xgshcl'
}
});
xgshcl
=
xgshcl
.
map
(
o
=>
{
return
{
fileId
:
o
.
id
,
projectId
:
project
.
id
,
proFieldKey
:
'xgshcl'
}
});
// 处理文件
// 处理文件
let
proFiles
=
_
.
concat
(
lxzl
,
lxpfwj
,
xgshcl
);
let
proFiles
=
_
.
concat
(
lxzl
,
lxpfwj
,
xgshcl
);
...
@@ -225,14 +225,14 @@ async function xiangmulixianggengxin(body, projectLzType) {
...
@@ -225,14 +225,14 @@ async function xiangmulixianggengxin(body, projectLzType) {
// 立项资料
// 立项资料
let
lxzl
=
body
.
lxzl
||
[]
;
let
lxzl
=
_
.
compact
(
body
.
lxzl
||
[])
;
let
needIds
=
[];
let
createIds
=
[];
let
needIds
=
[];
let
createIds
=
[];
lxzl
.
map
(
o
=>
{
if
(
!
o
.
proFieldKey
)
{
createIds
.
push
({
id
:
o
.
id
,
proFieldKey
:
'lxzl'
})
}
else
{
needIds
.
push
(
o
.
id
)
};
return
{
fileId
:
o
.
id
,
projectId
:
projectInfo
.
id
,
proFieldKey
:
'lxzl'
}
});
lxzl
.
map
(
o
=>
{
if
(
!
o
.
proFieldKey
)
{
createIds
.
push
({
id
:
o
.
id
,
proFieldKey
:
'lxzl'
})
}
else
{
needIds
.
push
(
o
.
id
)
};
return
{
fileId
:
o
.
id
,
projectId
:
projectInfo
.
id
,
proFieldKey
:
'lxzl'
}
});
// 立项批复文件
// 立项批复文件
let
lxpfwj
=
body
.
lxpfwj
||
[]
;
let
lxpfwj
=
_
.
compact
(
body
.
lxpfwj
||
[])
;
lxpfwj
.
map
(
o
=>
{
if
(
!
o
.
proFieldKey
)
{
createIds
.
push
({
id
:
o
.
id
,
proFieldKey
:
'lxpfwj'
})
}
else
{
needIds
.
push
(
o
.
id
)
};
return
{
fileId
:
o
.
id
,
projectId
:
projectInfo
.
id
,
proFieldKey
:
'lxpfwj'
}
});
lxpfwj
.
map
(
o
=>
{
if
(
!
o
.
proFieldKey
)
{
createIds
.
push
({
id
:
o
.
id
,
proFieldKey
:
'lxpfwj'
})
}
else
{
needIds
.
push
(
o
.
id
)
};
return
{
fileId
:
o
.
id
,
projectId
:
projectInfo
.
id
,
proFieldKey
:
'lxpfwj'
}
});
// 相关上会材料
// 相关上会材料
let
xgshcl
=
body
.
xgshcl
||
[]
;
let
xgshcl
=
_
.
compact
(
body
.
xgshcl
||
[])
;
xgshcl
.
map
(
o
=>
{
if
(
!
o
.
proFieldKey
)
{
createIds
.
push
({
id
:
o
.
id
,
proFieldKey
:
'xgshcl'
})
}
else
{
needIds
.
push
(
o
.
id
)
};
return
{
fileId
:
o
.
id
,
projectId
:
projectInfo
.
id
,
proFieldKey
:
'xgshcl'
}
});
xgshcl
.
map
(
o
=>
{
if
(
!
o
.
proFieldKey
)
{
createIds
.
push
({
id
:
o
.
id
,
proFieldKey
:
'xgshcl'
})
}
else
{
needIds
.
push
(
o
.
id
)
};
return
{
fileId
:
o
.
id
,
projectId
:
projectInfo
.
id
,
proFieldKey
:
'xgshcl'
}
});
// 处理文件
// 处理文件
//1. 删除
//1. 删除
...
@@ -421,29 +421,29 @@ async function xiangmujuecegengxin(body, projectLzType) {
...
@@ -421,29 +421,29 @@ async function xiangmujuecegengxin(body, projectLzType) {
await
Promise
.
all
(
pns9
.
map
(
item
=>
{
DB
.
ProjectSpyjjc
.
update
(
item
,
{
where
:
{
id
:
item
.
id
}
})
}));
await
Promise
.
all
(
pns9
.
map
(
item
=>
{
DB
.
ProjectSpyjjc
.
update
(
item
,
{
where
:
{
id
:
item
.
id
}
})
}));
// 立项资料
// 立项资料
let
lxzl
=
body
.
lxzl
||
[]
;
let
lxzl
=
_
.
compact
(
body
.
lxzl
||
[])
;
let
needIds
=
[];
let
createIds
=
[];
let
needIds
=
[];
let
createIds
=
[];
lxzl
.
map
(
o
=>
{
if
(
!
o
.
proFieldKey
)
{
createIds
.
push
({
id
:
o
.
id
,
proFieldKey
:
'lxzl'
})
}
else
{
needIds
.
push
(
o
.
id
)
};
return
{
fileId
:
o
.
id
,
projectId
:
projectInfo
.
id
,
proFieldKey
:
'lxzl'
}
});
lxzl
.
map
(
o
=>
{
if
(
!
o
.
proFieldKey
)
{
createIds
.
push
({
id
:
o
.
id
,
proFieldKey
:
'lxzl'
})
}
else
{
needIds
.
push
(
o
.
id
)
};
return
{
fileId
:
o
.
id
,
projectId
:
projectInfo
.
id
,
proFieldKey
:
'lxzl'
}
});
// 立项批复文件
// 立项批复文件
let
lxpfwj
=
body
.
lxpfwj
||
[]
;
let
lxpfwj
=
_
.
compact
(
body
.
lxpfwj
||
[])
;
lxpfwj
.
map
(
o
=>
{
if
(
!
o
.
proFieldKey
)
{
createIds
.
push
({
id
:
o
.
id
,
proFieldKey
:
'lxpfwj'
})
}
else
{
needIds
.
push
(
o
.
id
)
};
return
{
fileId
:
o
.
id
,
projectId
:
projectInfo
.
id
,
proFieldKey
:
'lxpfwj'
}
});
lxpfwj
.
map
(
o
=>
{
if
(
!
o
.
proFieldKey
)
{
createIds
.
push
({
id
:
o
.
id
,
proFieldKey
:
'lxpfwj'
})
}
else
{
needIds
.
push
(
o
.
id
)
};
return
{
fileId
:
o
.
id
,
projectId
:
projectInfo
.
id
,
proFieldKey
:
'lxpfwj'
}
});
// 相关上会材料
// 相关上会材料
let
xgshcl
=
body
.
xgshcl
||
[]
;
let
xgshcl
=
_
.
compact
(
body
.
xgshcl
||
[])
;
xgshcl
.
map
(
o
=>
{
if
(
!
o
.
proFieldKey
)
{
createIds
.
push
({
id
:
o
.
id
,
proFieldKey
:
'xgshcl'
})
}
else
{
needIds
.
push
(
o
.
id
)
};
return
{
fileId
:
o
.
id
,
projectId
:
projectInfo
.
id
,
proFieldKey
:
'xgshcl'
}
});
xgshcl
.
map
(
o
=>
{
if
(
!
o
.
proFieldKey
)
{
createIds
.
push
({
id
:
o
.
id
,
proFieldKey
:
'xgshcl'
})
}
else
{
needIds
.
push
(
o
.
id
)
};
return
{
fileId
:
o
.
id
,
projectId
:
projectInfo
.
id
,
proFieldKey
:
'xgshcl'
}
});
// 可研材料
// 可研材料
let
kycl
=
body
.
kycl
||
[]
;
let
kycl
=
_
.
compact
(
body
.
kycl
||
[])
;
kycl
.
map
(
o
=>
{
if
(
!
o
.
proFieldKey
)
{
createIds
.
push
({
id
:
o
.
id
,
proFieldKey
:
'kycl'
})
}
else
{
needIds
.
push
(
o
.
id
)
};
return
{
fileId
:
o
.
id
,
projectId
:
projectInfo
.
id
,
proFieldKey
:
'kycl'
}
});
kycl
.
map
(
o
=>
{
if
(
!
o
.
proFieldKey
)
{
createIds
.
push
({
id
:
o
.
id
,
proFieldKey
:
'kycl'
})
}
else
{
needIds
.
push
(
o
.
id
)
};
return
{
fileId
:
o
.
id
,
projectId
:
projectInfo
.
id
,
proFieldKey
:
'kycl'
}
});
// 经济指标初步测算材料
// 经济指标初步测算材料
let
jjzbcbcscl
=
body
.
jjzbcbcscl
||
[]
;
let
jjzbcbcscl
=
_
.
compact
(
body
.
jjzbcbcscl
||
[])
;
jjzbcbcscl
.
map
(
o
=>
{
if
(
!
o
.
proFieldKey
)
{
createIds
.
push
({
id
:
o
.
id
,
proFieldKey
:
'jjzbcbcscl'
})
}
else
{
needIds
.
push
(
o
.
id
)
};
return
{
fileId
:
o
.
id
,
projectId
:
projectInfo
.
id
,
proFieldKey
:
'jjzbcbcscl'
}
});
jjzbcbcscl
.
map
(
o
=>
{
if
(
!
o
.
proFieldKey
)
{
createIds
.
push
({
id
:
o
.
id
,
proFieldKey
:
'jjzbcbcscl'
})
}
else
{
needIds
.
push
(
o
.
id
)
};
return
{
fileId
:
o
.
id
,
projectId
:
projectInfo
.
id
,
proFieldKey
:
'jjzbcbcscl'
}
});
// 补充相关支撑材料
// 补充相关支撑材料
let
bcxgzccl
=
body
.
bcxgzccl
||
[]
;
let
bcxgzccl
=
_
.
compact
(
body
.
bcxgzccl
||
[])
;
bcxgzccl
.
map
(
o
=>
{
if
(
!
o
.
proFieldKey
)
{
createIds
.
push
({
id
:
o
.
id
,
proFieldKey
:
'bcxgzccl'
})
}
else
{
needIds
.
push
(
o
.
id
)
};
return
{
fileId
:
o
.
id
,
projectId
:
projectInfo
.
id
,
proFieldKey
:
'bcxgzccl'
}
});
bcxgzccl
.
map
(
o
=>
{
if
(
!
o
.
proFieldKey
)
{
createIds
.
push
({
id
:
o
.
id
,
proFieldKey
:
'bcxgzccl'
})
}
else
{
needIds
.
push
(
o
.
id
)
};
return
{
fileId
:
o
.
id
,
projectId
:
projectInfo
.
id
,
proFieldKey
:
'bcxgzccl'
}
});
// 其他相关支撑材料
// 其他相关支撑材料
let
qtxgzccl
=
body
.
qtxgzccl
||
[]
;
let
qtxgzccl
=
_
.
compact
(
body
.
qtxgzccl
||
[])
;
qtxgzccl
.
map
(
o
=>
{
if
(
!
o
.
proFieldKey
)
{
createIds
.
push
({
id
:
o
.
id
,
proFieldKey
:
'qtxgzccl'
})
}
else
{
needIds
.
push
(
o
.
id
)
};
return
{
fileId
:
o
.
id
,
projectId
:
projectInfo
.
id
,
proFieldKey
:
'qtxgzccl'
}
});
qtxgzccl
.
map
(
o
=>
{
if
(
!
o
.
proFieldKey
)
{
createIds
.
push
({
id
:
o
.
id
,
proFieldKey
:
'qtxgzccl'
})
}
else
{
needIds
.
push
(
o
.
id
)
};
return
{
fileId
:
o
.
id
,
projectId
:
projectInfo
.
id
,
proFieldKey
:
'qtxgzccl'
}
});
// 上会议案
// 上会议案
let
shya
=
body
.
shya
||
[]
;
let
shya
=
_
.
compact
(
body
.
shya
||
[])
;
shya
.
map
(
o
=>
{
if
(
!
o
.
proFieldKey
)
{
createIds
.
push
({
id
:
o
.
id
,
proFieldKey
:
'shya'
})
}
else
{
needIds
.
push
(
o
.
id
)
};
return
{
fileId
:
o
.
id
,
projectId
:
projectInfo
.
id
,
proFieldKey
:
'shya'
}
});
shya
.
map
(
o
=>
{
if
(
!
o
.
proFieldKey
)
{
createIds
.
push
({
id
:
o
.
id
,
proFieldKey
:
'shya'
})
}
else
{
needIds
.
push
(
o
.
id
)
};
return
{
fileId
:
o
.
id
,
projectId
:
projectInfo
.
id
,
proFieldKey
:
'shya'
}
});
// 处理文件
// 处理文件
//1. 删除
//1. 删除
...
...
controller/resourceController.js
View file @
d136765c
...
@@ -12,7 +12,7 @@ async function createResource(req, res, next) {
...
@@ -12,7 +12,7 @@ async function createResource(req, res, next) {
let
ret
=
await
DB
.
Resources
.
create
(
body
);
let
ret
=
await
DB
.
Resources
.
create
(
body
);
ret
=
ret
.
toJSON
();
ret
=
ret
.
toJSON
();
if
(
body
.
resourceInfos
&&
body
.
resourceInfos
.
length
&&
ret
.
id
)
{
if
(
body
.
resourceInfos
&&
body
.
resourceInfos
.
length
&&
ret
.
id
)
{
if
(
body
.
type
==
1
)
{
if
(
body
.
type
==
1
)
{
let
ris
=
[];
let
ris
=
[];
for
(
let
index
=
0
;
index
<
body
.
resourceInfos
.
length
;
index
++
)
{
for
(
let
index
=
0
;
index
<
body
.
resourceInfos
.
length
;
index
++
)
{
const
element
=
body
.
resourceInfos
[
index
];
const
element
=
body
.
resourceInfos
[
index
];
...
@@ -21,7 +21,7 @@ async function createResource(req, res, next) {
...
@@ -21,7 +21,7 @@ async function createResource(req, res, next) {
}
}
console
.
log
(
ris
,
"==="
)
console
.
log
(
ris
,
"==="
)
await
DB
.
ResourcesInfo
.
bulkCreate
(
ris
);
await
DB
.
ResourcesInfo
.
bulkCreate
(
ris
);
}
else
if
(
body
.
type
==
2
)
{
}
else
if
(
body
.
type
==
2
)
{
//树结构
//树结构
let
ris
=
[];
let
ris
=
[];
let
data
=
utils
.
flattenTreeIterative
(
body
.
resourceInfos
);
let
data
=
utils
.
flattenTreeIterative
(
body
.
resourceInfos
);
...
@@ -240,7 +240,10 @@ async function listResourceAll(req, res, next) {
...
@@ -240,7 +240,10 @@ async function listResourceAll(req, res, next) {
element
=
element
.
toJSON
()
element
=
element
.
toJSON
()
// console.log(element.resourcesInfos, "==")
// console.log(element.resourcesInfos, "==")
if
(
element
.
type
==
2
)
{
if
(
element
.
type
==
2
)
{
element
.
resourcesInfos
=
utils
.
buildTree2
(
element
.
resourcesInfos
,
'code'
,
'parentCode'
);
element
.
resourcesInfos
=
utils
.
buildTree2
(
element
.
resourcesInfos
,
{
keyName
:
"code"
,
parentKeyName
:
'parentCode'
,
});
}
}
obj
[
element
.
key
]
=
_
.
orderBy
(
element
.
resourcesInfos
||
[],
'order'
,
'asc'
);
obj
[
element
.
key
]
=
_
.
orderBy
(
element
.
resourcesInfos
||
[],
'order'
,
'asc'
);
}
}
...
...
module/projectModule.js
View file @
d136765c
...
@@ -59,8 +59,8 @@ async function handleProjectData(ret, queryAttrs) {
...
@@ -59,8 +59,8 @@ async function handleProjectData(ret, queryAttrs) {
// console.log(resMap[String(element[key])], String(element[key]), "=========================")
// console.log(resMap[String(element[key])], String(element[key]), "=========================")
element
[
key
]
=
resMap
[
String
(
element
[
key
])];
element
[
key
]
=
resMap
[
String
(
element
[
key
])];
}
else
if
(
rawAttributes
[
key
].
zjType
==
"duoxuan"
)
{
}
else
if
(
rawAttributes
[
key
].
zjType
==
"duoxuan"
)
{
if
(
_
.
isArray
(
element
[
key
])
&&
element
[
key
].
length
>
0
)
{
if
(
_
.
isArray
(
element
[
key
])
&&
element
[
key
].
length
>
0
)
{
element
[
key
].
map
(
o
=>
{
return
resMap
[
o
]
});
element
[
key
].
map
(
o
=>
{
return
resMap
[
o
]
});
element
[
key
]
=
element
[
key
].
join
(
','
)
element
[
key
]
=
element
[
key
].
join
(
','
)
}
}
}
}
...
@@ -80,7 +80,7 @@ async function handleProjectData(ret, queryAttrs) {
...
@@ -80,7 +80,7 @@ async function handleProjectData(ret, queryAttrs) {
async
function
getResourceInfoByIds
(
resouInfoIds
)
{
async
function
getResourceInfoByIds
(
resouInfoIds
)
{
let
ris
=
await
DB
.
ResourcesInfo
.
findAll
({
let
ris
=
await
DB
.
ResourcesInfo
.
findAll
({
where
:
{
id
:
{[
Op
.
in
]:
resouInfoIds
}
},
where
:
{
id
:
{
[
Op
.
in
]:
resouInfoIds
}
},
// raw: true,
// raw: true,
});
});
let
risMap
=
{};
let
risMap
=
{};
...
@@ -203,19 +203,22 @@ async function getProjectInfo({ id }) {
...
@@ -203,19 +203,22 @@ async function getProjectInfo({ id }) {
return
{};
return
{};
}
}
project
=
project
.
toJSON
();
project
=
project
.
toJSON
();
project
.
projectBjtjs
=
await
DB
.
ProjectBjtj
.
findAll
({
where
:{
projectId
:
id
},
raw
:
true
});
project
.
projectBjtjs
=
await
DB
.
ProjectBjtj
.
findAll
({
where
:
{
projectId
:
id
},
raw
:
true
});
project
.
projectCwpjzbs
=
await
DB
.
ProjectCwpjzb
.
findAll
({
where
:{
projectId
:
id
},
raw
:
true
});
project
.
projectCwpjzbs
=
await
DB
.
ProjectCwpjzb
.
findAll
({
where
:
{
projectId
:
id
},
raw
:
true
});
project
.
projectFxgls
=
await
DB
.
ProjectFxgl
.
findAll
({
where
:{
projectId
:
id
},
raw
:
true
});
project
.
projectFxgls
=
await
DB
.
ProjectFxgl
.
findAll
({
where
:
{
projectId
:
id
},
raw
:
true
});
project
.
projectGdxxs
=
await
DB
.
ProjectGdxx
.
findAll
({
where
:{
projectId
:
id
},
raw
:
true
});
project
.
projectGdxxs
=
await
DB
.
ProjectGdxx
.
findAll
({
where
:
{
projectId
:
id
},
raw
:
true
});
project
.
projectJczts
=
await
DB
.
ProjectJczt
.
findAll
({
where
:{
projectId
:
id
},
raw
:
true
});
project
.
projectJczts
=
await
DB
.
ProjectJczt
.
findAll
({
where
:
{
projectId
:
id
},
raw
:
true
});
project
.
projectJsgms
=
await
DB
.
ProjectJsgm
.
findAll
({
where
:{
projectId
:
id
},
raw
:
true
});
project
.
projectJsgms
=
await
DB
.
ProjectJsgm
.
findAll
({
where
:
{
projectId
:
id
},
raw
:
true
});
project
.
projectLcbjds
=
await
DB
.
ProjectLcbjd
.
findAll
({
where
:{
projectId
:
id
},
raw
:
true
});
project
.
projectLcbjds
=
await
DB
.
ProjectLcbjd
.
findAll
({
where
:
{
projectId
:
id
},
raw
:
true
});
project
.
projectSpyjs
=
await
DB
.
ProjectSpyj
.
findAll
({
where
:{
projectId
:
id
},
raw
:
true
});
project
.
projectSpyjs
=
await
DB
.
ProjectSpyj
.
findAll
({
where
:
{
projectId
:
id
},
raw
:
true
});
project
.
projectTzzjlls
=
await
DB
.
ProjectTzzjll
.
findAll
({
where
:{
projectId
:
id
},
raw
:
true
});
project
.
projectTzzjlls
=
await
DB
.
ProjectTzzjll
.
findAll
({
where
:
{
projectId
:
id
},
raw
:
true
});
project
.
projectTzzts
=
await
DB
.
ProjectTzzt
.
findAll
({
where
:{
projectId
:
id
},
raw
:
true
});
project
.
projectTzzts
=
await
DB
.
ProjectTzzt
.
findAll
({
where
:
{
projectId
:
id
},
raw
:
true
});
project
.
projectXmtzzes
=
await
DB
.
ProjectXmtzze
.
findAll
({
where
:{
projectId
:
id
},
raw
:
true
});
project
.
projectXmtzzes
=
await
DB
.
ProjectXmtzze
.
findAll
({
where
:
{
projectId
:
id
},
raw
:
true
});
// let files = await DB.ProjectXmtzze.findAll({projectId: id});
project
.
projectXmtzzes
=
utils
.
buildTree2
(
project
.
projectXmtzzes
,
'xh'
,
'parentXh'
);
project
.
projectXmtzzes
=
utils
.
buildTree2
(
project
.
projectXmtzzes
,
{
keyName
:
"xh"
,
parentKeyName
:
'parentXh'
,
});
//处理文件 还原成项目各个字段拥有的文件
//处理文件 还原成项目各个字段拥有的文件
let
files
=
project
.
files
||
[];
let
files
=
project
.
files
||
[];
...
@@ -282,7 +285,10 @@ async function getProjectInfoByLixiang({ id }) {
...
@@ -282,7 +285,10 @@ async function getProjectInfoByLixiang({ id }) {
// raw: true
// raw: true
});
});
project
=
project
.
toJSON
();
project
=
project
.
toJSON
();
project
.
projectXmtzzes
=
utils
.
buildTree2
(
project
.
projectXmtzzes
,
'xh'
,
'parentXh'
);
project
.
projectXmtzzes
=
utils
.
buildTree2
(
project
.
projectXmtzzes
,
{
keyName
:
"xh"
,
parentKeyName
:
'parentXh'
,
});
//处理文件 还原成项目各个字段拥有的文件
//处理文件 还原成项目各个字段拥有的文件
let
files
=
project
.
files
||
[];
let
files
=
project
.
files
||
[];
...
...
utils/index.js
View file @
d136765c
...
@@ -129,26 +129,54 @@ function flattenTree(forest, idDes = 'id', parentIdDes = 'parentId') {
...
@@ -129,26 +129,54 @@ function flattenTree(forest, idDes = 'id', parentIdDes = 'parentId') {
return
result
;
return
result
;
}
}
//
function
buildTree2
(
nodes
,
options
=
{})
{
function
buildTree2
(
nodes
,
keyid
=
'id'
,
keyParentId
=
'parentId'
)
{
// 合并配置和默认值
// 创建一个映射,将节点ID映射到节点对象
const
{
const
nodeMap
=
new
Map
(
nodes
.
map
(
node
=>
[
String
(
node
[
keyid
]),
{
...
node
,
children
:
[]
}]));
keyName
=
'id'
,
parentKeyName
=
'parentId'
,
// 遍历所有节点,并将它们添加到对应父节点的children数组中
orderField
=
'order'
,
filter
=
node
=>
node
.
del
===
0
}
=
options
;
// 创建节点映射表(使用Map提升性能)
const
nodeMap
=
new
Map
();
nodes
.
forEach
(
node
=>
{
nodes
.
forEach
(
node
=>
{
const
parentId
=
String
(
node
[
keyParentId
]);
if
(
!
filter
(
node
))
return
;
if
(
parentId
!==
null
)
{
nodeMap
.
set
(
String
(
node
[
keyName
]),
{
// 确保父节点在映射中存在
...
node
,
if
(
nodeMap
.
has
(
parentId
))
{
children
:
[]
// 将当前节点添加到父节点的children数组中
});
nodeMap
.
get
(
parentId
).
children
.
push
(
nodeMap
.
get
(
String
(
node
[
keyid
])));
});
nodeMap
.
get
(
parentId
).
children
=
_
.
orderBy
(
nodeMap
.
get
(
parentId
).
children
,
[
'order'
,
'code'
])
// 构建树形结构
const
roots
=
[];
nodeMap
.
forEach
((
node
,
nodeId
)
=>
{
const
parentRef
=
String
(
node
[
parentKeyName
]);
// 处理根节点
if
(
!
parentRef
||
parentRef
===
'null'
||
parentRef
===
'undefined'
)
{
roots
.
push
(
node
);
return
;
}
// 处理子节点
if
(
nodeMap
.
has
(
parentRef
))
{
const
parent
=
nodeMap
.
get
(
parentRef
);
parent
.
children
.
push
(
node
);
// 子节点排序(使用稳定排序)
if
(
parent
.
children
.
length
>
1
)
{
parent
.
children
.
sort
((
a
,
b
)
=>
(
a
[
orderField
]
||
0
)
-
(
b
[
orderField
]
||
0
)
);
}
}
}
}
});
});
// 从映射中提取顶级节点(parentId为null)
// 根节点排序
return
_
.
orderBy
(
Array
.
from
(
nodeMap
.
values
()).
filter
(
node
=>
node
[
keyParentId
]
==
null
),
[
'order'
,
'code'
]);
return
roots
.
sort
((
a
,
b
)
=>
(
a
[
orderField
]
||
0
)
-
(
b
[
orderField
]
||
0
)
);
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment