mirror of
https://gitee.com/nocobase/nocobase.git
synced 2024-12-04 13:18:55 +08:00
feat: add relation field component for table and detail
This commit is contained in:
parent
d755558009
commit
272b64b81b
@ -3,6 +3,7 @@ import React, { useEffect, useState } from 'react';
|
|||||||
import moment from 'moment';
|
import moment from 'moment';
|
||||||
import { Tag } from 'antd';
|
import { Tag } from 'antd';
|
||||||
import Icon from '@/components/icons';
|
import Icon from '@/components/icons';
|
||||||
|
import get from 'lodash/get';
|
||||||
|
|
||||||
const InterfaceTypes = new Map<string, any>();
|
const InterfaceTypes = new Map<string, any>();
|
||||||
|
|
||||||
@ -111,6 +112,18 @@ export function DataSourceField(props: any) {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function RealtionField(props: any) {
|
||||||
|
const { schema: { labelField }, value } = props;
|
||||||
|
if (!value) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
console.log(labelField, value);
|
||||||
|
const items = Array.isArray(value) ? value : [value];
|
||||||
|
return items.map(item => (
|
||||||
|
<span>{get(item, labelField)}</span>
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
registerFieldComponents({
|
registerFieldComponents({
|
||||||
string: StringField,
|
string: StringField,
|
||||||
textarea: TextareaField,
|
textarea: TextareaField,
|
||||||
@ -125,6 +138,8 @@ registerFieldComponents({
|
|||||||
createdAt: DateTimeField,
|
createdAt: DateTimeField,
|
||||||
updatedAt: DateTimeField,
|
updatedAt: DateTimeField,
|
||||||
icon: IconField,
|
icon: IconField,
|
||||||
|
createdBy: RealtionField,
|
||||||
|
updatedBy: RealtionField,
|
||||||
});
|
});
|
||||||
|
|
||||||
export default function Field(props: any) {
|
export default function Field(props: any) {
|
||||||
|
Loading…
Reference in New Issue
Block a user