@jswork/antd-components 1.0.78 → 1.0.80
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -56
- package/dist/main.cjs.js +77 -0
- package/dist/main.cjs.js.map +1 -0
- package/dist/main.d.mts +1062 -0
- package/dist/main.d.ts +1062 -34
- package/dist/main.esm.js +77 -0
- package/dist/main.esm.js.map +1 -0
- package/dist/style.css +2 -267
- package/dist/style.css.map +1 -0
- package/package.json +30 -75
- package/src/lib/_abstract-upload.tsx +131 -0
- package/src/lib/alert.tsx +53 -0
- package/src/lib/breadcrumb.tsx +40 -0
- package/src/lib/checkable-dropdown.tsx +170 -0
- package/src/lib/checkable-tag-list.tsx +122 -0
- package/src/lib/checkable-tag.tsx +101 -0
- package/src/lib/checkbox-group.tsx +72 -0
- package/src/lib/checkbox.tsx +59 -0
- package/src/lib/codeflask.tsx +17 -0
- package/src/lib/confirm-button.tsx +87 -0
- package/src/lib/date-picker.tsx +60 -0
- package/src/lib/editable-tag-group.tsx +234 -0
- package/src/lib/input-hidden.tsx +13 -0
- package/src/lib/input-number.tsx +52 -0
- package/src/lib/input-tags.tsx +140 -0
- package/src/lib/input-token.tsx +102 -0
- package/src/lib/input.tsx +58 -0
- package/src/lib/interactive-list.tsx +173 -0
- package/src/lib/pre-select.tsx +128 -0
- package/src/lib/radio-group.tsx +67 -0
- package/src/lib/range-picker.tsx +59 -0
- package/src/lib/rate.tsx +38 -0
- package/src/lib/search.tsx +49 -0
- package/src/lib/select.tsx +86 -0
- package/src/lib/slider-range.tsx +40 -0
- package/src/lib/slider.tsx +37 -0
- package/src/lib/switch.tsx +52 -0
- package/src/lib/textarea.tsx +29 -0
- package/src/lib/time-picker.tsx +66 -0
- package/src/lib/transfer.tsx +70 -0
- package/src/lib/tree-select.tsx +64 -0
- package/src/lib/tree.tsx +60 -0
- package/src/lib/upload-dragger.tsx +60 -0
- package/src/lib/upload-picture-card.tsx +56 -0
- package/src/lib/upload-picture.tsx +47 -0
- package/src/lib/upload.tsx +55 -0
- package/src/main.ts +34 -0
- package/src/style.scss +191 -0
- package/LICENSE.txt +0 -21
- package/dist/index.esm.js +0 -10
- package/dist/index.js +0 -10
- package/dist/lib/_abstract-upload.d.ts +0 -40
- package/dist/lib/alert.d.ts +0 -14
- package/dist/lib/breadcrumb.d.ts +0 -29
- package/dist/lib/checkable-dropdown.d.ts +0 -52
- package/dist/lib/checkable-tag-list.d.ts +0 -51
- package/dist/lib/checkable-tag.d.ts +0 -43
- package/dist/lib/checkbox-group.d.ts +0 -38
- package/dist/lib/checkbox.d.ts +0 -27
- package/dist/lib/codeflask.d.ts +0 -9
- package/dist/lib/confirm-button.d.ts +0 -23
- package/dist/lib/date-picker.d.ts +0 -26
- package/dist/lib/editable-tag-group.d.ts +0 -92
- package/dist/lib/input-hidden.d.ts +0 -7
- package/dist/lib/input-number.d.ts +0 -27
- package/dist/lib/input-tags.d.ts +0 -37
- package/dist/lib/input-token.d.ts +0 -39
- package/dist/lib/input.d.ts +0 -29
- package/dist/lib/interactive-list.d.ts +0 -56
- package/dist/lib/pre-select.d.ts +0 -57
- package/dist/lib/radio-group.d.ts +0 -42
- package/dist/lib/range-picker.d.ts +0 -27
- package/dist/lib/rate.d.ts +0 -23
- package/dist/lib/search.d.ts +0 -29
- package/dist/lib/select.d.ts +0 -43
- package/dist/lib/slider-range.d.ts +0 -23
- package/dist/lib/slider.d.ts +0 -22
- package/dist/lib/switch.d.ts +0 -27
- package/dist/lib/textarea.d.ts +0 -22
- package/dist/lib/time-picker.d.ts +0 -29
- package/dist/lib/transfer.d.ts +0 -37
- package/dist/lib/tree-select.d.ts +0 -32
- package/dist/lib/tree.d.ts +0 -31
- package/dist/lib/upload-dragger.d.ts +0 -28
- package/dist/lib/upload-picture-card.d.ts +0 -14
- package/dist/lib/upload-picture.d.ts +0 -14
- package/dist/lib/upload.d.ts +0 -28
- /package/{dist → src}/styles/input-tags.scss +0 -0
- /package/{dist → src}/styles/override.scss +0 -0
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import noop from '@jswork/noop';
|
|
3
|
+
import { Switch, SwitchProps } from 'antd';
|
|
4
|
+
import cx from 'classnames';
|
|
5
|
+
|
|
6
|
+
const CLASS_NAME = 'ac-switch';
|
|
7
|
+
type StdEventTarget = { target: { value: any } };
|
|
8
|
+
type StdCallback = (inEvent: StdEventTarget) => void;
|
|
9
|
+
|
|
10
|
+
type Props = {
|
|
11
|
+
className?: string;
|
|
12
|
+
value?: boolean;
|
|
13
|
+
onChange?: StdCallback;
|
|
14
|
+
} & SwitchProps;
|
|
15
|
+
|
|
16
|
+
export class AcSwitch extends React.Component<Props> {
|
|
17
|
+
static displayName = CLASS_NAME;
|
|
18
|
+
static formSchema = CLASS_NAME;
|
|
19
|
+
static defaultProps = {
|
|
20
|
+
onChange: noop
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
state = {
|
|
24
|
+
value: Boolean(this.props.value)
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
shouldComponentUpdate(nextProps: Readonly<Props>): boolean {
|
|
28
|
+
const { value } = nextProps;
|
|
29
|
+
if (value !== this.props.value) this.setState({ value });
|
|
30
|
+
return true;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
handleChange = (value) => {
|
|
34
|
+
const { onChange } = this.props;
|
|
35
|
+
const target = { value };
|
|
36
|
+
this.setState(target, () => onChange!({ target }));
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
render() {
|
|
40
|
+
const { className, value, onChange, ...props } = this.props;
|
|
41
|
+
const _value = this.state.value;
|
|
42
|
+
|
|
43
|
+
return (
|
|
44
|
+
<Switch
|
|
45
|
+
checked={_value}
|
|
46
|
+
className={cx(CLASS_NAME, className)}
|
|
47
|
+
onChange={this.handleChange}
|
|
48
|
+
{...props}
|
|
49
|
+
/>
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import noop from '@jswork/noop';
|
|
3
|
+
import { Input } from 'antd';
|
|
4
|
+
import cx from 'classnames';
|
|
5
|
+
import { TextAreaProps } from 'antd/es/input';
|
|
6
|
+
|
|
7
|
+
const CLASS_NAME = 'ac-textarea';
|
|
8
|
+
const TextArea = Input.TextArea;
|
|
9
|
+
type StdEventTarget = { target: { value: any } };
|
|
10
|
+
type StdCallback = (inEvent: StdEventTarget) => void;
|
|
11
|
+
|
|
12
|
+
type Props = {
|
|
13
|
+
className?: string;
|
|
14
|
+
value?: boolean;
|
|
15
|
+
onChange?: StdCallback;
|
|
16
|
+
} & TextAreaProps;
|
|
17
|
+
|
|
18
|
+
export class AcTextarea extends React.Component<Props> {
|
|
19
|
+
static displayName = CLASS_NAME;
|
|
20
|
+
static formSchema = CLASS_NAME;
|
|
21
|
+
static defaultProps = {
|
|
22
|
+
onChange: noop
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
render() {
|
|
26
|
+
const { className, defaultValue, ...props } = this.props;
|
|
27
|
+
return <TextArea className={cx(CLASS_NAME, className)} {...props} />;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import noop from '@jswork/noop';
|
|
3
|
+
import { TimePicker, TimePickerProps } from 'antd';
|
|
4
|
+
import cx from 'classnames';
|
|
5
|
+
import dayjs from 'dayjs';
|
|
6
|
+
|
|
7
|
+
const CLASS_NAME = 'ac-time-picker';
|
|
8
|
+
const STD_FORMAT = 'HH:mm:ss';
|
|
9
|
+
type StdEventTarget = { target: { value: any } };
|
|
10
|
+
type StdCallback = (inEvent: StdEventTarget) => void;
|
|
11
|
+
|
|
12
|
+
type Props = {
|
|
13
|
+
className?: string;
|
|
14
|
+
value?: string | dayjs.Dayjs;
|
|
15
|
+
defaultValue?: string | dayjs.Dayjs;
|
|
16
|
+
onChange?: StdCallback;
|
|
17
|
+
} & Omit<TimePickerProps, 'value' | 'defaultValue'>;
|
|
18
|
+
|
|
19
|
+
export class AcTimePicker extends React.Component<Props> {
|
|
20
|
+
static displayName = CLASS_NAME;
|
|
21
|
+
static formSchema = CLASS_NAME;
|
|
22
|
+
static defaultProps = {
|
|
23
|
+
onChange: noop,
|
|
24
|
+
format: STD_FORMAT
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
handleChange = (inEvent) => {
|
|
28
|
+
const value = this.stringify(inEvent);
|
|
29
|
+
const { onChange } = this.props;
|
|
30
|
+
onChange!({ target: { value } });
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
parse = (inValue) => {
|
|
34
|
+
const { format } = this.props;
|
|
35
|
+
return dayjs(inValue, format as string);
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
stringify = (inValue) => {
|
|
39
|
+
if (!inValue) return null;
|
|
40
|
+
const { format } = this.props;
|
|
41
|
+
return inValue.format(format as string);
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
normalize = (inValues) => {
|
|
45
|
+
Object.keys(inValues).forEach((key) => {
|
|
46
|
+
const value = inValues[key];
|
|
47
|
+
if (value) inValues[key] = this.parse(value);
|
|
48
|
+
else delete inValues[key];
|
|
49
|
+
});
|
|
50
|
+
return inValues;
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
render() {
|
|
54
|
+
const { className, value, defaultValue, onChange, ...props } = this.props;
|
|
55
|
+
const values = this.normalize({ value, defaultValue });
|
|
56
|
+
|
|
57
|
+
return (
|
|
58
|
+
<TimePicker
|
|
59
|
+
className={cx(CLASS_NAME, className)}
|
|
60
|
+
onChange={this.handleChange}
|
|
61
|
+
{...values}
|
|
62
|
+
{...props}
|
|
63
|
+
/>
|
|
64
|
+
);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import noop from '@jswork/noop';
|
|
3
|
+
import { Transfer, TransferProps } from 'antd';
|
|
4
|
+
import cx from 'classnames';
|
|
5
|
+
import { transferLabel } from '@jswork/antd-tpls';
|
|
6
|
+
|
|
7
|
+
const CLASS_NAME = 'ac-transfer';
|
|
8
|
+
type StdEventTarget = { target: { value: any } };
|
|
9
|
+
type StdCallback = (inEvent: StdEventTarget) => void;
|
|
10
|
+
type TemplateCallback = (item: { item: any }, options?: any) => React.ReactNode;
|
|
11
|
+
|
|
12
|
+
type Props = {
|
|
13
|
+
className?: string;
|
|
14
|
+
items?: any[];
|
|
15
|
+
template: TemplateCallback;
|
|
16
|
+
value?: any[];
|
|
17
|
+
onChange?: StdCallback;
|
|
18
|
+
} & TransferProps<any>;
|
|
19
|
+
|
|
20
|
+
export class AcTransfer extends React.Component<Props> {
|
|
21
|
+
static displayName = CLASS_NAME;
|
|
22
|
+
static formSchema = CLASS_NAME;
|
|
23
|
+
static defaultProps = {
|
|
24
|
+
items: [],
|
|
25
|
+
template: transferLabel,
|
|
26
|
+
onChange: noop
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
get templateCallback(): any {
|
|
30
|
+
const { template } = this.props;
|
|
31
|
+
return (item: any) => template({ item });
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
state = {
|
|
35
|
+
value: this.props.value
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
shouldComponentUpdate(nextProps: Readonly<Props>): boolean {
|
|
39
|
+
const { value } = nextProps;
|
|
40
|
+
const isNewValue = this.props.value !== value;
|
|
41
|
+
if (isNewValue && value !== this.state.value) {
|
|
42
|
+
this.setState({ value });
|
|
43
|
+
}
|
|
44
|
+
return true;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
handleChange = (inEvent) => {
|
|
48
|
+
const { onChange } = this.props;
|
|
49
|
+
const target = { value: inEvent };
|
|
50
|
+
this.setState(target, () => onChange!({ target }));
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
render() {
|
|
54
|
+
const { className, value, onChange, items, template, ...props } = this.props;
|
|
55
|
+
|
|
56
|
+
const _value = this.state.value;
|
|
57
|
+
|
|
58
|
+
return (
|
|
59
|
+
<Transfer
|
|
60
|
+
className={cx(CLASS_NAME, className)}
|
|
61
|
+
dataSource={items}
|
|
62
|
+
render={this.templateCallback}
|
|
63
|
+
targetKeys={_value}
|
|
64
|
+
rowKey={(item) => item.value}
|
|
65
|
+
onChange={this.handleChange}
|
|
66
|
+
{...props}
|
|
67
|
+
/>
|
|
68
|
+
);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import cx from 'classnames';
|
|
3
|
+
import noop from '@jswork/noop';
|
|
4
|
+
import { TreeSelect, TreeSelectProps } from 'antd';
|
|
5
|
+
import '@jswork/next-tree-walk';
|
|
6
|
+
import { treeSelectKv } from '@jswork/antd-tpls';
|
|
7
|
+
|
|
8
|
+
const CLASS_NAME = 'ac-tree-select';
|
|
9
|
+
type StdEventTarget = { target: { value: any } };
|
|
10
|
+
type StdCallback = (inEvent: StdEventTarget) => void;
|
|
11
|
+
|
|
12
|
+
// @see: https://github.com/afeiship/react-ant-tree-select
|
|
13
|
+
|
|
14
|
+
type Props = {
|
|
15
|
+
className?: string;
|
|
16
|
+
items?: any[];
|
|
17
|
+
template?: any;
|
|
18
|
+
itemsKey?: string | ((index: number, item: any) => any);
|
|
19
|
+
onChange?: StdCallback;
|
|
20
|
+
} & TreeSelectProps;
|
|
21
|
+
|
|
22
|
+
export class AcTreeSelect extends React.Component<Props> {
|
|
23
|
+
static displayName = CLASS_NAME;
|
|
24
|
+
static formSchema = CLASS_NAME;
|
|
25
|
+
static defaultProps = {
|
|
26
|
+
items: [],
|
|
27
|
+
template: treeSelectKv,
|
|
28
|
+
itemsKey: 'children',
|
|
29
|
+
onChange: noop
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
get childView() {
|
|
33
|
+
const { items, template, itemsKey } = this.props;
|
|
34
|
+
return nx.treeWalk(items!, { template, itemsKey });
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
handleChange = (inValue) => {
|
|
38
|
+
const { onChange } = this.props;
|
|
39
|
+
onChange!({ target: { value: inValue } });
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
render() {
|
|
43
|
+
const {
|
|
44
|
+
className,
|
|
45
|
+
items,
|
|
46
|
+
itemsKey,
|
|
47
|
+
template,
|
|
48
|
+
treeData,
|
|
49
|
+
onChange,
|
|
50
|
+
...props
|
|
51
|
+
} = this.props;
|
|
52
|
+
|
|
53
|
+
return (
|
|
54
|
+
<TreeSelect
|
|
55
|
+
data-component={CLASS_NAME}
|
|
56
|
+
className={cx(CLASS_NAME, className)}
|
|
57
|
+
onChange={this.handleChange}
|
|
58
|
+
treeNodeFilterProp="title"
|
|
59
|
+
{...props}>
|
|
60
|
+
{this.childView}
|
|
61
|
+
</TreeSelect>
|
|
62
|
+
);
|
|
63
|
+
}
|
|
64
|
+
}
|
package/src/lib/tree.tsx
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { Tree, TreeProps } from 'antd';
|
|
3
|
+
import cx from 'classnames';
|
|
4
|
+
import '@jswork/next-tree-walk';
|
|
5
|
+
import { treeKv, kv as KvTmpl } from '@jswork/antd-tpls';
|
|
6
|
+
|
|
7
|
+
const CLASS_NAME = 'ac-tree';
|
|
8
|
+
const DEFAULT_KV = {
|
|
9
|
+
label: 'label',
|
|
10
|
+
value: 'value'
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
type Props = {
|
|
14
|
+
className?: string;
|
|
15
|
+
items?: any[];
|
|
16
|
+
kv?: Record<string, string>;
|
|
17
|
+
template?: any;
|
|
18
|
+
itemsKey?: string | ((index: number, item: any) => any);
|
|
19
|
+
directory?: boolean;
|
|
20
|
+
} & TreeProps;
|
|
21
|
+
|
|
22
|
+
export class AcTree extends React.Component<Props> {
|
|
23
|
+
static displayName = CLASS_NAME;
|
|
24
|
+
static formSchema = CLASS_NAME;
|
|
25
|
+
static defaultProps = {
|
|
26
|
+
directory: false,
|
|
27
|
+
items: [],
|
|
28
|
+
kv: DEFAULT_KV,
|
|
29
|
+
template: treeKv,
|
|
30
|
+
itemsKey: 'children'
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
get childView() {
|
|
34
|
+
const { items, itemsKey } = this.props;
|
|
35
|
+
return nx.treeWalk(items!, { template: this.template, itemsKey });
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
template = (args) => {
|
|
39
|
+
const { template, kv } = this.props;
|
|
40
|
+
if (kv === DEFAULT_KV) return template!(args);
|
|
41
|
+
return KvTmpl(args, {
|
|
42
|
+
component: Tree.TreeNode,
|
|
43
|
+
...kv
|
|
44
|
+
});
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
render() {
|
|
48
|
+
const { className, children, items, template, itemsKey, directory, ...props } = this.props;
|
|
49
|
+
|
|
50
|
+
const RootComp: any = directory ? Tree.DirectoryTree : Tree;
|
|
51
|
+
|
|
52
|
+
if (items?.length === 0) return null;
|
|
53
|
+
|
|
54
|
+
return (
|
|
55
|
+
<RootComp className={cx(CLASS_NAME, className)} {...props}>
|
|
56
|
+
{this.childView}
|
|
57
|
+
</RootComp>
|
|
58
|
+
);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import noop from '@jswork/noop';
|
|
3
|
+
import { InboxOutlined } from '@ant-design/icons';
|
|
4
|
+
import { Upload } from 'antd';
|
|
5
|
+
import cx from 'classnames';
|
|
6
|
+
import { DraggerProps } from 'antd/es/upload';
|
|
7
|
+
|
|
8
|
+
const CLASS_NAME = 'ac-upload-dragger';
|
|
9
|
+
const { Dragger } = Upload;
|
|
10
|
+
type StdEventTarget = { target: { value: any } };
|
|
11
|
+
type StdCallback = (inEvent: StdEventTarget) => void;
|
|
12
|
+
type CustomRequest = (inEvent: any) => Promise<any>;
|
|
13
|
+
|
|
14
|
+
type Props = {
|
|
15
|
+
className?: string;
|
|
16
|
+
value?: any[];
|
|
17
|
+
defaultValue?: any[];
|
|
18
|
+
onChange?: StdCallback;
|
|
19
|
+
onRequest?: CustomRequest;
|
|
20
|
+
} & DraggerProps;
|
|
21
|
+
|
|
22
|
+
export class AcUploadDragger extends React.Component<Props> {
|
|
23
|
+
static displayName = CLASS_NAME;
|
|
24
|
+
static formSchema = CLASS_NAME;
|
|
25
|
+
static defaultProps = {
|
|
26
|
+
onChange: noop,
|
|
27
|
+
onRequest: (inEvent) => Promise.resolve(inEvent)
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
handleChange = (inEvent) => {
|
|
31
|
+
const { onChange } = this.props;
|
|
32
|
+
onChange!({ target: { value: inEvent } });
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
handleCustomRequest = (inRequestOption) => {
|
|
36
|
+
const { onRequest } = this.props;
|
|
37
|
+
const { file } = inRequestOption;
|
|
38
|
+
onRequest!(file)
|
|
39
|
+
.then((res) => inRequestOption.onSuccess(res, file))
|
|
40
|
+
.catch((err) => inRequestOption.onError(err, file));
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
render() {
|
|
44
|
+
const { className, value, onChange, ...props } = this.props;
|
|
45
|
+
return (
|
|
46
|
+
<Dragger
|
|
47
|
+
className={cx(CLASS_NAME, className)}
|
|
48
|
+
listType="picture"
|
|
49
|
+
onChange={this.handleChange}
|
|
50
|
+
customRequest={this.handleCustomRequest}
|
|
51
|
+
{...props}>
|
|
52
|
+
<p className="ant-upload-drag-icon">
|
|
53
|
+
<InboxOutlined />
|
|
54
|
+
</p>
|
|
55
|
+
<p className="ant-upload-text">单击或拖动文件到此区域以上传</p>
|
|
56
|
+
<p className="ant-upload-hint">支持单个或批量上传,请不要上传公司数据或其他重要文件</p>
|
|
57
|
+
</Dragger>
|
|
58
|
+
);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import noop from '@jswork/noop';
|
|
3
|
+
import { Space, Upload } from 'antd';
|
|
4
|
+
import cx from 'classnames';
|
|
5
|
+
import { UploadOutlined } from '@ant-design/icons';
|
|
6
|
+
|
|
7
|
+
import nx from '@jswork/next';
|
|
8
|
+
import weibo2res from '@jswork/weibo2res';
|
|
9
|
+
import '@jswork/next-gpid';
|
|
10
|
+
import { AcAbstractUpload } from './_abstract-upload';
|
|
11
|
+
|
|
12
|
+
const CLASS_NAME = 'ac-upload-picture-card';
|
|
13
|
+
const toWeiboPid = (inItem) => {
|
|
14
|
+
if (typeof inItem === 'string' && inItem.includes('sina.com.cn')) return weibo2res(inItem).pid;
|
|
15
|
+
return null;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export class AcUploadPictureCard extends AcAbstractUpload {
|
|
19
|
+
static displayName = CLASS_NAME;
|
|
20
|
+
static formSchema = CLASS_NAME;
|
|
21
|
+
static defaultProps = {
|
|
22
|
+
onChange: noop,
|
|
23
|
+
value: [],
|
|
24
|
+
transformURL: (pid) => (pid.includes('://') ? pid : `https://tva1.js.work/large/${pid}.jpg`),
|
|
25
|
+
transformResponse: (inFileList: any) => {
|
|
26
|
+
return inFileList.map((item) => {
|
|
27
|
+
return toWeiboPid(item) || item.uid || item.pid || nx.gpid(item.url);
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
render() {
|
|
33
|
+
const { className, value, onChange, ...props } = this.props;
|
|
34
|
+
const { fileList } = this.state;
|
|
35
|
+
|
|
36
|
+
return (
|
|
37
|
+
<div className={cx(CLASS_NAME, className)} ref={this.rootRef}>
|
|
38
|
+
<Upload
|
|
39
|
+
className={cx(`${CLASS_NAME}__uploader`, className)}
|
|
40
|
+
fileList={fileList}
|
|
41
|
+
listType="picture-card"
|
|
42
|
+
name="pic1"
|
|
43
|
+
multiple
|
|
44
|
+
previewFile={this.previewFile}
|
|
45
|
+
onPreview={this.handlePreview}
|
|
46
|
+
onChange={this.handleChange}
|
|
47
|
+
{...props}>
|
|
48
|
+
<Space direction="horizontal">
|
|
49
|
+
<UploadOutlined />
|
|
50
|
+
<span>上传</span>
|
|
51
|
+
</Space>
|
|
52
|
+
</Upload>
|
|
53
|
+
</div>
|
|
54
|
+
);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import noop from '@jswork/noop';
|
|
3
|
+
import { UploadOutlined } from '@ant-design/icons';
|
|
4
|
+
import { Upload, Button } from 'antd';
|
|
5
|
+
import cx from 'classnames';
|
|
6
|
+
import { AcAbstractUpload } from './_abstract-upload';
|
|
7
|
+
import nx from '@jswork/next';
|
|
8
|
+
|
|
9
|
+
const CLASS_NAME = 'ac-upload-picture';
|
|
10
|
+
|
|
11
|
+
export class AcUploadPicture extends AcAbstractUpload {
|
|
12
|
+
static displayName = CLASS_NAME;
|
|
13
|
+
static formSchema = CLASS_NAME;
|
|
14
|
+
static defaultProps = {
|
|
15
|
+
onChange: noop,
|
|
16
|
+
value: [],
|
|
17
|
+
maxCount: 1,
|
|
18
|
+
transformURL: (pid) => (pid.includes('://') ? pid : `https://tva1.js.work/large/${pid}.jpg`),
|
|
19
|
+
transformResponse: (inFileList: any) => {
|
|
20
|
+
return inFileList.map((item) => {
|
|
21
|
+
return item.uid || item.pid || nx.gpid(item.url);
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
render() {
|
|
27
|
+
const { className, value, onChange, ...props } = this.props;
|
|
28
|
+
const { fileList } = this.state;
|
|
29
|
+
|
|
30
|
+
return (
|
|
31
|
+
<div className={cx(CLASS_NAME, className)} ref={this.rootRef}>
|
|
32
|
+
<Upload
|
|
33
|
+
accept="images/*"
|
|
34
|
+
name="pic1"
|
|
35
|
+
listType="picture"
|
|
36
|
+
multiple={false}
|
|
37
|
+
onChange={this.handleChange}
|
|
38
|
+
onPreview={this.handlePreview}
|
|
39
|
+
previewFile={this.previewFile}
|
|
40
|
+
fileList={fileList}
|
|
41
|
+
{...props}>
|
|
42
|
+
<Button icon={<UploadOutlined />}>上传({fileList.length})</Button>
|
|
43
|
+
</Upload>
|
|
44
|
+
</div>
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import noop from '@jswork/noop';
|
|
3
|
+
import { Upload, Button } from 'antd';
|
|
4
|
+
import type { UploadProps, ButtonProps } from 'antd';
|
|
5
|
+
import { UploadOutlined } from '@ant-design/icons';
|
|
6
|
+
|
|
7
|
+
import cx from 'classnames';
|
|
8
|
+
|
|
9
|
+
const CLASS_NAME = 'ac-upload';
|
|
10
|
+
type StdEventTarget = { target: { value: any } };
|
|
11
|
+
type StdCallback = (inEvent: StdEventTarget) => void;
|
|
12
|
+
type CustomRequest = (inEvent: any) => Promise<any>;
|
|
13
|
+
|
|
14
|
+
type Props = {
|
|
15
|
+
className?: string;
|
|
16
|
+
value?: number;
|
|
17
|
+
onChange?: StdCallback;
|
|
18
|
+
onRequest?: CustomRequest;
|
|
19
|
+
btnProps?: ButtonProps;
|
|
20
|
+
} & UploadProps;
|
|
21
|
+
|
|
22
|
+
export class AcUpload extends React.Component<Props> {
|
|
23
|
+
static displayName = CLASS_NAME;
|
|
24
|
+
static formSchema = CLASS_NAME;
|
|
25
|
+
static defaultProps = {
|
|
26
|
+
onChange: noop,
|
|
27
|
+
onRequest: (inEvent) => Promise.resolve(inEvent)
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
handleChange = (inEvent) => {
|
|
31
|
+
const { onChange } = this.props;
|
|
32
|
+
onChange!({ target: { value: inEvent } });
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
handleCustomRequest = (inRequestOption) => {
|
|
36
|
+
const { onRequest } = this.props;
|
|
37
|
+
const { file } = inRequestOption;
|
|
38
|
+
onRequest!(file)
|
|
39
|
+
.then((res) => inRequestOption.onSuccess(res, file))
|
|
40
|
+
.catch((err) => inRequestOption.onError(err, file));
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
render() {
|
|
44
|
+
const { className, value, onChange, btnProps, ...props } = this.props;
|
|
45
|
+
return (
|
|
46
|
+
<Upload
|
|
47
|
+
className={cx(CLASS_NAME, className)}
|
|
48
|
+
onChange={this.handleChange}
|
|
49
|
+
customRequest={this.handleCustomRequest}
|
|
50
|
+
{...props}>
|
|
51
|
+
<Button icon={<UploadOutlined />} children="点击上传" {...btnProps} />
|
|
52
|
+
</Upload>
|
|
53
|
+
);
|
|
54
|
+
}
|
|
55
|
+
}
|
package/src/main.ts
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
export * from './lib/alert';
|
|
2
|
+
export * from './lib/breadcrumb';
|
|
3
|
+
export * from './lib/checkable-dropdown';
|
|
4
|
+
export * from './lib/checkable-tag';
|
|
5
|
+
export * from './lib/checkable-tag-list';
|
|
6
|
+
export * from './lib/checkbox';
|
|
7
|
+
export * from './lib/checkbox-group';
|
|
8
|
+
export * from './lib/codeflask';
|
|
9
|
+
export * from './lib/confirm-button';
|
|
10
|
+
export * from './lib/date-picker';
|
|
11
|
+
export * from './lib/editable-tag-group';
|
|
12
|
+
export * from './lib/input';
|
|
13
|
+
export * from './lib/input-hidden';
|
|
14
|
+
export * from './lib/input-number';
|
|
15
|
+
export * from './lib/input-tags';
|
|
16
|
+
export * from './lib/input-token';
|
|
17
|
+
export * from './lib/pre-select';
|
|
18
|
+
export * from './lib/radio-group';
|
|
19
|
+
export * from './lib/range-picker';
|
|
20
|
+
export * from './lib/rate';
|
|
21
|
+
export * from './lib/search';
|
|
22
|
+
export * from './lib/select';
|
|
23
|
+
export * from './lib/slider';
|
|
24
|
+
export * from './lib/slider-range';
|
|
25
|
+
export * from './lib/switch';
|
|
26
|
+
export * from './lib/textarea';
|
|
27
|
+
export * from './lib/time-picker';
|
|
28
|
+
export * from './lib/transfer';
|
|
29
|
+
export * from './lib/tree';
|
|
30
|
+
export * from './lib/tree-select';
|
|
31
|
+
export * from './lib/upload-dragger';
|
|
32
|
+
export * from './lib/upload-picture';
|
|
33
|
+
export * from './lib/upload-picture-card';
|
|
34
|
+
export * from './lib/upload';
|