Authored by 王水玲

星潮优化

@@ -24,6 +24,8 @@ const headTab = [ @@ -24,6 +24,8 @@ const headTab = [
24 } 24 }
25 ]; 25 ];
26 26
  27 +let md5Str = '';
  28 +
27 const processPublicData = (req, title) => { 29 const processPublicData = (req, title) => {
28 let renderData = { 30 let renderData = {
29 module: 'guang', 31 module: 'guang',
@@ -49,6 +51,7 @@ exports.index = (req, res, next) => { @@ -49,6 +51,7 @@ exports.index = (req, res, next) => {
49 pageHeadTab[0].cur = true; 51 pageHeadTab[0].cur = true;
50 52
51 starModel.getIndexData().then((result) => { 53 starModel.getIndexData().then((result) => {
  54 + md5Str = result.md5;
52 res.render('star/index', _.assign({ 55 res.render('star/index', _.assign({
53 page: 'star', 56 page: 'star',
54 isStarIndexPage: true, 57 isStarIndexPage: true,
@@ -58,22 +61,28 @@ exports.index = (req, res, next) => { @@ -58,22 +61,28 @@ exports.index = (req, res, next) => {
58 data: result.ads 61 data: result.ads
59 }, 62 },
60 starAvatar: result.starAvatar ? result.starAvatar : '', 63 starAvatar: result.starAvatar ? result.starAvatar : '',
61 - articles: result.articles 64 + articles: result.articles,
  65 + md5: result.md5
62 }, processPublicData(req, '星潮教室'))); 66 }, processPublicData(req, '星潮教室')));
63 }).catch(next); 67 }).catch(next);
64 }; 68 };
65 69
66 exports.getIndexHtml = (req, res, next) => { 70 exports.getIndexHtml = (req, res, next) => {
67 starModel.getIndexData().then((result) => { 71 starModel.getIndexData().then((result) => {
68 - res.render('star/index-html', _.assign({  
69 - layout: false,  
70 - content: {  
71 - focus: true,  
72 - data: result.ads  
73 - },  
74 - starAvatar: result.starAvatar ? result.starAvatar : '',  
75 - articles: result.articles  
76 - })); 72 + if (md5Str !== result.md5) {
  73 + res.render('star/index-html', _.assign({
  74 + layout: false,
  75 + content: {
  76 + focus: true,
  77 + data: result.ads
  78 + },
  79 + starAvatar: result.starAvatar ? result.starAvatar : '',
  80 + articles: result.articles
  81 + }));
  82 + } else {
  83 + res.json();
  84 + }
  85 +
77 }).catch(next); 86 }).catch(next);
78 }; 87 };
79 88
@@ -44,16 +44,19 @@ const _getResources = (page) => { @@ -44,16 +44,19 @@ const _getResources = (page) => {
44 * @param {[array]} list 44 * @param {[array]} list
45 * @return {[array]} 45 * @return {[array]}
46 */ 46 */
47 -const _processIndexData = (list) => { 47 +const _processIndexData = (dataList) => {
48 const formatData = { 48 const formatData = {
49 ads: [], 49 ads: [],
50 starAvatar: [], 50 starAvatar: [],
51 articles: [] 51 articles: []
52 }; 52 };
53 53
54 - list = list || {}; 54 + let list = dataList.data || {};
  55 +
55 list = camelCase(list); 56 list = camelCase(list);
56 57
  58 + formatData.md5 = dataList.md5;
  59 +
57 // 首页资源位数据处理 60 // 首页资源位数据处理
58 if (list.ads) { 61 if (list.ads) {
59 _.forEach(list.ads.data, (data) => { 62 _.forEach(list.ads.data, (data) => {
@@ -155,7 +158,7 @@ const getIndexData = () => { @@ -155,7 +158,7 @@ const getIndexData = () => {
155 client_type: 'iphone' 158 client_type: 'iphone'
156 })).then((result) => { 159 })).then((result) => {
157 if (result && result.code === 200) { 160 if (result && result.code === 200) {
158 - return _processIndexData(result.data); 161 + return _processIndexData(result);
159 } else { 162 } else {
160 logger.error('星潮教室首页数据返回 code 不是 200'); 163 logger.error('星潮教室首页数据返回 code 不是 200');
161 return {}; 164 return {};
@@ -102,11 +102,6 @@ function setIndexAction() { @@ -102,11 +102,6 @@ function setIndexAction() {
102 pullDown: function() { 102 pullDown: function() {
103 if (!stopLoading) { 103 if (!stopLoading) {
104 stopLoading = true; 104 stopLoading = true;
105 -  
106 - if (avatarSwiperClone) {  
107 - avatarSwiperClone.destroy(true, true);  
108 - avatarSwiperClone = '';  
109 - }  
110 getIndexHtml(); 105 getIndexHtml();
111 } 106 }
112 } 107 }
@@ -264,14 +259,17 @@ getIndexHtml = function() { @@ -264,14 +259,17 @@ getIndexHtml = function() {
264 success: function(data) { 259 success: function(data) {
265 stopLoading = false; 260 stopLoading = false;
266 261
267 - if (!data) {  
268 - stopLoading = true;  
269 - tip.show('没有更多内容了');  
270 - } 262 + if (data) {
  263 + if (avatarSwiperClone) {
  264 + avatarSwiperClone.destroy(true, true);
  265 + avatarSwiperClone = '';
  266 + }
  267 +
  268 + $starMain.html(data);
271 269
272 - $starMain.html(data); 270 + initAction();
  271 + }
273 272
274 - initAction();  
275 loading.hideLoadingMask(); 273 loading.hideLoadingMask();
276 }, 274 },
277 error: function() { 275 error: function() {