Authored by 陈峰

编辑页面及编辑页面的点赞操作等功能开发完毕

/**
* 编辑页
* @author: chenfeng<feng.chen@yoho.cn>
* @date: 2016/09/05
*/
'use strict';
const mRoot = '../models';
const indexModel = require(`${mRoot}/index`);
const headerModel = require('../../../doraemon/models/header'); // 头部model
const guangProcess = require(`${global.utils}/guang-process`);
const Promise = require('bluebird');
/**
* [编辑页面]
*/
const _editor = (req, res, next) => {
let uid = req.user.uid,
udid = req.sessionID,
id = req.query.id || 0,
title = '编辑简介',
parameter = {},
isApp = req.query.app_version || req.query.appVersion || false,
gender = req.query.gender || req.cookies._Channel && channels[req.cookies._Channel] || 1;
if (isApp === false) {
parameter = {
pageHeader: headerModel.setNav({
navTitle: title
}),
pageFooter: true
};
}
return Promise.all([indexModel.getAuthor(id), indexModel.getArticleList(gender, 0, uid, udid, 1, null, id)]).then(datas => {
let authorData = datas[0],
articleListData = datas[1];
let build = [];
articleListData.data.list.artList.forEach(articleData => {
build.push(guangProcess.formatArticle(articleData, true, isApp, false, uid));
});
res.render('index/list', Object.assign({
page: 'index-editor',
title: title,
guangList: true,
gender: gender,
guang: {
infos: build,
isApp: isApp,
authorInfo: authorData.data
}
}, parameter));
}).catch(next);
};
/**
* [逛列表页面的资讯分页]
* @param {[type]} req [description]
* @param {[type]} res [description]
* @param {Function} next [description]
* @return {[type]} [description]
*/
const _page = (req, res, next) => {
/* 判断是不是AJAX请求 */
if (!req.xhr) {
res.json({ code: 400, message: '非法请求', data: '' });
return;
}
/* 判断参数是否有效 */
let tag = req.query.tag,
sortId = req.query.type,
page = req.query.page,
gender = req.query.gender,
authorId = req.query.authorId,
isApp = req.query.isApp,
isTab = req.query.isTab,
showAuthor = true;
let uid = req.user.uid,
udid = req.sessionID;
if (sortId && !isNaN(sortId)) {
res.json({ code: 400, message: '参数错误', data: '' });
return;
}
if (!page && !isNaN(page)) {
res.json({ code: 400, message: '参数错误', data: '' });
return;
}
if (!authorId && isNaN(authorId)) {
showAuthor = false;
}
return indexModel.getPageData(gender, sortId, uid, udid, page, tag, authorId, isApp, showAuthor, isTab).then(data => {
if (data) {
res.render('index/page', Object.assign(data, { layout: false }));
} else {
res.json({ code: 400, message: '', data: '' });
}
}).catch(next);
};
module.exports = {
editor: _editor,
page: _page
};
... ...
/**
* 逛操作
* @author: chenfeng<feng.chen@yoho.cn>
* @date: 2016/09/06
*/
'use strict';
const mRoot = '../models';
const optModel = require(`${mRoot}/opt`);
const brandModel = require(`${mRoot}/brand`);
const helpers = global.yoho.helpers;
const stringProcess = require(`${global.utils}/string-process`);
/**
* [资讯文章点赞 (H5里显示点赞)]
*/
const _praiseArticle = (req, res, next) => {
/* 判断是不是AJAX请求 */
if (!req.xhr) {
res.json({ code: 400, message: '非法请求', data: '' });
return;
}
/* 判断参数是否有效 */
let id = req.body.id,
opt = req.body.opt || 'ok',
udid = req.sessionID;
if (!stringProcess.isNumeric(id)) {
res.json({ code: 400, message: '非法请求', data: '' });
return;
}
/* 执行点赞或取消操作 */
return optModel.praiseArticle(udid, id, opt).then((data) => {
res.json(data);
}).catch(next);
};
/**
* 资讯文章收藏 (APP里显示收藏)
*/
const _collectArticle = (req, res, next) => {
let result = {
code: 400,
message: '您未登录,无法收藏或者取消收藏。请先登录!',
data: ''
};
/* 判断是不是AJAX请求 */
if (!req.xhr) {
res.json(result);
return;
}
/* 判断参数是否有效 */
/* 判断用户是否登录 */
let id = req.body.id,
opt = req.body.opt || 'ok',
uid = req.user.uid;
if (!stringProcess.isNumeric(id) || !stringProcess.isNumeric(uid)) {
res.json(result);
return;
}
/* 执行收藏或取消操作 */
return optModel.collectArticle(uid, id, opt).then(data => {
if (!data) {
res.json({
code: 400,
message: '操作失败',
data: ''
});
return;
}
res.json({
code: 200,
message: '成功',
data: ''
});
});
};
/**
* [品牌收藏]
*/
const _favoriteBrand = (req, res, next) => {
let refer = helpers.urlFormat('/signin.html', {
refer: req.headers.referer
});
let result = {
code: 400,
message: '未登录',
data: ''
};
/* 判断是不是AJAX请求 */
if (!req.xhr) {
res.json(result);
return;
}
/* 判断参数是否有效 */
let id = req.body.id,
opt = req.body.opt || 'ok',
uid = req.user.uid;
if (!stringProcess.isNumeric(id) || !stringProcess.isNumeric(uid)) {
res.json(result);
return;
}
// 执行收藏或取消操作
return brandModel.favoriteBrand(uid, id, opt).then(data => {
if (!data) {
res.json({
code: 400,
message: '操作失败',
data: ''
});
return;
}
res.json({
code: 200,
message: '成功',
data: ''
});
});
};
module.exports = {
praiseArticle: _praiseArticle,
collectArticle: _collectArticle,
favoriteBrand: _favoriteBrand
};
... ...
'use strict';
const api = global.yoho.API;
/**
* [收藏品牌或者商品]
* @param {[int]} uid [用户ID]
* @param {[int]} id [品牌ID]
* @param {Boolean} isBrand [是品牌还是商品]
* @param {string} opt [操作(ok:表示确定,cancel:表示取消)]
* @return {[array]}
*/
const _favoriteBrand = (uid, id, isBrand, opt) => {
let param = {
uid: uid,
type: isBrand ? 'brand' : 'product'
};
if (opt === 'ok') {
param['id'] = id;
param['method'] = 'app.favorite.add';
} else {
param['fav_id'] = id;
param['method'] = 'app.favorite.cancel';
}
return api.post('', param);
};
module.exports = {
favoriteBrand: _favoriteBrand
};
... ...
'use strict';
const api = global.yoho.API;
const serviceAPI = global.yoho.ServiceAPI;
const logger = global.yoho.logger;
const helpers = global.yoho.helpers;
const guangProcess = require(`${global.utils}/guang-process`);
const _ = require('lodash');
/**
* [获取作者信息]
* @param {[int]} id [作者id]
* @return {[object]}
*/
const _getAuthor = (id) => {
return serviceAPI.get('guang/service/v1/author/getAuthor', {
author_id: id
}).then((result) => {
if (result && result.code === 200) {
return result;
} else {
logger.error('getAuthor code no 200');
return {};
}
});
};
/**
* [逛内容列表]
* @param {[string]} gender ["1,3"表示男, "2,3"表示女, "1,2,3"表示所有]
* @param {[int]} sortId [分类ID]
* @param {Number} uid [用户ID]
* @param {String} udid [客户端唯一标识]
* @param {Number} page [分页第几页, 默认第1页]
* @param {[string]} tag [标签]
* @param {[int]} authorId [作者ID]
* @param {[int]} limit [返回的限制数]
* @param {Boolean} useCache [是否使用缓存]
* @return {[array]}
*/
const _getArticleList = (gender, sortId, uid, udid, page, tag, authorId, limit, useCache) => {
let param = {
page: page || 1,
uid: uid || 0,
udid: udid || '',
gender: gender || '',
sort_id: sortId || undefined,
tag: tag || undefined,
author_id: authorId || undefined,
limit: limit || undefined
};
let cache = useCache ? 300 : false;
return serviceAPI.get('guang/api/v2/article/getList', param, cache).then((result) => {
if (result && result.code === 200) {
return result;
} else {
logger.error('getAuthor code no 200');
return [];
}
});
};
/**
* [获取切换逛类别或者分页时的文章数据]
* @param {[string]} gender ["1,3"表示男, "2,3"表示女]
* @param {[int]} sortId [分类ID]
* @param {[int]} uid [用户ID]
* @param {[string]} udid [客户端唯一标识]
* @param {[int]} page [分页第几页, 默认第1页]
* @param {[string]} tag [标签]
* @param {[string]} authorId [作者ID]
* @param {Boolean} isApp [是否是APP]
* @param {[Boolean]} showAuthor [是否显示作者]
* @param {Boolean} isTab [是否为tab切换操作]
* @return {[array]}
*/
const _getPageData = (gender, sortId, uid, udid, page, tag, authorId, isApp, showAuthor, isTab) => {
return _getArticleList(gender, sortId, uid, udid, page, tag, authorId).then(article => {
let result = {};
if (!article['data']['list']['artList']) {
return result;
}
let adList = article['data']['list']['adlist'];
// 广告列表
if (isTab && adList) {
let build = [];
adList.forEach(ad => {
build.push({
url: guangProcess.getFilterUrl(ad['url']),
img: helpers.image(ad['src'], 830, 327)
});
});
result['swiper'] = build;
}
/* 构建资讯文章内容 */
let build = [];
let artList = article['data']['list']['artList'];
artList.forEach(article => {
build.push(guangProcess.formatArticle(article, true, isApp, showAuthor, uid));
});
result['infos'] = build;
return result;
});
};
module.exports = {
getAuthor: _getAuthor,
getArticleList: _getArticleList,
getPageData: _getPageData
};
... ...
'use strict';
const serviceAPI = global.yoho.ServiceAPI;
/**
* [逛资讯点赞/取消赞]
* @param {[int]} udid [唯一客户端标识]
* @param {[int]} id [唯一资讯的ID]
* @param {[string]} opt [操作(ok:表示确定,cancel:表示取消)]
* @return {[array]}
*/
const _praiseArticle = (udid, id, opt) => {
let param = {
article_id: id,
udid: udid
};
if (opt === 'cancel') {
return serviceAPI.get('guang/api/v2/praise/cancel', param);
} else {
return serviceAPI.get('guang/api/v2/praise/setPraise', param);
}
};
/**
* [逛资讯收藏/取消收藏 (APP里调用)]
* @param {[int]} uid [用户id]
* @param {[int]} id [唯一资讯的ID]
* @param {[string]} opt [操作(ok:表示确定,cancel:表示取消)]
* @return {[array]}
*/
const _collectArticle = (uid, id, opt) => {
let param = {
article_id: id,
uid: uid
};
if (opt === 'cancel') {
return serviceAPI.get('guang/api/v1/favorite/cancelFavorite', param);
} else {
return serviceAPI.get('guang/api/v1/favorite/setFavorite', param);
}
};
module.exports = {
praiseArticle: _praiseArticle,
collectArticle: _collectArticle
};
... ...
... ... @@ -10,6 +10,8 @@ const express = require('express');
const cRoot = './controllers';
const star = require(cRoot + '/star');
const plusstar = require(cRoot + '/plusstar');
const index = require(cRoot + '/index');
const opt = require(cRoot + '/opt');
const router = express.Router(); // eslint-disable-line
... ... @@ -26,4 +28,9 @@ router.post('/star/setFavorite', star.setFavorite); // 收藏文章
router.get('/plusstar', plusstar.index); // 潮流优选
router.get('/plusstar/resources-template', plusstar.resourcesTemplate); // 潮流优选首页-资源位
router.get('/author/list', index.editor); // 编辑简介
router.get('/index/page', index.page); // 逛列表页面的资讯分页
router.post('/opt/praiseArticle', opt.praiseArticle); // 资讯文章点赞 (H5里显示点赞)
module.exports = router;
... ...
<div class="guang-list-page guang-page yoho-page">
{{# guang}}
{{# authorInfo}}
<div id="author-infos" class="editor-header clearfix" data-id={{id}}>
<div class="avatar">
<img src="{{avatar}}">
</div>
<div class="text">
<p class="name">{{name}}</p>
<p class="info">{{author_desc}}</p>
</div>
</div>
{{/ authorInfo}}
<div id="info-list" class="info-list">
{{# infos}}
{{> index/info}}
{{/ infos}}
</div>
<div id="load-more-info" class="load-more-info">
<div class="loading status hide">
正在加载...
</div>
<span class="no-more status">没有更多啦</span>
</div>
{{#if tag}}
<input id="tag" type="hidden" value={{tag}}>
{{/if}}
{{#if gender}}
<input id="gender" type="hidden" value={{gender}}>
{{/if}}
{{#if isApp}}
<input id="isApp" type="hidden" value={{isApp}}>
{{/if}}
{{/ guang}}
</div>
... ...
{{#if swiper}}
<div class="swiper-container">
<div class="swiper-wrapper">
<div class="swiper-slide">
<a href="{{url}}">
<img class="swiper-lazy" data-src="{{img}}">
</a>
<div class="swiper-lazy-preloader"></div>
</div>
</div>
<div class="swiper-pagination"></div>
</div>
{{/if}}
{{# infos}}
{{> index/info}}
{{/ infos}}
\ No newline at end of file
... ...
info>index
\ No newline at end of file
... ...
<div class="guang-info" data-id="{{id}}">
{{# author}}
<a class="info-author clearfix" href={{url}}>
<img class="lazy avatar" data-original={{avatar}}>
<span class="name">{{name}}</span>
</a>
{{/ author}}
<div class="info-img">
{{#if showTags}}
<a href="javascript:;" class="info-match">
{{# isTip}}
小贴士
<div class="info-tag tip"></div>
{{/ isTip}}
{{# isCollocation}}
搭配
<div class="info-tag collocation"></div>
{{/ isCollocation}}
{{# isFashionMan}}
潮人
<div class="info-tag fashion-man"></div>
{{/ isFashionMan}}
{{# isFashionGood}}
潮品
<div class="info-tag fashion-good"></div>
{{/ isFashionGood}}
{{# isTopic}}
话题
<div class="info-tag topic"></div>
{{/ isTopic}}
{{# isSpecialTopic}}
专题
<div class="info-tag special-topic"></div>
{{/ isSpecialTopic}}
</a>
{{/if}}
<a href="{{url}}">
<img class="lazy" data-original="{{img}}" alt="{{alt}}">
</a>
</div>
<div class="info-deps">
<a class="info-title-container" href="{{url}}">
<h2 class="info-title">{{title}}</h2>
</a>
<p class="info-text">{{text}}</p>
{{> index/tvls}}
</div>
</div>
\ No newline at end of file
... ...
<div class="time-view-like-share clearfix">
<i class="iconfont">&#xe603;</i>
{{publishTime}}&nbsp;&nbsp;&nbsp;&nbsp;
<i class="iconfont">&#xe602;</i>
<span class="page-view">{{pageView}}</span>
<div class="like-share-container">
{{#like}}
<i class="iconfont like-btn{{#isLiked}} like{{/isLiked}}">&#xe601;</i>
<span class="like-count">{{count}}</span>
{{/ like}}
{{# collect}}
<a href={{url}}>
<i class="iconfont collect-btn{{#isCollected}} collected{{/isCollected}}">&#xe605;</i>
</a>
{{/ collect}}
{{# share}}
<a href="{{.}}" class="iconfont share-btn">&#xe600;</a>
{{/ share}}
</div>
</div>
\ No newline at end of file
... ...

225 Bytes | W: | H:

10.1 KB | W: | H:

  • 2-up
  • Swipe
  • Onion skin
/**
* 列表页,编辑页
* @author: xuqi<qi.xu@yoho.cn>
* @date: 2015/10/10
*/
var $ = require('yoho-jquery');
var info = require('./info-common'),
loadMore = info.loadMore;
var winH = $(window).height();
var $author = $('#author-infos');
var $tag = $('#tag');
var $gender = $('#gender');
var $isApp = $('#isApp');
var setting = {
page: 2,
end: false
};
var $infos = $('#info-list');
info.initInfosEvt($infos);
if ($author.length > 0) {
$.extend(setting, {
authorId: $author.data('id'),
isApp: $isApp.val()
});
}
if ($tag.length > 0) {
$.extend(setting, {
tag: $tag.val(),
gender: $gender.val(),
isApp: $isApp.val()
});
}
function scrollHandler() {
if ($(window).scrollTop() + winH >= $(document).height() - 0.25 * $infos.height()) {
loadMore($infos, setting);
}
}
// srcoll to load more
$(window).scroll(function() {
window.requestAnimationFrame(scrollHandler);
});
... ...
/**
* 资讯相关API
* @author: xuqi<qi.xu@yoho.cn>
* @date: 2015/10/10
*/
var $ = require('yoho-jquery'),
Hammer = require('yoho-hammer'),
ellipsis = require('yoho-mlellipsis'),
lazyLoad = require('yoho-jquery-lazyload'),
Swiper = require('yoho-swiper');
var tip = require('../plugin/tip');
var loading = require('../plugin/loading');
var $loadMoreInfo = $('#load-more-info');
var $loading = $(''),
$noMore = $(''),
$swiper = $('');
var searching = false;
var mySwiper = {};
var isLoading = false;
ellipsis.init();
if ($loadMoreInfo.length > 0) {
$loading = $loadMoreInfo.children('.loading');
$noMore = $loadMoreInfo.children('.no-more');
}
// 获取url中的参数
function getUrlParam(name) {
// 构造一个含有目标参数的正则表达式对象
var reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)');
// 匹配目标参数
var r = window.location.search.substr(1).match(reg);
// 返回参数值
if (r != null) {
return r[2];
}
return null;
}
// 初始化swiper
function initSwiper(typeId) {
if (typeof typeId === undefined) {
return;
}
mySwiper[typeId] = new Swiper('.swiper-cont-' + typeId, {
lazyLoading: true,
wrapperClass: 'swiper-wrap-' + typeId,
pagination: '.swiper-pagi-' + typeId,
autoplay: 3000
});
}
/**
* 设置指定资讯项的Lazyload和文字截取
* @params $infos 资讯项
*/
function setLazyLoadAndMellipsis($infos) {
lazyLoad($infos.find('img.lazy'));
$infos.each(function() {
var $this = $(this),
$title = $this.find('.info-title'),
$text = $this.find('.info-text');
$title[0].mlellipsis(2);
$text[0].mlellipsis(2);
});
}
/**
* 初始化资讯列表事件绑定
* @params $container 逛资讯列表容器
*/
function initInfosEvt($container) {
var cHammer;
if (typeof $container === 'undefined') {
return;
}
if (typeof $container[0] === 'undefined') {
return;
}
cHammer = new Hammer($container[0]);
// 点赞或者收藏事件
cHammer.on('tap', function(e) {
var $this = $(e.target),
opt = 'ok',
$btn,
$info,
yhChannel;
// e.preventDefault();
// 点赞
$btn = $this.closest('.like-btn');
if ($btn.length > 0 && !isLoading) {
e.preventDefault();
if ($btn.hasClass('like')) {
opt = 'cancel';
}
$info = $this.closest('.guang-info');
isLoading = true;
$.ajax({
type: 'POST',
url: '/guang/opt/praiseArticle',
data: {
id: $info.data('id'),
opt: opt
},
success: function(data) {
var code = data.code;
if (code === 200) {
$btn.next('.like-count').text(data.data);
// 切换点赞状态
$btn.toggleClass('like');
}
},
error: function() {
tip.show('网络断开连接了~');
},
complete: function() {
isLoading = false;
}
});
return;
}
// APP收藏
$btn = $this.closest('.collect-btn');
if ($btn.length > 0) {
e.preventDefault();
if ($btn.hasClass('collected')) {
opt = 'cancel';
}
$info = $this.closest('.guang-info');
if (getUrlParam('yh_channel')) {
yhChannel = getUrlParam('yh_channel');
}
$.ajax({
type: 'POST',
url: '/guang/opt/collectArticle',
data: {
id: $info.data('id'),
opt: opt,
yh_channel: yhChannel,
uid: getUrlParam('uid')
},
success: function(data) {
if (data.code && data.code === 200) {
// 切换收藏状态
$btn.toggleClass('collected');
}
},
error: function() {
tip.show('网络断开连接了~');
}
});
}
});
setLazyLoadAndMellipsis($container.find('.guang-info'));
}
/**
* 资讯LoadMore
* @param $container 资讯容器 jqyeryObject
* @param opt 请求参数
* @param url[可选], 扩展请求的url而不使用默认值
*/
function loadMore($container, opt, url) {
var num;
if (searching) {
return;
}
if (opt.end) {
return;
}
if (opt.page === 1) {
// 显示loading
loading.showLoadingMask();
}
num = $container.find('.guang-info').length;
searching = true;
$.ajax({
type: 'GET',
url: url ? url : '/guang/index/page', // 对于指定url的使用指定url(存在不同的控制器)
data: opt,
success: function(data) {
var $newItems;
if (data === ' ') {
opt.end = true;
searching = false;
//
$loading.addClass('hide');
$noMore.removeClass('hide');
return;
}
$container.append(data);
$swiper = $container.find('.swiper-container');
if ($swiper.length) {
$swiper.addClass('swiper-cont-' + opt.type);
$swiper.children('.swiper-wrapper').addClass('swiper-wrap-' + opt.type);
$swiper.children('.swiper-pagination').addClass('swiper-pagi-' + opt.type);
initSwiper(opt.type);
}
if (num > 0) {
$newItems = $container.find('.guang-info:gt(' + (num - 1) + ')');
} else {
$newItems = $container.find('.guang-info');
}
setLazyLoadAndMellipsis($newItems);
if (opt.page === 1) {
loading.hideLoadingMask();
$loading.removeClass('hide');// 显示空屏加载时hide的隐藏
window.rePosFooter();// 插入内容后重新计算底部位置
}
opt.page++;
searching = false;
delete opt.isTab;
},
error: function() {
tip.show('网络断开连接了~');
searching = false;
delete opt.isTab;
}
});
}
exports.mySwiper = mySwiper;
exports.initSwiper = initSwiper;
exports.initInfosEvt = initInfosEvt;
exports.setLazyLoadAndMellipsis = setLazyLoadAndMellipsis;
exports.loadMore = loadMore;
... ...
... ... @@ -2,3 +2,4 @@
@import "filter";
@import "suspend-cart";
@import "error";
@import "loading";
... ...
.load-more-info {
width: 100%;
height: 3.5rem;
line-height: 3.5rem;
text-align: center;
font-size: 0.7rem;
overflow: hidden;
.status {
&.hide {
display: none;
}
}
}
\ No newline at end of file
... ...
@import "star/index";
@import "plusstar/index";
@import "index/index";
\ No newline at end of file
... ...
@import "info-list";
@import "info";
@import "tvls";
\ No newline at end of file
... ...
.guang-list-page {
.editor-header {
margin-bottom: 1.5rem;
padding-top: 1.8rem;
padding-bottom: 2.0rem;
background: #fff;
border-bottom: 0.05rem solid #e0e0e0;
}
.avatar {
float: left;
margin-left: 1.5rem;
img {
width: 5.0rem;
height: 5.0rem;
border-radius: 50%;
}
}
.text {
float: left;
margin-left: 1.6rem;
width: 23.75rem;
.name {
font-size: 1.6rem;
line-height: 2.0rem;
}
.info {
margin-top: 0.3rem;
color: #bdbdbf;
font-size: 1.2rem;
line-height: 1.6rem;
}
}
.swiper-container {
width: 100%;
height: 15.5rem;
img {
height: 100%;
width: 100%;
}
.swiper-pagination {
bottom: 0;
left: 0;
width: 100%;
}
.swiper-pagination-bullet-active {
background: #fff;
}
}
.guang-nav {
background-color: #fff;
overflow: hidden;
height: 4.0rem;
}
.guang-nav-item {
float: left;
color: #ccc;
font-size: 1.4rem;
padding: 0 1.1rem;
line-height: 4.0rem;
&.focus {
color: #000;
}
}
.bytouch{
background:#eee;
}
.info-list-container {
overflow-x: hidden;
background: #f0f0f0;
}
.info-list.hide {
display: none;
}
}
... ...
.guang-info {
margin-bottom: 1.5rem;
padding: 0 0 1.2rem 0;
border-top: 0.05rem solid #e0e0e0;
border-bottom: 0.05rem solid #e0e0e0;
background: #fff;
.info-author {
display: block;
width: 100%;
.avatar {
float: left;
margin-top: 1.0rem;
width: 2.5rem;
height: 2.5rem;
margin-left: 1.5rem;
border-radius: 50%;
}
.name {
float: left;
margin-left: 1.5rem;
padding: 1.5rem 0;
font-size: 1.4rem;
color: #000;
}
}
&:last-child {
margin-bottom: 0;
}
.info-img {
position: relative;
width: 100%;
img {
display: block;
width: 100%;
}
}
.info-match {
position: absolute;
top: 0;
left: 0;
width: 6.5rem;
height: 2.5rem;
line-height: 2.5rem;
font-size: 1.4rem;
color: #fff;
background: #000;
text-align: center;
text-decoration: none;
z-index: 1;
}
.info-tag {
position: absolute;
top: 0;
left: 5.25rem;
height: 2.5rem;
width: 2.5rem;
&.collocation {
background-image: url("/guang/info/collocation.png");
}
&.fashion-good {
background-image: url("/guang/info/fashion-good.png");
}
&.fashion-man {
background-image: url("/guang/info/fashion-man.png");
}
&.tip, &.special-topic {
background-image: url("/guang/info/tip.png");
}
&.topic {
background-image: url("/guang/info/topic.png");
}
}
.info-deps {
margin: 1.6rem 0 0 0;
padding: 0 2.0rem 0 1.5rem;
.info-title-container {
text-decoration: none;
color: #000;
}
.info-title{
line-height: 2.2rem;
color: #000;
font-size: 2.0rem;
font-weight:bold;
}
.info-text {
margin: 0.8rem 0 0 0;
line-height: 2.3rem;
font-size: 1.4rem;
color: #444;
}
.time-view-like-share {
margin-top: 0.8rem;
}
}
}
... ...
.time-view-like-share {
color: #b0b0b0;
line-height: 1.9rem;
height: 1.9rem;
font-size: 1.2rem;
.iconfont {
vertical-align: 9%;
margin-right: 0.2rem;
font-size: 1.2rem;
}
.like-share-container {
display: inline-block;
float: right;
> * {
float: left;
}
.iconfont {
position: relative;
height: 3.0rem;
line-height: 3.0rem;
display: inline-block;
color: #b0b0b0;
width: 3.0rem;
top: -0.7rem;
font-size: 1.7rem;
text-align: center;
margin-right: 0;
outline: none;
}
.share-btn {
margin-left: 1.0rem;
}
.like-btn.like {
color: #444;
}
.collect-btn {
margin-left: 1.0rem;
&.collected {
color: #D62927;
}
}
}
}
... ...
/**
* 逛处理类
*/
'use strict';
const helpers = global.yoho.helpers;
/**
* [格式化资讯文章]
* @param {[array]} articleData [需要格式化的资讯数据]]
* @param {[Boolean]} showTag [是否显示左上角标签]]
* @param {Boolean} isApp [是否显示分享,在APP客户端里嵌入需要传url链接]
* @param {[Boolean]} showAuthor [控制是否显示作者信息]
* @param {[int]} uid [当前登录的用户ID]
* @param {[string]} reqQueryString [查询字符串]
* @return {[array | false]}
*/
const _formatArticle = (articleData, showTag, isApp, showAuthor, uid, reqQueryString) => {
// 资讯ID不存在,则不显示
if (!articleData['id']) {
return false;
}
var result = {
id: articleData['id'],
showTags: showTag,
img: articleData['src'] ? helpers.image(articleData['src'], 640, 640) : '',
url: isApp ? `${helpers.https(articleData['url'])}&openby:yohobuy={"action":"go.h5","params":{"param":{"id":"${articleData['id']}"},"shareparam":{"id":"${articleData['id']}"},"share":"/guang/api/v1/share/guang","id":${articleData['id']},"type":1,"url":"http:${helpers.urlFormat('/info/index', null, 'guang')}","islogin":"N"}}` : articleData['url'],
title: articleData['title'],
text: articleData['intro'],
publishTime: articleData['publish_time'],
pageView: articleData['views_num']
};
if (result['url'].includes('feature.yoho.cn') ||
result['url'].includes('cdn.yoho.cn')) {
result['url'] = _transHttpsUrl(result['url']);
}
// 收藏
if (isApp) {
result['collect'] = [];
result['collect']['isCollected'] = articleData['isFavor'] === true;
let originUrl = helpers.urlFormat('/author/index', null, 'guang') + reqQueryString; // 跳转回的链接
let collectUrl = 'javascript:;'; // 根据用户是否登录做处理的链接
if (!uid) {
let playUrlEncode = originUrl.replace(/\//g, '\\/');
collectUrl = `${originUrl}?openby:yohobuy={"action":"go.weblogin","params":{"jumpurl":{"url":"${playUrlEncode}","param":{"from":"app"}},"requesturl":{"url":"","param":{}},"priority":"N"}}`;
}
result['collect']['url'] = collectUrl;
} // 点赞
else {
result['like'] = {};
result['like']['count'] = articleData['praise_num'];
result['like']['isLiked'] = articleData['isPraise'] === 'Y';
}
if (isApp && articleData['share']['url']) {
// 分享链接
result['share'] = `${articleData['share']['url']}?openby:yohobuy={"action":"go.share","params":{"title":"${articleData['title']}","content":"${articleData['intro']}","url":"${articleData['share']['url']}","pic":"https:${result['img']}"}}`;
}
// 判断是否显示作者信息
if (showAuthor && articleData['author']) {
if (!isApp) {
articleData['author']['url'] = _getFilterUrl(articleData['author']['url']);
}
// 编辑人员 app跳转url处理 20160601
let isLogin = uid ? true : false;
articleData['author']['url'] = `${helpers.https(articleData['author']['url'])}&openby:yohobuy={"action":"go.h5","params":{"param":{"id":"${articleData['author']['author_id']}"},"share":"","id":${articleData['author']['author_id']},"type":0,"islogin":"${isLogin} ","url":"https:${helpers.urlFormat('/author/index', {uid: uid}, 'guang')} "}}&uid=${uid}`;
result['author'] = articleData['author'];
if (result['author']['avatar']) {
result['author']['avatar'] = result['author']['avatar'].replace('http://', '//');
}
}
// 模板中需要的标签标识
if (showTag && articleData['category_id']) {
switch (articleData['category_id']) {
case '1': // 话题
result['isTopic'] = true;
break;
case '2': // 搭配
result['isCollocation'] = true;
break;
case '3': // 潮人
result['isFashionMan'] = true;
break;
case '4': // 潮品
result['isFashionGood'] = true;
break;
case '5': // 小贴士
result['isTip'] = true;
break;
case '19': // 专题
result['isSpecialTopic'] = true;
break;
}
}
return result;
};
/**
* [将首字符为//的url转换为http://]
* @param {[string]} url [需要转换的url]
* @return {[string]} [description]
*/
const _transHttpsUrl = (url) => {
return url.replace(/^\/\//g, 'http://');
};
const _getFilterUrl = (url) => {
url = url.replace('.m.yohobuy.com', global.yoho.config.subDomains.host).replace('www.yohobuy.com', global.yoho.config.siteUrl);
const whiteDomains = ['m.yohobuy.com', 'cdn.yoho.cn/myohobuy'];
const blackDomains = ['sale.m.yohobuy.com', 'cuxiao.m.yohobuy.com', 'activity.m.yohobuy.com', 'huodong.m.yohobuy.com', '/home/orders/pay'];
if (whiteDomains.every(_ => url.includes(_)) &&
blackDomains.every(_ => !url.includes(_))) {
url = url.replace('http://', '//');
}
if (url.includes('feature.yoho.cn')) {
url = _transHttpsUrl(url);
}
if (url.includes('openby:yohobuy=')) {
let filters = ['openby:yohobuy=', '&', '?'];
filters.forEach(_ => {
url = url.subString(0, url.lastIndexOf(_));
});
return url.replace(/(^\s*)|(\s*$)/g, '');
} else {
return url;
}
};
module.exports = {
formatArticle: _formatArticle,
transHttpsUrl: _transHttpsUrl,
getFilterUrl: _getFilterUrl
};
... ...
/**
* 字符串处理
*/
'use strict';
/**
* [判断数字]
* @param {[string]} str [验证参数]
* @return {[Boolean]}
*/
const _isNumeric = (str) => {
return /^\d+(\.\d+)?$/.test(str);
};
module.exports = {
isNumeric: _isNumeric
};
... ...