Authored by zzzzzzz

时间格式化

var liveModel = require("../models/live");
var liveModel = require('../models/live');
exports.index = (req, res, next) => {
liveModel.getAllList().then(result => {
... ... @@ -9,4 +9,4 @@ exports.index = (req, res, next) => {
record: result[3].data
});
}).catch(next);
};
\ No newline at end of file
};
... ...
'use strict';
var api = global.yoho.ServiceAPI;
//返回所有数据
const getAllList = () => {
return Promise.all([_getBestList(), _getLivingList(), _getPrelivingList(), _getRecordList()]);
}
//获取精选视频
//格式化时间戳
const _formatTime = (a, b) => {
let time = new Date(a);
let today = new Date();
let judge = time.getDate() - today.getDate();
let status = '';
if (judge == 1) {
status = b ? '预告明日' : '明天';
} else if (judge > 1) {
status = b ? `${(time.getMonth()+1)}.${time.getDate()}` : `${(time.getMonth()+1)}${time.getDate()}日`;
} else {
status = b ? '预告' : '今天';
}
return `${status} ${time.getHours()<10?'0'+time.getHours():time.getHours()}:${time.getMinutes()<10?'0'+time.getMinutes():time.getMinutes()}`;
};
// 获取精选视频
const _getBestList = () => {
return api.get('v1/living/best', {}, true);
}
//获取直播中所有视频
return api.get('v1/living/best', {}, true).then(result => {
let list = result.data;
for (let item of list) {
switch (item.living) {
case 0:
default:
item.pre_living = true;
break;
case 1:
item.now_living = true;
break;
case 2:
item.rec_living = true;
break;
}
}
return result;
});
};
// 获取直播中所有视频
const _getLivingList = () => {
return api.get('v1/living/listing', {}, true);
}
//获取直播预告列表
return api.get('v1/living/listing', {}, true);
};
// 获取直播预告列表
const _getPrelivingList = () => {
return api.get('v1/living/starting', {}, true);
}
//获取回看列表
return api.get('v1/living/starting', {}, true).then(result => {
let list = result.data;
for (let item of list) {
item.starting_time = _formatTime(item.starting_time);
}
return result;
});
};
// 获取回看列表
const _getRecordList = () => {
return api.get('v1/living/replaying', {}, true);
}
return api.get('v1/living/replaying', {}, true);
};
// 返回所有数据
const getAllList = () => {
return Promise.all([_getBestList(), _getLivingList(), _getPrelivingList(), _getRecordList()]);
};
//处理直播时间
module.exports = {
getAllList
}
\ No newline at end of file
getAllList
};
... ...
... ... @@ -3,8 +3,13 @@
{{#best}}
<div class="rec-child">
<img class="rec-pic" src="{{image pic 320 320}}" alt="直播预览">
{{#if now_living}}
<p class="living">直播</p>
<!-- <p class="pre-living">预告18:00</p> -->
{{else if pre_living}}
<p class="pre-living">12.12 18:00</p>
{{else rec_living}}
<p class="living">回放</p>
{{/if}}
<div class="rec-info">
<img class="rec-head" src="{{image master_pic 60 60}}" alt="头像">
<div class="rec-pannel">
... ... @@ -47,7 +52,7 @@
<a href="#">
<img class="pre-pic" src="{{image pic 150 150}}" alt="直播预览图">
<p class="pre-icon">预告</p>
<p class="pre-time">今天16:00</p>
<p class="pre-time">{{starting_time}}</p>
<div class="pre-pannel">
<p class="pre-title">{{title}}</p>
<p class="pre-cast">主播:{{master_name}}</p>
... ...
... ... @@ -25,7 +25,7 @@ $gray: #b0b0b0;
top: 30px;
left: 30px;
height: 35px;
width: 123px;
padding: 0 10px;
border: 1px solid $white;
border-radius: 20px;
color: $white;
... ...