Authored by 郭成尧

code-modified-step1

@@ -96,6 +96,81 @@ class DetailModel extends global.yoho.BaseModel { @@ -96,6 +96,81 @@ class DetailModel extends global.yoho.BaseModel {
96 } 96 }
97 97
98 /** 98 /**
  99 + * 获取文章接口调用
  100 + * @param {*} articleId
  101 + */
  102 + _getArticle(articleId) {
  103 + return serviceAPI.get(`${URI_PACKAGE_ARTICLE}getArticle`, {
  104 + article_id: articleId
  105 + }, {
  106 + cache: true
  107 + });
  108 + }
  109 +
  110 + /**
  111 + * 获取作者接口调用
  112 + * @param {*} authorId
  113 + */
  114 + _getAuthor(authorId) {
  115 + return serviceAPI.get(`${URI_PACKAGE_AUTHOR}getAuthor`, {
  116 + author_id: authorId
  117 + }, {
  118 + cache: true
  119 + });
  120 + }
  121 +
  122 + /**
  123 + * 获取文章详情接口调用
  124 + * @param {*} articleId
  125 + */
  126 + _getArticleContent(articleId) {
  127 + return serviceAPI.get(`${URI_PACKAGE_ARTICLE}getArticleContent`, {
  128 + article_id: articleId
  129 + }, {
  130 + cache: true
  131 + });
  132 + }
  133 +
  134 + /**
  135 + * 获取文章相关品牌接口调用
  136 + * @param {*} articleId
  137 + */
  138 + _getBrand(articleId) {
  139 + return serviceAPI.get(`${URI_PACKAGE_ARTICLE}getBrand`, {
  140 + article_id: articleId
  141 + }, {
  142 + cache: true
  143 + });
  144 + }
  145 +
  146 + /**
  147 + * 获取资讯相关的其它资讯接口调用
  148 + * @param {*} articleId
  149 + * @param {*} tag
  150 + */
  151 + _getOtherArticle(articleId, tag) {
  152 + return serviceAPI.get(`${URI_PACKAGE_ARTICLE}getOtherArticle`, {
  153 + article_id: articleId,
  154 + tags: tag,
  155 + offset: 0,
  156 + limit: 3
  157 + }, {
  158 + cache: true
  159 + });
  160 + }
  161 +
  162 + /**
  163 + * APP 获取微信模块
  164 + */
  165 + _getSingleTemplateWechat() {
  166 + return api.get('', {
  167 + method: 'app.resources.getSingleTemplate',
  168 + module: 'wechat',
  169 + key: 'guang_detail_wechat'
  170 + });
  171 + }
  172 +
  173 + /**
99 * [逛资讯详情页数据封装] 174 * [逛资讯详情页数据封装]
100 * @param {[int]} id [内容ID] 175 * @param {[int]} id [内容ID]
101 * @param {Boolean} isApp [标识是否是APP访问] 176 * @param {Boolean} isApp [标识是否是APP访问]
@@ -111,188 +186,126 @@ class DetailModel extends global.yoho.BaseModel { @@ -111,188 +186,126 @@ class DetailModel extends global.yoho.BaseModel {
111 }; 186 };
112 187
113 // 获取资讯 188 // 获取资讯
114 - let param = {  
115 - article_id: id  
116 -  
117 - // private_key: sign.privateKey[clientType]  
118 - };  
119 -  
120 - return serviceAPI.get(`${URI_PACKAGE_ARTICLE}getArticle`, param, {  
121 - cache: true  
122 - }).then(data => {  
123 - // 接口要判断一下返回状态是否成功 189 + return this._getArticle(id).then(data => {
  190 + // 调用接口失败
124 if (!data || data.code !== 200) { 191 if (!data || data.code !== 200) {
125 result.code = 400; 192 result.code = 400;
126 return result; 193 return result;
127 } 194 }
128 - let article = data.data || {};  
129 -  
130 - result.getArticle = article;  
131 -  
132 - let promises = [];  
133 -  
134 - // 获取作者信息  
135 - param = {  
136 - author_id: article.author_id  
137 - };  
138 -  
139 - // param.client_secret = sign.apiSign(param);  
140 - promises.push(serviceAPI.get(`${URI_PACKAGE_AUTHOR}getAuthor`, param, {  
141 - cache: true  
142 - }));  
143 -  
144 - // 获取资讯内容  
145 - param = {  
146 - article_id: id  
147 -  
148 - // private_key: sign.privateKey[clientType]  
149 - };  
150 -  
151 - // param.client_secret = sign.apiSign(param);  
152 - promises.push(serviceAPI.get(`${URI_PACKAGE_ARTICLE}getArticleContent`, param, {  
153 - cache: true  
154 - }));  
155 -  
156 - // 获取资讯相关的品牌  
157 - param = {  
158 - article_id: id  
159 -  
160 - // private_key: sign.privateKey[clientType]  
161 - };  
162 -  
163 - // param.client_secret = sign.apiSign(param);  
164 - promises.push(serviceAPI.get(`${URI_PACKAGE_ARTICLE}getBrand`, param, {  
165 - cache: true  
166 - })); 195 + let article = result.getArticle = data && data.data || {};
  196 + let promises = [
  197 + this._getAuthor(article.author_id),
  198 + this._getArticleContent(id),
  199 + this._getBrand(id)
  200 + ];
167 201
168 // 获取资讯相关的其它资讯 202 // 获取资讯相关的其它资讯
169 if (typeof article.tag !== 'undefined') { 203 if (typeof article.tag !== 'undefined') {
170 - param = {  
171 - article_id: id,  
172 - tags: article.tag,  
173 - offset: 0,  
174 - limit: 3  
175 -  
176 - // private_key: sign.privateKey[clientType]  
177 - };  
178 -  
179 - // param.client_secret = sign.apiSign(param);  
180 - promises.push(serviceAPI.get(`${URI_PACKAGE_ARTICLE}getOtherArticle`, param, {  
181 - cache: true  
182 - })); 204 + promises.push(this._getOtherArticle(id, article.tag));
183 } 205 }
184 206
  207 + // APP 获取微信模块
185 if (isApp) { 208 if (isApp) {
186 - promises.push(api.get('', {  
187 - method: 'app.resources.getSingleTemplate',  
188 - module: 'wechat',  
189 - key: 'guang_detail_wechat'  
190 - })); 209 + promises.push(this._getSingleTemplateWechat);
191 } 210 }
192 211
193 if (isShare) { 212 if (isShare) {
194 let navGender = _.cloneDeep(channel); 213 let navGender = _.cloneDeep(channel);
195 214
196 - promises.push(this._getLeftNav(navGender));  
197 - }  
198 -  
199 - if (isShare) {  
200 - promises.push(this._getShareData(id)); 215 + promises.push(
  216 + this._getLeftNav(navGender),
  217 + this._getShareData(id)
  218 + );
201 } 219 }
202 220
203 return Promise.all(promises).then(datas => { 221 return Promise.all(promises).then(datas => {
204 222
205 let getArticleContent = []; 223 let getArticleContent = [];
206 224
207 - if (datas) {  
208 - if (datas[1]) { 225 + if (!datas) {
  226 + return result;
  227 + }
209 228
210 - getArticleContent = datas[1].data; 229 + if (datas[1]) {
  230 + result.getArticleContent = getArticleContent = datas[1].data;
  231 + }
211 232
212 - result.getArticleContent = getArticleContent; 233 + if (isApp && datas[4] && datas[4].data) {
  234 + let preCount = 0;
  235 + let i;
213 236
  237 + for (i = 0; i < getArticleContent.length; i++) {
  238 + if (getArticleContent[i].singleImage ||
  239 + getArticleContent[i].text || getArticleContent[i].smallPic) {
  240 + preCount++;
  241 + }
214 } 242 }
215 243
216 - if (isApp && datas[4] && datas[4].data) {  
217 -  
218 - let preCount = 0;  
219 - let i; 244 + _.forEach(datas[4].data, item => {
  245 + item.src = helpers.image(item.src, 280, 210, 1);
  246 + });
220 247
221 - for (i = 0; i < getArticleContent.length; i++) {  
222 - if (getArticleContent[i].singleImage ||  
223 - getArticleContent[i].text || getArticleContent[i].smallPic) {  
224 - preCount++;  
225 - }  
226 - } 248 + getArticleContent.splice(preCount, 0, {
  249 + weixinPublic: datas[4].data
  250 + });
  251 + }
227 252
228 - _.forEach(datas[4].data, item => {  
229 - item.src = helpers.image(item.src, 280, 210, 1);  
230 - }); 253 + if (isShare && datas[5]) {
  254 + if (datas[5].wechatShareImgUrl) {
  255 + datas[5].wechatShareImgUrl =
  256 + datas[5].wechatShareImgUrl.substring(datas[5].wechatShareImgUrl.indexOf('//'));
231 257
232 - getArticleContent.splice(preCount, 0, {  
233 - weixinPublic: datas[4].data  
234 - });  
235 - }  
236 -  
237 - if (isShare && datas[5]) {  
238 -  
239 - if (datas[5].wechatShareImgUrl) {  
240 - datas[5].wechatShareImgUrl =  
241 - datas[5].wechatShareImgUrl.substring(datas[5].wechatShareImgUrl.indexOf('//'));  
242 -  
243 - if (datas[5].wechatShareImgUrl.indexOf('?') === -1) {  
244 - datas[5].wechatShareImgUrl = datas[5].wechatShareImgUrl +  
245 - '?imageView2/2/interlace/1/q/75';  
246 - }  
247 - } else if (datas[5].qqShareImgUrl) {  
248 - datas[5].qqShareImgUrl =  
249 - datas[5].qqShareImgUrl.substring(datas[5].qqShareImgUrl.indexOf('//'));  
250 -  
251 - if (datas[5].qqShareImgUrl.indexOf('?') === -1) {  
252 - datas[5].qqShareImgUrl = datas[5].wechatShareImgUrl + '?imageView2/2/interlace/1/q/75';  
253 - }  
254 - } else if (datas[5].showShareImgUrl) {  
255 - datas[5].showShareImgUrl =  
256 - datas[5].showShareImgUrl.substring(datas[5].showShareImgUrl.indexOf('//'));  
257 -  
258 - if (datas[5].showShareImgUrl.indexOf('?') === -1) {  
259 - datas[5].showShareImgUrl = datas[5].showShareImgUrl + '?imageView2/2/interlace/1/q/75';  
260 - } 258 + if (datas[5].wechatShareImgUrl.indexOf('?') === -1) {
  259 + datas[5].wechatShareImgUrl = datas[5].wechatShareImgUrl +
  260 + '?imageView2/2/interlace/1/q/75';
261 } 261 }
  262 + } else if (datas[5].qqShareImgUrl) {
  263 + datas[5].qqShareImgUrl =
  264 + datas[5].qqShareImgUrl.substring(datas[5].qqShareImgUrl.indexOf('//'));
262 265
263 - let preCount = 0;  
264 - let i; 266 + if (datas[5].qqShareImgUrl.indexOf('?') === -1) {
  267 + datas[5].qqShareImgUrl = datas[5].wechatShareImgUrl + '?imageView2/2/interlace/1/q/75';
  268 + }
  269 + } else if (datas[5].showShareImgUrl) {
  270 + datas[5].showShareImgUrl =
  271 + datas[5].showShareImgUrl.substring(datas[5].showShareImgUrl.indexOf('//'));
265 272
266 - for (i = 0; i < getArticleContent.length; i++) {  
267 - if (getArticleContent[i].singleImage ||  
268 - getArticleContent[i].text || getArticleContent[i].smallPic) {  
269 - preCount = i + 1;  
270 - } 273 + if (datas[5].showShareImgUrl.indexOf('?') === -1) {
  274 + datas[5].showShareImgUrl = datas[5].showShareImgUrl + '?imageView2/2/interlace/1/q/75';
271 } 275 }
  276 + }
272 277
273 - getArticleContent.splice(preCount, 0, {  
274 - shareCode: datas[5]  
275 - }); 278 + let preCount = 0;
  279 + let i;
276 280
  281 + for (i = 0; i < getArticleContent.length; i++) {
  282 + if (getArticleContent[i].singleImage ||
  283 + getArticleContent[i].text || getArticleContent[i].smallPic) {
  284 + preCount = i + 1;
  285 + }
277 } 286 }
278 287
279 - if (datas[0]) {  
280 - result.getAuthor = datas[0].data;  
281 - } 288 + getArticleContent.splice(preCount, 0, {
  289 + shareCode: datas[5]
  290 + });
  291 + }
282 292
  293 + if (datas[0]) {
  294 + result.getAuthor = datas[0].data;
  295 + }
283 296
284 - if (datas[2]) {  
285 - result.getBrand = datas[2].data;  
286 - }  
287 297
288 - if (isShare && datas[4]) {  
289 - result.sideNav = datas[4];  
290 - } 298 + if (datas[2]) {
  299 + result.getBrand = datas[2].data;
  300 + }
291 301
292 - if (datas.length === 5 && isApp || datas.length === 4 && !isApp || datas.length === 6 && isShare) {  
293 - if (datas[3]) {  
294 - result.getOtherArticle = datas[3].data;  
295 - } 302 + if (isShare && datas[4]) {
  303 + result.sideNav = datas[4];
  304 + }
  305 +
  306 + if (datas.length === 5 && isApp || datas.length === 4 && !isApp || datas.length === 6 && isShare) {
  307 + if (datas[3]) {
  308 + result.getOtherArticle = datas[3].data;
296 } 309 }
297 } 310 }
298 311
@@ -36,20 +36,9 @@ @@ -36,20 +36,9 @@
36 <img class="lazy" data-original={{image2 bigImage q=60}}> 36 <img class="lazy" data-original={{image2 bigImage q=60}}>
37 {{/if}} 37 {{/if}}
38 38
39 - <div class="label-box" style="top: 30px; left: 40px;">  
40 - <div class="lable-focus">  
41 - <div class="focus-big">  
42 - <div class="focus-small"></div>  
43 - </div>  
44 - </div>  
45 - <div class="lable-info-box">  
46 - <span class="lable-text">这个是商品标题</span>  
47 - </div>  
48 - <div class="lable-btn">  
49 - <span class="iconfont">&#xe62c;</span>  
50 - <span class="iconfont plus">&#xe624;</span>  
51 - </div>  
52 - </div> 39 + {{#tagList}}
  40 + {{> detail/img-label}}
  41 + {{/tagList}}
53 </div> 42 </div>
54 {{/if}} 43 {{/if}}
55 44
  1 +<div class="label-box" style="top: 30px; left: 40px;">
  2 + <div class="lable-focus">
  3 + <div class="focus-big">
  4 + <div class="focus-small"></div>
  5 + </div>
  6 + </div>
  7 + <div class="lable-info-box">
  8 + <span class="lable-text">这个是商品标题</span>
  9 + </div>
  10 + <div class="lable-btn">
  11 + <span class="iconfont">&#xe62c;</span>
  12 + <span class="iconfont plus">&#xe624;</span>
  13 + </div>
  14 +</div>
@@ -14,8 +14,8 @@ const domains = { @@ -14,8 +14,8 @@ const domains = {
14 liveApi: 'http://testapi.live.yohops.com:9999/', 14 liveApi: 'http://testapi.live.yohops.com:9999/',
15 singleApi: 'http://api-test3.yohops.com:9999/', 15 singleApi: 'http://api-test3.yohops.com:9999/',
16 16
17 - api: 'http://dev-api.yohops.com:9999/',  
18 - service: 'http://dev-service.yohops.com:9999/', 17 + api: 'http://api-test3.yohops.com:9999/',
  18 + service: 'http://service-test3.yohops.com:9999/',
19 global: 'http://api-global.yohobuy.com', 19 global: 'http://api-global.yohobuy.com',
20 20
21 // liveApi: 'http://api.live.yoho.cn/', 21 // liveApi: 'http://api.live.yoho.cn/',