diff --git a/backend/1.json b/backend/1.json new file mode 100644 index 0000000..6d738ab --- /dev/null +++ b/backend/1.json @@ -0,0 +1,101 @@ +[ + { + "add": false, + "delete": false, + "edit": false, + "view": true, + "name": "id", + "type": "string", + "addDefault": "0000001" + }, + { + "add": true, + "delete": true, + "edit": true, + "view": true, + "name": "name", + "type": "string", + "addDefault": "" + }, + { + "add": true, + "delete": true, + "edit": true, + "view": true, + "name": "add", + "type": "boolean", + "addDefault": true + }, + { + "add": true, + "delete": true, + "edit": true, + "view": true, + "name": "delete", + "type": "boolean", + "addDefault": true + }, + { + "add": true, + "delete": true, + "edit": true, + "view": true, + "name": "edit", + "type": "boolean", + "addDefault": true + }, + { + "add": true, + "delete": true, + "edit": true, + "view": true, + "name": "view", + "type": "boolean", + "addDefault": true + }, + { + "add": true, + "delete": true, + "edit": true, + "view": true, + "name": "type", + "type": "string", + "addDefault": "" + }, + { + "add": true, + "delete": true, + "edit": true, + "view": true, + "name": "addDefault", + "type": "string", + "addDefault": "" + }, + { + "add": true, + "delete": true, + "edit": true, + "view": true, + "name": "remark", + "type": "string", + "addDefault": "" + }, + { + "add": true, + "delete": true, + "edit": true, + "view": true, + "name": "createdAt", + "type": "string", + "addDefault": "" + }, + { + "add": true, + "delete": true, + "edit": true, + "view": true, + "name": "updatedAt", + "type": "string", + "addDefault": "" + } +] diff --git a/backend/2.json b/backend/2.json new file mode 100644 index 0000000..6d738ab --- /dev/null +++ b/backend/2.json @@ -0,0 +1,101 @@ +[ + { + "add": false, + "delete": false, + "edit": false, + "view": true, + "name": "id", + "type": "string", + "addDefault": "0000001" + }, + { + "add": true, + "delete": true, + "edit": true, + "view": true, + "name": "name", + "type": "string", + "addDefault": "" + }, + { + "add": true, + "delete": true, + "edit": true, + "view": true, + "name": "add", + "type": "boolean", + "addDefault": true + }, + { + "add": true, + "delete": true, + "edit": true, + "view": true, + "name": "delete", + "type": "boolean", + "addDefault": true + }, + { + "add": true, + "delete": true, + "edit": true, + "view": true, + "name": "edit", + "type": "boolean", + "addDefault": true + }, + { + "add": true, + "delete": true, + "edit": true, + "view": true, + "name": "view", + "type": "boolean", + "addDefault": true + }, + { + "add": true, + "delete": true, + "edit": true, + "view": true, + "name": "type", + "type": "string", + "addDefault": "" + }, + { + "add": true, + "delete": true, + "edit": true, + "view": true, + "name": "addDefault", + "type": "string", + "addDefault": "" + }, + { + "add": true, + "delete": true, + "edit": true, + "view": true, + "name": "remark", + "type": "string", + "addDefault": "" + }, + { + "add": true, + "delete": true, + "edit": true, + "view": true, + "name": "createdAt", + "type": "string", + "addDefault": "" + }, + { + "add": true, + "delete": true, + "edit": true, + "view": true, + "name": "updatedAt", + "type": "string", + "addDefault": "" + } +] diff --git a/backend/3.json b/backend/3.json new file mode 100644 index 0000000..6d738ab --- /dev/null +++ b/backend/3.json @@ -0,0 +1,101 @@ +[ + { + "add": false, + "delete": false, + "edit": false, + "view": true, + "name": "id", + "type": "string", + "addDefault": "0000001" + }, + { + "add": true, + "delete": true, + "edit": true, + "view": true, + "name": "name", + "type": "string", + "addDefault": "" + }, + { + "add": true, + "delete": true, + "edit": true, + "view": true, + "name": "add", + "type": "boolean", + "addDefault": true + }, + { + "add": true, + "delete": true, + "edit": true, + "view": true, + "name": "delete", + "type": "boolean", + "addDefault": true + }, + { + "add": true, + "delete": true, + "edit": true, + "view": true, + "name": "edit", + "type": "boolean", + "addDefault": true + }, + { + "add": true, + "delete": true, + "edit": true, + "view": true, + "name": "view", + "type": "boolean", + "addDefault": true + }, + { + "add": true, + "delete": true, + "edit": true, + "view": true, + "name": "type", + "type": "string", + "addDefault": "" + }, + { + "add": true, + "delete": true, + "edit": true, + "view": true, + "name": "addDefault", + "type": "string", + "addDefault": "" + }, + { + "add": true, + "delete": true, + "edit": true, + "view": true, + "name": "remark", + "type": "string", + "addDefault": "" + }, + { + "add": true, + "delete": true, + "edit": true, + "view": true, + "name": "createdAt", + "type": "string", + "addDefault": "" + }, + { + "add": true, + "delete": true, + "edit": true, + "view": true, + "name": "updatedAt", + "type": "string", + "addDefault": "" + } +] diff --git a/backend/4.json b/backend/4.json new file mode 100644 index 0000000..6d738ab --- /dev/null +++ b/backend/4.json @@ -0,0 +1,101 @@ +[ + { + "add": false, + "delete": false, + "edit": false, + "view": true, + "name": "id", + "type": "string", + "addDefault": "0000001" + }, + { + "add": true, + "delete": true, + "edit": true, + "view": true, + "name": "name", + "type": "string", + "addDefault": "" + }, + { + "add": true, + "delete": true, + "edit": true, + "view": true, + "name": "add", + "type": "boolean", + "addDefault": true + }, + { + "add": true, + "delete": true, + "edit": true, + "view": true, + "name": "delete", + "type": "boolean", + "addDefault": true + }, + { + "add": true, + "delete": true, + "edit": true, + "view": true, + "name": "edit", + "type": "boolean", + "addDefault": true + }, + { + "add": true, + "delete": true, + "edit": true, + "view": true, + "name": "view", + "type": "boolean", + "addDefault": true + }, + { + "add": true, + "delete": true, + "edit": true, + "view": true, + "name": "type", + "type": "string", + "addDefault": "" + }, + { + "add": true, + "delete": true, + "edit": true, + "view": true, + "name": "addDefault", + "type": "string", + "addDefault": "" + }, + { + "add": true, + "delete": true, + "edit": true, + "view": true, + "name": "remark", + "type": "string", + "addDefault": "" + }, + { + "add": true, + "delete": true, + "edit": true, + "view": true, + "name": "createdAt", + "type": "string", + "addDefault": "" + }, + { + "add": true, + "delete": true, + "edit": true, + "view": true, + "name": "updatedAt", + "type": "string", + "addDefault": "" + } +] diff --git a/backend/5.json b/backend/5.json new file mode 100644 index 0000000..6d738ab --- /dev/null +++ b/backend/5.json @@ -0,0 +1,101 @@ +[ + { + "add": false, + "delete": false, + "edit": false, + "view": true, + "name": "id", + "type": "string", + "addDefault": "0000001" + }, + { + "add": true, + "delete": true, + "edit": true, + "view": true, + "name": "name", + "type": "string", + "addDefault": "" + }, + { + "add": true, + "delete": true, + "edit": true, + "view": true, + "name": "add", + "type": "boolean", + "addDefault": true + }, + { + "add": true, + "delete": true, + "edit": true, + "view": true, + "name": "delete", + "type": "boolean", + "addDefault": true + }, + { + "add": true, + "delete": true, + "edit": true, + "view": true, + "name": "edit", + "type": "boolean", + "addDefault": true + }, + { + "add": true, + "delete": true, + "edit": true, + "view": true, + "name": "view", + "type": "boolean", + "addDefault": true + }, + { + "add": true, + "delete": true, + "edit": true, + "view": true, + "name": "type", + "type": "string", + "addDefault": "" + }, + { + "add": true, + "delete": true, + "edit": true, + "view": true, + "name": "addDefault", + "type": "string", + "addDefault": "" + }, + { + "add": true, + "delete": true, + "edit": true, + "view": true, + "name": "remark", + "type": "string", + "addDefault": "" + }, + { + "add": true, + "delete": true, + "edit": true, + "view": true, + "name": "createdAt", + "type": "string", + "addDefault": "" + }, + { + "add": true, + "delete": true, + "edit": true, + "view": true, + "name": "updatedAt", + "type": "string", + "addDefault": "" + } +] diff --git a/backend/6.json b/backend/6.json new file mode 100644 index 0000000..6d738ab --- /dev/null +++ b/backend/6.json @@ -0,0 +1,101 @@ +[ + { + "add": false, + "delete": false, + "edit": false, + "view": true, + "name": "id", + "type": "string", + "addDefault": "0000001" + }, + { + "add": true, + "delete": true, + "edit": true, + "view": true, + "name": "name", + "type": "string", + "addDefault": "" + }, + { + "add": true, + "delete": true, + "edit": true, + "view": true, + "name": "add", + "type": "boolean", + "addDefault": true + }, + { + "add": true, + "delete": true, + "edit": true, + "view": true, + "name": "delete", + "type": "boolean", + "addDefault": true + }, + { + "add": true, + "delete": true, + "edit": true, + "view": true, + "name": "edit", + "type": "boolean", + "addDefault": true + }, + { + "add": true, + "delete": true, + "edit": true, + "view": true, + "name": "view", + "type": "boolean", + "addDefault": true + }, + { + "add": true, + "delete": true, + "edit": true, + "view": true, + "name": "type", + "type": "string", + "addDefault": "" + }, + { + "add": true, + "delete": true, + "edit": true, + "view": true, + "name": "addDefault", + "type": "string", + "addDefault": "" + }, + { + "add": true, + "delete": true, + "edit": true, + "view": true, + "name": "remark", + "type": "string", + "addDefault": "" + }, + { + "add": true, + "delete": true, + "edit": true, + "view": true, + "name": "createdAt", + "type": "string", + "addDefault": "" + }, + { + "add": true, + "delete": true, + "edit": true, + "view": true, + "name": "updatedAt", + "type": "string", + "addDefault": "" + } +] diff --git a/backend/7.json b/backend/7.json new file mode 100644 index 0000000..6d738ab --- /dev/null +++ b/backend/7.json @@ -0,0 +1,101 @@ +[ + { + "add": false, + "delete": false, + "edit": false, + "view": true, + "name": "id", + "type": "string", + "addDefault": "0000001" + }, + { + "add": true, + "delete": true, + "edit": true, + "view": true, + "name": "name", + "type": "string", + "addDefault": "" + }, + { + "add": true, + "delete": true, + "edit": true, + "view": true, + "name": "add", + "type": "boolean", + "addDefault": true + }, + { + "add": true, + "delete": true, + "edit": true, + "view": true, + "name": "delete", + "type": "boolean", + "addDefault": true + }, + { + "add": true, + "delete": true, + "edit": true, + "view": true, + "name": "edit", + "type": "boolean", + "addDefault": true + }, + { + "add": true, + "delete": true, + "edit": true, + "view": true, + "name": "view", + "type": "boolean", + "addDefault": true + }, + { + "add": true, + "delete": true, + "edit": true, + "view": true, + "name": "type", + "type": "string", + "addDefault": "" + }, + { + "add": true, + "delete": true, + "edit": true, + "view": true, + "name": "addDefault", + "type": "string", + "addDefault": "" + }, + { + "add": true, + "delete": true, + "edit": true, + "view": true, + "name": "remark", + "type": "string", + "addDefault": "" + }, + { + "add": true, + "delete": true, + "edit": true, + "view": true, + "name": "createdAt", + "type": "string", + "addDefault": "" + }, + { + "add": true, + "delete": true, + "edit": true, + "view": true, + "name": "updatedAt", + "type": "string", + "addDefault": "" + } +] diff --git a/backend/8.json b/backend/8.json new file mode 100644 index 0000000..6d738ab --- /dev/null +++ b/backend/8.json @@ -0,0 +1,101 @@ +[ + { + "add": false, + "delete": false, + "edit": false, + "view": true, + "name": "id", + "type": "string", + "addDefault": "0000001" + }, + { + "add": true, + "delete": true, + "edit": true, + "view": true, + "name": "name", + "type": "string", + "addDefault": "" + }, + { + "add": true, + "delete": true, + "edit": true, + "view": true, + "name": "add", + "type": "boolean", + "addDefault": true + }, + { + "add": true, + "delete": true, + "edit": true, + "view": true, + "name": "delete", + "type": "boolean", + "addDefault": true + }, + { + "add": true, + "delete": true, + "edit": true, + "view": true, + "name": "edit", + "type": "boolean", + "addDefault": true + }, + { + "add": true, + "delete": true, + "edit": true, + "view": true, + "name": "view", + "type": "boolean", + "addDefault": true + }, + { + "add": true, + "delete": true, + "edit": true, + "view": true, + "name": "type", + "type": "string", + "addDefault": "" + }, + { + "add": true, + "delete": true, + "edit": true, + "view": true, + "name": "addDefault", + "type": "string", + "addDefault": "" + }, + { + "add": true, + "delete": true, + "edit": true, + "view": true, + "name": "remark", + "type": "string", + "addDefault": "" + }, + { + "add": true, + "delete": true, + "edit": true, + "view": true, + "name": "createdAt", + "type": "string", + "addDefault": "" + }, + { + "add": true, + "delete": true, + "edit": true, + "view": true, + "name": "updatedAt", + "type": "string", + "addDefault": "" + } +] diff --git a/backend/index.js b/backend/index.js new file mode 100644 index 0000000..fb77ee1 --- /dev/null +++ b/backend/index.js @@ -0,0 +1,9 @@ +const fs = require('fs') +const files = fs.readdirSync(__dirname) +let routes = {} +for (file of files) { + if (file !== 'index.js') { + routes[file] = require('./' + file) + } +} +module.exports = routes diff --git a/model/index.js b/model/index.js index 098e194..6241b64 100644 --- a/model/index.js +++ b/model/index.js @@ -189,8 +189,8 @@ const fieldTypes = { object: Object, }; const target = {}; -let targetArray = ["field", "type", "data", "template"]; -for (let i = 0; i < targetArray.length; i++) { +let targetArray = ["field", "type", "data", "template", "backend"]; +for (let i = 0;i < targetArray.length;i++) { let item = targetArray[i]; const targetObj = require("../" + item); Object.keys(targetObj).forEach((key) => { diff --git a/routes/ruleModel7.js b/routes/ruleModel7.js index 3ccdd2e..ce1ffae 100644 --- a/routes/ruleModel7.js +++ b/routes/ruleModel7.js @@ -2,7 +2,7 @@ var Models = require("../model/index"); let express = require("express"); let xlsx = require('node-xlsx') let router = express.Router(); -["field", "type", "data", "template"].forEach((item) => { +["field", "type", "data", "template", "backend"].forEach((item) => { let templateData = require("../" + item); let getFileds = (key, state, data) => { let jsonArray = templateData[key + ".json"]; @@ -22,7 +22,7 @@ let router = express.Router(); router.post("/list/" + item + "/" + key + "/import", async (req, res) => { let currentId = "1"; let preRow = - (await Models[item + key].find({}).sort({ createdAt: -1 }).limit(1)) || + (await Models[item + key]?.find({}).sort({ createdAt: -1 }).limit(1)) || []; if (!preRow[0] || !preRow[0].id) { currentId = "0000001"; @@ -54,7 +54,7 @@ let router = express.Router(); router.post("/list/" + item + "/" + key + "/export", async (req, res) => { const data = req.body; if (JSON.stringify(data) === "{}") { - data = await Models[item + key].find({}) + data = await Models[item + key]?.find({}) data = res.json(data) } const excelData = [ @@ -70,25 +70,23 @@ let router = express.Router(); // 添加 router.post("/list/" + item + "/" + key, async (req, res) => { let currentId = "1"; - let preRow = - (await Models[item + key].find({}).sort({ createdAt: -1 }).limit(1)) || - []; + let preRow = (await Models[item + key]?.find({})?.sort({ createdAt: -1 })?.limit(1)) || []; if (!preRow[0] || !preRow[0].id) { currentId = "0000001"; } else { currentId = String(Number(preRow[0].id) + 1); currentId = "0".repeat(7 - currentId.length) + currentId; } - let result = await Models[item + key].create({ + let result = await Models[item + key]?.create({ ...getFileds(key, "add", req.body), id: currentId, - }); + }) || []; return res.json(result); }); // 更新 router.put("/list/" + item + "/" + key, async (req, res) => { let { id = 1 } = req.body; - let target = await Models[item + key].find({ id }); + let target = await Models[item + key]?.find({ id }); if (!target.length) { res.send({ status: "error", message: "没有找到" }); return; @@ -102,7 +100,7 @@ let router = express.Router(); // 删除 router.delete("/list/" + item + "/" + key, async (req, res) => { let { id } = req.body; - let target = await Models[item + key].find({ + let target = await Models[item + key]?.find({ $or: id.map((id) => ({ id })), }); if (!target.length) { @@ -146,10 +144,9 @@ let router = express.Router(); newQuery[key] = query[key]; } }); - let total = (await Models[item + key].countDocuments(query)) || 0; + let total = (await Models[item + key]?.countDocuments(query)) || 0; let users = - (await Models[item + key] - .find(newQuery, { _id: 0 }) + (await Models[item + key]?.find(newQuery, { _id: 0 }) .sort(sorter) .skip((current - 1) * pageSize) .limit(pageSize)) || []; @@ -158,8 +155,7 @@ let router = express.Router(); let o = users[i]; if (o.hasChildren) { let childrens = - (await Models[item + key] - .find({ type: o.hasChildren }, { _id: 0 }) + (await Models[item + key]?.find({ type: o.hasChildren }, { _id: 0 }) .sort(sorter) .skip((current - 1) * pageSize) .limit(pageSize)) || []; diff --git a/template/1.json b/template/1.json index 594b057..ebb5717 100644 --- a/template/1.json +++ b/template/1.json @@ -51,7 +51,7 @@ "view": true, "name": "search", "type": "object", - "addDefault": {} + "addDefault": "" }, { "add": true, @@ -60,7 +60,7 @@ "view": true, "name": "table", "type": "object", - "addDefault": {} + "addDefault": "" }, { "add": true, @@ -69,7 +69,7 @@ "view": true, "name": "create", "type": "object", - "addDefault": {} + "addDefault": "" }, { "add": true, @@ -78,7 +78,7 @@ "view": true, "name": "edit", "type": "object", - "addDefault": {} + "addDefault": "" }, { "add": true, @@ -87,7 +87,7 @@ "view": true, "name": "view", "type": "object", - "addDefault": {} + "addDefault": "" }, { "add": true, @@ -106,14 +106,5 @@ "name": "updatedAt", "type": "string", "addDefault": "" - }, - { - "add": true, - "delete": true, - "edit": true, - "view": true, - "name": "backend", - "type": "object", - "addDefault": {} } ]