Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
mr-julyedu
Overview
Overview
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
baiguangyao
mr-julyedu
Commits
2c5d5fe4
Commit
2c5d5fe4
authored
Jun 13, 2019
by
zhanghaozhe
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
search
parent
fd5a59a5
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
143 additions
and
72 deletions
+143
-72
src/common/VList/index.js
+1
-1
src/components/search/index.js
+37
-15
src/components/search/index.scss
+35
-25
src/components/search/search-result.js
+40
-5
src/components/search/searchHead.js
+18
-25
src/utils/index.js
+12
-1
No files found.
src/common/VList/index.js
View file @
2c5d5fe4
...
...
@@ -3,7 +3,7 @@ import './index.scss'
const
VList
=
(
props
)
=>
{
return
(
<
li
className
=
'v-list-item'
onClick
=
{
e
=>
props
.
handleClick
(
props
.
id
)}
>
<
li
className
=
'v-list-item'
onClick
=
{
e
=>
props
.
handleClick
(
props
.
id
)}
>
<
div
className
=
"content"
>
<
div
className
=
"cover"
>
{
props
.
status
}
...
...
src/components/search/index.js
View file @
2c5d5fe4
...
...
@@ -7,13 +7,12 @@ import { Link } from 'react-router-dom'
class
Search
extends
PureComponent
{
constructor
(
props
)
{
super
(
props
);
this
.
state
=
{
history
:
JSON
.
parse
(
localStorage
.
getItem
(
'history'
))
||
[],
state
=
{
searchHistory
:
JSON
.
parse
(
localStorage
.
getItem
(
'searchHistory'
))
||
[],
hot_words
:
[],
searchList
:
[]
}
searchList
:
[],
value
:
''
}
async
componentDidMount
()
{
...
...
@@ -29,21 +28,43 @@ class Search extends PureComponent {
}
clearHistory
=
()
=>
{
localStorage
.
setItem
(
'searchHistory'
,
null
)
this
.
setState
({
searchHistory
:
[]
})
}
handleChange
=
value
=>
{
this
.
setState
({
value
})
}
handleSearch
=
()
=>
{
this
.
props
.
history
.
push
(
`/search-result?word=
${
encodeURIComponent
(
this
.
state
.
value
)}
`
)
}
render
()
{
let
querystring
=
this
.
props
.
location
.
query
?
this
.
props
.
location
.
query
.
s
:
''
;
const
{
searchHistory
}
=
this
.
state
return
(
<
div
className
=
"search-page"
>
<
SearchHead
value
=
{
querystring
}
returnbtn
=
{
true
}
/
>
<
SearchHead
searchHistory
=
{
this
.
state
.
searchHistory
}
clearHistory
=
{
this
.
clearHistory
}
value
=
{
this
.
state
.
value
}
handleChange
=
{
this
.
handleChange
}
handleSearch
=
{
this
.
handleSearch
}
/
>
<
div
className
=
"search-main"
>
<
div
className
=
"search-land
search-history
"
>
<
label
>
<
div
className
=
"search-land"
>
<
div
className
=
'search-history'
>
<
span
>
最近搜索
<
/span
>
<
i
className
=
"iconfont iconiconfront-56"
/>
<
/
label
>
<
i
className
=
"iconfont iconiconfront-56"
onClick
=
{
this
.
clearHistory
}
/
>
<
/
div
>
<
div
className
=
"search-tag"
>
{
this
.
state
.
h
istory
.
length
>
0
?
this
.
state
.
h
istory
.
map
((
v
,
i
)
=>
{
searchH
istory
.
length
>
0
?
searchH
istory
.
map
((
v
,
i
)
=>
{
return
(
<
Tag
key
=
{
i
}
>
{
v
}
<
/Tag>
)
})
:
<
div
style
=
{{
textAlign
:
'center'
,
padding
:
'20px'
}}
>
暂无历史
<
/div
>
...
...
@@ -58,8 +79,9 @@ class Search extends PureComponent {
{
this
.
state
[
'hot_words'
].
length
>
0
?
this
.
state
[
'hot_words'
].
map
((
v
,
i
)
=>
{
console
.
log
(
encodeURIComponent
(
v
));
return
(
<
Link
key
=
{
i
}
to
=
{
`/search-result?word=
${
v
}
`
}
>
<
Link
key
=
{
i
}
to
=
{
`/search-result?word=
${
encodeURIComponent
(
v
)
}
`
}
>
<
Tag
>
{
v
}
<
/Tag
>
<
/Link
>
)
...
...
src/components/search/index.scss
View file @
2c5d5fe4
.search-page
{
.search-main
{
.search-page
{
.search-main
{
background-color
:
#fff
;
padding
:
10px
;
.search-land
{
label
{
margin-bottom
:
10px
;
padding
:
10px
;
.search-land
{
.search-history
{
margin-bottom
:
10px
;
display
:
flex
;
justify-content
:
space-between
;
span
{
font-size
:
16px
;
}
img
{
width
:
16px
;
height
:
16px
;
span
{
font-size
:
16px
;
}
img
{
width
:
16px
;
height
:
16px
;
display
:
block
;
}
}
.search-tag
{
.search-tag
{
overflow
:
hidden
;
}
}
.search-hot
{
margin-top
:
10px
;
.search-hot
{
margin-top
:
10px
;
}
ul
,
li
{
ul
,
li
{
list-style
:
none
;
padding
:
0
;
margin
:
0
;
padding
:
0
;
margin
:
0
;
}
.list
{
padding
:
10px
0
;
border-bottom
:
1px
solid
#eee
;
.list
{
padding
:
10px
0
;
border-bottom
:
1px
solid
#eee
;
}
.list
:last-child
{
border-bottom
:
0
;
.list
:last-child
{
border-bottom
:
0
;
}
}
.searct-lists
{
padding
:
0
10px
;
.searct-lists
{
padding
:
0
10px
;
}
}
\ No newline at end of file
src/components/search/search-result.js
View file @
2c5d5fe4
...
...
@@ -17,28 +17,61 @@ const Bottom = ({item}) => {
class
SearchResult
extends
PureComponent
{
state
=
{
courseList
:
[]
courseList
:
[],
value
:
''
,
searchHistory
:
JSON
.
parse
(
localStorage
.
getItem
(
'searchHistory'
))
||
[]
}
componentDidMount
()
{
http
.
get
(
`
${
api
[
'search-api'
]}
/search/
${
encodeURIComponent
(
getParam
(
'word'
))}
?type=course&page=1`
)
this
.
getCourses
(
getParam
(
'word'
))
}
getCourses
=
(
word
)
=>
{
http
.
get
(
`
${
api
[
'search-api'
]}
/search/
${
word
}
?type=course&page=1`
)
.
then
(
res
=>
{
const
data
=
res
.
data
if
(
data
.
errno
===
0
)
{
this
.
setState
({
courseList
:
data
.
data
.
info
.
search_data
.
course
courseList
:
data
.
data
.
info
[
'search_data'
]
.
course
});
}
})
}
handleClick
=
id
=>
{
this
.
props
.
history
.
push
(
`/detail?id=
${
id
}
`
)
}
handleSearch
=
()
=>
{
this
.
getCourses
(
this
.
state
.
value
)
}
handleChange
=
value
=>
{
this
.
setState
({
value
})
}
clearHistory
=
()
=>
{
localStorage
.
setItem
(
'searchHistory'
,
null
)
this
.
setState
({
searchHistory
:
[]
})
}
render
()
{
const
{
courseList
}
=
this
.
state
return
(
<
div
className
=
'search-result'
>
<
SearchHeader
/>
<
SearchHeader
handleSearch
=
{
this
.
handleSearch
}
value
=
{
this
.
state
.
value
}
handleChange
=
{
this
.
handleChange
}
searchHistory
=
{
this
.
state
.
searchHistory
}
clearHistory
=
{
this
.
clearHistory
}
/
>
<
ul
>
{
...
...
@@ -57,7 +90,9 @@ class SearchResult extends PureComponent {
<
VList
img
=
{
item
.
image_name
}
handleClick
=
{
this
.
handleClick
}
key
=
{
item
.
course_id
}
info
=
{
Info
}
/
>
info
=
{
Info
}
id
=
{
item
[
'course_id'
]}
/
>
)
})
:
null
}
...
...
src/components/search/searchHead.js
View file @
2c5d5fe4
...
...
@@ -5,53 +5,46 @@ import { withRouter } from 'react-router-dom'
import
'./search_header.scss'
class
SearchHead
extends
PureComponent
{
constructor
(
props
)
{
super
(
props
);
this
.
state
=
{
visible
:
false
,
selected
:
''
,
val
:
this
.
props
.
value
||
''
}
}
// 返回某个页面
returnPage
()
{
returnPage
=
()
=>
{
this
.
props
.
history
.
go
(
-
1
)
}
//组件装载完毕
componentDidMount
()
{
this
.
refs
.
search
.
focus
();
}
search
=
()
=>
{
this
.
storeKeyword
()
this
.
props
.
handleSearch
()
}
storeKeyword
=
()
=>
{
let
searchHistory
=
this
.
props
.
searchHistory
||
[]
localStorage
.
setItem
(
'searchHistory'
,
JSON
.
stringify
([...
searchHistory
,
this
.
props
.
value
]))
}
render
()
{
return
(
<
div
className
=
"search-head"
>
<
div
className
=
"left"
onClick
=
{()
=>
{
// 返回某个页面
this
.
returnPage
()
}}
>
<
i
className
=
"iconfont iconiconfront-68"
/>
<
div
className
=
"left"
onClick
=
{
this
.
returnPage
}
>
<
i
className
=
"iconfont iconiconfront-68"
onClick
=
{
this
.
props
.
clearHistory
}
/
>
<
/div
>
<
div
className
=
"center"
>
<
SearchBar
value
=
{
this
.
state
.
val
}
value
=
{
this
.
props
.
value
}
showCancelButton
cancelText
=
{
" "
}
ref
=
"search"
focus
=
{
true
}
onChange
=
{(
val
)
=>
{
this
.
setState
({
val
})
this
.
props
.
search
.
changeVal
(
val
)
}}
onChange
=
{
this
.
props
.
handleChange
}
placeholder
=
"搜索课程"
/>
<
/div
>
<
div
className
=
"right right-btn"
>
<
div
className
=
"submit-btn"
>
搜索
<
div
className
=
"right right-btn"
onClick
=
{
this
.
search
}
>
<
div
className
=
"submit-btn"
>
搜索
<
/div
>
<
/div
>
<
/div
>
...
...
src/utils/index.js
View file @
2c5d5fe4
export
{
default
as
http
}
from
'./http'
export
{
default
as
api
}
from
'./api'
export
{
html
,
initCaptcha
}
export
{
html
,
initCaptcha
,
browser
}
export
const
getParam
=
(
key
,
str
)
=>
{
...
...
@@ -69,3 +69,13 @@ export const is_weixin = () => {
}
return
false
;
}
const
browser
=
(
function
()
{
const
ua
=
navigator
.
userAgent
return
{
isWeixin
:
/MicroMessenger/i
.
test
(
ua
),
isAndroid
:
/Android/i
.
test
(
ua
),
isIOS
:
/
\(
i
[^
;
]
+;
(
U;
)?
CPU.+Mac OS X/i
.
test
(
ua
),
isIPad
:
/iPad/i
.
test
(
ua
)
}
})()
\ 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