index.js
3.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
import React,{Component} from 'react';
import WhiteBar from '@src/components/Common/WhiteBar';
import {Table,Input,Form,Button,Row,Col,Select,DatePicker,Message,Modal} from 'antd';
import {Link} from 'react-router-dom';
import { API_MENU_MANAGE, API_FILEUPLOAD_MANAGE,API_SYS_CMS } from '@src/Api';
import axios from '@src/axios/index';
import Utils from '@src/utils/utils';
import Storage from '@src/utils/localStorage';
export default class BannerManage extends Component {
state = {
bannersData: [],
pagination: {},
isLoading: true
}
params = {
pageSize: 10,
pageNum: 1
}
componentWillMount () {
let btnAuth = Storage.get('btnAuth')
this.setState({btnAuth})
}
componentDidMount () {
this.getBanners();
}
getBanners = () => {
let _this = this;
this.setState({isLoading: true});
axios.ajax({
url: API_SYS_CMS.getAppBanner,
data: {
...this.params
}
}).then((res) => {
this.setState({isLoading: false});
let dataList = [];
if (res.records.length > 0) {
dataList = res.records.map((item) => {
return {...item,key: item.id}
})
}
this.setState({
bannersData: dataList,
pagination: Utils.pagination(res, (current) => {
_this.params.pageNum = current;
_this.setState({isLoading: true});
this.getBanners();
})
})
});
}
deleteConfirm = (id,title) => {
let _this = this;
Modal.confirm({
title: `是否删除${title}的广告图`,
okText: '确定',
cancelText: '取消',
onOk () {
_this.delete(id);
},
onCancel () {
console.log('取消');
}
});
}
delete = (id) => {
axios.ajax({
url: API_SYS_CMS.deleteBannerById,
data: {
id: id
}
}).then((res) => {
Message.success('删除成功');
this.getBanners();
});
}
seeDetail = (id) => {
this.props.history.push({pathname: `/home/permission/bannerManage/bannerDetail/${id}`});
}
update = (id) => {
this.props.history.push({pathname: `/home/permission/bannerManage/bannerAdd/${id}`});
}
render () {
const columns = [
{title: '标题',dataIndex: 'title'},
{title: '创建时间',dataIndex: 'createTime',render: (createTime) => {
return Utils.formateDateToYMDSFM(createTime);
}},
{title: '更新时间',dataIndex: 'updateTime',render: (updateTime) => {
return Utils.formateDateToYMDSFM(updateTime);
}},
{title: '地址',dataIndex: 'cover',width: 300, render: (cover) => {
return Utils.formatTableColumn(cover);
}},
{title: '状态',dataIndex: 'state',render: (state) => {
return {'1': '有效','2': '无效'}[state]
}},
{title: '操作', render: (key,record) => {
const id = record.id;
const title = record.title;
return (
<div>
{
this.state.btnAuth.indexOf('banner-update') !== -1 ?
<Button onClick={this.update.bind(this,id)} style={{margin: '0 10px'}}>
修改
</Button> : ''
}
{
this.state.btnAuth.indexOf('banner-delete') !== -1 ?
<Button onClick={this.deleteConfirm.bind(this,id,title)}>删除</Button>
: ''
}
</div>
)
}}
]
return (
<div className="com-BannerManage">
<WhiteBar title="图片管理" />
<div style={{paddingLeft: 20}}>
{
this.state.btnAuth.indexOf('banner-add') !== -1 ?
<Button>
<Link to="/home/permission/bannerManage/bannerAdd">新增</Link>
</Button>
: ''
}
</div>
<WhiteBar title="详细数据" />
<div style={{background: '#fff',padding: 20}}>
<Table
dataSource={this.state.bannersData}
pagination={this.state.pagination}
loading={this.state.isLoading}
columns={columns}>
</Table>
</div>
</div>
)
}
}