This commit is contained in:
Taric Xin
2022-03-25 13:35:56 +08:00
parent 99dddaac1e
commit 81c42f2cea
6 changed files with 17 additions and 16 deletions

View File

@ -11,27 +11,25 @@ import { DictSelectService } from './dict-select.service';
{
provide: NG_VALUE_ACCESSOR,
useExisting: forwardRef(() => DictSelectComponent),
multi: true,
},
multi: true
}
],
changeDetection: ChangeDetectionStrategy.OnPush,
changeDetection: ChangeDetectionStrategy.OnPush
})
export class DictSelectComponent implements OnInit, ControlValueAccessor {
private onChangeFn?: (val: string) => void;
private onTouchedFn?: () => void;
defaultUrl = `/api/mdc/pbc/dictItems/getDictValue`;
@Input() value: any = '' || []; // 默认选中值
@Input() url: string = ''; // 获取字典数据的地址
@Input() params = {};// 请求参数
@Input() params = {}; // 请求参数
dictList: any[] = [];
@Input() containsAllLabel = true; // 是否包含全部这一选项
@Input() mode: 'multiple' | 'tags' | 'default' = 'default';
constructor(public service: DictSelectService, public cdr: ChangeDetectorRef) { }
constructor(public service: DictSelectService, public cdr: ChangeDetectorRef) {}
writeValue(geo: string): void {
if (geo == null) {
@ -55,9 +53,10 @@ export class DictSelectComponent implements OnInit, ControlValueAccessor {
this.service.getDictList(this.url || this.defaultUrl, this.params).subscribe(res => {
if (res) {
this.dictList = res || [];
if (this.dictList.length > 0 && this.containsAllLabel) {
if (this.dictList.length > 0 && this.containsAllLabel !== false) {
const obj = { label: '全部', value: '' };
this.dictList.unshift(obj);
console.log(this.dictList);
}
this.cdr.markForCheck();
}
@ -70,5 +69,4 @@ export class DictSelectComponent implements OnInit, ControlValueAccessor {
isEmpty(val: any) {
return val === undefined || val === null || val === '';
}
}