Skip to content

Commit

Permalink
Merge pull request #62 from hocgin/v4.0.35
Browse files Browse the repository at this point in the history
V4.0.35
  • Loading branch information
hocgin authored Dec 19, 2021
2 parents 72fe74b + acedd2c commit c161877
Show file tree
Hide file tree
Showing 8 changed files with 91 additions and 36 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@hocgin/ui",
"version": "4.0.34",
"version": "4.0.35",
"sideEffects": [
".less",
".css"
Expand Down
40 changes: 23 additions & 17 deletions src/Promise/components/Schema/scheme.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -108,20 +108,31 @@ export const SchemeColumns: Record<string, ProRenderFieldPropsType> = {
// 搜索框
[prefix('search')]: {
render: (text: any, props: any) => {
let params: any = props?.params || {};
text = params?.defaultValue;
if (!text) {
return <span>-</span>;
}
return <div>{text}</div>;
},
renderFormItem: (text: any, props: any) => {
let params: any = props?.params || {};
return (
<Promise.Search
{...props?.fieldProps}
multiple={params?.multiple}
useAction={params?.useAction}
/>
);
let valueEnum = props?.valueEnum || {};

let options: any = [];
if (text) {
options = Object.keys(valueEnum).map((key) => ({
value: key,
// title
key: valueEnum[key]?.text || valueEnum[key],
}));
}
return <Promise.Search options={options}
defaultValue={params?.defaultValue}
multiple={params?.multiple}
useAction={params?.useAction}
{...props?.fieldProps}
/>;
},
},
// 树型选择框
Expand Down Expand Up @@ -244,7 +255,7 @@ export const SchemeColumns: Record<string, ProRenderFieldPropsType> = {
return <Input {...props?.fieldProps} />;
},
},
// 链接
// 编号
[prefix('encoding')]: {
render: (text: any, props: any) => {
if (!text) {
Expand All @@ -253,15 +264,10 @@ export const SchemeColumns: Record<string, ProRenderFieldPropsType> = {
return <div>{text}</div>;
},
renderFormItem: (text: any, props: any) => {
let { prefix, randExp, defaultValue } = props?.params || {};
return (
<Promise.Encoding
prefix={prefix}
randEx={randExp}
defaultValue={defaultValue}
{...props?.fieldProps}
/>
);
let { prefix, randExp } = props?.params || {};
return <Promise.Encoding prefix={prefix} randEx={randExp}
{...props?.fieldProps}
/>;
},
},
// https://procomponents.ant.design/components/field
Expand Down
36 changes: 30 additions & 6 deletions src/Promise/components/Search/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { SearchOption } from '@/Utils/types/rt-grass';
import { UseAction } from './type';
import styles from './index.less';
import { UserOutlined } from '@ant-design/icons';
import { useUpdateEffect, useRequest } from 'ahooks';
import { useUpdateEffect, useRequest, useMount } from 'ahooks';

const Index: React.FC<{
/**
Expand All @@ -20,8 +20,30 @@ const Index: React.FC<{
* 选择提示
*/
placeholder?: string;
}> = ({ multiple = false, placeholder = '请选择..', useAction, ...rest }) => {
let [data, setData] = useState<SearchOption[]>([]);
/**
* 默认值
*/
defaultValue?: string;
/**
* 变更值
* @param values
*/
onChange?: (values: any | any[]) => void;
/**
* 默认 options
*/
options?: SearchOption[];
}> = ({
multiple = false,
placeholder = '请选择..',
onChange,
useAction,
defaultValue,
options = [],
...rest
}) => {

let [data, setData] = useState<SearchOption[]>(options);
let [keyword, setKeyword] = useState<string>();
let style = { minWidth: '10em', width: '100%' };
let service = Utils.Lang.nilService(useAction?.initialValues, []);
Expand All @@ -30,21 +52,23 @@ const Index: React.FC<{
onSuccess: (data: SearchOption[]) => setData(data || []),
});

useUpdateEffect(() => run(keyword), [keyword]);
useUpdateEffect(() => run(keyword, false), [keyword]);

return (
<Select
defaultValue={defaultValue}
loading={loading}
showSearch
onChange={onChange}
showArrow={false}
filterOption={false}
allowClear
style={style}
mode={multiple ? 'multiple' : undefined}
notFoundContent={loading ? <Spin size="small" /> : null}
notFoundContent={loading ? <Spin size='small' /> : null}
onSearch={setKeyword}
placeholder={placeholder}
optionLabelProp="label"
optionLabelProp='label'
{...rest}
>
{data.map(({ key, image, description, value }: SearchOption) => (
Expand Down
2 changes: 1 addition & 1 deletion src/Promise/components/Search/type.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Option, SearchOption } from '@/Utils/types/rt-grass';

export interface UseAction {
initialValues: (keyword?: string) => Promise<SearchOption[]>;
initialValues: (keyword?: string, started?: boolean) => Promise<SearchOption[]>;
}
2 changes: 1 addition & 1 deletion src/Promise/demos/basic.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export default () => {
<Promise.Select useAction={useAction} />
<Promise.Select multiple={true} useAction={useAction} />
<Divider>搜索选择器</Divider>
<Promise.Search useAction={searchUseAction} />
<Promise.Search useAction={searchUseAction} defaultValue={'默认'} />
<Promise.Search useAction={searchUseAction} multiple={true} />
<Divider>单选按钮</Divider>
<Promise.RadioButton useAction={useAction} />
Expand Down
30 changes: 28 additions & 2 deletions src/Promise/demos/scheme-archive-config.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ export const config: any = {
return {
title: '666',
state: 'vx',
search: 'search_key',
searchName: 'searchName',
};
},
submit: async (params: Record<string, any>) => {
Expand All @@ -29,8 +31,32 @@ export const config: any = {
],
},
width: 'm',
},
{
}, {
fieldProps: {
name: ['search', 'searchName'],
},
title: 'search',
valueType: 'dependency',
columns: ({ search, searchName }: any) => {
return [{
title: 'search',
dataIndex: 'search',
valueType: Dom.columnPrefix('search'),
hideInTable: true,
valueEnum: {
[search]: searchName,
},
params: {
useAction: {
initialValues: async (params: Record<string, any>) => [{
key: 'lab',
value: 'vx',
}],
},
},
}];
},
}, {
title: '状态',
dataIndex: 'state',
valueType: 'select',
Expand Down
3 changes: 1 addition & 2 deletions src/Promise/demos/scheme-exhibit-config.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ export const config: any = {
},
];
},
},
{
}, {
title: '下拉选择',
dataIndex: 'gin_select_name',
valueType: Dom.columnPrefix('select'),
Expand Down
12 changes: 6 additions & 6 deletions src/Promise/demos/scheme-table-config.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { TableDropdown } from '@ant-design/pro-table';
import { Space, Divider } from 'antd';
import { config as addConfig } from './scheme-archive-config';
import { config as viewConfig } from './scheme-exhibit-config';
import { Promise } from '@hocgin/ui';
import { Dom, Promise } from '@hocgin/ui';
import data from './table-config';

let deleteConfig = {
Expand Down Expand Up @@ -58,7 +58,7 @@ export const config: any = {
let viewConfigs = {
...viewConfig,
trigger: (
<a key="view" rel="noopener noreferrer">
<a key='view' rel='noopener noreferrer'>
详情
</a>
),
Expand All @@ -67,7 +67,7 @@ export const config: any = {
...addConfig,
id: id,
trigger: (
<a key="update" rel="noopener noreferrer">
<a key='update' rel='noopener noreferrer'>
修改
</a>
),
Expand All @@ -76,14 +76,14 @@ export const config: any = {
return (
<div key={id}>
<Promise.ExhibitSchemaConfig key={1} config={viewConfigs} />
<Divider key={2} type="vertical" />
<Divider key={2} type='vertical' />
<Promise.ArchiveSchemaConfig
key={'scheme-table-config.tsx@columns'}
config={addConfigs}
/>
<Divider key={4} type="vertical" />
<Divider key={4} type='vertical' />
<TableDropdown
key="actionGroup"
key='actionGroup'
onSelect={() => action?.reload()}
menus={[
{
Expand Down

1 comment on commit c161877

@vercel
Copy link

@vercel vercel bot commented on c161877 Dec 19, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.