import React, { useContext, useRef, useState } from 'react';
import type { ProFormColumnsType } from '@ant-design/pro-form';
import { BetaSchemaForm } from '@ant-design/pro-form';
import ProProvider from '@ant-design/pro-provider';
import { Input, Space, Tag } from 'antd';
import ProTable from '@ant-design/pro-table';
import ProDescriptions from '@ant-design/pro-descriptions';
import ProCard from '@ant-design/pro-card';
const valueEnum = {
0: 'close',
1: 'running',
2: 'online',
3: 'error',
};
export type TableListItem = {
key: number;
name: string;
status: {
label: string | number;
value: number;
}[];
};
const TagList: React.FC<{
value?: {
key: string;
label: string;
}[];
onChange?: (
value: {
key: string;
label: string;
}[],
) => void;
}> = ({ value, onChange }) => {
const ref = useRef(null);
const [newTags, setNewTags] = useState<
{
key: string;
label: string;
}[]
>([]);
const [inputValue, setInputValue] = useState('');
const handleInputChange = (e: React.ChangeEvent) => {
setInputValue(e.target.value);
};
const handleInputConfirm = () => {
let tempsTags = [...(value || [])];
if (inputValue && tempsTags.filter((tag) => tag.label === inputValue).length === 0) {
tempsTags = [...tempsTags, { key: `new-${tempsTags.length}`, label: inputValue }];
}
onChange?.(tempsTags);
setNewTags([]);
setInputValue('');
};
return (
{(value || []).concat(newTags).map((item) => (
{item.label}
))}
);
};
const columns: ProFormColumnsType[] = [
{
title: '标签',
valueType: 'group',
columns: [
{
title: '只读链接',
readonly: true,
dataIndex: 'name',
valueType: 'link',
},
{
title: '链接',
dataIndex: 'name',
valueType: 'link',
},
],
},
{
title: '路径',
valueType: 'group',
columns: [
{
title: '标签',
dataIndex: 'status',
key: 'status',
valueType: 'tags',
},
{
title: '只读标签',
readonly: true,
dataIndex: 'status',
key: 'status',
valueType: 'tags',
},
],
},
];
const tableColumns = [
{
title: '链接',
dataIndex: 'name',
valueType: 'link',
},
{
title: '标签',
dataIndex: 'status',
key: 'status',
valueType: 'tags',
},
];
const initialValue = {
key: 1,
name: `TradeCode 1`,
status: [
{
value: Math.floor(Math.random() * 10),
label: valueEnum[Math.floor(Math.random() * 10) % 4],
},
{
value: Math.floor(Math.random() * 10),
label: valueEnum[Math.floor(Math.random() * 10) % 4],
},
],
};
export default () => {
const values = useContext(ProProvider);
return (
{text},
renderFormItem: (text, props) => (
),
},
tags: {
render: (text) => {
return (
<>
{[text].flat(1).map((item) => (
{item.label}
))}
>
);
},
renderFormItem: (text, props) => ,
},
},
}}
>
initialValues={initialValue}
columns={columns}
title="自定义 valueType"
/>
);
};