lrf 2 yıl önce
ebeveyn
işleme
54f7e6ac1d
1 değiştirilmiş dosya ile 28 ekleme ve 4 silme
  1. 28 4
      app/public/ts-template.js

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

@@ -150,10 +150,19 @@ const interfaceContext = (data) => {
   const have_required = columns.find((f) => f.required);
   fc.push(`import { Rule, RuleType } from '@midwayjs/validate';`);
   fc.push(`import { ApiProperty } from '@midwayjs/swagger';`);
-  fc.push(`import _ = require('lodash');`);
   if (have_required) fc.push(`import { FrameworkErrorEnum, SearchBase, ServiceError } from 'free-midway-component';`);
   else fc.push(`import { SearchBase } from 'free-midway-component';`);
+  fc.push(`import get = require('lodash/get');`);
+  fc.push(`const dealVO = (cla, data) => {`);
+  fc.push(`  for (const key in cla) {`);
+  fc.push(`    const val = get(data, key);`);
+  fc.push(`    if (val || val === 0) cla[key] = val;`);
+  fc.push(`  }`);
+  fc.push(`};`);
   fc.push(`export class FVO_${name} {`);
+  fc.push(`  constructor(data: object) {`);
+  fc.push(`    dealVO(this, data);`);
+  fc.push(`  }`);
   fc.push(`  @ApiProperty({ description: '数据id' })`);
   fc.push(`  _id: string = undefined;`);
   for (const col of columns) {
@@ -177,7 +186,12 @@ const interfaceContext = (data) => {
   }
   fc.push(`}`);
   fc.push(`\n`);
-  fc.push(`export class QVO_${name} extends FVO_${name} {}`);
+  fc.push(`export class QVO_${name} extends FVO_${name} {`);
+  fc.push(`  constructor(data: object) {`);
+  fc.push(`    super(data);`);
+  fc.push(`    dealVO(this, data);`);
+  fc.push(`  }`);
+  fc.push(`}`);
   fc.push(`\n`);
   fc.push(`export class CDTO_${name} {`);
   for (const col of columns) {
@@ -186,7 +200,12 @@ const interfaceContext = (data) => {
   }
   fc.push(`}`);
   fc.push(`\n`);
-  fc.push(`export class CVO_${name} extends FVO_${name} {}`);
+  fc.push(`export class CVO_${name} extends FVO_${name} {`);
+  fc.push(`  constructor(data: object) {`);
+  fc.push(`    super(data);`);
+  fc.push(`    dealVO(this, data);`);
+  fc.push(`  }`);
+  fc.push(`}`);
   fc.push(`\n`);
   fc.push(`export class UDTO_${name} extends CDTO_${name} {
     @ApiProperty({ description: '数据id' })
@@ -194,7 +213,12 @@ const interfaceContext = (data) => {
     _id: string = undefined;
 }`);
   fc.push(`\n`);
-  fc.push(`export class UVAO_${name} extends FVO_${name} {}`);
+  fc.push(`export class UVAO_${name} extends FVO_${name} {`);
+  fc.push(`  constructor(data: object) {`);
+  fc.push(`    super(data);`);
+  fc.push(`    dealVO(this, data);`);
+  fc.push(`  }`);
+  fc.push(`}`);
   return fc.join('\n');
 };