mirror of
https://gitee.com/nocobase/nocobase.git
synced 2024-12-03 04:38:15 +08:00
fix: improve field options
This commit is contained in:
parent
184adb924d
commit
afce1142d9
@ -115,13 +115,16 @@ export function DataSourceField(props: any) {
|
||||
export function RealtionField(props: any) {
|
||||
const { schema: { labelField }, value } = props;
|
||||
if (!value) {
|
||||
return;
|
||||
return null;
|
||||
}
|
||||
console.log(labelField, value);
|
||||
const items = Array.isArray(value) ? value : [value];
|
||||
return items.map(item => (
|
||||
<span>{get(item, labelField)}</span>
|
||||
));
|
||||
return (
|
||||
<>
|
||||
{items.map(item => (
|
||||
<span>{get(item, labelField)}</span>
|
||||
))}
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
registerFieldComponents({
|
||||
|
@ -15,7 +15,6 @@ export default {
|
||||
name: 'sort',
|
||||
scope: ['collection'],
|
||||
title: '排序',
|
||||
defaultValue: 1,
|
||||
component: {
|
||||
type: 'sort',
|
||||
className: 'drag-visible',
|
||||
@ -57,6 +56,7 @@ export default {
|
||||
type: 'string',
|
||||
name: 'interface',
|
||||
title: '字段类型',
|
||||
required: true,
|
||||
dataSource: options,
|
||||
createOnly: true,
|
||||
component: {
|
||||
@ -90,6 +90,16 @@ export default {
|
||||
"target": "timeFormat",
|
||||
"condition": "{{ ['time'].indexOf($self.value) !== -1 }}"
|
||||
},
|
||||
{
|
||||
"type": "value:visible",
|
||||
"target": "component.showInForm",
|
||||
"condition": "{{ ['createdAt', 'updatedAt', 'createdBy', 'updatedBy'].indexOf($self.value) === -1 }}"
|
||||
},
|
||||
{
|
||||
"type": "value:visible",
|
||||
"target": "required",
|
||||
"condition": "{{ ['createdAt', 'updatedAt', 'createdBy', 'updatedBy'].indexOf($self.value) === -1 }}"
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
|
@ -6,6 +6,7 @@ export * as types from './types';
|
||||
|
||||
export const options = [
|
||||
{
|
||||
key: 'basic',
|
||||
title: '基本类型',
|
||||
children: [
|
||||
types.string,
|
||||
@ -17,6 +18,7 @@ export const options = [
|
||||
],
|
||||
},
|
||||
{
|
||||
key: 'media',
|
||||
title: '多媒体类型',
|
||||
children: [
|
||||
types.wysiwyg,
|
||||
@ -24,6 +26,7 @@ export const options = [
|
||||
],
|
||||
},
|
||||
{
|
||||
key: 'choices',
|
||||
title: '选择类型',
|
||||
children: [
|
||||
types.boolean,
|
||||
@ -34,6 +37,7 @@ export const options = [
|
||||
],
|
||||
},
|
||||
{
|
||||
key: 'datetime',
|
||||
title: '日期和时间',
|
||||
children: [
|
||||
types.datetime,
|
||||
@ -41,6 +45,7 @@ export const options = [
|
||||
],
|
||||
},
|
||||
{
|
||||
key: 'relation',
|
||||
title: '关系类型',
|
||||
children: [
|
||||
types.subTable,
|
||||
@ -48,15 +53,17 @@ export const options = [
|
||||
],
|
||||
},
|
||||
{
|
||||
key: 'systemInfo',
|
||||
title: '系统信息',
|
||||
children: [
|
||||
types.createdAt,
|
||||
types.createdBy,
|
||||
types.updatedAt,
|
||||
types.createdBy,
|
||||
types.updatedBy,
|
||||
],
|
||||
},
|
||||
{
|
||||
key: 'developerMode',
|
||||
title: '开发者模式',
|
||||
children: [
|
||||
types.primaryKey,
|
||||
@ -66,7 +73,8 @@ export const options = [
|
||||
types.icon,
|
||||
],
|
||||
}
|
||||
].map(({title, children}: any) => ({
|
||||
].map(({key, title, children}: any) => ({
|
||||
key,
|
||||
label: title,
|
||||
children: children.map(child => ({
|
||||
label: child.title,
|
||||
|
@ -338,30 +338,13 @@ export const linkTo = {
|
||||
},
|
||||
};
|
||||
|
||||
export const createdBy = {
|
||||
title: '创建者',
|
||||
// disabled: true,
|
||||
options: {
|
||||
interface: 'createdBy',
|
||||
type: 'createdBy',
|
||||
name: 'createdBy',
|
||||
filterable: true,
|
||||
target: 'users',
|
||||
labelField: 'nickname',
|
||||
foreignKey: 'created_by_id',
|
||||
appends: true,
|
||||
component: {
|
||||
type: 'drawerSelect',
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
export const createdAt = {
|
||||
title: '创建时间',
|
||||
options: {
|
||||
interface: 'createdAt',
|
||||
type: 'date',
|
||||
name: 'created_at',
|
||||
// name: 'created_at',
|
||||
field: 'created_at',
|
||||
showTime: true,
|
||||
dateFormat: 'YYYY/MM/DD',
|
||||
timeFormat: 'HH:mm:ss',
|
||||
@ -374,12 +357,49 @@ export const createdAt = {
|
||||
},
|
||||
};
|
||||
|
||||
export const updatedAt = {
|
||||
title: '修改时间',
|
||||
options: {
|
||||
interface: 'updatedAt',
|
||||
type: 'date',
|
||||
// name: 'updated_at',
|
||||
field: 'updated_at',
|
||||
showTime: true,
|
||||
dateFormat: 'YYYY/MM/DD',
|
||||
timeFormat: 'HH:mm:ss',
|
||||
required: true,
|
||||
filterable: true,
|
||||
sortable: true,
|
||||
component: {
|
||||
type: 'date',
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
export const createdBy = {
|
||||
title: '创建人',
|
||||
// disabled: true,
|
||||
options: {
|
||||
interface: 'createdBy',
|
||||
type: 'createdBy',
|
||||
// name: 'createdBy',
|
||||
filterable: true,
|
||||
target: 'users',
|
||||
labelField: 'nickname',
|
||||
foreignKey: 'created_by_id',
|
||||
appends: true,
|
||||
component: {
|
||||
type: 'drawerSelect',
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
export const updatedBy = {
|
||||
title: '更新人',
|
||||
title: '修改人',
|
||||
// disabled: true,
|
||||
options: {
|
||||
interface: 'updatedBy',
|
||||
name: 'updatedBy',
|
||||
// name: 'updatedBy',
|
||||
type: 'updatedBy',
|
||||
filterable: true,
|
||||
target: 'users',
|
||||
@ -392,24 +412,6 @@ export const updatedBy = {
|
||||
},
|
||||
};
|
||||
|
||||
export const updatedAt = {
|
||||
title: '更新时间',
|
||||
options: {
|
||||
interface: 'updatedAt',
|
||||
type: 'date',
|
||||
name: 'updated_at',
|
||||
showTime: true,
|
||||
dateFormat: 'YYYY/MM/DD',
|
||||
timeFormat: 'HH:mm:ss',
|
||||
required: true,
|
||||
filterable: true,
|
||||
sortable: true,
|
||||
component: {
|
||||
type: 'date',
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
/**
|
||||
* 字段分组(暂缓)
|
||||
*
|
||||
|
@ -32,6 +32,10 @@ const transforms = {
|
||||
title: field.title||field.name,
|
||||
...(field.component||{}),
|
||||
}
|
||||
if (field.get('name') === 'interface' && ctx.state.developerMode === false) {
|
||||
const dataSource = field.get('dataSource').filter(item => item.key !== 'developerMode');
|
||||
field.set('dataSource', dataSource);
|
||||
}
|
||||
if (field.get('name') === 'filter' && field.get('collection_name') === 'views') {
|
||||
const { values } = ctx.action.params;
|
||||
const all = await Field.findAll({
|
||||
@ -76,7 +80,7 @@ const transforms = {
|
||||
set(prop, 'x-component-props.mode', 'multiple');
|
||||
}
|
||||
if (['radio', 'select', 'multipleSelect', 'checkboxes'].includes(interfaceType)) {
|
||||
prop.enum = get(field.options, 'dataSource', []);
|
||||
prop.enum = field.get('dataSource');
|
||||
}
|
||||
schema[field.name] = {
|
||||
...prop,
|
||||
|
Loading…
Reference in New Issue
Block a user