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
郝肖肖
7 years ago
Commit
aaa51f2c8162f2bc03cc7356694759411d9e9344
1 parent
f467581b
'news-详情页'
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
84 additions
and
119 deletions
apps/news/controllers/index.js
apps/news/models/news-service.js
apps/news/router.js
apps/news/views/action/news-detail.hbs
public/js/news/detail.page.js
public/scss/news/_detail.css
apps/news/controllers/index.js
View file @
aaa51f2
...
...
@@ -27,8 +27,19 @@ exports.index = (req, res, next) => {
*/
exports
.
detail
=
(
req
,
res
,
next
)
=>
{
let
channel
=
req
.
yoho
.
channel
;
let
id
=
req
.
params
[
0
]
||
0
;
let
cid
=
req
.
params
[
1
]
||
0
;
let
query
=
{
channel
:
channel
,
id
:
id
,
cid
:
cid
,
};
req
.
ctx
(
newsService
).
detail
(
channel
,
req
.
query
).
then
(
result
=>
{
if
(
!
id
||
!
cid
)
{
return
next
();
}
req
.
ctx
(
newsService
).
detail
(
channel
,
query
).
then
(
result
=>
{
return
res
.
render
(
'news-detail'
,
Object
.
assign
({
title
:
'新闻详情页 | '
+
(
res
.
locals
.
title
||
''
),
module
:
'news'
,
...
...
apps/news/models/news-service.js
View file @
aaa51f2
...
...
@@ -82,7 +82,7 @@ module.exports = class extends global.yoho.BaseModel {
url
:
helpers
.
urlFormat
(
`
/
news
/
$
{
articleData
.
id
}
_$
{
articleData
.
cid
}.
html
`
),
img
:
helpers
.
image
(
articleData
.
image
,
width
,
height
,
1
),
title
:
articleData
.
title
,
pTime
:
moment
(
articleData
.
update_time
*
1000
).
format
(
'YYYY年MM月DD HH:mm'
),
pTime
:
articleData
.
update_time
&&
moment
(
articleData
.
update_time
*
1000
).
format
(
'YYYY年MM月DD HH:mm'
),
pView
:
articleData
.
views_num
,
content
:
articleData
.
summary
,
isVideo
:
articleData
.
videoUrl
?
true
:
false
...
...
@@ -127,12 +127,12 @@ module.exports = class extends global.yoho.BaseModel {
let
apiMethod
=
[
headerModel
.
requestHeaderData
(
channel
),
newsAPi
.
getPolymerizationList
(
params
),
newsAPi
.
getRecoArticles
(
params
),
newsAPi
.
getAds
({
content_code
:
ADS_CODE
[
channel
]
||
ADS_CODE
.
boys
,
isAdDegrade
:
_
.
get
(
this
.
ctx
,
'req.app.locals.pc.guang.removeAd'
,
false
)
}),
newsAPi
.
getPolymerizationList
(
params
),
];
return
Promise
.
all
(
apiMethod
).
then
(
result
=>
{
...
...
@@ -141,14 +141,14 @@ module.exports = class extends global.yoho.BaseModel {
// 头部数据
Object
.
assign
(
responseData
,
result
[
0
]);
// 列表数据
Object
.
assign
(
responseData
,
this
.
_formatArticle
(
result
[
1
],
params
));
// 获取精彩推荐
Object
.
assign
(
responseData
,
this
.
_formatRecoArticles
(
result
[
2
]));
Object
.
assign
(
responseData
,
this
.
_formatRecoArticles
(
result
[
1
]));
// 获取广告数据
Object
.
assign
(
responseData
,
this
.
_formatAds
(
result
[
3
]));
Object
.
assign
(
responseData
,
this
.
_formatAds
(
result
[
2
]));
// 列表数据
Object
.
assign
(
responseData
,
this
.
_formatArticle
(
result
[
3
],
params
));
// 导航pathNav
Object
.
assign
(
responseData
,
this
.
getPathNav
(
channel
));
...
...
@@ -157,29 +157,54 @@ module.exports = class extends global.yoho.BaseModel {
});
}
_formatDetail
(
rdata
)
{
let
contents
=
_
.
get
(
rdata
,
'data.contents'
,
{});
let
header
=
{
title
:
contents
.
title
,
time
:
contents
.
update_time
&&
moment
(
contents
.
update_time
*
1000
).
format
(
'YYYY年MM月DD HH:mm'
),
};
return
{
header
:
header
,
content
:
contents
.
content
};
}
detail
(
channel
,
param
)
{
let
params
=
{
id
:
param
.
id
||
20735
,
cid
:
param
.
cid
||
11893
id
:
param
.
id
,
cid
:
param
.
cid
};
let
newsAPi
=
new
NewsAPi
(
this
.
ctx
);
let
apiMethod
=
[
headerModel
.
requestHeaderData
(
channel
),
new
NewsAPi
(
this
.
ctx
).
getContentDetail
(
params
)
newsAPi
.
getRecoArticles
(
params
),
newsAPi
.
getAds
({
content_code
:
ADS_CODE
[
channel
]
||
ADS_CODE
.
boys
,
isAdDegrade
:
_
.
get
(
this
.
ctx
,
'req.app.locals.pc.guang.removeAd'
,
false
)
}),
newsAPi
.
getContentDetail
(
params
)
];
return
Promise
.
all
(
apiMethod
).
then
(
result
=>
{
let
responseData
=
{};
// 头部数据
Object
.
assign
(
responseData
,
result
[
0
]);
// 获取精彩推荐
Object
.
assign
(
responseData
,
this
.
_formatRecoArticles
(
result
[
1
]));
// 获取广告数据
Object
.
assign
(
responseData
,
this
.
_formatAds
(
result
[
2
]));
// 列表数据
Object
.
assign
(
responseData
,
this
.
_formatDetail
(
result
[
3
],
params
));
// 导航pathNav
Object
.
assign
(
responseData
,
this
.
getPathNav
(
channel
,
[{
href
:
helpers
.
urlFormat
(
'/news'
),
name
:
'新闻详情页'
,
pathTitle
:
'新闻详情页'
name
:
_
.
get
(
responseData
,
'header.title'
,
'新闻详情页'
),
pathTitle
:
_
.
get
(
responseData
,
'header.title'
,
'新闻详情页'
)
}]));
// 头部数据
Object
.
assign
(
responseData
,
result
[
0
]);
return
responseData
;
});
}
...
...
apps/news/router.js
View file @
aaa51f2
...
...
@@ -12,7 +12,7 @@ const cRoot = './controllers';
const
newsController
=
require
(
`
$
{
cRoot
}
/index`
)
;
router
.
get
([
'/'
,
'/index/index'
],
newsController
.
index
);
router
.
get
(
/
^
\/
news
\/([\d]
+
)
_
([\d]
+
)
.html/
,
newsController
.
detail
);
router
.
get
(
/
\/([\d]
+
)
_
([\d]
+
)
.html/
,
newsController
.
detail
);
// ajax
...
...
apps/news/views/action/news-detail.hbs
View file @
aaa51f2
...
...
@@ -4,112 +4,35 @@
{{#
header
}}
<h1
class=
"detail-title"
>
{{
title
}}
</h1>
<div
class=
"article-info clearfix"
>
<div
class=
"article-author"
>
<div
class=
"author-avatar"
>
<a
href=
"
{{
authorUrl
}}
"
target=
"_blank"
>
<img
src=
"
{{
image2
avatar
}}
"
>
</a>
{{#if
authorUrl
}}
<div
class=
"article-author"
>
<div
class=
"author-avatar"
>
<a
href=
"
{{
authorUrl
}}
"
target=
"_blank"
>
<img
src=
"
{{
image2
avatar
}}
"
>
</a>
</div>
</div>
</div>
<div
class=
"author-info"
>
<a
class=
"author-name"
href=
"
{{
authorUrl
}}
"
>
{{
name
}}
</a>
</div>
<div
class=
"author-info"
>
<a
class=
"author-name"
href=
"
{{
authorUrl
}}
"
>
{{
name
}}
</a>
</div>
{{/if}}
<div
class=
"article-status clearfix"
>
<span
class=
"article-time"
>
{{
time
}}
</span>
<span
class=
"article-click"
>
点击:
<em>
{{
click
}}
</em></span>
<a
href=
"#comment-info"
id=
"article-comment"
class=
"article-comment"
><em
class=
"comment-num"
>
{{
commentNum
}}
</em>
条评论
</a>
<span
class=
"article-time"
>
<i
class=
"iconfont"
>

</i>
{{
time
}}
</span>
{{#if
click
}}
<span
class=
"article-click"
>
点击:
<em>
{{
click
}}
</em></span>
{{/if}}
{{#if
commentNum
}}
<a
href=
"#comment-info"
id=
"article-comment"
class=
"article-comment"
><em
class=
"comment-num"
>
{{
commentNum
}}
</em>
条评论
</a>
{{/if}}
</div>
</div>
{{/
header
}}
<div
class=
"article-main"
>
{{#
content
}}
{{#
video
}}
<div
class=
"article-video block"
>
{{{
.
}}}
</div>
{{/
video
}}
{{#
pic
}}
<div
class=
"article-pic block"
>
<img
class=
"lazy"
data-original=
"
{{
image2
.
}}
"
>
</div>
{{/
pic
}}
{{#
text
}}
<div
class=
"article-text block"
>
<p>
{{{
.
}}}
</p>
</div>
{{/
text
}}
{{#if
smallPic
}}
<div
class=
"article-small-pic block clearfix"
>
{{#
smallPic
}}
<img
class=
"lazy"
data-original=
"
{{
image2
.
}}
"
>
{{/
smallPic
}}
</div>
{{/if}}
{{#
relatedReco
}}
<div
class=
"related-reco block clearfix"
>
<div
class=
"block-header"
>
相关推荐
{{#
moreReco
}}
<a
class=
"more-reco"
href=
"
{{
.
}}
"
>
MORE >
</a>
{{/
moreReco
}}
</div>
<div
class=
"recos clearfix"
>
{{#
recos
}}
{{>
product
/
good
}}
{{/
recos
}}
</div>
</div>
{{/
relatedReco
}}
{{/
content
}}
</div>
{{#if
brands
}}
<div
class=
"related-brand block clearfix"
>
<div
class=
"block-header"
>
相关品牌
</div>
<div
class=
"brands"
>
{{#
brands
}}
<div
class=
"brand"
>
<a
class=
"thumb"
href=
"
{{
url
}}
"
target=
"_blank"
>
<img
class=
"lazy"
data-original=
"
{{
image2
thumb
}}
"
>
</a>
<p
class=
"brand-name"
>
{{
name
}}
</p>
</div>
{{/
brands
}}
</div>
</div>
{{/if}}
{{#
userInfo
}}
<div
class=
"user-handle"
>
<ul
class=
"clearfix"
>
<li
id=
"prise-btn"
class=
"like-status
{{#
isLike
}}
liked
{{/
isLike
}}
"
>
<a
href=
"javascript:;"
>
<i
class=
"iconfont"
>

</i>
<span
class=
"like-num"
>
{{
likeNum
}}
</span>
</a>
</li>
<li
id=
"collect-btn"
class=
"sort-collect
{{#
isCollected
}}
collected
{{/
isCollected
}}
"
>
<a
href=
"javascript:;"
>
<i
class=
"iconfont"
>

</i>
<span>
收藏
</span>
<span
class=
"cancel-collect"
>
取消收藏
</span>
</a>
</li>
</ul>
</div>
{{/
userInfo
}}
<div
class=
"article-bottom-info clearfix"
>
{{#if
tag
}}
<div
class=
"article-tag clearfix"
>
<i
class=
"tag-icon iconfont"
>

</i>
<ul
class=
"clearfix"
>
{{#
tag
}}
<li>
<a
href=
"
{{
url
}}
"
target=
"_blank"
>
{{
name
}}
</a>
</li>
{{/
tag
}}
</ul>
</div>
{{/if}}
{{{
content
}}}
</div>
</div>
...
...
public/js/news/detail.page.js
View file @
aaa51f2
var
$
=
require
(
'yoho-jquery'
),
lazyLoad
=
require
(
'yoho-jquery-lazyload'
);
require
(
'../common'
);
require
(
'./img-blink'
);
require
(
'./right-side'
);
...
...
public/scss/news/_detail.css
View file @
aaa51f2
...
...
@@ -10,6 +10,11 @@
font-style
:
italic
;
}
i
.iconfont
{
color
:
#ccc
;
font-style
:
normal
;
}
.block
{
margin
:
15px
0
;
}
...
...
Please
register
or
login
to post a comment