From d0cc2c6bbc1cbf58021b1eb0fdea2bf10e6ac7b4 Mon Sep 17 00:00:00 2001 From: caicai8 <1149225589@qq.com> Date: Tue, 31 Dec 2019 16:22:39 +0800 Subject: [PATCH] time --- public/react/src/forge/Main/Index.js | 95 +++++++++++++++++------- public/react/src/forge/Main/IndexItem.js | 79 ++++++++++---------- public/react/src/forge/Main/list.css | 1 + 3 files changed, 109 insertions(+), 66 deletions(-) diff --git a/public/react/src/forge/Main/Index.js b/public/react/src/forge/Main/Index.js index f80466b66..08ab2a23b 100644 --- a/public/react/src/forge/Main/Index.js +++ b/public/react/src/forge/Main/Index.js @@ -1,6 +1,6 @@ import React , { Component } from 'react'; -import { Menu , Input , Dropdown , Icon, Result } from 'antd'; +import { Menu , Input , Dropdown , Icon, Spin , Pagination } from 'antd'; import { Link } from 'react-router-dom'; import '../css/index.css' import './list.css'; @@ -18,7 +18,9 @@ class Index extends Component{ page:1, limit:15, search:undefined, - sort:undefined + sort:undefined, + total:0, + isSpin:true, } } @@ -34,30 +36,67 @@ class Index extends Component{ user_id:current_user && current_user.user_id, page, limit, - name:search, + search, sort_by:sort }}).then((result)=>{ if(result){ this.setState({ - projectsList:result.data + projectsList:result.data.projects, + total:result.data.total_count, + isSpin:false }) } }).catch((error)=>{}) } + // 排序 + ChangeSoryBy=(e)=>{ + this.setState({ + sort_by:e.key, + page:1, + search:undefined, + isSpin:true + }) + const { limit } = this.state; + this.getListData(1 ,limit , undefined , e.key); + } + + // 搜索 + searchFun=(value)=>{ + // console.log(value) + this.setState({ + page:1, + search:value, + isSpin:true + }) + const { limit , sort } = this.state; + this.getListData(1 ,limit, value , sort); + } + // 翻页 + ChangePage=(page)=>{ + this.setState({ + page + }) + const { limit, search , sort } = this.state; + this.getListData(page,limit, search , sort); + } + render(){ const menu=( - - - 1st menu item - - - 2nd menu item - + + 更新时间排序 + 创建时间排序 + fork数据排序 + 点赞数量排序 ) - const { projectsList } = this.state; + const { projectsList , isSpin , total , limit , page } = this.state; + + const pagination = ( + total && total > 0 && + + ) return(
@@ -100,21 +139,23 @@ class Index extends Component{
-
- console.log(value)} - className="list-r-Search" - /> - - - 排序 - - -
- + +
+ + + + 排序 + + +
+ +
) diff --git a/public/react/src/forge/Main/IndexItem.js b/public/react/src/forge/Main/IndexItem.js index ad33b05c6..87b0cf9c7 100644 --- a/public/react/src/forge/Main/IndexItem.js +++ b/public/react/src/forge/Main/IndexItem.js @@ -1,43 +1,46 @@ import React , { Component } from 'react'; - -import { Menu , Input , Dropdown , Icon, Result } from 'antd'; +import { getImageUrl } from 'educoder'; import { Link } from 'react-router-dom'; import '../css/index.css' import './list.css'; +//把时间戳转换为几分钟或几小时前或几天前 +function getDateDiff(dateTimeStamp){ + var minute = 1000 * 60; + var hour = minute * 60; + var day = hour * 24; + var month = day * 30; + + var now = new Date().getTime(); + var diffValue = now - dateTimeStamp; + if(diffValue < 0){return;} + var monthC =diffValue/month; + var weekC =diffValue/(7*day); + var dayC =diffValue/day; + var hourC =diffValue/hour; + var minC =diffValue/minute; -class IndexItem extends Component{ - renderList=(list)=>{ - if(list && list.length >0 ){ - list.map((item,key)=>{ - return( -
- -
-
- {item.name} - - {item.forked_count} - 10 - { item.language && item.language.id && } - - -
-
-

{item.description}

-
-
- - {item.visits} - { item.category && item.category.id && {item.category.name}} - - 最后更新于9小时前 -
-
-
- ) - }) - } + var result = ""; + if(monthC>=1){ + result="" + parseInt(monthC) + "月前"; + } + else if(weekC>=1){ + result="" + parseInt(weekC) + "周前"; + } + else if(dayC>=1){ + result=""+ parseInt(dayC) +"天前"; + } + else if(hourC>=1){ + result=""+ parseInt(hourC) +"小时前"; } + else if(minC>=1){ + result=""+ parseInt(minC) +"分钟前"; + }else + result="刚刚"; + return result; +} + +class IndexItem extends Component{ + render(){ const { projects } = this.props; @@ -45,15 +48,14 @@ class IndexItem extends Component{ projects && projects.length >0 && projects.map((item,key)=>{ return(
- +
{item.name} { item.forked_count ? { item.forked_count}:"" } - { item.prasies_count ? { item.prasies_count }:"" } + { item.praises_count } { item.language && item.language.id ? :"" } -
@@ -64,14 +66,13 @@ class IndexItem extends Component{ {item.visits} { item.category && item.category.id && {item.category.name}} - 最后更新于9小时前 + {item.last_update_time ? {getDateDiff(item.last_update_time)} : "" }
) }) ) - console.log(renderList); return(
{ renderList } diff --git a/public/react/src/forge/Main/list.css b/public/react/src/forge/Main/list.css index ded2d3068..28ddcdb8f 100644 --- a/public/react/src/forge/Main/list.css +++ b/public/react/src/forge/Main/list.css @@ -120,6 +120,7 @@ border-left: #efefef; padding:0px 4px; border-radius: 0px 4px 4px 0px; + color: #999; } .p-r-content{ margin-top:10px;