Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
J
jinfa-platform
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
黄庭坚
jinfa-platform
Commits
00f04378
Commit
00f04378
authored
Aug 18, 2021
by
XieZhiXiong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: 修复设置默认地址后没有刷新地址列表的问题
parent
bed2cfcb
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
29 additions
and
10 deletions
+29
-10
index.tsx
...ents/AddressSelect/components/AddressRadioGroup/index.tsx
+19
-6
index.tsx
src/components/AddressSelect/index.tsx
+8
-3
interface.ts
src/components/AddressSelect/interface.ts
+2
-1
No files found.
src/components/AddressSelect/components/AddressRadioGroup/index.tsx
View file @
00f04378
...
...
@@ -2,10 +2,10 @@
* @Author: XieZhiXiong
* @Date: 2021-08-05 14:23:40
* @LastEditors: XieZhiXiong
* @LastEditTime: 2021-08-
09 16:53:25
* @LastEditTime: 2021-08-
18 11:04:54
* @Description: 地址单选框组
*/
import
React
,
{
useState
,
useEffect
,
useMemo
}
from
'react'
;
import
React
,
{
useState
,
useEffect
,
useMemo
,
useRef
}
from
'react'
;
import
{
Radio
,
Button
,
Modal
,
message
,
RadioChangeEvent
}
from
'antd'
;
import
{
ExclamationCircleOutlined
}
from
'@ant-design/icons'
;
import
{
PublicApi
}
from
'@/services/api'
;
...
...
@@ -86,6 +86,9 @@ const AddressRadioGroup: React.FC<IProps> = (props) => {
const
context
=
React
.
useContext
(
AddressSelectContext
);
// 记录是否是新增或编辑操作
const
actionFlagRef
=
useRef
<
boolean
>
(
false
);
const
triggerChange
=
(
value
:
AddressValueType
)
=>
{
if
(
onChange
)
{
onChange
(
value
);
...
...
@@ -123,7 +126,7 @@ const AddressRadioGroup: React.FC<IProps> = (props) => {
triggerChange
(
undefined
);
}
if
(
isDefaultAddress
&&
defaultItem
)
{
if
(
isDefaultAddress
&&
defaultItem
&&
!
actionFlagRef
.
current
)
{
const
{
shipperName
,
receiverName
,
...
rest
}
=
defaultItem
;
const
next
=
{
name
:
shipperName
||
receiverName
,
...
...
@@ -141,8 +144,15 @@ const AddressRadioGroup: React.FC<IProps> = (props) => {
});
};
const
refresh
=
()
=>
{
context
?
context
?.
refresh
()
:
getAddressList
();
const
refresh
=
(
actionFlag
?:
boolean
)
=>
{
if
(
context
)
{
context
?.
refresh
(
actionFlag
);
}
{
// 重新获取列表,把新添加的内容加载出来
// 不触发默认值提交
actionFlagRef
.
current
=
true
;
getAddressList
();
}
};
useEffect
(()
=>
{
...
...
@@ -224,7 +234,7 @@ const AddressRadioGroup: React.FC<IProps> = (props) => {
try
{
const
res
=
addressType
===
2
?
await
PublicApi
.
getLogisticsShipperAddressGet
({
id
:
`
${
id
}
`
})
:
await
PublicApi
.
getLogisticsReceiverAddressGet
({
id
:
`
${
id
}
`
});
if
(
res
.
code
===
1000
)
{
addressType
===
2
const
updateRes
=
addressType
===
2
?
await
PublicApi
.
postLogisticsShipperAddressUpdate
({
...(
res
.
data
as
GetLogisticsShipperAddressGetResponse
),
isDefault
:
1
,
...
...
@@ -233,6 +243,9 @@ const AddressRadioGroup: React.FC<IProps> = (props) => {
...(
res
.
data
as
GetLogisticsReceiverAddressGetResponse
),
isDefault
:
1
,
});
if
(
updateRes
.
code
===
1000
)
{
refresh
(
true
);
}
}
}
catch
(
error
)
{
console
.
warn
(
error
);
...
...
src/components/AddressSelect/index.tsx
View file @
00f04378
...
...
@@ -256,7 +256,7 @@ const AddressSelect: React.FC<IProps> = (props) => {
name
:
values
.
name
,
phone
:
values
.
phone
,
};
// 重新获取列表,
打
新添加的内容加载出来
// 重新获取列表,
把
新添加的内容加载出来
// 不触发默认值提交
actionFlagRef
.
current
=
true
;
getAddressList
();
...
...
@@ -295,7 +295,7 @@ const AddressSelect: React.FC<IProps> = (props) => {
name
:
values
.
name
,
phone
:
values
.
phone
,
};
// 重新获取列表,
打
新添加的内容加载出来
// 重新获取列表,
把
新添加的内容加载出来
// 不触发默认值提交
actionFlagRef
.
current
=
true
;
getAddressList
();
...
...
@@ -437,6 +437,11 @@ const AddressSelect: React.FC<IProps> = (props) => {
}
};
const
onRefresh
=
(
actionFlag
?:
boolean
)
=>
{
actionFlagRef
.
current
=
!!
actionFlag
;
getAddressList
();
};
const
options
=
useMemo
(()
=>
{
return
list
.
map
((
item
)
=>
({
value
:
item
.
id
,
...
...
@@ -448,7 +453,7 @@ const AddressSelect: React.FC<IProps> = (props) => {
<
AddressSelectContextProvider
value=
{
{
addressList
:
list
,
refresh
:
getAddressList
,
refresh
:
onRefresh
,
}
}
>
<
div
className=
{
styles
[
'address-select'
]
}
>
...
...
src/components/AddressSelect/interface.ts
View file @
00f04378
...
...
@@ -15,5 +15,5 @@ export interface AddressSelectContextProps {
/**
* 重新加载列表
*/
refresh
:
()
=>
void
,
refresh
:
(
actionFlag
?:
boolean
)
=>
void
,
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment