Commit d1a71d13 authored by zhangwenshuai's avatar zhangwenshuai

update apolloTable textarea

parent a0a4fe78
...@@ -79,7 +79,7 @@ export const config: any = { ...@@ -79,7 +79,7 @@ export const config: any = {
3: { 3: {
name: '多行文本', name: '多行文本',
editComp: ApolloTextArea, editComp: ApolloTextArea,
cellComp: CellContainer(ApolloTextArea), cellComp: ApolloTextArea,
getFormatter: GetFormatter.TEXTAREA, getFormatter: GetFormatter.TEXTAREA,
setFormatter: SetFormatter.TEXTAREA, setFormatter: SetFormatter.TEXTAREA,
componentAttr: { componentAttr: {
......
...@@ -19,7 +19,11 @@ ...@@ -19,7 +19,11 @@
text-overflow: ellipsis; text-overflow: ellipsis;
word-break: break-all; word-break: break-all;
} }
.tooltip { .tooltip{
max-height: 300px;
overflow: auto;
}
.tooltipTitle {
//min-width: 500px; //min-width: 500px;
.more { .more {
margin-left: @marginGen; margin-left: @marginGen;
......
...@@ -44,8 +44,9 @@ export const ApolloTextAreaDetail = (props: TextAreaProps) => { ...@@ -44,8 +44,9 @@ export const ApolloTextAreaDetail = (props: TextAreaProps) => {
<div className={styles.container} ref={container}> <div className={styles.container} ref={container}>
{dotVisible ? ( {dotVisible ? (
<Tooltip <Tooltip
overlayClassName={styles.tooltip}
title={ title={
<div className={styles.tooltip}> <div className={styles.tooltipTitle}>
{value} {value}
{value.length === cutLength && <span className={styles.more} onClick={getMore}>查看更多</span>} {value.length === cutLength && <span className={styles.more} onClick={getMore}>查看更多</span>}
</div> </div>
......
import React, { useEffect, useState } from 'react'; import React, { useEffect, useState } from 'react';
import { Input } from 'antd'; import { Input, Modal } from 'antd';
import styles from './styles.less'; import styles from './styles.less';
import { antiAssign } from '../../../../utils/utils'; import { antiAssign } from '../../../../utils/utils';
import { ApolloTextAreaProps } from '../editInterface'; import { ApolloTextAreaProps } from '../editInterface';
import { Consumer } from '../../../context'; import { Consumer } from '../../../context';
export const ApolloTextArea = (props: ApolloTextAreaProps) => { export const ApolloTextArea = (props: ApolloTextAreaProps) => {
const { maxLength, onChange, value, cutLength, getDetail, rowData } = props; const { maxLength, onChange, value, cutLength, getDetail, rowData, onEmitChange, columnConfig, origin } = props;
const selfProps = antiAssign(props, ['columnConfig', 'onChange', 'value']); const { columnChsName } = columnConfig;
const selfProps = antiAssign(props, ['columnConfig', 'onChange', 'value', 'cutLength', 'getDetail', 'rowData', 'onEmitChange']);
const [curValue, setCurValue] = useState(value); const [curValue, setCurValue] = useState(value);
const [visible, setVisible] = useState(false);
useEffect(() => { useEffect(() => {
setCurValue(value); if (origin !== 'editForm') {
}, [value]); setCurValue(value);
useEffect(() => {
if (value && value.length === cutLength) {
getMore(); getMore();
} }
}, []); }, [value]);
// useEffect(() => {
// if (value && value.length === cutLength) {
// getMore();
// }
// }, []);
const changeValue = (e) => { const changeValue = (e) => {
if (typeof onChange === 'function') { if (typeof onChange === 'function') {
...@@ -24,30 +29,84 @@ export const ApolloTextArea = (props: ApolloTextAreaProps) => { ...@@ -24,30 +29,84 @@ export const ApolloTextArea = (props: ApolloTextAreaProps) => {
} }
}; };
const changeCurValue = (e) => {
if (typeof onChange === 'function') {
setCurValue(e.target.value);
}
};
const hide = () => {
if (typeof onEmitChange === 'function') {
onEmitChange(value);
}
setVisible(false);
}
const confirmChange = () => {
if (typeof onEmitChange === 'function') {
onEmitChange(curValue);
}
setVisible(false);
}
const getMore = async () => { const getMore = async () => {
let newValue = await getDetail({ rowId: rowData.id }); if (getDetail && rowData) {
if (newValue) { let newValue = await getDetail({ rowId: rowData.id });
newValue = newValue[0] && newValue[0].value; if (newValue) {
setCurValue(newValue); newValue = newValue[0] && newValue[0].value;
setCurValue(newValue);
setVisible(true);
}
} }
}; };
if (origin === 'editForm') {
return (
<Consumer>
{({ locale }) => {
return (
<div className={styles.container}>
<Input.TextArea
className={styles.inputForm}
{...selfProps}
value={value}
onChange={changeValue}
/>
{!!maxLength && (
<span className={styles.wordNumberForm}>
{`${locale.alreadyInput} ${(value || '').length}/${maxLength}`}
</span>
)}
</div>
);
}}
</Consumer>
)
}
return ( return (
<Consumer> <Consumer>
{({ locale }) => { {({ locale }) => {
return ( return (
<div className={styles.container}> <div className={styles.container}>
<Input.TextArea <Input
className={styles.input}
{...selfProps} {...selfProps}
value={curValue} value={value}
onChange={changeValue} onChange={changeValue}
/> />
{!!maxLength && ( <Modal visible={visible} title={columnChsName} onCancel={hide} onOk={confirmChange}>
<span className={styles.wordNumber}> <Input.TextArea
{`${locale.alreadyInput} ${(curValue || '').length}/${maxLength}`} className={styles.input}
</span> {...selfProps}
)} value={curValue}
onChange={changeCurValue}
/>
{!!maxLength && (
<span className={styles.wordNumber}>
{`${locale.alreadyInput} ${(curValue || '').length}/${maxLength}`}
</span>
)}
</Modal>
</div> </div>
); );
}} }}
......
...@@ -2,11 +2,10 @@ ...@@ -2,11 +2,10 @@
position: relative; position: relative;
top: 0; top: 0;
left: 0; left: 0;
.input { .inputForm{
padding-bottom: 18px; padding-bottom: 18px;
max-height: 500px !important;
} }
.wordNumber { .wordNumberForm {
position: absolute; position: absolute;
right: 20px; right: 20px;
bottom: 2px; bottom: 2px;
...@@ -14,3 +13,14 @@ ...@@ -14,3 +13,14 @@
font-size: 12px; font-size: 12px;
} }
} }
.input {
padding-bottom: 18px;
max-height: 500px !important;
}
.wordNumber {
position: absolute;
right: 35px;
bottom: 80px;
color: #e1e1e1;
font-size: 12px;
}
\ No newline at end of file
...@@ -59,7 +59,7 @@ const EditForm = (props: any) => { ...@@ -59,7 +59,7 @@ const EditForm = (props: any) => {
validateFirst={validateFirst} validateFirst={validateFirst}
validateTrigger={validateTrigger} validateTrigger={validateTrigger}
> >
<EditComp {...transferColumn} columnConfig={item} disabled={readOnlyFlag} /> <EditComp {...transferColumn} columnConfig={item} disabled={readOnlyFlag} origin="editForm" />
</FormItem> </FormItem>
); );
}; };
......
...@@ -116,7 +116,7 @@ class FormWrap extends Component { ...@@ -116,7 +116,7 @@ class FormWrap extends Component {
validateTrigger, validateTrigger,
rules: [{ required: !!item.requiredFlag, message: '必填项不能为空' }, ...rules], rules: [{ required: !!item.requiredFlag, message: '必填项不能为空' }, ...rules],
initialValue: getFormat(detailConfig, item, value), initialValue: getFormat(detailConfig, item, value),
})(<EditComp {...transferColumn} columnConfig={item} disabled={disabled} />)} })(<EditComp {...transferColumn} columnConfig={item} disabled={disabled} origin="editForm" />)}
</FormItem> </FormItem>
); );
}; };
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment