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 {
source: Image.propTypes.source,
};
static getSlicedUrl(src, width, height, mode = 1) {
if (!src) {
return '';
}
width = PixelRatio.getPixelSizeForLayoutSize(width);
height = PixelRatio.getPixelSizeForLayoutSize(height);
let newSrc = src;
if (src.indexOf('imageView') === -1) {
newSrc = src + '?imageView2/' + mode + '/w/' + width + '/h/' + height;
} else {
newSrc = src.replace('{mode}', mode)
.replace('{width}', width)
.replace('{height}', height);
}
__DEV__ && console.log(newSrc);
return newSrc;
}
constructor(props) {
super (props);
... ... @@ -29,19 +50,7 @@ export default class SlicedImage extends React.Component {
_generateImageUrl(src) {
let style = StyleSheet.flatten(this.props.style);
let {width, height} = style;
width = PixelRatio.getPixelSizeForLayoutSize(width);
height = PixelRatio.getPixelSizeForLayoutSize(height);
let newSrc = src;
if (src.indexOf('imageView') === -1) {
newSrc = src + '?imageView2/' + this.mode + '/w/' + width + '/h/' + height;
} else {
newSrc = src.replace('{mode}', this.mode)
.replace('{width}', width)
.replace('{height}', height);
}
// __DEV__ && console.log(newSrc);
let newSrc = SlicedImage.getSlicedUrl(src, width, height, this.mode);
return newSrc;
}
... ...
... ... @@ -11,6 +11,7 @@ import HomeService from '../../services/HomeService';
import timeago from '../../utils/timeago';
import {number10KFormater} from '../../utils/numberFormater';
import {loginThenSyncUserInfo} from '../user/userActions';
import SlicedImage from '../../../common/components/SlicedImage';
const {
... ... @@ -302,6 +303,10 @@ function parseBNS(json) {
forumInfo.map((item, i) => {
let {hotPost, newPost} = item;
let hotAvatar = hotPost && hotPost.user && hotPost.user.headIcon ? hotPost.user.headIcon : '';
hotAvatar = SlicedImage.getSlicedUrl(hotAvatar, 30, 30);
let newAvatar = newPost && newPost.user && newPost.user.headIcon ? newPost.user.headIcon : '';
newAvatar = SlicedImage.getSlicedUrl(newAvatar, 30, 30);
let sectionItem = {
header: {
id: item.forumCode ? item.forumCode : 0,
... ... @@ -313,14 +318,14 @@ function parseBNS(json) {
like: number10KFormater(item.praiseNum),
},
hot: {
avatar: hotPost && hotPost.user && hotPost.user.headIcon ? hotPost.user.headIcon : '',
avatar: hotAvatar,
content: hotPost && hotPost.contentData ? decodeURI(hotPost.contentData) : '',
hasImg: hotPost && hotPost.hasImgFlg ? hotPost.hasImgFlg : '',
postId: hotPost && hotPost.postId ? hotPost.postId : '',
postTitle: hotPost && hotPost.postsTitle ? decodeURI(hotPost.postsTitle) : '',
},
new: {
avatar: newPost && newPost.user && newPost.user.headIcon ? newPost.user.headIcon : '',
avatar: newAvatar,
content: newPost && newPost.contentData ? decodeURI(newPost.contentData) : '',
hasImg: newPost && newPost.hasImgFlg ? newPost.hasImgFlg : '',
postId: newPost && newPost.postId ? newPost.postId : '',
... ...