Authored by 于良

bug fix: http://jira.yoho.cn:8888/browse/YH-2681 review by 盖剑秋

@@ -15,6 +15,27 @@ export default class SlicedImage extends React.Component { @@ -15,6 +15,27 @@ export default class SlicedImage extends React.Component {
15 source: Image.propTypes.source, 15 source: Image.propTypes.source,
16 }; 16 };
17 17
  18 + static getSlicedUrl(src, width, height, mode = 1) {
  19 + if (!src) {
  20 + return '';
  21 + }
  22 +
  23 + width = PixelRatio.getPixelSizeForLayoutSize(width);
  24 + height = PixelRatio.getPixelSizeForLayoutSize(height);
  25 + let newSrc = src;
  26 + if (src.indexOf('imageView') === -1) {
  27 + newSrc = src + '?imageView2/' + mode + '/w/' + width + '/h/' + height;
  28 + } else {
  29 + newSrc = src.replace('{mode}', mode)
  30 + .replace('{width}', width)
  31 + .replace('{height}', height);
  32 + }
  33 +
  34 + __DEV__ && console.log(newSrc);
  35 +
  36 + return newSrc;
  37 + }
  38 +
18 constructor(props) { 39 constructor(props) {
19 super (props); 40 super (props);
20 41
@@ -29,19 +50,7 @@ export default class SlicedImage extends React.Component { @@ -29,19 +50,7 @@ export default class SlicedImage extends React.Component {
29 _generateImageUrl(src) { 50 _generateImageUrl(src) {
30 let style = StyleSheet.flatten(this.props.style); 51 let style = StyleSheet.flatten(this.props.style);
31 let {width, height} = style; 52 let {width, height} = style;
32 - width = PixelRatio.getPixelSizeForLayoutSize(width);  
33 - height = PixelRatio.getPixelSizeForLayoutSize(height);  
34 - let newSrc = src;  
35 - if (src.indexOf('imageView') === -1) {  
36 - newSrc = src + '?imageView2/' + this.mode + '/w/' + width + '/h/' + height;  
37 - } else {  
38 - newSrc = src.replace('{mode}', this.mode)  
39 - .replace('{width}', width)  
40 - .replace('{height}', height);  
41 - }  
42 -  
43 - // __DEV__ && console.log(newSrc);  
44 - 53 + let newSrc = SlicedImage.getSlicedUrl(src, width, height, this.mode);
45 return newSrc; 54 return newSrc;
46 } 55 }
47 56
@@ -11,6 +11,7 @@ import HomeService from '../../services/HomeService'; @@ -11,6 +11,7 @@ import HomeService from '../../services/HomeService';
11 import timeago from '../../utils/timeago'; 11 import timeago from '../../utils/timeago';
12 import {number10KFormater} from '../../utils/numberFormater'; 12 import {number10KFormater} from '../../utils/numberFormater';
13 import {loginThenSyncUserInfo} from '../user/userActions'; 13 import {loginThenSyncUserInfo} from '../user/userActions';
  14 +import SlicedImage from '../../../common/components/SlicedImage';
14 15
15 const { 16 const {
16 17
@@ -302,6 +303,10 @@ function parseBNS(json) { @@ -302,6 +303,10 @@ function parseBNS(json) {
302 forumInfo.map((item, i) => { 303 forumInfo.map((item, i) => {
303 let {hotPost, newPost} = item; 304 let {hotPost, newPost} = item;
304 305
  306 + let hotAvatar = hotPost && hotPost.user && hotPost.user.headIcon ? hotPost.user.headIcon : '';
  307 + hotAvatar = SlicedImage.getSlicedUrl(hotAvatar, 30, 30);
  308 + let newAvatar = newPost && newPost.user && newPost.user.headIcon ? newPost.user.headIcon : '';
  309 + newAvatar = SlicedImage.getSlicedUrl(newAvatar, 30, 30);
305 let sectionItem = { 310 let sectionItem = {
306 header: { 311 header: {
307 id: item.forumCode ? item.forumCode : 0, 312 id: item.forumCode ? item.forumCode : 0,
@@ -313,14 +318,14 @@ function parseBNS(json) { @@ -313,14 +318,14 @@ function parseBNS(json) {
313 like: number10KFormater(item.praiseNum), 318 like: number10KFormater(item.praiseNum),
314 }, 319 },
315 hot: { 320 hot: {
316 - avatar: hotPost && hotPost.user && hotPost.user.headIcon ? hotPost.user.headIcon : '', 321 + avatar: hotAvatar,
317 content: hotPost && hotPost.contentData ? decodeURI(hotPost.contentData) : '', 322 content: hotPost && hotPost.contentData ? decodeURI(hotPost.contentData) : '',
318 hasImg: hotPost && hotPost.hasImgFlg ? hotPost.hasImgFlg : '', 323 hasImg: hotPost && hotPost.hasImgFlg ? hotPost.hasImgFlg : '',
319 postId: hotPost && hotPost.postId ? hotPost.postId : '', 324 postId: hotPost && hotPost.postId ? hotPost.postId : '',
320 postTitle: hotPost && hotPost.postsTitle ? decodeURI(hotPost.postsTitle) : '', 325 postTitle: hotPost && hotPost.postsTitle ? decodeURI(hotPost.postsTitle) : '',
321 }, 326 },
322 new: { 327 new: {
323 - avatar: newPost && newPost.user && newPost.user.headIcon ? newPost.user.headIcon : '', 328 + avatar: newAvatar,
324 content: newPost && newPost.contentData ? decodeURI(newPost.contentData) : '', 329 content: newPost && newPost.contentData ? decodeURI(newPost.contentData) : '',
325 hasImg: newPost && newPost.hasImgFlg ? newPost.hasImgFlg : '', 330 hasImg: newPost && newPost.hasImgFlg ? newPost.hasImgFlg : '',
326 postId: newPost && newPost.postId ? newPost.postId : '', 331 postId: newPost && newPost.postId ? newPost.postId : '',