fix: 修改移动端下拉框适配自定义数据选择 (#1102)

Reviewed-on: daoyoucloud/tachybase#1102
Reviewed-by: sealday <zhanglin@daoyoucloud.com>
Co-authored-by: wjh <wwwjh0710@163.com>
Co-committed-by: wjh <wwwjh0710@163.com>
This commit is contained in:
wjh 2024-06-03 10:35:46 +08:00 committed by sealday
parent e48c0a649d
commit f3100030d7
3 changed files with 22 additions and 34 deletions

View File

@ -14,17 +14,7 @@ export const MInput: ComposedInput = connect(
return { placeholder: '请输入内容', clearable: true, ...props, style: { '--font-size': '12px' } }; return { placeholder: '请输入内容', clearable: true, ...props, style: { '--font-size': '12px' } };
}), }),
mapReadPretty((props) => { mapReadPretty((props) => {
return ( return <text style={{ overflow: 'hidden', textOverflow: 'ellipsis' }}>{props.value}</text>;
<Input
{...props}
readOnly
className={css`
.adm-text-area-element {
font-size: 12px;
}
`}
/>
);
}), }),
); );
@ -34,17 +24,7 @@ const MTextArea = connect(
return { ...props, placeholder: '请输入内容', clearable: true, style: { '--font-size': '12px' } }; return { ...props, placeholder: '请输入内容', clearable: true, style: { '--font-size': '12px' } };
}), }),
mapReadPretty((props) => { mapReadPretty((props) => {
return ( return <div style={{ overflow: 'hidden', textOverflow: 'ellipsis' }}>{props.value}</div>;
<TextArea
{...props}
readOnly
className={css`
.adm-text-area-element {
font-size: 12px;
}
`}
/>
);
}), }),
); );

View File

@ -23,7 +23,7 @@ import schema from './schema';
import { useStyles } from './style'; import { useStyles } from './style';
export const AntdSelect = observer((props) => { export const AntdSelect = observer((props) => {
const { value, collectionName, service, fieldNames, addMode, onChange, multiple } = props as any; const { value, collectionName, service, fieldNames, addMode, onChange, multiple, mode } = props as any;
const [popupVisible, setPopupVisible] = useState(false); const [popupVisible, setPopupVisible] = useState(false);
const [searchValue, setSearchValue] = useState(''); const [searchValue, setSearchValue] = useState('');
const { styles } = useStyles(); const { styles } = useStyles();
@ -139,7 +139,7 @@ export const AntdSelect = observer((props) => {
}; };
return ( return (
<BlockItem> <BlockItem>
{collectionName ? ( {!value || typeof value === 'object' ? (
<div <div
onClick={() => { onClick={() => {
setPopupVisible(true); setPopupVisible(true);
@ -147,7 +147,7 @@ export const AntdSelect = observer((props) => {
}} }}
style={{ color: '#c5c5c5' }} style={{ color: '#c5c5c5' }}
> >
{isArray(value) ? ( {isArray(value) && value.length ? (
value.map((item, index) => ( value.map((item, index) => (
<Space key={index}>{`${item.label}${value.length - 1 === index ? '' : ','}`}</Space> <Space key={index}>{`${item.label}${value.length - 1 === index ? '' : ','}`}</Space>
)) ))
@ -176,7 +176,7 @@ export const AntdSelect = observer((props) => {
</Space> </Space>
) : null} ) : null}
<Divider /> <Divider />
{multiple ? ( {multiple || mode === 'multiple' ? (
<CheckList <CheckList
multiple multiple
className={`${styles['checkListStyle']}`} className={`${styles['checkListStyle']}`}
@ -201,7 +201,7 @@ export const AntdSelect = observer((props) => {
<PickerView <PickerView
columns={[options]} columns={[options]}
onChange={(value) => { onChange={(value) => {
const changeValue = options.find((item) => item[fieldNames.value] === value[0]); const changeValue = options.find((item) => item['value'] === value[0]);
setSelectValue(changeValue); setSelectValue(changeValue);
}} }}
/> />

View File

@ -38,15 +38,23 @@ export const MSelect = connect(
const field = useField<any>(); const field = useField<any>();
const collectionField = useCollectionField(); const collectionField = useCollectionField();
const dataSource = field.dataSource || collectionField?.uiSchema.enum || []; const dataSource = field.dataSource || collectionField?.uiSchema.enum || [];
const options =
typeof value === 'object'
? value
.map((item) => {
if (dataSource.find((dataItem) => dataItem.value === item.value)) {
return item;
}
})
.filter(Boolean)
: dataSource.filter((item) => item.value.toString() === value);
return ( return (
<div> <div>
{dataSource {options.map((option, key) => (
.filter((option) => option.value == value) <Tag key={key} color={getMobileColor(option.color)} style={{ margin: '5px' }}>
.map((option, key) => ( {option.label}
<Tag key={key} color={getMobileColor(option.color)}> </Tag>
{option.label} ))}
</Tag>
))}
</div> </div>
); );
} }