json样式优化,mapping优化

This commit is contained in:
rickcole 2020-06-18 13:04:55 +08:00
parent 331d08e4d5
commit d52a7b03b1
2 changed files with 33 additions and 15 deletions

View File

@ -45,7 +45,8 @@ const twilight = {
WebkitUserSelect: 'none', WebkitUserSelect: 'none',
backgroundColor: 'rgba(255, 255, 255, 0.4)', backgroundColor: 'rgba(255, 255, 255, 0.4)',
whiteSpace: 'nowrap', whiteSpace: 'nowrap',
display: 'inline-block' display: 'inline-block',
width: '100%'
} }
}; };
@ -80,7 +81,8 @@ const eighties = {
WebkitUserSelect: 'none', WebkitUserSelect: 'none',
backgroundColor: '#2D2D2D', backgroundColor: '#2D2D2D',
whiteSpace: 'nowrap', whiteSpace: 'nowrap',
display: 'inline-block' display: 'inline-block',
width: '100%'
} }
}; };
@ -99,12 +101,31 @@ export class JSONField extends React.Component<JSONProps, object> {
valueRenderer(raw: any) { valueRenderer(raw: any) {
if (typeof raw === 'string' && /^\"?https?:\/\//.test(raw)) { if (typeof raw === 'string' && /^\"?https?:\/\//.test(raw)) {
return ( return (
<a href={raw.replace(/^\"(.*)\"$/, '$1')} target="_blank"> <a
className="word-break"
style={{
whiteSpace: 'normal',
wordBreak: 'break-all',
wordWrap: 'break-word'
}}
href={raw.replace(/^\"(.*)\"$/, '$1')}
target="_blank"
>
{raw} {raw}
</a> </a>
); );
} }
return raw; return (
<span
style={{
whiteSpace: 'normal',
wordBreak: 'break-all',
wordWrap: 'break-word'
}}
>
{raw}
</span>
);
} }
shouldExpandNode = (keyName: any, data: any, level: any) => { shouldExpandNode = (keyName: any, data: any, level: any) => {

View File

@ -20,23 +20,20 @@ export class MappingField extends React.Component<MappingProps, object> {
}; };
render() { render() {
const { const {className, placeholder, map, render, classnames: cx} = this.props;
className, let key = this.props.value;
value,
placeholder,
map,
render,
classnames: cx
} = this.props;
let viewValue: React.ReactNode = ( let viewValue: React.ReactNode = (
<span className="text-muted">{placeholder}</span> <span className="text-muted">{placeholder}</span>
); );
let key = value === true ? '1' : value;
key = typeof key === 'string' ? key.trim() : key; // trim 一下,干掉一些空白字符。 key = typeof key === 'string' ? key.trim() : key; // trim 一下,干掉一些空白字符。
if (typeof value !== 'undefined' && map && (map[key] || map['*'])) { if (typeof key !== 'undefined' && map && (map[key] ?? map['*'])) {
viewValue = render('tpl', map[key] || map['*']); viewValue = render(
'tpl',
map[key] ?? (key === true && map['1'] ? map['1'] : map['*']) // 兼容旧用法,即 value 为 true 时映射 1
);
} }
return <span className={cx('MappingField', className)}>{viewValue}</span>; return <span className={cx('MappingField', className)}>{viewValue}</span>;