CollectionFieldInterfaceManager
主要是用来管理 CollectionFieldInterface 和 CollectionFieldInterfaceGroups,其被 DataSourceManager 管理。
1. CollectionFieldInterfaceGroups
CollectionFieldInterfaceGroups 是用来对数据表字段进行分组的。
2. 实例方法
field interface
addFieldInterfaces()
添加 field interface。
class CollectionFieldInterfaceManager {
addFieldInterfaces(fieldInterfaces: CollectionFieldInterface[]): void
}
class CheckboxFieldInterface extends CollectionFieldInterface {
name = 'checkbox';
type = 'object';
group = 'choices';
title = '{{t("Checkbox")}}';
// ...
}
class MyPlugin extends Plugin {
async load() {
this.app.dataSourceManager.collectionFieldInterfaceManager.addFieldInterfaces([CheckboxFieldInterface]);
// or
this.app.dataSourceManager.addFieldInterfaces([CheckboxFieldInterface]);
}
}
getFieldInterface(name)
获取 field interface。
class CollectionFieldInterfaceManager {
getFieldInterface<T extends CollectionFieldInterface>(name: string): T;
}
class MyPlugin extends Plugin {
async load() {
const fieldInterface = this.app.dataSourceManager.collectionFieldInterfaceManager.getFieldInterface('checkbox'); // checkboxFieldInterface
}
}
getFieldInterfaces()
获取所有的 field interface。
class CollectionFieldInterfaceManager {
getFieldInterfaces(): CollectionFieldInterface[];
}
class MyPlugin extends Plugin {
async load() {
const fieldInterfaces = this.app.dataSourceManager.collectionFieldInterfaceManager.getFieldInterfaces();
}
}
添加 Field interface 组件选项。
interface CollectionFieldInterfaceComponentOption {
label: string;
value: string;
useVisible?: () => boolean;
useProps?: () => any;
}
class CollectionFieldInterfaceManager {
addFieldInterfaceComponentOption(interfaceName: string, componentOption: CollectionFieldInterfaceComponentOption): void
}
class MyPlugin extends Plugin {
async load() {
this.app.dataSourceManager.collectionFieldInterfaceManager.addFieldInterfaceComponentOption('url', {
label: 'Preview',
value: 'Input.Preview',
});
}
}
field interface group
addFieldInterfaceGroups(fieldGroups)
添加 field interface group。
class CollectionFieldInterfaceManager {
addFieldInterfaceGroups(fieldGroups: Record<string, { label: string; order?: number }>): void;
}
class MyPlugin extends Plugin {
async load() {
this.app.dataSourceManager.collectionFieldInterfaceManager.addFieldInterfaceGroups({
'test': {
label: 'Test',
order: 1,
}
});
// or
this.app.dataSourceManager.addFieldInterfaceGroups({
'test': {
label: 'Test',
order: 1,
}
});
}
}
getFieldInterfaceGroups()
获取所有的 field interface group。
class CollectionFieldInterfaceManager {
getFieldInterfaceGroups(): Record<string, { label: string; order?: number }>;
}
class MyPlugin extends Plugin {
async load() {
const fieldInterfaceGroups = this.app.dataSourceManager.collectionFieldInterfaceManager.getFieldInterfaceGroups(); // { 'test': { label: 'Test', order: 1 } }
}
}
getFieldInterfaceGroup(name)
获取 field interface group。
class CollectionFieldInterfaceManager {
getFieldInterfaceGroup(name: string): { label: string; order?: number };
}
class MyPlugin extends Plugin {
async load() {
const fieldInterfaceGroup = this.app.dataSourceManager.collectionFieldInterfaceManager.getFieldInterfaceGroup('test'); // { label: 'Test', order: 1 }
}
}