Authored by zzzzzzz

状态码容错处理

... ... @@ -3,14 +3,15 @@ var liveModel = require('../models/live');
exports.index = (req, res, next) => {
liveModel.getAllList().then(result => {
console.log(result);
res.render('entry', {
title: '直播列表',
module: 'activity',
page: 'entry',
best: result[0].data,
living: result[1].data,
pre: result[2].data,
record: result[3].data
best: result[0] && result[0].data,
living: result[1] && result[1].data,
pre: result[2] && result[2].data,
record: result[3] && result[3].data
});
}).catch(next);
};
... ...
... ... @@ -22,46 +22,68 @@ const _formatTime = (a, b) => {
// 获取精选视频
const _getBestList = () => {
return api.get('v1/living/best', {}, true).then(result => {
if (result && result.code === 200) {
let list = result.data;
for (let item of list) {
switch (item.living) {
case 0:
default:
item.pre_living = true;
break;
case 1:
default:
item.now_living = true;
break;
case 2:
item.rec_living = true;
break;
}
//格式化时间
item.starting_time = _formatTime(item.starting_time, true);
}
return result;
} else {
return false;
}
});
};
// 获取直播中所有视频
const _getLivingList = () => {
return api.get('v1/living/listing', {}, true);
return api.get('v1/living/listing', {}, true).then(result => {
if (result && result.code === 200) {
return result;
} else {
return false;
}
});
};
// 获取直播预告列表
const _getPrelivingList = () => {
return api.get('v1/living/starting', {}, true).then(result => {
if (result && result.code === 200) {
let list = result.data;
for (let item of list) {
item.starting_time = _formatTime(item.starting_time);
}
return result;
} else {
return false;
}
});
};
// 获取回看列表
const _getRecordList = () => {
return api.get('v1/living/replaying', {}, true);
return api.get('v1/living/replaying', {}, true).then(result => {
if (result && result.code === 200) {
return result;
} else {
return false;
}
});
};
// 返回所有数据
... ...
... ... @@ -2,12 +2,12 @@
<div class="live-rec">
{{#best}}
<div class="rec-child">
<a href="#">
<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}}"}}'>
<img class="rec-pic" src="{{image pic 320 320}}" alt="直播预览">
{{#if now_living}}
<p class="living">直播</p>
{{else if pre_living}}
<p class="pre-living">12.12 18:00</p>
<p class="pre-living">{{starting_time}}</p>
{{else rec_living}}
<p class="living">回放</p>
{{/if}}
... ... @@ -81,7 +81,7 @@
</div>
</header>
<section>
<a href="#">
<a href="{{url}}">
<div class="record-icon"></div>
<img class="main-bg" src="{{image pic 640 640}}" alt="精彩回放">
<p class="main-living">回放</p>
... ...
var $ = require('yoho-jquery'),
lazyLoad = require('yoho-jquery-lazyload');
lazyLoad($('img'));
\ No newline at end of file
... ...