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
shenshaokai
jinfa-platform
Commits
f6cde94d
Commit
f6cde94d
authored
Mar 24, 2021
by
GuanHua
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: 渠道商城搜索历史保存和提示
parent
ea52d975
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
57 additions
and
4 deletions
+57
-4
index.less
src/pages/lxMall/components/ChannelHeader/index.less
+13
-2
index.tsx
src/pages/lxMall/components/ChannelHeader/index.tsx
+44
-1
index.tsx
src/pages/lxMall/components/Header/index.tsx
+0
-1
No files found.
src/pages/lxMall/components/ChannelHeader/index.less
View file @
f6cde94d
...
...
@@ -61,12 +61,23 @@
.mall_search_input {
display: inline-block;
width: 5
21
px;
width: 5
10
px;
height: 36px;
line-height: 36px;
outline: none;
border: none;
text-indent: 12px;
box-shadow: none;
:global {
.ant-input {
border: none;
&:active,
&:focus {
box-shadow: none;
}
}
}
}
.search_btn {
...
...
src/pages/lxMall/components/ChannelHeader/index.tsx
View file @
f6cde94d
import
React
,
{
useState
,
useEffect
}
from
'react'
import
{
history
}
from
'umi'
import
{
Input
}
from
'antd'
import
{
Input
,
AutoComplete
}
from
'antd'
import
{
GetTemplateWebMemberChannelWebMemberChannelMainResponse
}
from
'@/services/TemplateApi'
import
isEmpty
from
'lodash/isEmpty'
import
styles
from
'./index.less'
...
...
@@ -18,6 +18,7 @@ interface HeaderPropsType {
const
Header
:
React
.
FC
<
HeaderPropsType
>
=
(
props
)
=>
{
const
{
id
,
shopUrlParam
,
shopInfo
,
type
}
=
props
const
[
searchValue
,
setSearchValue
]
=
useState
<
string
>
(
""
)
const
[
options
,
setOptions
]
=
useState
<
{
value
:
string
}[]
>
([])
const
{
search
}
=
history
.
location
.
query
useEffect
(()
=>
{
...
...
@@ -29,15 +30,32 @@ const Header: React.FC<HeaderPropsType> = (props) => {
},
[
search
])
const
handleSearchCommodity
=
()
=>
{
if
(
!
isEmpty
(
searchValue
))
{
let
key
=
'ChannelSearchHistory'
switch
(
type
)
{
case
LAYOUT_TYPE
.
channel
:
history
.
push
(
`
${
GlobalConfig
.
channelRootRoute
}
/commodity/search?channelId=
${
shopUrlParam
}
&search=
${
encodeURIComponent
(
searchValue
)}
`
)
break
case
LAYOUT_TYPE
.
ichannel
:
key
=
'iChannelSearchHistory'
history
.
push
(
`
${
GlobalConfig
.
ichannelRootRoute
}
/commodity/search?channelId=
${
shopUrlParam
}
&search=
${
encodeURIComponent
(
searchValue
)}
`
)
break
}
const
storageHistory
=
localStorage
.
getItem
(
key
)
let
newSearchHistory
:
{
value
:
string
}[]
=
[]
if
(
storageHistory
)
{
const
searchHistory
:
{
value
:
string
}[]
=
JSON
.
parse
(
storageHistory
)
if
(
searchHistory
.
every
((
item
)
=>
item
.
value
!==
searchValue
))
{
newSearchHistory
=
[...
searchHistory
,
{
value
:
searchValue
}]
}
else
{
newSearchHistory
=
[...
searchHistory
]
}
}
else
{
newSearchHistory
=
[{
value
:
searchValue
}]
}
setOptions
(
newSearchHistory
)
localStorage
.
setItem
(
key
,
JSON
.
stringify
(
newSearchHistory
))
}
else
{
switch
(
type
)
{
case
LAYOUT_TYPE
.
channel
:
...
...
@@ -50,6 +68,23 @@ const Header: React.FC<HeaderPropsType> = (props) => {
}
}
const
onSelect
=
(
data
:
string
)
=>
{
setSearchValue
(
data
)
}
const
handleSearch
=
(
searchText
:
string
)
=>
{
let
key
=
'ChannelSearchHistory'
if
(
type
===
LAYOUT_TYPE
.
ichannel
)
{
key
=
'iChannelSearchHistory'
}
const
storageHistory
=
localStorage
.
getItem
(
key
)
if
(
storageHistory
)
{
const
searchHistory
:
{
value
:
string
}[]
=
JSON
.
parse
(
storageHistory
)
const
result
=
searchHistory
.
filter
((
item
)
=>
item
.
value
.
indexOf
(
searchText
)
>
-
1
)
setOptions
(
result
)
}
}
return
(
<
div
className=
{
styles
.
header
}
>
<
div
className=
{
styles
.
header_container
}
>
...
...
@@ -60,7 +95,15 @@ const Header: React.FC<HeaderPropsType> = (props) => {
</
div
>
<
div
className=
{
styles
.
mall_search
}
>
<
div
className=
{
styles
.
mall_search_box
}
>
<
AutoComplete
className=
{
styles
.
mall_search_input
}
value=
{
searchValue
}
options=
{
options
}
onSelect=
{
onSelect
}
onSearch=
{
handleSearch
}
>
<
Input
className=
{
styles
.
mall_search_input
}
value=
{
searchValue
}
placeholder=
"请输入关键词"
onChange=
{
e
=>
setSearchValue
(
e
.
target
.
value
)
}
onPressEnter=
{
()
=>
handleSearchCommodity
()
}
/>
</
AutoComplete
>
<
div
className=
{
styles
.
search_btn
}
onClick=
{
()
=>
handleSearchCommodity
()
}
>
搜索
</
div
>
</
div
>
</
div
>
...
...
src/pages/lxMall/components/Header/index.tsx
View file @
f6cde94d
...
...
@@ -95,7 +95,6 @@ const Header: React.FC<HeaderPropsType> = (props) => {
}
const
handleSearch
=
(
searchText
:
string
)
=>
{
console
.
log
(
searchText
,
"searchText"
)
const
param
=
{
name
:
searchText
}
...
...
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