@gm-pc/react 1.24.7-beta.6 → 1.24.7-beta.8

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gm-pc/react",
3
- "version": "1.24.7-beta.6",
3
+ "version": "1.24.7-beta.8",
4
4
  "description": "观麦前端基础组件库",
5
5
  "author": "liyatang <liyatang@qq.com>",
6
6
  "homepage": "https://github.com/gmfe/gm-pc#readme",
@@ -24,7 +24,7 @@
24
24
  "dependencies": {
25
25
  "@gm-common/hooks": "^2.10.0",
26
26
  "@gm-common/tool": "^2.10.0",
27
- "@gm-pc/locales": "^1.24.7-beta.6",
27
+ "@gm-pc/locales": "^1.24.7-beta.8",
28
28
  "big.js": "^6.0.1",
29
29
  "classnames": "^2.2.5",
30
30
  "lodash": "^4.17.19",
@@ -48,5 +48,5 @@
48
48
  "react-router-dom": "^5.2.0",
49
49
  "react-window": "^1.8.5"
50
50
  },
51
- "gitHead": "c762f1339236ce80bc519f8acf1d6d7f9f00cc52"
51
+ "gitHead": "3f0df53aec9bd33fac253c45126a45826e7364e6"
52
52
  }
@@ -1,4 +1,4 @@
1
- import React, { FC } from 'react'
1
+ import React, { FC, useState } from 'react'
2
2
  import { DialogProps, DialogStatic } from './types'
3
3
  import { getLocale } from '@gm-pc/locales'
4
4
  import _ from 'lodash'
@@ -15,6 +15,7 @@ const Dialog: FC<DialogProps> & DialogStatic = ({
15
15
  onHide = () => Dialog.hide(),
16
16
  children,
17
17
  }) => {
18
+ const [loading, setLoading] = useState(false)
18
19
  return (
19
20
  <Modal
20
21
  title={title}
@@ -26,20 +27,28 @@ const Dialog: FC<DialogProps> & DialogStatic = ({
26
27
  <div>{children}</div>
27
28
  {buttons && (
28
29
  <Flex justifyEnd className='gm-dialog-buttons gm-margin-top-10'>
29
- {_.map(buttons, (btn) => (
30
- <Button
31
- loading={btn.loading}
32
- key={btn.text}
33
- type={btn.btnType}
34
- disabled={btn.disabled}
35
- onClick={() => {
36
- btn.onClick()
37
- }}
38
- className='gm-margin-left-10'
39
- >
40
- {btn.text}
41
- </Button>
42
- ))}
30
+ {_.map(buttons, (btn) => {
31
+ const isPrimary = btn.btnType === 'primary' || btn.btnType === 'danger'
32
+
33
+ return (
34
+ <Button
35
+ loading={btn.loading || (isPrimary && loading)}
36
+ key={btn.text}
37
+ type={btn.btnType}
38
+ disabled={btn.disabled}
39
+ onClick={() => {
40
+ setLoading(true)
41
+ // console.log('btn.onClick', btn.onClick())
42
+ Promise.resolve(btn.onClick()).finally(() => {
43
+ setLoading(false)
44
+ })
45
+ }}
46
+ className='gm-margin-left-10'
47
+ >
48
+ {btn.text}
49
+ </Button>
50
+ )
51
+ })}
43
52
  </Flex>
44
53
  )}
45
54
  </Modal>
@@ -129,10 +129,17 @@ const FormGroup: FC<FormGroupProps> = ({
129
129
  export default FormGroup
130
130
 
131
131
  type ActionProps = Omit<FormGroupProps, 'formRefs' | 'onSubmitValidated' | 'onSubmit'> & {
132
- onSubmit?(event: BaseSyntheticEvent): void
132
+ onSubmit?(event: BaseSyntheticEvent): Promise<void> | void
133
133
  }
134
134
 
135
135
  const Action: FC<ActionProps> = ({ onCancel, onSubmit, disabled, saveText, actions }) => {
136
+ const [loading, setLoading] = useState(false)
137
+
138
+ const handleClick = (e: BaseSyntheticEvent) => {
139
+ setLoading(true)
140
+ Promise.resolve(onSubmit?.(e)).finally(() => setLoading(false))
141
+ }
142
+
136
143
  return (
137
144
  <>
138
145
  {onCancel && (
@@ -141,7 +148,7 @@ const Action: FC<ActionProps> = ({ onCancel, onSubmit, disabled, saveText, actio
141
148
  <div className='gm-gap-10' />
142
149
  </>
143
150
  )}
144
- <Button type='primary' disabled={disabled} onClick={onSubmit}>
151
+ <Button type='primary' disabled={disabled} loading={loading} onClick={handleClick}>
145
152
  {saveText || getLocale('确定')}
146
153
  </Button>
147
154
  {actions}