|
@@ -17,6 +17,9 @@ const ModelContext = (data) => {
|
|
fc.push(`import { BaseModel } from 'free-midway-component';`);
|
|
fc.push(`import { BaseModel } from 'free-midway-component';`);
|
|
const has_money = columns.find((f) => f.type === 'Money' || f.type === 'money');
|
|
const has_money = columns.find((f) => f.type === 'Money' || f.type === 'money');
|
|
if (has_money) fc.push(`import { Decimal128 } from 'mongoose';`);
|
|
if (has_money) fc.push(`import { Decimal128 } from 'mongoose';`);
|
|
|
|
+ // 添加secret需要isString函数
|
|
|
|
+ const has_secret = columns.find((f) => f.type === 'Secret' || f.type === 'secret');
|
|
|
|
+ if (has_secret) fc.push(`import { isString } from 'lodash';`);
|
|
fc.push(`@modelOptions({`);
|
|
fc.push(`@modelOptions({`);
|
|
fc.push(` schemaOptions: { collection: '${table_name}' },`);
|
|
fc.push(` schemaOptions: { collection: '${table_name}' },`);
|
|
fc.push(`})`);
|
|
fc.push(`})`);
|
|
@@ -27,8 +30,20 @@ const ModelContext = (data) => {
|
|
const prop = _.pick(col, ['required', 'index', 'zh', 'ref', 'remark']);
|
|
const prop = _.pick(col, ['required', 'index', 'zh', 'ref', 'remark']);
|
|
if (def) prop.default = def;
|
|
if (def) prop.default = def;
|
|
const modelType = getModelType(type);
|
|
const modelType = getModelType(type);
|
|
- fc.push(` @prop(${JSON.stringify(prop)})`);
|
|
|
|
- fc.push(` ${title}: ${modelType}`);
|
|
|
|
|
|
+ switch (modelType) {
|
|
|
|
+ case 'secret':
|
|
|
|
+ prop.select = false;
|
|
|
|
+ fc.push(` // 手动删除set前的大括号,处理太麻烦了.就手动删除吧`);
|
|
|
|
+ fc.push(` @prop(${JSON.stringify(prop)}, set: (val) => { if (isString(val)) { return { secret: val }; } return val; } })`);
|
|
|
|
+ fc.push(` ${title}: string`);
|
|
|
|
+ break;
|
|
|
|
+
|
|
|
|
+ default:
|
|
|
|
+ fc.push(` @prop(${JSON.stringify(prop)})`);
|
|
|
|
+ fc.push(` ${title}: ${modelType}`);
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+
|
|
}
|
|
}
|
|
|
|
|
|
fc.push(`}`);
|
|
fc.push(`}`);
|