Toggle navigation
Toggle navigation
This project
Loading...
Sign in
fe
/
yohobuy-node
·
Commits
Go to a project
GitLab
Go to group
Project
Activity
Files
Commits
Pipelines
0
Builds
0
Graphs
Milestones
Issues
1
Merge Requests
0
Members
Labels
Wiki
Forks
Network
Create a new issue
Download as
Email Patches
Plain Diff
Browse Files
Authored by
OF1706
8 years ago
Commit
6f62ff5ff9fb3234991d3ea245f851b7844e6ca1
1 parent
921193eb
searchTerms sum
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
63 additions
and
21 deletions
apps/product/controllers/search.js
apps/product/models/search-api.js
apps/product/models/search.js
doraemon/views/partial/header.hbs
public/js/header.js
apps/product/controllers/search.js
View file @
6f62ff5
...
...
@@ -118,14 +118,17 @@ const serachFilterBrands = (req, res, next) => {
const
searchHistory
=
(
req
,
res
)
=>
{
let
history
=
req
.
cookies
[
'_History'
];
let
q
=
req
.
query
.
query
||
''
;
let
history
=
_
.
trim
(
req
.
cookies
[
'_History'
]);
let
q
=
_
.
trim
(
decodeURIComponent
(
req
.
query
.
query
)
||
''
);
history
=
history
?
history
.
split
(
','
)
:
[];
history
=
_
.
reject
(
history
,
old
=>
old
===
q
?
true
:
false
);
history
.
unshift
(
q
);
res
.
cookie
(
'_History'
,
_
.
take
(
history
,
9
).
join
(
','
),
{
if
(
q
!=
''
){
history
.
unshift
(
q
);
}
res
.
cookie
(
'_History'
,
_
.
take
(
history
,
9
).
join
(
','
),
{
domain
:
config
.
cookieDomain
,
maxAge
:
60
*
60
*
24
*
1000
*
30
// 一月
});
...
...
@@ -153,7 +156,7 @@ const searchHistory = (req, res) => {
* @return {[type]} [description]
*/
const
searchRecommend
=
(
req
,
res
,
next
)
=>
{
search
.
getSearchRecommend
(
req
.
query
).
then
(
result
=>
{
search
.
getSearchRecommend
(
req
.
yoho
.
channel
,
req
.
query
).
then
(
result
=>
{
if
(
req
.
query
.
json
===
'1'
)
{
return
res
.
send
(
result
);
...
...
@@ -162,7 +165,7 @@ const searchRecommend = (req, res, next) => {
let
dest
=
{
code
:
200
,
message
:
'recommend'
,
data
:
result
||
''
data
:
result
||
''
,
};
res
.
type
(
'text/javascript'
);
...
...
apps/product/models/search-api.js
View file @
6f62ff5
...
...
@@ -424,11 +424,12 @@ const getBrands4Filter = (params) => {
* 搜索 热门搜索和默认搜索
* @return
*/
const
getSearchRecommend
=
(
params
)
=>
{
const
getSearchRecommend
=
(
channel
,
params
)
=>
{
let
finalParams
=
{
method
:
'app.search.getTerms'
,
content
:
params
.
content
||
''
,
yh_channel
:
channel
,
sort
:
params
.
sort
,
status
:
params
.
status
,
type
:
params
.
type
...
...
apps/product/models/search.js
View file @
6f62ff5
...
...
@@ -192,10 +192,30 @@ exports.getBrands4Filter = (params) => {
* @param {[type]} origin [description]
* @return {[type]} [description]
*/
exports
.
getSearchRecommend
=
(
params
)
=>
{
return
searchApi
.
getSearchRecommend
(
params
).
then
(
result
=>
{
exports
.
getSearchRecommend
=
(
channel
,
params
)
=>
{
return
searchApi
.
getSearchRecommend
(
channel
,
params
).
then
(
result
=>
{
if
(
result
.
code
===
200
)
{
let
channelNum
=
1
;
switch
(
channel
)
{
case
'boys'
:
channelNum
=
1
;
break
;
case
'girls'
:
channelNum
=
2
;
break
;
case
'kids'
:
channelNum
=
3
;
break
;
case
'lifestyle'
:
channelNum
=
3
;
break
;
default
:
break
;
}
let
resData
=
{
hotTerms
:
[],
};
...
...
doraemon/views/partial/header.hbs
View file @
6f62ff5
...
...
@@ -97,7 +97,7 @@
<div
class=
"search-2016"
>
<form
action=
"//search.yohobuy.com"
method=
"get"
id=
"search-form"
>
<input
type=
"hidden"
id=
"defaultsearch"
value=
"
{{
defaultSearch
}}
"
>
<input
class=
"search-key"
type=
"text"
name=
"query"
id=
"query-key"
autocomplete=
"off"
x-webkit-speech=
""
lang=
"zh-CN"
x-webkit-grammar=
"builtin:translate"
value=
""
maxlength=
"30"
>
<input
class=
"search-key"
type=
"text"
name=
"query"
id=
"query-key"
autocomplete=
"off"
x-webkit-speech=
""
lang=
"zh-CN"
x-webkit-grammar=
"builtin:translate"
value=
""
maxlength=
"30"
>
<a
class=
"search-btn"
href=
"javascript:submitSearch();"
></a>
</form>
<ul
class=
"search-hot"
>
...
...
@@ -322,7 +322,7 @@
\{{
/
data
}}
</script>
<script
type=
"text/html"
id=
"search-suggest-history"
>
<p class="search-suggest-title">最近搜过<a class="searchDel" href="#">
删除
</a></p>
<p class="search-suggest-title">最近搜过<a class="searchDel" href="#">
清空
</a></p>
\{{#data}}
<li>
<a style="display: block;" href="\{{href}}" class="clearfix clear search-item" title="\{{keyword}}"
...
...
public/js/header.js
View file @
6f62ff5
...
...
@@ -867,15 +867,15 @@ function actionAddKeyWords() {
function
searchSuggestHistory
()
{
let
$queryKey
=
$
(
'#query-key'
);
$
.
getJSON
(
'//search.yohobuy.com/product/search/history?query='
+
$queryKey
.
val
(
),
function
(
jsonData
)
{
$
.
getJSON
(
'//search.yohobuy.com/product/search/history?query='
+
encodeURIComponent
(
$queryKey
.
val
()
),
function
(
jsonData
)
{
var
searchSuggestHistoryHtml
;
searchSuggestHistoryHtml
=
handlebars
.
compile
(
$searchHistoryHbs
.
html
()
||
''
);
$searchHistory
.
html
(
searchSuggestHistoryHtml
(
jsonData
)).
show
();
$
(
".search-suggest-title .searchDel"
).
click
(
function
(){
console
.
log
(
"****&&&&&&&&&&&"
);
window
.
setCookie
(
'_History'
,
''
,{
domain
:
'.yohobuy.com'
});
$
(
this
).
closest
(
'.search-suggest-history'
).
hide
();
return
false
;
});
});
...
...
@@ -885,20 +885,38 @@ function searchSuggestHistory() {
* 搜索 历史记录 dom
* @return {[type]} [description]
*/
$searchKey
.
keydown
(
function
()
{
}).
focus
(
function
()
{
}).
focus
(
function
(
e
)
{
var
val
=
$
.
trim
(
$
(
this
).
val
());
searchSuggestHistory
();
if
(
val
===
''
)
{
if
(
$searchHistory
&&
$searchHistory
.
length
)
{
val
=
val
.
replace
(
new
RegExp
(
'\''
,
'gm'
),
''
);
// 去掉特殊字符
searchSuggestHistory
(
val
);
// if(e.keyCode === 13){
var
val
=
$
.
trim
(
$
(
this
).
val
());
searchSuggestHistory
();
if
(
val
===
''
)
{
if
(
$searchHistory
&&
$searchHistory
.
length
)
{
val
=
val
.
replace
(
new
RegExp
(
'\''
,
'gm'
),
''
);
// 去掉特殊字符
searchSuggestHistory
(
val
);
}
}
}
// }
});
// $searchKey.keydown(function() {
//
// }).focus(function() {
//
// var val = $.trim($(this).val());
// searchSuggestHistory();
// if (val === '') {
// if ($searchHistory && $searchHistory.length) {
// val = val.replace(new RegExp('\'', 'gm'), ''); // 去掉特殊字符
// searchSuggestHistory(val);
// }
// }
// });
/**
* 搜索 热门搜索和默认搜索 api
* @return {[type]} [description]
...
...
Please
register
or
login
to post a comment