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,110 +186,51 @@ class DetailModel extends global.yoho.BaseModel { @@ -111,110 +186,51 @@ 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]) {  
209 -  
210 - getArticleContent = datas[1].data;  
211 -  
212 - result.getArticleContent = getArticleContent; 225 + if (!datas) {
  226 + return result;
  227 + }
213 228
  229 + if (datas[1]) {
  230 + result.getArticleContent = getArticleContent = datas[1].data;
214 } 231 }
215 232
216 if (isApp && datas[4] && datas[4].data) { 233 if (isApp && datas[4] && datas[4].data) {
217 -  
218 let preCount = 0; 234 let preCount = 0;
219 let i; 235 let i;
220 236
@@ -235,7 +251,6 @@ class DetailModel extends global.yoho.BaseModel { @@ -235,7 +251,6 @@ class DetailModel extends global.yoho.BaseModel {
235 } 251 }
236 252
237 if (isShare && datas[5]) { 253 if (isShare && datas[5]) {
238 -  
239 if (datas[5].wechatShareImgUrl) { 254 if (datas[5].wechatShareImgUrl) {
240 datas[5].wechatShareImgUrl = 255 datas[5].wechatShareImgUrl =
241 datas[5].wechatShareImgUrl.substring(datas[5].wechatShareImgUrl.indexOf('//')); 256 datas[5].wechatShareImgUrl.substring(datas[5].wechatShareImgUrl.indexOf('//'));
@@ -273,7 +288,6 @@ class DetailModel extends global.yoho.BaseModel { @@ -273,7 +288,6 @@ class DetailModel extends global.yoho.BaseModel {
273 getArticleContent.splice(preCount, 0, { 288 getArticleContent.splice(preCount, 0, {
274 shareCode: datas[5] 289 shareCode: datas[5]
275 }); 290 });
276 -  
277 } 291 }
278 292
279 if (datas[0]) { 293 if (datas[0]) {
@@ -294,7 +308,6 @@ class DetailModel extends global.yoho.BaseModel { @@ -294,7 +308,6 @@ class DetailModel extends global.yoho.BaseModel {
294 result.getOtherArticle = datas[3].data; 308 result.getOtherArticle = datas[3].data;
295 } 309 }
296 } 310 }
297 - }  
298 311
299 return result; 312 return result;
300 }); 313 });
@@ -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/',