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 };
@@ -16,52 +16,74 @@ const _formatTime = (a, b) => { @@ -16,52 +16,74 @@ const _formatTime = (a, b) => {
16 status = b ? '预告' : '今天'; 16 status = b ? '预告' : '今天';
17 } 17 }
18 return `${status} ${time.getHours() < 10 ? '0' + time.getHours() : time.getHours()} 18 return `${status} ${time.getHours() < 10 ? '0' + time.getHours() : time.getHours()}
19 - :${time.getMinutes() < 10 ? '0' + time.getMinutes() : time.getMinutes()}`; 19 + :${time.getMinutes() < 10 ? '0' + time.getMinutes() : time.getMinutes()}`;
20 }; 20 };
21 21
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 - let list = result.data; 25 + if (result && result.code === 200) {
  26 + let list = result.data;
26 27
27 - for (let item of list) {  
28 - switch (item.living) {  
29 - case 0:  
30 - default:  
31 - item.pre_living = true;  
32 - break;  
33 - case 1:  
34 - item.now_living = true;  
35 - break;  
36 - case 2:  
37 - item.rec_living = true;  
38 - break; 28 + for (let item of list) {
  29 + switch (item.living) {
  30 + case 0:
  31 + item.pre_living = true;
  32 + break;
  33 + case 1:
  34 + default:
  35 + item.now_living = true;
  36 + break;
  37 + case 2:
  38 + item.rec_living = true;
  39 + break;
  40 + }
  41 + //格式化时间
  42 + item.starting_time = _formatTime(item.starting_time, true);
39 } 43 }
  44 + return result;
  45 + } else {
  46 + return false;
40 } 47 }
41 - return result;  
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 => {
53 - let list = result.data; 65 + if (result && result.code === 200) {
  66 + let list = result.data;
54 67
55 - for (let item of list) {  
56 - item.starting_time = _formatTime(item.starting_time); 68 + for (let item of list) {
  69 + item.starting_time = _formatTime(item.starting_time);
  70 + }
  71 + return result;
  72 + } else {
  73 + return false;
57 } 74 }
58 - return result;  
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'));