Authored by 郭成尧

code-modified-step1

... ... @@ -96,6 +96,81 @@ class DetailModel extends global.yoho.BaseModel {
}
/**
* 获取文章接口调用
* @param {*} articleId
*/
_getArticle(articleId) {
return serviceAPI.get(`${URI_PACKAGE_ARTICLE}getArticle`, {
article_id: articleId
}, {
cache: true
});
}
/**
* 获取作者接口调用
* @param {*} authorId
*/
_getAuthor(authorId) {
return serviceAPI.get(`${URI_PACKAGE_AUTHOR}getAuthor`, {
author_id: authorId
}, {
cache: true
});
}
/**
* 获取文章详情接口调用
* @param {*} articleId
*/
_getArticleContent(articleId) {
return serviceAPI.get(`${URI_PACKAGE_ARTICLE}getArticleContent`, {
article_id: articleId
}, {
cache: true
});
}
/**
* 获取文章相关品牌接口调用
* @param {*} articleId
*/
_getBrand(articleId) {
return serviceAPI.get(`${URI_PACKAGE_ARTICLE}getBrand`, {
article_id: articleId
}, {
cache: true
});
}
/**
* 获取资讯相关的其它资讯接口调用
* @param {*} articleId
* @param {*} tag
*/
_getOtherArticle(articleId, tag) {
return serviceAPI.get(`${URI_PACKAGE_ARTICLE}getOtherArticle`, {
article_id: articleId,
tags: tag,
offset: 0,
limit: 3
}, {
cache: true
});
}
/**
* APP 获取微信模块
*/
_getSingleTemplateWechat() {
return api.get('', {
method: 'app.resources.getSingleTemplate',
module: 'wechat',
key: 'guang_detail_wechat'
});
}
/**
* [逛资讯详情页数据封装]
* @param {[int]} id [内容ID]
* @param {Boolean} isApp [标识是否是APP访问]
... ... @@ -111,188 +186,126 @@ class DetailModel extends global.yoho.BaseModel {
};
// 获取资讯
let param = {
article_id: id
// private_key: sign.privateKey[clientType]
};
return serviceAPI.get(`${URI_PACKAGE_ARTICLE}getArticle`, param, {
cache: true
}).then(data => {
// 接口要判断一下返回状态是否成功
return this._getArticle(id).then(data => {
// 调用接口失败
if (!data || data.code !== 200) {
result.code = 400;
return result;
}
let article = data.data || {};
result.getArticle = article;
let promises = [];
// 获取作者信息
param = {
author_id: article.author_id
};
// param.client_secret = sign.apiSign(param);
promises.push(serviceAPI.get(`${URI_PACKAGE_AUTHOR}getAuthor`, param, {
cache: true
}));
// 获取资讯内容
param = {
article_id: id
// private_key: sign.privateKey[clientType]
};
// param.client_secret = sign.apiSign(param);
promises.push(serviceAPI.get(`${URI_PACKAGE_ARTICLE}getArticleContent`, param, {
cache: true
}));
// 获取资讯相关的品牌
param = {
article_id: id
// private_key: sign.privateKey[clientType]
};
// param.client_secret = sign.apiSign(param);
promises.push(serviceAPI.get(`${URI_PACKAGE_ARTICLE}getBrand`, param, {
cache: true
}));
let article = result.getArticle = data && data.data || {};
let promises = [
this._getAuthor(article.author_id),
this._getArticleContent(id),
this._getBrand(id)
];
// 获取资讯相关的其它资讯
if (typeof article.tag !== 'undefined') {
param = {
article_id: id,
tags: article.tag,
offset: 0,
limit: 3
// private_key: sign.privateKey[clientType]
};
// param.client_secret = sign.apiSign(param);
promises.push(serviceAPI.get(`${URI_PACKAGE_ARTICLE}getOtherArticle`, param, {
cache: true
}));
promises.push(this._getOtherArticle(id, article.tag));
}
// APP 获取微信模块
if (isApp) {
promises.push(api.get('', {
method: 'app.resources.getSingleTemplate',
module: 'wechat',
key: 'guang_detail_wechat'
}));
promises.push(this._getSingleTemplateWechat);
}
if (isShare) {
let navGender = _.cloneDeep(channel);
promises.push(this._getLeftNav(navGender));
}
if (isShare) {
promises.push(this._getShareData(id));
promises.push(
this._getLeftNav(navGender),
this._getShareData(id)
);
}
return Promise.all(promises).then(datas => {
let getArticleContent = [];
if (datas) {
if (datas[1]) {
if (!datas) {
return result;
}
getArticleContent = datas[1].data;
if (datas[1]) {
result.getArticleContent = getArticleContent = datas[1].data;
}
result.getArticleContent = getArticleContent;
if (isApp && datas[4] && datas[4].data) {
let preCount = 0;
let i;
for (i = 0; i < getArticleContent.length; i++) {
if (getArticleContent[i].singleImage ||
getArticleContent[i].text || getArticleContent[i].smallPic) {
preCount++;
}
}
if (isApp && datas[4] && datas[4].data) {
let preCount = 0;
let i;
_.forEach(datas[4].data, item => {
item.src = helpers.image(item.src, 280, 210, 1);
});
for (i = 0; i < getArticleContent.length; i++) {
if (getArticleContent[i].singleImage ||
getArticleContent[i].text || getArticleContent[i].smallPic) {
preCount++;
}
}
getArticleContent.splice(preCount, 0, {
weixinPublic: datas[4].data
});
}
_.forEach(datas[4].data, item => {
item.src = helpers.image(item.src, 280, 210, 1);
});
if (isShare && datas[5]) {
if (datas[5].wechatShareImgUrl) {
datas[5].wechatShareImgUrl =
datas[5].wechatShareImgUrl.substring(datas[5].wechatShareImgUrl.indexOf('//'));
getArticleContent.splice(preCount, 0, {
weixinPublic: datas[4].data
});
}
if (isShare && datas[5]) {
if (datas[5].wechatShareImgUrl) {
datas[5].wechatShareImgUrl =
datas[5].wechatShareImgUrl.substring(datas[5].wechatShareImgUrl.indexOf('//'));
if (datas[5].wechatShareImgUrl.indexOf('?') === -1) {
datas[5].wechatShareImgUrl = datas[5].wechatShareImgUrl +
'?imageView2/2/interlace/1/q/75';
}
} else if (datas[5].qqShareImgUrl) {
datas[5].qqShareImgUrl =
datas[5].qqShareImgUrl.substring(datas[5].qqShareImgUrl.indexOf('//'));
if (datas[5].qqShareImgUrl.indexOf('?') === -1) {
datas[5].qqShareImgUrl = datas[5].wechatShareImgUrl + '?imageView2/2/interlace/1/q/75';
}
} else if (datas[5].showShareImgUrl) {
datas[5].showShareImgUrl =
datas[5].showShareImgUrl.substring(datas[5].showShareImgUrl.indexOf('//'));
if (datas[5].showShareImgUrl.indexOf('?') === -1) {
datas[5].showShareImgUrl = datas[5].showShareImgUrl + '?imageView2/2/interlace/1/q/75';
}
if (datas[5].wechatShareImgUrl.indexOf('?') === -1) {
datas[5].wechatShareImgUrl = datas[5].wechatShareImgUrl +
'?imageView2/2/interlace/1/q/75';
}
} else if (datas[5].qqShareImgUrl) {
datas[5].qqShareImgUrl =
datas[5].qqShareImgUrl.substring(datas[5].qqShareImgUrl.indexOf('//'));
let preCount = 0;
let i;
if (datas[5].qqShareImgUrl.indexOf('?') === -1) {
datas[5].qqShareImgUrl = datas[5].wechatShareImgUrl + '?imageView2/2/interlace/1/q/75';
}
} else if (datas[5].showShareImgUrl) {
datas[5].showShareImgUrl =
datas[5].showShareImgUrl.substring(datas[5].showShareImgUrl.indexOf('//'));
for (i = 0; i < getArticleContent.length; i++) {
if (getArticleContent[i].singleImage ||
getArticleContent[i].text || getArticleContent[i].smallPic) {
preCount = i + 1;
}
if (datas[5].showShareImgUrl.indexOf('?') === -1) {
datas[5].showShareImgUrl = datas[5].showShareImgUrl + '?imageView2/2/interlace/1/q/75';
}
}
getArticleContent.splice(preCount, 0, {
shareCode: datas[5]
});
let preCount = 0;
let i;
for (i = 0; i < getArticleContent.length; i++) {
if (getArticleContent[i].singleImage ||
getArticleContent[i].text || getArticleContent[i].smallPic) {
preCount = i + 1;
}
}
if (datas[0]) {
result.getAuthor = datas[0].data;
}
getArticleContent.splice(preCount, 0, {
shareCode: datas[5]
});
}
if (datas[0]) {
result.getAuthor = datas[0].data;
}
if (datas[2]) {
result.getBrand = datas[2].data;
}
if (isShare && datas[4]) {
result.sideNav = datas[4];
}
if (datas[2]) {
result.getBrand = datas[2].data;
}
if (datas.length === 5 && isApp || datas.length === 4 && !isApp || datas.length === 6 && isShare) {
if (datas[3]) {
result.getOtherArticle = datas[3].data;
}
if (isShare && datas[4]) {
result.sideNav = datas[4];
}
if (datas.length === 5 && isApp || datas.length === 4 && !isApp || datas.length === 6 && isShare) {
if (datas[3]) {
result.getOtherArticle = datas[3].data;
}
}
... ...
... ... @@ -36,20 +36,9 @@
<img class="lazy" data-original={{image2 bigImage q=60}}>
{{/if}}
<div class="label-box" style="top: 30px; left: 40px;">
<div class="lable-focus">
<div class="focus-big">
<div class="focus-small"></div>
</div>
</div>
<div class="lable-info-box">
<span class="lable-text">这个是商品标题</span>
</div>
<div class="lable-btn">
<span class="iconfont">&#xe62c;</span>
<span class="iconfont plus">&#xe624;</span>
</div>
</div>
{{#tagList}}
{{> detail/img-label}}
{{/tagList}}
</div>
{{/if}}
... ...
<div class="label-box" style="top: 30px; left: 40px;">
<div class="lable-focus">
<div class="focus-big">
<div class="focus-small"></div>
</div>
</div>
<div class="lable-info-box">
<span class="lable-text">这个是商品标题</span>
</div>
<div class="lable-btn">
<span class="iconfont">&#xe62c;</span>
<span class="iconfont plus">&#xe624;</span>
</div>
</div>
\ No newline at end of file
... ...
... ... @@ -14,8 +14,8 @@ const domains = {
liveApi: 'http://testapi.live.yohops.com:9999/',
singleApi: 'http://api-test3.yohops.com:9999/',
api: 'http://dev-api.yohops.com:9999/',
service: 'http://dev-service.yohops.com:9999/',
api: 'http://api-test3.yohops.com:9999/',
service: 'http://service-test3.yohops.com:9999/',
global: 'http://api-global.yohobuy.com',
// liveApi: 'http://api.live.yoho.cn/',
... ...