Toggle navigation
Toggle navigation
This project
Loading...
Sign in
fe
/
yohobuy-mobile
·
Commits
Go to a project
GitLab
Go to group
Project
Activity
Files
Commits
Pipelines
0
Builds
0
Graphs
Milestones
Issues
0
Merge Requests
0
Members
Labels
Wiki
Forks
Network
Create a new issue
Download as
Email Patches
Plain Diff
Browse Files
Authored by
xuqi
10 years ago
Commit
3d7ab339dd37d1093b78b08fcf5aade8efa2c09b
1 parent
231c89b8
文章点赞和取消点赞
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
62 additions
and
37 deletions
mobile/public/js/data.js
mobile/public/js/ps.js
mobile/public/js/tag.js
mobile/router.js
mobile/views/controller/favorite.js
mobile/views/partials/common/time-view-like-share.html
mobile/public/js/data.js
View file @
3d7ab33
...
...
@@ -330,7 +330,11 @@ module.exports = function(flag) {
url
:
''
,
publishTime
:
'2月13日 12:34'
,
pageView
:
3445
,
like
:
true
,
//like为false则不显示点赞
like
:
{
count
:
123
,
isLiked
:
true
},
share
:
false
//不显示share标签
}
]
...
...
@@ -349,7 +353,10 @@ module.exports = function(flag) {
url
:
''
,
publishTime
:
'2月13日 12:34'
,
pageView
:
3445
,
like
:
true
,
like
:
{
count
:
459
,
isLiked
:
true
},
share
:
false
//不显示share标签
},
{
...
...
@@ -364,7 +371,7 @@ module.exports = function(flag) {
url
:
''
,
publishTime
:
'2月13日 12:34'
,
pageView
:
3445
,
like
:
tru
e
,
like
:
fals
e
,
share
:
false
}
];
...
...
@@ -390,7 +397,10 @@ module.exports = function(flag) {
url
:
''
,
publishTime
:
'2月13日 12:34'
,
pageView
:
3445
,
like
:
true
,
like
:
{
count
:
459
,
isLiked
:
true
},
share
:
false
//不显示share标签
},
{
...
...
@@ -405,7 +415,7 @@ module.exports = function(flag) {
url
:
''
,
publishTime
:
'2月13日 12:34'
,
pageView
:
3445
,
like
:
tru
e
,
like
:
fals
e
,
share
:
false
}
]
...
...
@@ -490,7 +500,10 @@ module.exports = function(flag) {
'In England中Panul Smith缔造了一个传奇'
,
publishTime
:
'2月13日 12:34'
,
pageView
:
3445
,
like
:
true
,
like
:
{
count
:
459
,
isLiked
:
true
},
share
:
true
,
url
:
''
,
likeUrl
:
''
...
...
@@ -503,7 +516,10 @@ module.exports = function(flag) {
'In England中Panul Smith缔造了一个传奇'
,
publishTime
:
'2月13日 12:34'
,
pageView
:
3445
,
like
:
true
,
like
:
{
count
:
100
,
isLiked
:
false
},
share
:
true
,
url
:
''
,
likeUrl
:
''
...
...
mobile/public/js/ps.js
View file @
3d7ab33
...
...
@@ -130,22 +130,24 @@ exports.init = function() {
$
(
'#info-content'
).
delegate
(
'.like-btn'
,
'touchstart'
,
function
(
e
)
{
var
$cur
=
$
(
e
.
currentTarget
),
$info
=
$cur
.
closest
(
'.info-block'
),
id
=
$info
.
data
(
'id'
);
id
=
$info
.
data
(
'id'
),
url
;
//取消点赞的处理
$cur
.
toggleClass
(
'like'
);
if
(
$cur
.
hasClass
(
'like'
))
{
$cur
.
next
(
'span.like-count'
).
text
(
''
);
$cur
.
toggleClass
(
'like'
);
return
;
url
=
'/guang/info/praise'
;
}
else
{
url
=
'/guang/info/cancelpraise'
;
}
$
.
ajax
({
type
:
'GET'
,
url
:
'/favorite/praise'
,
url
:
url
,
data
:
{
id
:
id
}
}).
then
(
function
(
data
)
{
if
(
data
.
code
===
200
)
{
$cur
.
toggleClass
(
'like'
);
//更新点赞数
$cur
.
next
(
'span.like-count'
).
text
(
data
.
data
);
}
else
if
(
data
.
code
===
400
)
{
...
...
mobile/public/js/tag.js
View file @
3d7ab33
...
...
@@ -85,26 +85,27 @@ exports.init = function() {
this
.
mlellipsis
(
2
);
});
//文章点赞
//文章点赞
和取消点赞
$
(
'.tag-container'
).
delegate
(
'.like-btn'
,
'touchstart'
,
function
(
e
)
{
var
$cur
=
$
(
e
.
currentTarget
),
$info
=
$cur
.
closest
(
'.tag-content'
),
id
=
$info
.
data
(
'id'
);
//点赞的只有取消点赞的效果, 不发送请求, 不改变点赞数字
id
=
$info
.
data
(
'id'
),
url
;
$cur
.
toggleClass
(
'like'
);
if
(
$cur
.
hasClass
(
'like'
))
{
$cur
.
next
(
'span.like-count'
).
text
(
''
);
$cur
.
toggleClass
(
'like'
);
return
;
url
=
'/guang/info/praise'
;
}
else
{
url
=
'/guang/info/cancelpraise'
;
}
$
.
ajax
({
type
:
'GET'
,
url
:
'/favorite/praise'
,
url
:
url
,
data
:
{
id
:
id
}
}).
then
(
function
(
data
)
{
if
(
data
.
code
===
200
)
{
$cur
.
toggleClass
(
'like'
);
//更新点赞数
$cur
.
next
(
'span.like-count'
).
text
(
data
.
data
);
}
else
if
(
data
.
code
===
400
)
{
...
...
mobile/router.js
View file @
3d7ab33
...
...
@@ -28,7 +28,9 @@ module.exports = function(app) {
app
.
get
(
'/favorite/product'
,
fav
.
prod
);
//商品收藏或取消收藏
app
.
get
(
'/favorite/brand'
,
fav
.
brand
);
//品牌收藏或取消收藏
app
.
get
(
'/favorite/praise'
,
fav
.
article
);
//文章点赞或取消点赞
app
.
get
(
'/guang/info/praise'
,
fav
.
article
);
//文章点赞或取消点赞
app
.
get
(
'/guang/info/cancelpraise'
,
fav
.
article
);
app
.
get
(
'/common/articletpl'
,
ps
.
readTpl
);
//获取相关资讯模板
app
.
get
(
'/common/goodinfo'
,
template
.
readTpl
);
//读取模板
...
...
mobile/views/controller/favorite.js
View file @
3d7ab33
...
...
@@ -48,17 +48,21 @@ exports.brand = function(req, res) {
//文章点赞或取消点赞
exports
.
article
=
function
(
req
,
res
)
{
if
(
req
.
query
.
st
===
'0'
)
{
res
.
send
({
code
:
400
,
message
:
""
,
data
:
99
});
}
else
{
res
.
send
({
code
:
200
,
message
:
""
,
data
:
100
});
}
// if (req.query.st === '0') {
// res.send({
// code: 400,
// message: "",
// data: 99
// });
// } else {
// res.send({
// code: 200,
// message: "",
// data: 100
// });
// }
res
.
send
({
code
:
200
,
data
:
parseInt
(
Math
.
random
()
*
100
,
10
)
});
};
\ No newline at end of file
...
...
mobile/views/partials/common/time-view-like-share.html
View file @
3d7ab33
...
...
@@ -5,8 +5,8 @@
{{pageView}}
<div
class=
"like-share-container"
>
{{# like}}
<a
href=
"javascript:;"
class=
"iconfont like-btn"
>

</a>
<span
class=
"like-count"
></span>
<a
href=
"javascript:;"
class=
"iconfont like-btn{{#isLiked}} like{{/isLiked}}"
>

</a>
<span
class=
"like-count"
>
{{count}}
</span>
{{/ like}}
{{# share}}
<a
href=
"{{.}}"
class=
"iconfont share-btn"
>

</a>
...
...
Please
register
or
login
to post a comment