lrf 2 anos atrás
pai
commit
8d9771101e
3 arquivos alterados com 22 adições e 5 exclusões
  1. 3 0
      app/model/table.js
  2. 17 4
      app/public/table-template.js
  3. 2 1
      package.json

+ 3 - 0
app/model/table.js

@@ -6,10 +6,13 @@ const { ObjectId } = require('mongoose').Types;
 const column = new Schema(
   {
     title: { type: String, required: true }, // 字段名,必须是英文
+    zh: { type: String }, //中文
     type: { type: String, default: 'String' }, // 字段类型,默认:String
     required: { type: Boolean, default: false }, // 是否必填,默认:否
     index: { type: Boolean, default: false },
     def: { type: String }, // 默认值
+    ref: { type: String }, //关联表名
+    getProp: { type: String }, //ref获取的属性; 使用分号(;)分隔
     remark: { type: String },
   },
   {

+ 17 - 4
app/public/table-template.js

@@ -8,14 +8,27 @@ module.exports = (data) => {
   let has_ObjectId = false;
   let has_Secret = false;
   const configArr = [];
+  const updateArr = [];
   let configSearchStr = '';
   for (let i = 0; i < columns.length; i++) {
-    const { title, type, required = false, remark, index, def } = columns[i];
+    const { title, type, required = false, remark, index, def, zh, ref, getProp } = columns[i];
+    let refStr;
+    if (ref) {
+      const propList = getProp.split(';');
+      let propStr = '[';
+      for (const p of propList) {
+        if (p !== _.head(propList)) propStr = `${propStr}, `;
+        propStr = `${propStr}'${p}'`;
+      }
+      propStr += ']';
+      refStr = `ref: '${_.capitalize(ref)}', getProp: ${propStr}`;
+    }
     const str = `  ${title}: { type: ${type || 'String'}, required: ${required} ${type === 'Secret' ? ', select: false' : ''} ${def ? `, default: '${def}'` : ''}${
-      remark ? `, zh: '${remark}'` : ''
-    } }, // ${remark || ''} \n`;
+      zh ? `, zh: '${zh}'` : ''
+    }${refStr ? `,${refStr}` : ''} }, // ${remark || ''} \n`;
     columnStr += str;
     configArr.push(`'${required ? '!' : ''}${title}'`);
+    updateArr.push(`'${title}'`);
     if (index) {
       indexStr += `schema.index({ '${title}': 1 });\n`;
       configSearchStr += `'${title}': '${title}' ,\n`;
@@ -53,7 +66,7 @@ module.exports = {
   },
   update: {
     params: ["!id"],
-    requestBody: [${configArr.join(',')}],
+    requestBody: [${updateArr.join(',')}],
   },
   show: {
     parameters: {

+ 2 - 1
package.json

@@ -9,9 +9,10 @@
   "dependencies": {
     "egg": "^2.15.1",
     "egg-scripts": "^2.11.0",
+    "jsonwebtoken": "^8.5.1",
     "lodash": "^4.17.21",
     "moment": "^2.29.1",
-    "naf-framework-mongoose-free": "^0.0.8"
+    "naf-framework-mongoose-free": "^0.0.23"
   },
   "devDependencies": {
     "autod": "^3.0.1",