Skip to content

Commit ae7534e

Browse files
authored
Merge pull request #221 from yaob421123/master
feat(Login): 登录组件新增initialValues默认值api
2 parents a8f45e2 + 59ff365 commit ae7534e

File tree

3 files changed

+7
-2
lines changed

3 files changed

+7
-2
lines changed
File renamed without changes.

packages/user-login/README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -531,15 +531,14 @@ export interface UserLoginProps {
531531
| ---- | ---- | ---- | ---- | ---- |
532532
| api | 请求接口 | 是 | `string` | - |
533533
| align | 卡片框的位置 | 否 | `枚举类型:'left' \| 'right' \| 'center'` | `center` |
534+
| initialValues | 表单默认值 | 否 | `object` | - |
534535
| footer | 页脚 | 否 | `React.ReactNode` | `true` |
535536
| bg | 页面背景图,可以`require('./image.png')`或者是图片链接 | 否 | `string` | - |
536537
| logo | logo头像, 值为`null` 不显示logo | 否 | `string` | - |
537538
| children | 替换卡片位置内容 | 否 | `React.ReactNode` | - |
538539
| projectName | 项目名称(页面标题) 如果值为`null` 不显示标题 | 否 | `string\|null` | `UIW Admin` |
539540
| btnProps | 登录按钮属性 | 否 | `Omit<ButtonProps, 'ref'>` | `{}` |
540541
| buttons | 登录按钮位置的自定义按钮组, title 为显示标题 | 否 | `(Omit<ButtonProps, 'ref'> & { title?: React.ReactNode })[]` | - |
541-
| onSuccess | 登录接口返回 | 是 | `(resp: any, form: (FormValue \| undefined)) => void` | `()=>null` |
542-
| onBefore | 用接口之前 , 可以通过这个添加额外参数 返回 false 则不进行登录操作 | 否 | `(store: FormValue) => (Record<string, any> \| boolean)` | - |
543542
| requestConfig | `request` 请求 `options` 配置参数 | 否 | `Options` | - |
544543
| saveField | 默认输入框保存字段 | 否 | `{userName(登录账号字段)?:string,passWord(密码字段)?:string}` | `{userName:"username",passWord:"password"}` |
545544
| defaultFieldsConfig | 默认输入框保存字段 | 否 | `{userName(账户输入框)?:Partial<FieldsProps>,passWord(密码输入框)?:Partial<FieldsProps>}` | - |
@@ -550,6 +549,8 @@ export interface UserLoginProps {
550549
| classNameBody | 卡片框`className` | 否 | `string` | - |
551550
| styleBody | 卡片框`style` | 否 | `React.CSSProperties` | - |
552551
| styleContainer | 背景框`style` 可再次调整背景图样式 | 否 | `React.CSSProperties` | - |
552+
| onSuccess | 登录接口返回 | 是 | `(resp: any, form: (FormValue \| undefined)) => void` | `()=>null` |
553+
| onBefore | 用接口之前 , 可以通过这个添加额外参数 返回 false 则不进行登录操作 | 否 | `(store: FormValue) => (Record<string, any> \| boolean)` | - |
553554
554555
```tsx
555556
export interface FieldsProps<T = any> extends FormFieldsProps<T> {

packages/user-login/src/index.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ export interface UserLoginProps {
6767
/** 密码 */
6868
passWord?: string;
6969
};
70+
initialValues?: any;
7071
/** 默认 输入框 属性配置 */
7172
defaultFieldsConfig?: {
7273
userName?: Partial<FieldsProps>;
@@ -100,6 +101,7 @@ const Login = (props: UserLoginProps) => {
100101
buttons,
101102
saveField,
102103
fields,
104+
initialValues = {},
103105
isDefaultFields = true,
104106
defaultFieldsConfig,
105107
styleContainer = {},
@@ -131,6 +133,7 @@ const Login = (props: UserLoginProps) => {
131133
label: `${userNameLabel}`,
132134
labelFor: userName,
133135
required: true,
136+
initialValue: initialValues && initialValues[userName],
134137
children: (
135138
<input
136139
type="text"
@@ -147,6 +150,7 @@ const Login = (props: UserLoginProps) => {
147150
label: `${passWordLabel}`,
148151
labelFor: passWord,
149152
required: true,
153+
initialValue: initialValues && initialValues[passWord],
150154
children: (
151155
<input
152156
disabled={!!isLoading}

0 commit comments

Comments
 (0)