Skip to content

Commit

Permalink
chore: 更新组件和文档
Browse files Browse the repository at this point in the history
  • Loading branch information
giscafer committed Nov 6, 2021
1 parent 490800a commit fd91b9e
Show file tree
Hide file tree
Showing 43 changed files with 1,577 additions and 293 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
- 如果要去掉,可以注释`styles/reset/index.less`
- Swagger Doc Api TypeScript 接口代码生成
- 主题换色
- 沉淀组件:http://components.leekhub.com

## 使用说明

Expand Down Expand Up @@ -53,7 +54,7 @@ TypeScript 的 API 生成通过自研 `@roothub/cli` 来生成,生成的文件
**BaseApi**

```bash
rh api http://81.70.xx.84/leekhub-model-server/v2/api-docs?group=PROTOCOL%20SERVER%20base%20API -n
rh api http://81.70.xx.84/leekhub-model-server/v2/api-docs?group=LEEKHUB%20SERVER%20base%20API -n
```

执行示例 eg:
Expand Down
6 changes: 3 additions & 3 deletions src/components/EditableTagGroup/Demo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
* @Description: Demo
*/

import { Space } from "antd";
import React, { useState } from "react";
import EditableTagGroup from ".";
import { Space } from 'antd';
import React, { useState } from 'react';
import EditableTagGroup from '.';

export default (): React.ReactNode => {
const [tags, setTags] = useState<string[]>([]);
Expand Down
6 changes: 3 additions & 3 deletions src/components/EditableTagGroup/index.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
title: 可编辑标签组
title: EditableTagGroup
sidemenu: false
---

Expand All @@ -21,8 +21,8 @@ sidemenu: false
## Demo

```tsx
import React from "react";
import Demo from "@/components/EditableTagGroup/Demo.tsx";
import React from 'react';
import Demo from '@/components/EditableTagGroup/Demo.tsx';

export default function () {
return <Demo />;
Expand Down
24 changes: 12 additions & 12 deletions src/components/EditableTagGroup/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
* @Description: 用数组生成一组标签,可以动态添加和删除。
*/

import { PlusOutlined } from "@ant-design/icons";
import { Input, Row, Tag, Tooltip } from "antd";
import type { ChangeEvent } from "react";
import React, { useCallback, useRef, useState } from "react";
import { PlusOutlined } from '@ant-design/icons';
import { Input, Row, Tag, Tooltip } from 'antd';
import type { ChangeEvent } from 'react';
import React, { useCallback, useRef, useState } from 'react';

type EditableTagGroupProps = {
value?: string[]; // 标签数组
Expand All @@ -30,7 +30,7 @@ const EditableTagGroup: React.FC<EditableTagGroupProps> = ({
}) => {
const inputRef = useRef<Input>(null);
const [inputVisible, setInputVisible] = useState(false);
const [inputValue, setInputValue] = useState("");
const [inputValue, setInputValue] = useState('');

/**
* 标签删除回调
Expand Down Expand Up @@ -69,7 +69,7 @@ const EditableTagGroup: React.FC<EditableTagGroupProps> = ({
}

setInputVisible(false);
setInputValue("");
setInputValue('');
}, [inputValue, onChange, value]);

return (
Expand Down Expand Up @@ -99,9 +99,9 @@ const EditableTagGroup: React.FC<EditableTagGroupProps> = ({
<Tag
onClick={showInput}
style={{
background: "#ffffff",
borderStyle: "dashed",
cursor: "pointer",
background: '#ffffff',
borderStyle: 'dashed',
cursor: 'pointer',
}}
>
<Row align="middle">
Expand All @@ -113,9 +113,9 @@ const EditableTagGroup: React.FC<EditableTagGroupProps> = ({
{disabled && showButton && value?.length === 0 && (
<Tag
style={{
background: "#f5f5f5",
borderStyle: "dashed",
cursor: "not-allowed",
background: '#f5f5f5',
borderStyle: 'dashed',
cursor: 'not-allowed',
}}
>
<Row align="middle">
Expand Down
14 changes: 0 additions & 14 deletions src/components/EditableTree/index.md

This file was deleted.

12 changes: 6 additions & 6 deletions src/components/FileImportModal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
* @Description: 文件导入弹窗
*/

import { ModalForm, ProFormUploadButton } from "@ant-design/pro-form";
import { Form } from "antd";
import React from "react";
import { ModalForm, ProFormUploadButton } from '@ant-design/pro-form';
import { Form } from 'antd';
import React from 'react';

const FileImportModal: React.FC<{
visible?: boolean;
Expand All @@ -18,9 +18,9 @@ const FileImportModal: React.FC<{
onFinish?: (formData: any) => Promise<boolean | void>;
}> = ({
visible = false,
title = "",
title = '',
width = 600,
downloadUrl = "",
downloadUrl = '',
onCancel = () => {},
onOk = () => {},
onFinish = () => Promise.resolve(),
Expand Down Expand Up @@ -48,7 +48,7 @@ const FileImportModal: React.FC<{
name="file"
title="上传文件"
max={1}
rules={[{ required: true, message: "请选择文件" }]}
rules={[{ required: true, message: '请选择文件' }]}
fieldProps={{
beforeUpload: () => false,
}}
Expand Down
3 changes: 3 additions & 0 deletions src/components/RhDrawer/api.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import type { DrawerPropType } from '.';

export const DrawerPropTypeApi: React.FC<DrawerPropType> = () => null;
36 changes: 36 additions & 0 deletions src/components/RhDrawer/demo.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import RhDrawer from '.';
import { useRef } from 'react';
import type { RhDrawerProps } from '.';
import { message } from 'antd';
import { ProFormText } from '@ant-design/pro-form';

function Demo() {
// const [currentRow, setCurrentRow] = useState();

const rhDrawerRef = useRef<any>();

const DrawerProps: RhDrawerProps = {
text: '新建自定义参数',
title: '创建自定义参数',
// initialValues: currentRow,
onFinish: async (values) => {
console.log(values);
return await new Promise((resolve) => {
setTimeout(() => {
message.success('创建成功');
resolve(true);
}, 1000);
});
},
};
return (
<div>
<RhDrawer ref={rhDrawerRef} {...DrawerProps}>
<ProFormText name="name" label="名称" />
<ProFormText name="age" label="年龄" />
</RhDrawer>
</div>
);
}

export default Demo;
16 changes: 16 additions & 0 deletions src/components/RhDrawer/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
title: RhDrawer
sidemenu: false
---

# RhDrawer

Drawer 组件,简易封装

## Demo

<code src="./demo.tsx"/>

<API src="./api.ts"/>

其他 Api 见 [DrawerForm](https://procomponents.ant.design/components/modal-form)
162 changes: 162 additions & 0 deletions src/components/RhDrawer/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
import type { DrawerFormProps } from '@ant-design/pro-form';
import { DrawerForm } from '@ant-design/pro-form';
import type { FormInstance } from 'antd';
import { Button } from 'antd';
import type { ReactNode } from 'react';
import React, {
forwardRef,
useEffect,
useImperativeHandle,
useRef,
useState,
} from 'react';

type RhDrawRef = React.Ref<{
formRef: React.MutableRefObject<FormInstance<any> | undefined>;
setVisible: React.Dispatch<React.SetStateAction<boolean>>;
}>;

export type DrawerPropType = {
/**
* 抽屉的标题
*/
text?: ReactNode;
/**
* 关闭回调
*/
onCloseCallback?: (e: any) => any;
/**
* 提交数据时触发,内部校验了数据。
*/
onFinish?: (e: any) => Promise<boolean>;
};

export type RhDrawerProps = Omit<DrawerFormProps, 'onFinish'> & DrawerPropType;

function RhDrawer(
{
text,
children = '',
layout = 'vertical',
width = 480,
initialValues,
onFinish = () => Promise.resolve(false),
onCloseCallback = () => {},
...restProps
}: RhDrawerProps,
ref: RhDrawRef
) {
const [visible, setVisible] = useState<boolean>(false);
const [loading, setLoading] = useState<boolean>(false);
const formRef = useRef<FormInstance>();

useImperativeHandle(ref, () => {
return {
formRef,
setVisible,
};
});

useEffect(() => {
if (initialValues) {
formRef.current?.setFieldsValue(initialValues);
}
}, [initialValues]);

const open = () => {
formRef.current?.resetFields(); // 保证每次都能清空
setVisible(true);
};

const trigger: JSX.Element =
text && typeof text === 'string' ? (
<Button type="primary" ghost onClick={open}>
{text}
</Button>
) : (
<div
style={{ display: 'inline-block', cursor: 'pointer' }}
onClick={open}
>
{text}
</div>
);

// eslint-disable-next-line no-param-reassign
restProps.drawerProps = {
...restProps.drawerProps,
maskClosable: false,
onClose: (e) => {
setVisible(false);
formRef.current?.resetFields();
onCloseCallback(e);
},
};
const drawerFormProps: DrawerFormProps = {
formRef,
visible,
layout,
width,
labelCol: { span: 6 },
trigger,
submitter: {
render: () => [
<Button
key="close"
onClick={() => {
setVisible(false);
onCloseCallback(false);
formRef.current?.resetFields();
}}
>
取消
</Button>,
<Button
key="save"
type="primary"
onClick={async () => {
formRef.current?.submit();
}}
loading={loading}
>
确定
</Button>,
],
},
onFinish: async () => {
const values = await formRef.current?.validateFields();
setLoading(true);
try {
const canClose = await onFinish(values);
// 操作成功才会清除
if (canClose) {
formRef.current?.resetFields();
setVisible(false);
}
setLoading(false);
} catch {
// formRef.current?.resetFields();
setLoading(false);
}
},
...restProps,
};

return (
<div>
<DrawerForm
{...drawerFormProps}
onVisibleChange={(v) => {
if (!v) {
formRef.current?.resetFields();
onCloseCallback(v);
}
}}
>
{children}
</DrawerForm>
</div>
);
}

export default forwardRef(RhDrawer);
21 changes: 21 additions & 0 deletions src/components/RhEditableLabel/demo.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { useState } from 'react';
import RhEditableLabel from '.';

function Demo() {
const [value, setValue] = useState('LeekHub');
return (
<div>
<RhEditableLabel
value={value}
beforeUpdate={async () => {
return Promise.resolve(true);
}}
onChange={(v) => {
setValue(v);
}}
/>
</div>
);
}

export default Demo;
Loading

0 comments on commit fd91b9e

Please sign in to comment.