浏览代码

添加ts模板的 es类型

lrf 1 年之前
父节点
当前提交
3911d06725
共有 2 个文件被更改,包括 6 次插入4 次删除
  1. 1 0
      app/model/table.js
  2. 5 4
      app/public/ts-template.js

+ 1 - 0
app/model/table.js

@@ -8,6 +8,7 @@ const column = new Schema(
     title: { type: String, required: true }, // 字段名,必须是英文
     title: { type: String, required: true }, // 字段名,必须是英文
     zh: { type: String }, //中文
     zh: { type: String }, //中文
     type: { type: String, default: 'String' }, // 字段类型,默认:String
     type: { type: String, default: 'String' }, // 字段类型,默认:String
+    esType: { type: String }, //es数据类型
     required: { type: Boolean, default: false }, // 是否必填,默认:否
     required: { type: Boolean, default: false }, // 是否必填,默认:否
     index: { type: Boolean, default: false },
     index: { type: Boolean, default: false },
     def: { type: String }, // 默认值
     def: { type: String }, // 默认值

+ 5 - 4
app/public/ts-template.js

@@ -27,23 +27,24 @@ const ModelContext = (data) => {
   // 处理字段
   // 处理字段
   for (const col of columns) {
   for (const col of columns) {
     const { type, title, def } = col;
     const { type, title, def } = col;
-    const prop = _.pick(col, ['required', 'index', 'zh', 'ref', 'remark']);
+    const prop = _.pick(col, ['required', 'index', 'zh', 'ref', 'remark', 'esType']);
     if (def) prop.default = def;
     if (def) prop.default = def;
     const modelType = getModelType(type);
     const modelType = getModelType(type);
     switch (modelType) {
     switch (modelType) {
       case 'secret':
       case 'secret':
         prop.select = false;
         prop.select = false;
+        // 手动删除引号.变成方法.这里处理不了
+        prop.set = `(val) => { if (isString(val)) { return { secret: val }; } return val; }`;
         fc.push(`  // 手动删除set前的大括号,处理太麻烦了.就手动删除吧`);
         fc.push(`  // 手动删除set前的大括号,处理太麻烦了.就手动删除吧`);
-        fc.push(`  @prop(${JSON.stringify(prop)}, set: (val) => { if (isString(val)) { return { secret: val }; } return val; } })`);
+        fc.push(`  @prop(${JSON.stringify(prop)})`);
         fc.push(`  ${title}: object`);
         fc.push(`  ${title}: object`);
         break;
         break;
-    
+
       default:
       default:
         fc.push(`  @prop(${JSON.stringify(prop)})`);
         fc.push(`  @prop(${JSON.stringify(prop)})`);
         fc.push(`  ${title}: ${modelType}`);
         fc.push(`  ${title}: ${modelType}`);
         break;
         break;
     }
     }
-    
   }
   }
 
 
   fc.push(`}`);
   fc.push(`}`);