明树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
87c890bf
Commit
87c890bf
authored
Nov 19, 2025
by
zhangqi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
根据resource.type展示数据
parent
e541bf62
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
51 additions
and
20 deletions
+51
-20
dev.json
config/dev.json
+1
-1
resourceController.js
controller/resourceController.js
+50
-19
No files found.
config/dev.json
View file @
87c890bf
...
...
@@ -11,7 +11,7 @@
"host"
:
"localhost"
,
"port"
:
3306
,
"username"
:
"root"
,
"password"
:
"
123456
"
,
"password"
:
"
zhangqi1997.
"
,
"database"
:
"gzbjt"
,
"logging"
:
true
},
...
...
controller/resourceController.js
View file @
87c890bf
const
{
buildTree
}
=
require
(
"../utils"
);
const
errorMessage
=
require
(
"../utils/errorMessage"
);
const
{
Op
}
=
require
(
'sequelize'
);
const
{
Op
,
where
}
=
require
(
'sequelize'
);
/**
...
...
@@ -8,6 +9,30 @@ const { Op } = require('sequelize');
async
function
createResource
(
req
,
res
,
next
)
{
try
{
const
body
=
req
.
body
;
// await DB.Resources.bulkCreate(
// [
// { "key": "k1a92f", "name": "公交车" },
// { "key": "u3b81x", "name": "地铁" },
// { "key": "p9c44m", "name": "高铁" },
// { "key": "n7d22t", "name": "出租车" },
// { "key": "q4e93z", "name": "轻轨" },
// { "key": "t6f81k", "name": "磁悬浮列车" },
// { "key": "r8g55w", "name": "轮渡" },
// { "key": "s2h19p", "name": "共享单车" },
// { "key": "w9j73v", "name": "电动车" },
// { "key": "a5k33q", "name": "自驾车" },
// { "key": "y1l87u", "name": "长途客车" },
// { "key": "d3m41b", "name": "飞机" },
// { "key": "f8n22h", "name": "直升机" },
// { "key": "c4p66r", "name": "城际铁路" },
// { "key": "m2q99s", "name": "轨道交通" },
// { "key": "j7r55d", "name": "大巴车" },
// { "key": "z3s13e", "name": "顺风车" },
// { "key": "e9t80y", "name": "三轮车" },
// { "key": "h5u28i", "name": "地面有轨电车" },
// { "key": "b6v71o", "name": "高速公路客运" }
// ]
// )
const
ret
=
await
DB
.
Resources
.
create
(
body
);
return
res
.
sendData
(
ret
);
}
catch
(
error
)
{
...
...
@@ -114,26 +139,32 @@ async function deleteResourceInfo(req, res, next) {
async
function
listResourceInfo
(
req
,
res
,
next
)
{
try
{
let
search
=
{
where
:
{
del
:
0
}
};
let
page
=
req
.
body
.
page
||
1
;
let
limit
=
req
.
body
.
pageSize
||
10
;
//翻页
let
offset
=
(
page
-
1
)
*
limit
;
if
(
req
.
body
.
name
)
{
search
.
where
=
{
[
Op
.
or
]:
[
//根据value值模糊搜索
{
value
:
{
[
Op
.
like
]:
`%
${
req
.
body
.
name
}
%`
}
}
],
del
:
0
,
const
body
=
req
.
body
;
if
(
!
body
.
resourceId
)
{
return
res
.
sendError
(
errorMessage
.
resourceNotFound
)
}
const
resource
=
await
DB
.
Resources
.
findOne
({
where
:
{
id
:
body
.
resourceId
},
raw
:
true
});
let
search
=
{
where
:
{
[
Op
.
and
]:
[
{
del
:
0
},
{
resourceId
:
resource
.
id
},
(
req
.
body
.
name
?
[{
value
:
{
[
Op
.
like
]:
`%
${
req
.
body
.
name
}
%`
}
}]
:
[])
]
},
raw
:
true
}
search
.
limit
=
limit
;
search
.
offset
=
offset
;
//指定显示字段,空数组会报错
search
.
attributes
=
req
.
body
.
attributes
||
null
;
let
ret
=
await
DB
.
ResourcesInfo
.
findAndCountAll
(
search
);
// search.attributes = req.body.attributes || null;
let
ret
=
await
DB
.
ResourcesInfo
.
findAll
(
search
);
console
.
log
(
"ret"
,
ret
)
if
(
resource
.
type
===
1
)
{
return
res
.
sendData
(
ret
);
}
else
if
(
resource
.
type
===
2
)
{
//ret为json数据数组
const
treeData
=
buildTree
(
ret
);
return
res
.
sendData
(
treeData
);
}
}
catch
(
error
)
{
next
(
error
);
}
...
...
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