Authored by yyq

Merge branch 'master' of git.yoho.cn:fe/yoho-community-web

@@ -71,6 +71,7 @@ export default { @@ -71,6 +71,7 @@ export default {
71 list: [], 71 list: [],
72 heights: 0, 72 heights: 0,
73 startIndex: 0, 73 startIndex: 0,
  74 + currentIndex: 0,
74 loadings: [], 75 loadings: [],
75 startOffset: 0, 76 startOffset: 0,
76 noMore: false 77 noMore: false
@@ -228,13 +229,20 @@ export default { @@ -228,13 +229,20 @@ export default {
228 updateIndex() { 229 updateIndex() {
229 // update visible items start index 230 // update visible items start index
230 let top = this.$el.scrollTop; 231 let top = this.$el.scrollTop;
  232 + let hasTopItem = false;
231 233
232 for (let i = 0; i < this.items.length; i++) { 234 for (let i = 0; i < this.items.length; i++) {
233 if (this.items[i].top > top) { 235 if (this.items[i].top > top) {
234 this.startIndex = Math.max(0, i - 1); 236 this.startIndex = Math.max(0, i - 1);
  237 + hasTopItem = true;
235 break; 238 break;
236 } 239 }
237 } 240 }
  241 + if (hasTopItem) {
  242 + this.currentIndex = this.startIndex;
  243 + } else {
  244 + this.currentIndex = this.items.length - 1;
  245 + }
238 }, 246 },
239 getStartItemOffset() { 247 getStartItemOffset() {
240 if (this.items[this.startIndex]) { 248 if (this.items[this.startIndex]) {
@@ -254,7 +262,7 @@ export default { @@ -254,7 +262,7 @@ export default {
254 } 262 }
255 this.updateIndex(); 263 this.updateIndex();
256 264
257 - this.$emit('scroll', {scrollTop: this.$el.scrollTop, startIndex: this.startIndex, item: this.items[this.startIndex]}); 265 + this.$emit('scroll', {scrollTop: this.$el.scrollTop, startIndex: this.currentIndex, item: this.items[this.currentIndex]});
258 }, 266 },
259 _onResize() { 267 _onResize() {
260 this.getStartItemOffset(); 268 this.getStartItemOffset();
1 <template> 1 <template>
2 - <button class="btn-follow hover-opacity" :class="followClass" @click="onFollow">{{followText}}</button> 2 + <div class="btn-follow hover-opacity" :class="followClass" @click="onFollow">{{followText}}</div>
3 </template> 3 </template>
4 4
5 <script> 5 <script>
1 <template> 1 <template>
2 - <Article ref="article" :on-fetch="onFetch" @on-follow="onFollow">  
3 - <template v-slot:thumb>  
4 - <ArticleItem v-for="data in currentList" :key="data.articleId" :data="data"></ArticleItem>  
5 - </template>  
6 - </Article> 2 + <Article ref="article" :on-fetch="onFetch" @on-follow="onFollow"></Article>
7 </template> 3 </template>
8 4
9 <script> 5 <script>
@@ -24,9 +20,6 @@ export default { @@ -24,9 +20,6 @@ export default {
24 created() { 20 created() {
25 this.id = this.$route.params.id; 21 this.id = this.$route.params.id;
26 }, 22 },
27 - serverPrefetch() {  
28 - return this.onFetch();  
29 - },  
30 beforeRouteUpdate(to, from, next) { 23 beforeRouteUpdate(to, from, next) {
31 if (this.$route.params.id !== to.params.id) { 24 if (this.$route.params.id !== to.params.id) {
32 this.id = to.params.id; 25 this.id = to.params.id;
@@ -51,13 +44,6 @@ export default { @@ -51,13 +44,6 @@ export default {
51 this.$refs.article.init(); 44 this.$refs.article.init();
52 }, 45 },
53 async onFetch() { 46 async onFetch() {
54 - if (this.page === 1 && this.articleList.length) {  
55 - this.page++;  
56 - this.fetchArticleProductFavs({  
57 - articles: this.articleList  
58 - });  
59 - return this.articleList;  
60 - }  
61 const articleId = parseInt(this.id, 10); 47 const articleId = parseInt(this.id, 10);
62 48
63 if (!articleId) { 49 if (!articleId) {
@@ -96,7 +96,6 @@ export default { @@ -96,7 +96,6 @@ export default {
96 }); 96 });
97 }, 97 },
98 onShare() { 98 onShare() {
99 - console.log(this.data.imageUrl)  
100 this.$yoho.share({ 99 this.$yoho.share({
101 title: '逛资讯', 100 title: '逛资讯',
102 imgUrl: this.data.imageUrl, 101 imgUrl: this.data.imageUrl,
1 <template> 1 <template>
2 <div class="article-item-slide"> 2 <div class="article-item-slide">
3 <Slide :data="data.blockList" :threshold="0.2" :auto-play="false" :loop="false" :options="scrollOption" @change="onChange"> 3 <Slide :data="data.blockList" :threshold="0.2" :auto-play="false" :loop="false" :options="scrollOption" @change="onChange">
4 - <SlideItem v-for="(item, inx) in data.blockList" :key="inx">  
5 - <ImageFormat :lazy="lazy" class="image-slide-item" :src="item.contentData" :width="item.width" :height="item.height"></ImageFormat> 4 + <SlideItem :style="slideItemStyle" v-for="(item, inx) in data.blockList" :key="inx">
  5 + <ImageFormat :mode="1" :lazy="lazy" :style="getImageStyle(item)" class="image-slide-item" :src="item.contentData" :width="item.width" :height="item.height"></ImageFormat>
6 </SlideItem> 6 </SlideItem>
7 <template slot="dots" slot-scope="props"> 7 <template slot="dots" slot-scope="props">
8 <span class="slide-dot" 8 <span class="slide-dot"
@@ -19,7 +19,9 @@ @@ -19,7 +19,9 @@
19 </template> 19 </template>
20 20
21 <script> 21 <script>
  22 +import {first} from 'lodash';
22 import {Slide} from 'cube-ui'; 23 import {Slide} from 'cube-ui';
  24 +import {mapState} from 'vuex';
23 25
24 export default { 26 export default {
25 name: 'ArticleItemSlide', 27 name: 'ArticleItemSlide',
@@ -43,7 +45,52 @@ export default { @@ -43,7 +45,52 @@ export default {
43 currentIndex: 1, 45 currentIndex: 1,
44 }; 46 };
45 }, 47 },
  48 + computed: {
  49 + ...mapState(['yoho']),
  50 + slideItemStyle() {
  51 + const {width, height} = this.firstBlockSize;
  52 +
  53 + if (width && height) {
  54 + return {
  55 + width: `${width}px`,
  56 + height: `${height}px`,
  57 + display: 'flex',
  58 + 'justify-content': 'center',
  59 + 'align-items': 'center'
  60 + };
  61 + }
  62 + },
  63 + firstBlockSize() {
  64 + const {width, height} = first(this.data.blockList) || {};
  65 +
  66 + if (width && height) {
  67 + const scale = width / height;
  68 +
  69 + return {
  70 + width: this.yoho.window.clientWidth,
  71 + height: this.yoho.window.clientWidth / scale,
  72 + };
  73 + }
  74 + return {};
  75 + }
  76 + },
46 methods: { 77 methods: {
  78 + getImageStyle({width, height}) {
  79 + const {height: fHeight} = this.firstBlockSize;
  80 + const scale = width / height;
  81 +
  82 + if (scale > 1) {
  83 + return {
  84 + width: `${this.yoho.window.clientWidth}px`,
  85 + height: `${this.yoho.window.clientWidth / scale}px`
  86 + };
  87 + } else if (scale < 1) {
  88 + return {
  89 + width: `${fHeight * scale}px`,
  90 + height: `${fHeight}px`
  91 + };
  92 + }
  93 + },
47 onChange(inx) { 94 onChange(inx) {
48 this.currentIndex = inx + 1; 95 this.currentIndex = inx + 1;
49 }, 96 },
@@ -88,7 +135,6 @@ export default { @@ -88,7 +135,6 @@ export default {
88 .article-item-slide { 135 .article-item-slide {
89 position: relative; 136 position: relative;
90 width: 750px; 137 width: 750px;
91 - height: 750px;  
92 overflow: hidden; 138 overflow: hidden;
93 139
94 & /deep/ .cube-slide-dots { 140 & /deep/ .cube-slide-dots {
@@ -120,8 +166,6 @@ export default { @@ -120,8 +166,6 @@ export default {
120 } 166 }
121 167
122 .image-slide-item { 168 .image-slide-item {
123 - width: 750px;  
124 - height: 750px;  
125 overflow: hidden; 169 overflow: hidden;
126 } 170 }
127 171
1 import * as Types from './types'; 1 import * as Types from './types';
2 -import { get } from 'lodash'; 2 +import {getArticleImageSize} from 'utils/image-handler';
  3 +import { get, first } from 'lodash';
3 4
4 export default { 5 export default {
5 [Types.FETCH_ARTICLE_DETAIL_REQUEST](state) { 6 [Types.FETCH_ARTICLE_DETAIL_REQUEST](state) {
@@ -13,6 +14,15 @@ export default { @@ -13,6 +14,15 @@ export default {
13 state.articleList = state.articleList.concat(data); 14 state.articleList = state.articleList.concat(data);
14 15
15 state.articleList.forEach((item, index) => { 16 state.articleList.forEach((item, index) => {
  17 + const imageBlocks = get(item, 'blockList', []).filter(block => block.templateKey === 'image');
  18 + const firstImage = first(imageBlocks);
  19 +
  20 + if (firstImage) {
  21 + let {width, height} = getArticleImageSize(firstImage);
  22 +
  23 + firstImage.width = width;
  24 + firstImage.height = height;
  25 + }
16 item.index = index; 26 item.index = index;
17 }); 27 });
18 data.forEach(item => { 28 data.forEach(item => {
  1 +const MIN_SCALE = 3 / 4;
  2 +
  3 +export function getArticleImageSize({width, height}) {
  4 + if (width / height < MIN_SCALE) {
  5 + return {
  6 + width,
  7 + height: width / MIN_SCALE
  8 + };
  9 + }
  10 + return {width, height};
  11 +}
@@ -58,7 +58,7 @@ module.exports = { @@ -58,7 +58,7 @@ module.exports = {
58 activity: '//activity.yohobuy.com', 58 activity: '//activity.yohobuy.com',
59 index: '//m.yohobuy.com' 59 index: '//m.yohobuy.com'
60 }, 60 },
61 - useCache: false, 61 + useCache: true,
62 loggers: { 62 loggers: {
63 infoFile: { 63 infoFile: {
64 close: true, 64 close: true,
1 module.exports = [ 1 module.exports = [
2 { 2 {
3 - route: /mapp\/order\/ufo\/\d+\.html/,  
4 - },  
5 - {  
6 - route: /mapp\/coupon\/ufo/,  
7 - },  
8 - {  
9 - route: /mapp\/coupon\/yoho/,  
10 - },  
11 - {  
12 - route: /mapp\/license\/form.html/, 3 + route: /article\/\d+/,
  4 +
  5 + // cacheKey: '$url$params',
  6 + // cache: true
13 } 7 }
14 ]; 8 ];
@@ -62,10 +62,10 @@ const handlerError = (err = {}, req, res, next) => { @@ -62,10 +62,10 @@ const handlerError = (err = {}, req, res, next) => {
62 return next(err); 62 return next(err);
63 }; 63 };
64 64
65 -const getCacheKey = (urlPath, cackeKey = '') => { 65 +const getCacheKey = (urlPath, cacheKey = '') => {
66 const urlObj = url.parse(urlPath); 66 const urlObj = url.parse(urlPath);
67 67
68 - return md5(cackeKey 68 + return md5(cacheKey
69 .replace('$url', urlObj.pathname) 69 .replace('$url', urlObj.pathname)
70 .replace('$params', urlObj.query)); 70 .replace('$params', urlObj.query));
71 }; 71 };
@@ -84,7 +84,7 @@ const render = (route) => { @@ -84,7 +84,7 @@ const render = (route) => {
84 if (isDegrade) { 84 if (isDegrade) {
85 return res.send(degradeHtml); 85 return res.send(degradeHtml);
86 } 86 }
87 - const ck = route.cackeKey ? getCacheKey(req.url, route.cackeKey) : void 0; 87 + const ck = route.cacheKey ? getCacheKey(req.url, route.cacheKey) : void 0;
88 88
89 if (config.useCache && route.cache && ck) { 89 if (config.useCache && route.cache && ck) {
90 const html = await redis.getAsync(ck); 90 const html = await redis.getAsync(ck);
@@ -116,7 +116,7 @@ const devRender = (route) => { @@ -116,7 +116,7 @@ const devRender = (route) => {
116 return async(req, res, next) => { 116 return async(req, res, next) => {
117 try { 117 try {
118 res.setHeader('X-YOHO-Version', pkg.version); 118 res.setHeader('X-YOHO-Version', pkg.version);
119 - const ck = route.cackeKey ? getCacheKey(req.url, route.cackeKey) : void 0; 119 + const ck = route.cacheKey ? getCacheKey(req.url, route.cacheKey) : void 0;
120 120
121 // return require('request-promise')({ 121 // return require('request-promise')({
122 // url: 'http://m.yohobuy.com:6005/degrade.html' 122 // url: 'http://m.yohobuy.com:6005/degrade.html'