client: simple template card usage

This commit is contained in:
fantasticit 2022-09-16 20:48:01 +08:00
parent 22e48e32b3
commit 64113f48f1
1 changed files with 31 additions and 30 deletions

View File

@ -21,6 +21,17 @@ export interface IProps {
onClosePreview?: () => void; onClosePreview?: () => void;
} }
const bodyStyle = {
overflow: 'auto',
};
const titleContainerStyle = {
marginBottom: 12,
whiteSpace: 'nowrap',
textOverflow: 'ellipsis',
overflow: 'hidden',
} as React.CSSProperties;
const flexStyle = { display: 'flex' };
export const TemplateCard: React.FC<IProps> = ({ export const TemplateCard: React.FC<IProps> = ({
template, template,
onClick, onClick,
@ -35,26 +46,35 @@ export const TemplateCard: React.FC<IProps> = ({
Router.push(`/template/${template.id}/`); Router.push(`/template/${template.id}/`);
}, [template]); }, [template]);
const cancel = useCallback(() => {
toggleVisible(false);
onClosePreview && onClosePreview();
}, [toggleVisible, onClosePreview]);
const preview = useCallback(() => {
toggleVisible(true);
onOpenPreview && onOpenPreview();
}, [toggleVisible, onOpenPreview]);
const useTemplate = useCallback(() => {
onClick && onClick(template.id);
}, [onClick, template.id]);
return ( return (
<> <>
<Modal <Modal
title="模板预览" title="模板预览"
width={'calc(100vh - 120px)'} width={'calc(100vh - 120px)'}
height={'calc(100vh - 120px)'} height={'calc(100vh - 120px)'}
bodyStyle={{ bodyStyle={bodyStyle}
overflow: 'auto',
}}
visible={visible} visible={visible}
onCancel={() => { onCancel={cancel}
toggleVisible(false);
onClosePreview && onClosePreview();
}}
footer={null} footer={null}
fullScreen fullScreen
> >
<TemplateReader key={template.id} templateId={template.id} /> <TemplateReader key={template.id} templateId={template.id} />
</Modal> </Modal>
<div className={cls(styles.cardWrap, getClassNames(template.id))}> <div className={cls(styles.cardWrap, getClassNames(template.id))} onClick={useTemplate}>
<header> <header>
<IconDocument /> <IconDocument />
<div className={styles.rightWrap}> <div className={styles.rightWrap}>
@ -68,14 +88,7 @@ export const TemplateCard: React.FC<IProps> = ({
</div> </div>
</header> </header>
<main> <main>
<div <div style={titleContainerStyle}>
style={{
marginBottom: 12,
whiteSpace: 'nowrap',
textOverflow: 'ellipsis',
overflow: 'hidden',
}}
>
<Text strong>{template.title}</Text> <Text strong>{template.title}</Text>
</div> </div>
<div> <div>
@ -92,28 +105,16 @@ export const TemplateCard: React.FC<IProps> = ({
</main> </main>
<footer> <footer>
<Text type="tertiary" size="small"> <Text type="tertiary" size="small">
<div style={{ display: 'flex' }}> <div style={flexStyle}>
使 使
{template.usageAmount} {template.usageAmount}
</div> </div>
</Text> </Text>
</footer> </footer>
<div className={styles.actions}> <div className={styles.actions}>
<Button <Button theme="solid" type="tertiary" onClick={preview}>
theme="solid"
type="tertiary"
onClick={() => {
toggleVisible(true);
onOpenPreview && onOpenPreview();
}}
>
</Button> </Button>
{onClick && (
<Button type="primary" theme="solid" onClick={() => onClick && onClick(template.id)}>
使
</Button>
)}
</div> </div>
</div> </div>
</> </>