lrf %!s(int64=2) %!d(string=hai) anos
pai
achega
9ae1b0b9dd
Modificáronse 2 ficheiros con 33 adicións e 6 borrados
  1. 19 0
      .vscode/launch.json
  2. 14 6
      app/public/ts-template.js

+ 19 - 0
.vscode/launch.json

@@ -0,0 +1,19 @@
+// .vscode/launch.json
+{
+  "version": "0.2.0",
+  "configurations": [
+    {
+      "name": "Launch Egg",
+      "type": "node",
+      "request": "launch",
+      "cwd": "${workspaceRoot}",
+      "runtimeExecutable": "npm",
+      "windows": { "runtimeExecutable": "npm.cmd" },
+      "runtimeArgs": ["run", "debug"],
+      "console": "integratedTerminal",
+      "protocol": "auto",
+      "restart": true,
+      "autoAttachChildProcesses": true
+    }
+  ]
+}

+ 14 - 6
app/public/ts-template.js

@@ -10,7 +10,6 @@ const getModelType = (type, interf = false) => {
   return modelType;
 };
 const ModelContext = (data) => {
-  const result = [];
   const { name: table_name, columns } = data;
   const prefix = _.upperFirst(table_name);
   let fc = [];
@@ -25,7 +24,7 @@ const ModelContext = (data) => {
   // 处理字段
   for (const col of columns) {
     const { type, title, def } = col;
-    const prop = _.pick(col, ['required', 'index', 'zh', 'remark']);
+    const prop = _.pick(col, ['required', 'index', 'zh', 'ref', 'remark']);
     if (def) prop.default = def;
     const modelType = getModelType(type);
     fc.push(`  @prop(${JSON.stringify(prop)})`);
@@ -79,8 +78,8 @@ const ControllerContext = (data) => {
   fc.push(`    return result;`);
   fc.push(`  }`);
   // query
-  fc.push(`@Get('/')@ApiResponse({ type: QueryVO_${name} })`);
-  fc.push(`  async query(@Query('filter') filter: QueryDTO_${name}, @Query('skip') skip: number,@Query('limit') limit: number){`);
+  fc.push(`@Get('/')@ApiQuery({name:'query'})@ApiResponse({ type: QueryVO_${name} })`);
+  fc.push(`  async query(@Query() filter: QueryDTO_${name}, @Query('skip') skip: number,@Query('limit') limit: number){`);
   fc.push(`    const data = await this.service.query(filter, { skip, limit });`);
   fc.push(`    const total = await this.service.count(filter);`);
   fc.push(`    return { data, total };`);
@@ -160,18 +159,23 @@ const interfaceContext = (data) => {
   fc.push(`      this[key] = _.get(data, key);`);
   fc.push(`    }`);
   fc.push(`  }`);
+  fc.push(`  @ApiProperty({ description: '数据id' })`);
+  fc.push(`  _id: string = undefined;`);
   for (const col of columns) {
     const cfc = getInterfaceColumn(col);
     fc.push(...cfc);
   }
   fc.push(`}`);
   fc.push(`\n`);
+  const indexs = columns.filter((f) => f.index);
+  const props = indexs.map((i) => `'${i.title}'`).join(', ');
   fc.push(`export class QueryDTO_${name} extends SearchBase {`);
   fc.push(`  constructor() {`);
   fc.push(`    const like_prop = [];`);
+  fc.push(`    const props = [${props}];`);
   fc.push(`    super({ like_prop });`);
   fc.push(`  }`);
-  for (const col of columns.filter((f) => f.index)) {
+  for (const col of indexs) {
     const cfc = getInterfaceColumn(col);
     fc.push(...cfc);
   }
@@ -188,7 +192,11 @@ const interfaceContext = (data) => {
   fc.push(`\n`);
   fc.push(`export class CreateVO_${name} extends FetchVO_${name} {}`);
   fc.push(`\n`);
-  fc.push(`export class UpdateDTO_${name} extends CreateDTO_${name} {}`);
+  fc.push(`export class UpdateDTO_${name} extends CreateDTO_${name} {
+    @ApiProperty({ description: '数据id' })
+    @Rule(RuleType['string']().empty())
+    _id: string = undefined;
+}`);
   fc.push(`\n`);
   fc.push(`export class UpdateVO_${name} extends FetchVO_${name} {}`);
   return fc.join('\n');