mirror of
https://gitee.com/nocobase/nocobase.git
synced 2025-07-02 11:12:20 +08:00
refactor: table column field model
This commit is contained in:
parent
dbaafc3e71
commit
6d7594c118
@ -158,7 +158,7 @@ export const DateTimeFormat = {
|
|||||||
ctx.model.setComponentProps({ ...params });
|
ctx.model.setComponentProps({ ...params });
|
||||||
},
|
},
|
||||||
defaultParams: (ctx) => {
|
defaultParams: (ctx) => {
|
||||||
const { showTime, dateFormat, timeFormat, picker } = ctx.model.field.componentProps;
|
const { showTime, dateFormat, timeFormat, picker } = ctx.model.field.componentProps || {};
|
||||||
return {
|
return {
|
||||||
picker: picker || 'date',
|
picker: picker || 'date',
|
||||||
dateFormat: dateFormat || 'YYYY-MM-DD',
|
dateFormat: dateFormat || 'YYYY-MM-DD',
|
||||||
|
@ -107,7 +107,7 @@ const AssociationSelectReadPretty = (props) => {
|
|||||||
return <span style={ellipsis ? null : { whiteSpace: 'normal' }}>{items}</span>;
|
return <span style={ellipsis ? null : { whiteSpace: 'normal' }}>{items}</span>;
|
||||||
};
|
};
|
||||||
|
|
||||||
export class AssociationSelectReadPrettyFieldModel extends TableColumnModel {
|
export class AssociationSelectColumnFieldModel extends TableColumnModel {
|
||||||
public static readonly supportedFieldInterfaces = [
|
public static readonly supportedFieldInterfaces = [
|
||||||
'm2m',
|
'm2m',
|
||||||
'm2o',
|
'm2o',
|
||||||
@ -156,7 +156,7 @@ export class AssociationSelectReadPrettyFieldModel extends TableColumnModel {
|
|||||||
// });
|
// });
|
||||||
|
|
||||||
//标题字段设置 todo 复用
|
//标题字段设置 todo 复用
|
||||||
AssociationSelectReadPrettyFieldModel.registerFlow({
|
AssociationSelectColumnFieldModel.registerFlow({
|
||||||
key: 'fieldNames',
|
key: 'fieldNames',
|
||||||
auto: true,
|
auto: true,
|
||||||
sort: 200,
|
sort: 200,
|
||||||
|
@ -24,7 +24,7 @@ const ReadPretty: FC<CheckboxReadPrettyProps> = (props) => {
|
|||||||
return props.showUnchecked ? <CloseOutlined style={{ color: '#ff4d4f' }} /> : <Checkbox disabled />;
|
return props.showUnchecked ? <CloseOutlined style={{ color: '#ff4d4f' }} /> : <Checkbox disabled />;
|
||||||
};
|
};
|
||||||
|
|
||||||
export class CheckboxFieldMode extends TableColumnModel {
|
export class CheckboxColumnFieldModel extends TableColumnModel {
|
||||||
public static readonly supportedFieldInterfaces = ['checkbox'];
|
public static readonly supportedFieldInterfaces = ['checkbox'];
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
|
@ -29,7 +29,7 @@ const ReadPretty = (props: any) => {
|
|||||||
};
|
};
|
||||||
return <div className={cls(prefixCls, props.className)}>{getLabels()}</div>;
|
return <div className={cls(prefixCls, props.className)}>{getLabels()}</div>;
|
||||||
};
|
};
|
||||||
export class DateTimeReadPrettyFieldModel extends TableColumnModel {
|
export class DateTimeColumnFieldModel extends TableColumnModel {
|
||||||
public static readonly supportedFieldInterfaces = [
|
public static readonly supportedFieldInterfaces = [
|
||||||
'date',
|
'date',
|
||||||
'datetimeNoTz',
|
'datetimeNoTz',
|
||||||
@ -50,7 +50,7 @@ export class DateTimeReadPrettyFieldModel extends TableColumnModel {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
DateTimeReadPrettyFieldModel.registerFlow({
|
DateTimeColumnFieldModel.registerFlow({
|
||||||
key: 'key3',
|
key: 'key3',
|
||||||
auto: true,
|
auto: true,
|
||||||
sort: 1000,
|
sort: 1000,
|
||||||
|
@ -14,7 +14,7 @@ import { useTranslation } from 'react-i18next';
|
|||||||
import { TableColumnModel } from '../../TableColumnModel';
|
import { TableColumnModel } from '../../TableColumnModel';
|
||||||
import { InputNumberReadPretty } from '../components/InputNumberReadPretty';
|
import { InputNumberReadPretty } from '../components/InputNumberReadPretty';
|
||||||
|
|
||||||
export class NumberReadPrettyFieldModel extends TableColumnModel {
|
export class NumberColumnFieldModel extends TableColumnModel {
|
||||||
public static readonly supportedFieldInterfaces = ['number', 'integer'];
|
public static readonly supportedFieldInterfaces = ['number', 'integer'];
|
||||||
render() {
|
render() {
|
||||||
return (value, record, index) => {
|
return (value, record, index) => {
|
||||||
@ -45,7 +45,7 @@ const UnitConversion = () => {
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
NumberReadPrettyFieldModel.registerFlow({
|
NumberColumnFieldModel.registerFlow({
|
||||||
key: 'format',
|
key: 'format',
|
||||||
sort: 100,
|
sort: 100,
|
||||||
title: 'Specific properties',
|
title: 'Specific properties',
|
||||||
@ -136,7 +136,7 @@ NumberReadPrettyFieldModel.registerFlow({
|
|||||||
},
|
},
|
||||||
defaultParams: (ctx) => {
|
defaultParams: (ctx) => {
|
||||||
const { formatStyle, unitConversion, unitConversionType, separator, step, addonBefore, addonAfter } =
|
const { formatStyle, unitConversion, unitConversionType, separator, step, addonBefore, addonAfter } =
|
||||||
ctx.model.getProps().componentProps;
|
ctx.model.getComponentProps();
|
||||||
const { step: prescition } = ctx.model.field?.getComponentProps() || {};
|
const { step: prescition } = ctx.model.field?.getComponentProps() || {};
|
||||||
return {
|
return {
|
||||||
formatStyle: formatStyle || 'normal',
|
formatStyle: formatStyle || 'normal',
|
||||||
|
@ -21,7 +21,7 @@ const toValue = (value: any, callback: (v: number) => number) => {
|
|||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
};
|
};
|
||||||
export class PercentReadPrettyFieldModel extends TableColumnModel {
|
export class PercentColumnFieldModel extends TableColumnModel {
|
||||||
public static readonly supportedFieldInterfaces = ['percent'];
|
public static readonly supportedFieldInterfaces = ['percent'];
|
||||||
render() {
|
render() {
|
||||||
return (value, record, index) => {
|
return (value, record, index) => {
|
||||||
|
@ -1,46 +0,0 @@
|
|||||||
/**
|
|
||||||
* This file is part of the NocoBase (R) project.
|
|
||||||
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
|
|
||||||
* Authors: NocoBase Team.
|
|
||||||
*
|
|
||||||
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
||||||
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
||||||
*/
|
|
||||||
|
|
||||||
import React, { FC } from 'react';
|
|
||||||
import { Tag } from 'antd';
|
|
||||||
import { TableColumnModel } from '../../TableColumnModel';
|
|
||||||
|
|
||||||
const ReadPretty: FC<any> = (props) => {
|
|
||||||
const { value, dataSource } = props;
|
|
||||||
|
|
||||||
if (!value) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
return (
|
|
||||||
<div>
|
|
||||||
{dataSource
|
|
||||||
.filter((option) => option.value == value)
|
|
||||||
.map((option, key) => (
|
|
||||||
<Tag key={key} color={option.color} icon={option.icon}>
|
|
||||||
{option.label}
|
|
||||||
</Tag>
|
|
||||||
))}
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
export class RadioGroupReadPrettyFieldModel extends TableColumnModel {
|
|
||||||
public static readonly supportedFieldInterfaces = ['radioGroup'];
|
|
||||||
|
|
||||||
render() {
|
|
||||||
return (value, record, index) => {
|
|
||||||
return (
|
|
||||||
<>
|
|
||||||
{<ReadPretty value={value} {...this.getComponentProps()} />}
|
|
||||||
{this.renderQuickEditButton(record)}
|
|
||||||
</>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
@ -18,8 +18,8 @@ const fieldNames = {
|
|||||||
color: 'color',
|
color: 'color',
|
||||||
icon: 'icon',
|
icon: 'icon',
|
||||||
};
|
};
|
||||||
export class SelectReadPrettyFieldModel extends TableColumnModel {
|
export class SelectColumnFieldModel extends TableColumnModel {
|
||||||
public static readonly supportedFieldInterfaces = ['select', 'multipleSelect'];
|
public static readonly supportedFieldInterfaces = ['select', 'multipleSelect', 'radioGroup', 'checkboxGroup'];
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
return (value, record, index) => {
|
return (value, record, index) => {
|
||||||
|
@ -12,5 +12,5 @@ export * from './NumberFieldModel';
|
|||||||
export * from './PercentFieldModel';
|
export * from './PercentFieldModel';
|
||||||
export * from './AssociationSelectFieldModel';
|
export * from './AssociationSelectFieldModel';
|
||||||
export * from './CheckboxFieldMode';
|
export * from './CheckboxFieldMode';
|
||||||
export * from './RadioGroupFieldModel';
|
// export * from './RadioGroupFieldModel';
|
||||||
export * from './DateTimeFieldModel';
|
export * from './DateTimeFieldModel';
|
||||||
|
Loading…
x
Reference in New Issue
Block a user