|
|
@ -3,6 +3,8 @@ import _isString from 'lodash/isString';
|
|
|
|
import _isNil from 'lodash/isNil';
|
|
|
|
import _isNil from 'lodash/isNil';
|
|
|
|
import { Button, Input, Space } from 'antd';
|
|
|
|
import { Button, Input, Space } from 'antd';
|
|
|
|
import { Icon } from '@iconify/react';
|
|
|
|
import { Icon } from '@iconify/react';
|
|
|
|
|
|
|
|
import { t } from 'tailchat-shared';
|
|
|
|
|
|
|
|
import { DelayTip } from './DelayTip';
|
|
|
|
|
|
|
|
|
|
|
|
export type FullModalFieldEditorRenderComponent = React.FC<{
|
|
|
|
export type FullModalFieldEditorRenderComponent = React.FC<{
|
|
|
|
value: string;
|
|
|
|
value: string;
|
|
|
@ -43,6 +45,13 @@ interface FullModalFieldProps {
|
|
|
|
onSave?: (val: string) => void;
|
|
|
|
onSave?: (val: string) => void;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 计算要显示的title
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
function useTitle(value?: string) {
|
|
|
|
|
|
|
|
return _isString(value) ? value : undefined;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* 字段编辑器
|
|
|
|
* 字段编辑器
|
|
|
|
*/
|
|
|
|
*/
|
|
|
@ -50,6 +59,7 @@ const FullModalFieldEditor: React.FC<FullModalFieldProps> = React.memo(
|
|
|
|
(props) => {
|
|
|
|
(props) => {
|
|
|
|
const [isEditing, setIsEditing] = useState(false);
|
|
|
|
const [isEditing, setIsEditing] = useState(false);
|
|
|
|
const [editingValue, setEditingValue] = useState(props.value ?? '');
|
|
|
|
const [editingValue, setEditingValue] = useState(props.value ?? '');
|
|
|
|
|
|
|
|
const valueTitle = useTitle(props.value);
|
|
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
useEffect(() => {
|
|
|
|
setEditingValue(props.value ?? '');
|
|
|
|
setEditingValue(props.value ?? '');
|
|
|
@ -71,26 +81,32 @@ const FullModalFieldEditor: React.FC<FullModalFieldProps> = React.memo(
|
|
|
|
{isEditing && !_isNil(EditorComponent) ? (
|
|
|
|
{isEditing && !_isNil(EditorComponent) ? (
|
|
|
|
<EditorComponent value={editingValue} onChange={setEditingValue} />
|
|
|
|
<EditorComponent value={editingValue} onChange={setEditingValue} />
|
|
|
|
) : (
|
|
|
|
) : (
|
|
|
|
<span>{props.content ?? props.value}</span>
|
|
|
|
<span title={valueTitle}>{props.content ?? props.value}</span>
|
|
|
|
)}
|
|
|
|
)}
|
|
|
|
|
|
|
|
|
|
|
|
<Button
|
|
|
|
{!isEditing ? (
|
|
|
|
icon={
|
|
|
|
<DelayTip title={t('编辑')}>
|
|
|
|
isEditing ? (
|
|
|
|
<Button
|
|
|
|
<Icon className="anticon" icon="mdi:close" />
|
|
|
|
icon={<Icon className="anticon" icon="mdi:square-edit-outline" />}
|
|
|
|
) : (
|
|
|
|
onClick={handleEditing}
|
|
|
|
<Icon className="anticon" icon="mdi:square-edit-outline" />
|
|
|
|
/>
|
|
|
|
)
|
|
|
|
</DelayTip>
|
|
|
|
}
|
|
|
|
) : (
|
|
|
|
onClick={handleEditing}
|
|
|
|
<>
|
|
|
|
/>
|
|
|
|
<DelayTip title={t('取消')}>
|
|
|
|
|
|
|
|
<Button
|
|
|
|
{isEditing && (
|
|
|
|
icon={<Icon className="anticon" icon="mdi:close" />}
|
|
|
|
<Button
|
|
|
|
onClick={handleEditing}
|
|
|
|
type="primary"
|
|
|
|
/>
|
|
|
|
icon={<Icon className="anticon" icon="mdi:check" />}
|
|
|
|
</DelayTip>
|
|
|
|
onClick={handleSave}
|
|
|
|
<DelayTip title={t('保存变更')}>
|
|
|
|
/>
|
|
|
|
<Button
|
|
|
|
|
|
|
|
type="primary"
|
|
|
|
|
|
|
|
icon={<Icon className="anticon" icon="mdi:check" />}
|
|
|
|
|
|
|
|
onClick={handleSave}
|
|
|
|
|
|
|
|
/>
|
|
|
|
|
|
|
|
</DelayTip>
|
|
|
|
|
|
|
|
</>
|
|
|
|
)}
|
|
|
|
)}
|
|
|
|
</Space>
|
|
|
|
</Space>
|
|
|
|
);
|
|
|
|
);
|
|
|
@ -100,7 +116,7 @@ FullModalFieldEditor.displayName = 'FullModalFieldEditor';
|
|
|
|
|
|
|
|
|
|
|
|
export const FullModalField: React.FC<FullModalFieldProps> = React.memo(
|
|
|
|
export const FullModalField: React.FC<FullModalFieldProps> = React.memo(
|
|
|
|
(props) => {
|
|
|
|
(props) => {
|
|
|
|
const valueTitle = _isString(props.value) ? props.value : undefined;
|
|
|
|
const valueTitle = useTitle(props.value);
|
|
|
|
|
|
|
|
|
|
|
|
const allowEditor = props.editable === true && !_isNil(props.renderEditor);
|
|
|
|
const allowEditor = props.editable === true && !_isNil(props.renderEditor);
|
|
|
|
|
|
|
|
|
|
|
|