import { Component, inject } from '@angular/core';
import { of, delay } from 'rxjs';
import { YelonFormModule, SFSchema } from '@yelon/form';
import type { SFTreeSelectWidgetSchema } from '@yelon/form/widgets/tree-select';
import { NzMessageService } from 'ng-zorro-antd/message';
@Component({
selector: 'form-tree-select-simple',
template: ` <sf [schema]="schema" (formSubmit)="submit($event)" /> `,
standalone: true,
imports: [YelonFormModule]
})
export class FormTreeSelectSimpleComponent {
private readonly msg = inject(NzMessageService);
schema: SFSchema = {
properties: {
status1: {
type: 'string',
title: '基本',
enum: [
{ title: '待支付', key: 'WAIT_BUYER_PAY' },
{ title: '已支付', key: 'TRADE_SUCCESS' },
{ title: '交易完成', key: 'TRADE_FINISHED' }
],
default: 'WAIT_BUYER_PAY',
ui: {
widget: 'tree-select'
} as SFTreeSelectWidgetSchema
},
status2: {
type: 'string',
title: '多选',
enum: [
{ title: '待支付', key: 'WAIT_BUYER_PAY' },
{ title: '已支付', key: 'TRADE_SUCCESS' },
{ title: '交易完成', key: 'TRADE_FINISHED' }
],
default: ['WAIT_BUYER_PAY', 'TRADE_SUCCESS'],
ui: {
widget: 'tree-select',
multiple: true
} as SFTreeSelectWidgetSchema
},
status3: {
type: 'string',
title: '可勾选',
default: ['WAIT_BUYER_PAY', 'TRADE_FINISHED'],
ui: {
widget: 'tree-select',
checkable: true,
asyncData: () =>
of([
{ title: '待支付', key: 'WAIT_BUYER_PAY' },
{ title: '已支付', key: 'TRADE_SUCCESS' },
{ title: '交易完成', key: 'TRADE_FINISHED' }
]).pipe(delay(10))
} as SFTreeSelectWidgetSchema
},
// 异步数据
async: {
type: 'string',
title: 'Async',
enum: [
{ title: '待支付', key: 'WAIT_BUYER_PAY' },
{ title: '已支付', key: 'TRADE_SUCCESS' },
{ title: '交易完成', key: 'TRADE_FINISHED' }
],
ui: {
widget: 'tree-select',
expandChange: () => {
return of([
{ title: '待支付', key: 'WAIT_BUYER_PAY' },
{ title: '已支付', key: 'TRADE_SUCCESS' },
{ title: '交易完成', key: 'TRADE_FINISHED' }
]).pipe(delay(10));
}
} as SFTreeSelectWidgetSchema
}
}
};
submit(value: {}): void {
this.msg.success(JSON.stringify(value));
}
}