Showing
4 changed files
with
145 additions
and
2 deletions
1 | -import { getConfig } from '@qx/utils'; | 1 | + |
2 | +import { createRequest } from '@qx/utils'; | ||
3 | +const request = createRequest(); | ||
4 | + | ||
2 | /** | 5 | /** |
3 | * | 6 | * |
4 | * @param appCode | 7 | * @param appCode |
@@ -13,6 +16,5 @@ export function getFieldOptions( | @@ -13,6 +16,5 @@ export function getFieldOptions( | ||
13 | funCode: string, | 16 | funCode: string, |
14 | params?: { useKey?: boolean; withRender?: boolean }, | 17 | params?: { useKey?: boolean; withRender?: boolean }, |
15 | ) { | 18 | ) { |
16 | - const { request } = getConfig(); | ||
17 | return request.get(`/qx-apaas-lowcode/app/${appCode}/form/${funCode}/field/option`, { params }); | 19 | return request.get(`/qx-apaas-lowcode/app/${appCode}/form/${funCode}/field/option`, { params }); |
18 | } | 20 | } |
src/qx-tags-input/index.md
0 → 100644
1 | +--- | ||
2 | +nav: | ||
3 | + path: /component | ||
4 | + title: 组件 | ||
5 | + order: 1 | ||
6 | +group: | ||
7 | + path: /common | ||
8 | + title: 公共组件方法 | ||
9 | + order: 0 | ||
10 | +--- | ||
11 | + | ||
12 | +## QxTagsInput 标签输入框 | ||
13 | + | ||
14 | +Demo: | ||
15 | + | ||
16 | +```tsx | ||
17 | +import React, { useState } from 'react'; | ||
18 | +import 'antd/lib/button/style/index.less'; | ||
19 | +import { QxTagsInput } from '@qx/common'; | ||
20 | + | ||
21 | +export default () => { | ||
22 | + const [value, setValue] = useState([ | ||
23 | + 'jsadlfjlf', | ||
24 | + 'djslfjaljdlsf123', | ||
25 | + 'jsadlfjlfjalsf123', | ||
26 | + '3dsfjlsjflsdsjf24', | ||
27 | + 'vdsnflsjfsjfskljfvvv', | ||
28 | + ]); | ||
29 | + const handleChange = (newValue) => { | ||
30 | + setValue(newValue); | ||
31 | + }; | ||
32 | + return <QxTagsInput value={value} onChange={handleChange} />; | ||
33 | +}; | ||
34 | +``` | ||
35 | + | ||
36 | +```tsx | ||
37 | +import React, { useState } from 'react'; | ||
38 | +import 'antd/lib/button/style/index.less'; | ||
39 | +import { QxTagsInput } from '@qx/common'; | ||
40 | + | ||
41 | +export default () => { | ||
42 | + return <QxTagsInput disabled />; | ||
43 | +}; | ||
44 | +``` | ||
45 | + | ||
46 | +More skills for writing demo: https://d.umijs.org/guide/basic#write-component-demo |
src/qx-tags-input/index.tsx
0 → 100644
1 | +import React from 'react'; | ||
2 | +import { Tag } from 'antd'; | ||
3 | +import './style.less'; | ||
4 | +import { CloseOutlined } from '@ant-design/icons'; | ||
5 | + | ||
6 | +interface QxTagsInputProps { | ||
7 | + style?: any; | ||
8 | + value?: string[]; | ||
9 | + onChange?: (value) => void; | ||
10 | + maxLength?: number; | ||
11 | + disabled?: boolean; | ||
12 | +} | ||
13 | + | ||
14 | +export const QxTagsInput: React.FC<QxTagsInputProps> = (props) => { | ||
15 | + const { style = {}, onChange = () => {}, maxLength = 200, disabled = false } = props; | ||
16 | + | ||
17 | + const handleCloseTag = (index: number) => { | ||
18 | + const _value = [...(props.value || [])]; | ||
19 | + _value.splice(index, 1); | ||
20 | + onChange(_value); | ||
21 | + }; | ||
22 | + | ||
23 | + function handleChange(e) { | ||
24 | + const newValueItem = e.target.value.trim(); | ||
25 | + if (newValueItem && (props.value || []).indexOf(newValueItem) === -1) { | ||
26 | + onChange([...(props.value || []), newValueItem]); | ||
27 | + } | ||
28 | + e.target.value = ''; | ||
29 | + } | ||
30 | + | ||
31 | + const handleKeyPress = (e) => { | ||
32 | + if (e.keyCode == 13) { | ||
33 | + handleChange(e); | ||
34 | + } | ||
35 | + }; | ||
36 | + const handleBlur = (e) => { | ||
37 | + handleChange(e); | ||
38 | + }; | ||
39 | + | ||
40 | + return ( | ||
41 | + <div className={'qx-tags-input ant-input'} style={style}> | ||
42 | + {(props.value || []).map((item, index) => { | ||
43 | + return ( | ||
44 | + <Tag | ||
45 | + closeIcon={<CloseOutlined />} | ||
46 | + key={item} | ||
47 | + closable={true} | ||
48 | + onClose={() => handleCloseTag(index)} | ||
49 | + > | ||
50 | + {item} | ||
51 | + </Tag> | ||
52 | + ); | ||
53 | + })} | ||
54 | + <input | ||
55 | + type="text" | ||
56 | + disabled={disabled} | ||
57 | + className={'qx-tags-input__box'} | ||
58 | + onKeyUp={handleKeyPress} | ||
59 | + onBlur={handleBlur} | ||
60 | + placeholder={'请输入'} | ||
61 | + maxLength={maxLength} | ||
62 | + /> | ||
63 | + </div> | ||
64 | + ); | ||
65 | +}; |
src/qx-tags-input/style.less
0 → 100644
1 | +.qx-tags-input.ant-input { | ||
2 | + display: flex; | ||
3 | + flex-wrap: wrap; | ||
4 | + min-height: 32px; | ||
5 | + padding: 1px; | ||
6 | + | ||
7 | + > .ant-tag { | ||
8 | + margin: 3px; | ||
9 | + | ||
10 | + &:first-child { | ||
11 | + margin-left: 10px; | ||
12 | + } | ||
13 | + | ||
14 | + ~ .qx-tags-input__box { | ||
15 | + padding-left: 5px; | ||
16 | + } | ||
17 | + } | ||
18 | +} | ||
19 | + | ||
20 | +.qx-tags-input__box { | ||
21 | + flex: 1; | ||
22 | + min-width: 52px; | ||
23 | + padding-left: 10px; | ||
24 | + border: none; | ||
25 | + outline: none; | ||
26 | + | ||
27 | + &::placeholder { | ||
28 | + color: #bfbfbf; | ||
29 | + } | ||
30 | +} |