字典支持多级

This commit is contained in:
小鹏 2022-07-15 18:31:43 +08:00
parent 9710751c19
commit f96d980254
2 changed files with 32 additions and 0 deletions

View File

@ -10,6 +10,7 @@ import { DictInfoService } from '../../service/info';
@CoolController({ @CoolController({
api: ['add', 'delete', 'update', 'info', 'list', 'page'], api: ['add', 'delete', 'update', 'info', 'list', 'page'],
entity: DictInfoEntity, entity: DictInfoEntity,
service: DictInfoService,
listQueryOp: { listQueryOp: {
fieldEq: ['typeId'], fieldEq: ['typeId'],
keyWordLikeFields: ['name'], keyWordLikeFields: ['name'],

View File

@ -69,4 +69,35 @@ export class DictInfoService extends BaseService {
return e.name; return e.name;
}); });
} }
/**
*
* @param data
* @param type
*/
async modifyAfter(data: any, type: 'delete' | 'update' | 'add') {
if (type === 'delete') {
for (const id of data) {
await this.delChildDict(id);
}
}
}
/**
*
* @param id
*/
private async delChildDict(id) {
const delDict = await this.dictInfoEntity.find({ parentId: id });
if (_.isEmpty(delDict)) {
return;
}
const delDictIds = delDict.map(e => {
return e.id;
});
await this.dictInfoEntity.delete(delDictIds);
for (const dictId of delDictIds) {
await this.delChildDict(dictId);
}
}
} }