From 94feedf62ea49b8038c8d669727e212909588c73 Mon Sep 17 00:00:00 2001
From: caishi <1149225589@qq.com>
Date: Fri, 22 May 2020 15:20:36 +0800
Subject: [PATCH] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E5=BA=93=E7=9B=AE=E5=BD=95?=
=?UTF-8?q?=E5=A2=9E=E5=8A=A0time?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/forge/Main/CoderRootDirectory.js | 24 ++++++----
src/forge/Utils/Time.js | 65 ++++++++++++++++++++++++++++
2 files changed, 81 insertions(+), 8 deletions(-)
create mode 100644 src/forge/Utils/Time.js
diff --git a/src/forge/Main/CoderRootDirectory.js b/src/forge/Main/CoderRootDirectory.js
index f65ff7b2..bd4f1186 100644
--- a/src/forge/Main/CoderRootDirectory.js
+++ b/src/forge/Main/CoderRootDirectory.js
@@ -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) => (
this.goToSubRoot(item.path)}>
{text}
),
},{
- dataIndex:"commit",
+ dataIndex:"message",
width:"60%",
- render:(text,item)=>(
- item && item.message ? {item.message} :""
+ render:(text,item)=>
+ (
+ item.commit && item.commit.message ? {item.commit.message} :""
+ )
+ },{
+ dataIndex:"time",
+ width:"10%",
+ render:(text)=>(
+ text ? {Time(`${text}`)} :""
)
}
];
diff --git a/src/forge/Utils/Time.js b/src/forge/Utils/Time.js
new file mode 100644
index 00000000..921d9c4a
--- /dev/null
+++ b/src/forge/Utils/Time.js
@@ -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;
+
+}
\ No newline at end of file