import React, {PureComponent} from "react";
import {connect} from 'react-redux';
import axios from "axios";
import {ArchivesWrapper, ArticleTop, MainWrapper} from "./style";
import {Link} from 'react-router-dom';
import {Spin} from "antd";
const setYears = (time) => {
const date = new Date(time);
let Y = date.getFullYear() + '年';
let M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '月';
return (Y + M)
};
const setDay = (time) => {
const date = new Date(time);
return date.getDate() + '日'
};
const ArchivesList = (props) => {
const {list, loading} = props;
const Class = ['info', 'dark', 'success', 'black', 'warning', 'primary', 'danger'];
if (loading) {
return (
)
} else {
return (
)
}
};
class Archives extends PureComponent {
constructor(props) {
super(props);
this.state = {
timg: '',
list: [],
loading: true
}
}
render() {
const {list, loading} = this.state;
return (
文章归档
)
}
componentDidMount() {
this.getArchives();
this.getTimg();
}
getArchives() {
this.setState({loading: true});
axios.get('/posts/archive/v1/list').then((res) => {
if (res.success === 1) {
this.setState({
list: res.models,
loading: false
})
}
});
}
getTimg() {
const list = this.props.topImg;
const num = this.getrand(0, list.length - 1);
this.setState({timg: list[num].img})
}
getrand(m, n) {
return Math.floor(Math.random() * (n - m + 1)) + m;
}
}
const mapState = (state) => {
return {
topImg: state.getIn(['image', 'topImg'])
}
};
export default connect(mapState)(Archives)