代码库目录增加time
This commit is contained in:
parent
786702815f
commit
94feedf62e
|
|
@ -1,11 +1,9 @@
|
|||
import React , { Component } from 'react';
|
||||
import {Menu, Spin} from 'antd';
|
||||
import { getImageUrl , markdownToHTML } from 'educoder';
|
||||
import { getImageUrl } from 'educoder';
|
||||
import { Link } from 'react-router-dom';
|
||||
import Top from './DetailTop';
|
||||
|
||||
import './list.css';
|
||||
import readme_img from '../Images/book.svg';
|
||||
import SelectBranch from '../Branch/SelectBranch';
|
||||
import CloneAddress from '../Branch/CloneAddress';
|
||||
import RootTable from './RootTable';
|
||||
|
|
@ -13,6 +11,8 @@ import CoderRootFileDetail from './CoderRootFileDetail';
|
|||
import { truncateCommitId } from '../common/util';
|
||||
import RenderHtml from '../../components/render-html';
|
||||
|
||||
import Time from '../Utils/Time';
|
||||
|
||||
import axios from 'axios';
|
||||
/**
|
||||
* address:http和SSH,http_url(对应git地址)
|
||||
|
|
@ -202,6 +202,7 @@ class CoderRootDirectory extends Component{
|
|||
data && data.map((item,key)=>{
|
||||
rootList.push({
|
||||
key,
|
||||
message:item.commit && item.commit.message,
|
||||
...item
|
||||
})
|
||||
if(item.name === 'README.md'){
|
||||
|
|
@ -279,21 +280,28 @@ class CoderRootDirectory extends Component{
|
|||
const { branchLastCommit , http_url , isManager , isDeveloper } = this.props;
|
||||
const { projectsId } = this.props.match.params;
|
||||
|
||||
|
||||
console.log(rootList);
|
||||
const columns = [
|
||||
{
|
||||
dataIndex: 'name',
|
||||
width:"40%",
|
||||
width:"30%",
|
||||
render: (text,item) => (
|
||||
<a onClick={()=>this.goToSubRoot(item.path)}>
|
||||
<i className={ item.type === "file" ? "iconfont icon-wenjia font-15 color-green-file mr5":"iconfont icon-wenjian1 color-green-file font-15 mr5"}></i>{text}
|
||||
</a>
|
||||
),
|
||||
},{
|
||||
dataIndex:"commit",
|
||||
dataIndex:"message",
|
||||
width:"60%",
|
||||
render:(text,item)=>(
|
||||
item && item.message ? <span>{item.message}</span> :""
|
||||
render:(text,item)=>
|
||||
(
|
||||
item.commit && item.commit.message ? <span>{item.commit.message}</span> :""
|
||||
)
|
||||
},{
|
||||
dataIndex:"time",
|
||||
width:"10%",
|
||||
render:(text)=>(
|
||||
text ? <span>{Time(`${text}`)}</span> :""
|
||||
)
|
||||
}
|
||||
];
|
||||
|
|
|
|||
|
|
@ -0,0 +1,65 @@
|
|||
|
||||
function getDateTime(value, dataformat) {
|
||||
Date.prototype.format = function (format) {
|
||||
var date = {
|
||||
"M+": this.getMonth() + 1,
|
||||
"d+": this.getDate(),
|
||||
"h+": this.getHours(),
|
||||
"m+": this.getMinutes(),
|
||||
"s+": this.getSeconds(),
|
||||
"q+": Math.floor((this.getMonth() + 3) / 3),
|
||||
"S+": this.getMilliseconds()
|
||||
};
|
||||
if (/(y+)/i.test(format)) {
|
||||
format = format.replace(RegExp.$1, (this.getFullYear() + '').substr(4 - RegExp.$1.length));
|
||||
}
|
||||
|
||||
for (var k in date) {
|
||||
if (new RegExp("(" + k + ")").test(format)) {
|
||||
format = format.replace(RegExp.$1, RegExp.$1.length == 1 ? date[k] : ("00" + date[k]).substr(("" + date[k]).length));
|
||||
}
|
||||
}
|
||||
return format;
|
||||
};
|
||||
//注意,毫秒的话就不用乘以1000了,秒才要乘以1000
|
||||
var date = new Date(value);
|
||||
return date.format(dataformat);
|
||||
}
|
||||
|
||||
export default function Time(UTCtiem) {
|
||||
var dateTime = new Date(UTCtiem);
|
||||
|
||||
var year = dateTime.getFullYear();
|
||||
var month = dateTime.getMonth() + 1;
|
||||
var day = dateTime.getDate();
|
||||
var hour = dateTime.getHours();
|
||||
var minute = dateTime.getMinutes();
|
||||
var ms = dateTime.getTime();
|
||||
|
||||
var now = new Date();
|
||||
var msNow= now.getTime();
|
||||
|
||||
var milliseconds = 0;
|
||||
var timeSpanStr;
|
||||
milliseconds = msNow - ms;
|
||||
|
||||
if (milliseconds <= 1000 * 60 * 1) {
|
||||
timeSpanStr = '刚刚';
|
||||
}
|
||||
else if (1000 * 60 * 1 < milliseconds && milliseconds <= 1000 * 60 * 60) {
|
||||
timeSpanStr = Math.round((milliseconds / (1000 * 60))) + '分钟前';
|
||||
}
|
||||
else if (1000 * 60 * 60 * 1 < milliseconds && milliseconds <= 1000 * 60 * 60 * 24) {
|
||||
timeSpanStr = Math.round(milliseconds / (1000 * 60 * 60)) + '小时前';
|
||||
}
|
||||
else if (1000 * 60 * 60 * 24 < milliseconds && milliseconds <= 1000 * 60 * 60 * 24 * 15) {
|
||||
timeSpanStr = Math.round(milliseconds / (1000 * 60 * 60 * 24)) + '天前';
|
||||
}
|
||||
else if (milliseconds > 1000 * 60 * 60 * 24 * 15 && year == now.getFullYear()) {
|
||||
timeSpanStr = month + '-' + day + ' ' + hour + ':' + minute;
|
||||
} else {
|
||||
timeSpanStr = year + '-' + month + '-' + day + ' ' + hour + ':' + minute;
|
||||
}
|
||||
return timeSpanStr;
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue