Authored by zzzzzzz

状态码容错处理

@@ -3,14 +3,15 @@ var liveModel = require('../models/live'); @@ -3,14 +3,15 @@ var liveModel = require('../models/live');
3 3
4 exports.index = (req, res, next) => { 4 exports.index = (req, res, next) => {
5 liveModel.getAllList().then(result => { 5 liveModel.getAllList().then(result => {
  6 + console.log(result);
6 res.render('entry', { 7 res.render('entry', {
7 title: '直播列表', 8 title: '直播列表',
8 module: 'activity', 9 module: 'activity',
9 page: 'entry', 10 page: 'entry',
10 - best: result[0].data,  
11 - living: result[1].data,  
12 - pre: result[2].data,  
13 - record: result[3].data 11 + best: result[0] && result[0].data,
  12 + living: result[1] && result[1].data,
  13 + pre: result[2] && result[2].data,
  14 + record: result[3] && result[3].data
14 }); 15 });
15 }).catch(next); 16 }).catch(next);
16 }; 17 };
@@ -22,46 +22,68 @@ const _formatTime = (a, b) => { @@ -22,46 +22,68 @@ const _formatTime = (a, b) => {
22 // 获取精选视频 22 // 获取精选视频
23 const _getBestList = () => { 23 const _getBestList = () => {
24 return api.get('v1/living/best', {}, true).then(result => { 24 return api.get('v1/living/best', {}, true).then(result => {
  25 + if (result && result.code === 200) {
25 let list = result.data; 26 let list = result.data;
26 27
27 for (let item of list) { 28 for (let item of list) {
28 switch (item.living) { 29 switch (item.living) {
29 case 0: 30 case 0:
30 - default:  
31 item.pre_living = true; 31 item.pre_living = true;
32 break; 32 break;
33 case 1: 33 case 1:
  34 + default:
34 item.now_living = true; 35 item.now_living = true;
35 break; 36 break;
36 case 2: 37 case 2:
37 item.rec_living = true; 38 item.rec_living = true;
38 break; 39 break;
39 } 40 }
  41 + //格式化时间
  42 + item.starting_time = _formatTime(item.starting_time, true);
40 } 43 }
41 return result; 44 return result;
  45 + } else {
  46 + return false;
  47 + }
42 }); 48 });
43 }; 49 };
44 50
45 // 获取直播中所有视频 51 // 获取直播中所有视频
46 const _getLivingList = () => { 52 const _getLivingList = () => {
47 - return api.get('v1/living/listing', {}, true); 53 + return api.get('v1/living/listing', {}, true).then(result => {
  54 + if (result && result.code === 200) {
  55 + return result;
  56 + } else {
  57 + return false;
  58 + }
  59 + });
48 }; 60 };
49 61
50 // 获取直播预告列表 62 // 获取直播预告列表
51 const _getPrelivingList = () => { 63 const _getPrelivingList = () => {
52 return api.get('v1/living/starting', {}, true).then(result => { 64 return api.get('v1/living/starting', {}, true).then(result => {
  65 + if (result && result.code === 200) {
53 let list = result.data; 66 let list = result.data;
54 67
55 for (let item of list) { 68 for (let item of list) {
56 item.starting_time = _formatTime(item.starting_time); 69 item.starting_time = _formatTime(item.starting_time);
57 } 70 }
58 return result; 71 return result;
  72 + } else {
  73 + return false;
  74 + }
59 }); 75 });
60 }; 76 };
61 77
62 // 获取回看列表 78 // 获取回看列表
63 const _getRecordList = () => { 79 const _getRecordList = () => {
64 - return api.get('v1/living/replaying', {}, true); 80 + return api.get('v1/living/replaying', {}, true).then(result => {
  81 + if (result && result.code === 200) {
  82 + return result;
  83 + } else {
  84 + return false;
  85 + }
  86 + });
65 }; 87 };
66 88
67 // 返回所有数据 89 // 返回所有数据
@@ -2,12 +2,12 @@ @@ -2,12 +2,12 @@
2 <div class="live-rec"> 2 <div class="live-rec">
3 {{#best}} 3 {{#best}}
4 <div class="rec-child"> 4 <div class="rec-child">
5 - <a href="#"> 5 + <a href='http://aaa.com/?aaa=1 & openby:yohobuy={"action":"go.videolive", "params":{"type":"{{living}}","videourl":"xxx.xxx.xxx","talkurl":"xxx.xxx.xxx","room":"{{room_id}}"}}'>
6 <img class="rec-pic" src="{{image pic 320 320}}" alt="直播预览"> 6 <img class="rec-pic" src="{{image pic 320 320}}" alt="直播预览">
7 {{#if now_living}} 7 {{#if now_living}}
8 <p class="living">直播</p> 8 <p class="living">直播</p>
9 {{else if pre_living}} 9 {{else if pre_living}}
10 - <p class="pre-living">12.12 18:00</p> 10 + <p class="pre-living">{{starting_time}}</p>
11 {{else rec_living}} 11 {{else rec_living}}
12 <p class="living">回放</p> 12 <p class="living">回放</p>
13 {{/if}} 13 {{/if}}
@@ -81,7 +81,7 @@ @@ -81,7 +81,7 @@
81 </div> 81 </div>
82 </header> 82 </header>
83 <section> 83 <section>
84 - <a href="#"> 84 + <a href="{{url}}">
85 <div class="record-icon"></div> 85 <div class="record-icon"></div>
86 <img class="main-bg" src="{{image pic 640 640}}" alt="精彩回放"> 86 <img class="main-bg" src="{{image pic 640 640}}" alt="精彩回放">
87 <p class="main-living">回放</p> 87 <p class="main-living">回放</p>
  1 +var $ = require('yoho-jquery'),
  2 + lazyLoad = require('yoho-jquery-lazyload');
  3 +
  4 +lazyLoad($('img'));