明树Git Lab

Commit 51673c70 authored by zfp1's avatar zfp1

update

parent aa087116
Pipeline #105982 passed with stage
in 4 seconds
......@@ -62,7 +62,7 @@ async function updateResource(req, res, next) {
} else if (req.body.type == 2) {
//树结构
let ris = [];
let data = utils.flattenTreeIterative(req.body.resourceInfos);
let data = utils.flattenTree(req.body.resourceInfos, 'key', 'parentKey');
for (let index = 0; index < data.length; index++) {
const element = data[index];
element.resourceId = ress.id;
......@@ -115,6 +115,29 @@ async function listResource(req, res, next) {
next(error);
}
};
async function getResource(req, res, next) {
try {
if (!req.body.id) {
return res.sendError(errorMessage.resourceNotFound)
}
let ress = await DB.Resources.findOne({ where: { id: req.body.id } });
if (!(ress && ress.id)) {
return res.sendError(errorMessage.resourceNotFound)
}
if (ress.type == 1) {
let ressinfos = await DB.ResourcesInfo.findAll({where: {resourceId: ress.id}, raw: true});
ress.resourceInfos = ressinfos;
} else if (ress.type == 2) {
let ressinfos = await DB.ResourcesInfo.findAll({where: {resourceId: ress.id}, raw: true});
let tree = await utils.buildTree2(ressinfos, {keyName: 'key', parentKeyName: 'parentKey'})
ress.resourceInfos = tree;
}
return res.sendData(ret);
} catch (error) {
next(error);
}
};
/**
* 资源库字段controller
......@@ -284,7 +307,7 @@ module.exports = {
updateResource,
deleteResource,
listResource,
getResource,
createResourceInfo,
updateResourceInfo,
......
......@@ -21,6 +21,10 @@ const ResourcesInfo = sequelize.define('ResourcesInfo', {
type: DataTypes.STRING,
comment: "资源库字段key"
},
parentKey: {
type: DataTypes.STRING,
comment: "资源库key"
},
value: {
type: DataTypes.STRING,
comment: "资源库字段value"
......
......@@ -11,6 +11,7 @@ router.post('/createResource', resourceController.createResource);
router.post('/deleteResource', resourceController.deleteResource);
router.post('/updateResource', resourceController.updateResource);
router.post('/listResource', resourceController.listResource);
router.post('/getResource', resourceController.getResource);
/**
* 资源库字段详情
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment