123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396 |
- import React from 'react';
- import { Icon, Button, Spin, message, Table, Input, Modal, DatePicker, Upload, Select } from 'antd';
- import { beforeUpload, getBase64 } from '../../../tools';
- import moment from 'moment';
- import ajax from 'jquery/src/ajax/xhr.js';
- import $ from 'jquery/src/ajax';
- const Avatar = React.createClass({
- getInitialState() {
- return {
- imageUrl: ''
- }
- },
- handleChange(info) {
- if (info.file.status === 'done') {
-
- getBase64(info.file.originFileObj, imageUrl => this.setState({ imageUrl }));
- this.props.urlData(info.file.response.data);
- }
- },
- componentWillReceiveProps(nextProps) {
- if (this.props.id != nextProps.id) {
- this.state.imageUrl = null;
- };
- },
- render() {
- const imageUrl = this.state.imageUrl;
- return (
- <Upload
- className="avatar-uploader"
- name={this.props.name}
- showUploadList={false}
- action={globalConfig.context + "/api/admin/banners/upload"}
- data={{ 'sign': this.props.sign }}
- beforeUpload={beforeUpload}
- onChange={this.handleChange} >
- {
- (imageUrl || this.props.imageUrl) ?
- <img src={imageUrl || this.props.imageUrl} role="presentation" id={this.props.name} /> :
- <Icon type="plus" className="avatar-uploader-trigger" />
- }
- </Upload>
- );
- }
- });
- const Lecture = React.createClass({
- loadData(pageNo) {
- this.setState({
- loading: true
- });
- $.ajax({
- method: "get",
- dataType: "json",
- crossDomain: false,
- url: globalConfig.context + '/api/admin/banners/list',
- data: {
- pageNo: pageNo || 1,
- pageSize: this.state.pagination.pageSize,
- key: this.state.searchKey
- },
- success: function (data) {
- let theArr = [];
- if (!data.data) {
- if (data.error && data.error.length) {
- message.warning(data.error[0].message);
- };
- } else {
- for (let i = 0; i < data.data.length; i++) {
- let thisdata = data.data[i];
- theArr.push({
- key: i,
- id: thisdata.id,
- sign: thisdata.sign,
- text: thisdata.text,
- imgurl: thisdata.imgurl,
- url: thisdata.url,
- width: thisdata.width,
- height: thisdata.height,
- startDate: thisdata.startDate,
- endDate: thisdata.endDate
- });
- };
- this.state.pagination.current = data.data.pageNo;
- this.state.pagination.total = data.data.totalCount;
- };
- this.setState({
- tableData: theArr,
- pagination: this.state.pagination
- });
- }.bind(this),
- }).always(function () {
- this.setState({
- loading: false
- });
- }.bind(this));
- },
- getInitialState() {
- return {
- loading: false,
- visible: false,
- selectedRowKeys: [],
- selectedRows: [],
- keysObj: {},
- RowData: {},
- pagination: {
- defaultCurrent: 1,
- defaultPageSize: 10,
- showQuickJumper: true,
- pageSize: 10,
- onChange: function (page) {
- this.loadData(page);
- }.bind(this),
- showTotal: function (total) {
- return '共' + total + '条数据';
- }
- },
- columns: [
- {
- title: '位置',
- dataIndex: 'sign',
- key: 'sign',
- render: text => { return this.state.keysObj[text] }
- }, {
- title: '广告图描述',
- dataIndex: 'text',
- key: 'text',
- }, {
- title: '广告图url',
- dataIndex: 'imgurl',
- key: 'imgurl',
- }, {
- title: '跳转链接',
- dataIndex: 'url',
- key: 'url',
- }, {
- title: '宽度',
- dataIndex: 'width',
- key: 'width',
- }, {
- title: '高度',
- dataIndex: 'height',
- key: 'height',
- }, {
- title: '开始时间',
- dataIndex: 'startDate',
- key: 'startDate',
- }, {
- title: '结束时间',
- dataIndex: 'endDate',
- key: 'endDate',
- }
- ],
- tableData: []
- };
- },
- tableRowClick(record, index) {
- this.state.RowData = record;
- this.setState({
- visible: true
- });
- },
- componentWillMount() {
- this.loadData();
- },
- submit() {
- if (!this.state.RowData.sign) {
- message.warning('必须选择一个位置!');
- return;
- };
- if (!this.state.RowData.imgurl) {
- message.warning('必须上传一张广告图!');
- return;
- };
- if (!this.state.RowData.url) {
- message.warning('必须填写跳转链接!');
- return;
- };
- this.setState({
- loading: true
- });
- $.ajax({
- method: "post",
- dataType: "json",
- crossDomain: false,
- url: globalConfig.context + '/api/admin/banners/save',
- data: {
- id: this.state.RowData.id || null,
- sign: this.state.RowData.sign,
- text: this.state.RowData.text,
- imgurl: this.state.RowData.imgurl,
- url: this.state.RowData.url,
- width: this.state.RowData.width,
- height: this.state.RowData.height,
- startDate: this.state.RowData.startDate,
- endDate: this.state.RowData.endDate
- },
- success: function (data) {
- if (data.error && data.error.length) {
- message.warning(data.error[0].message);
- } else {
- message.success('保存成功!');
- this.setState({ visible: false });
- this.loadData();
- };
- }.bind(this),
- }).always(function () {
- this.setState({
- loading: false
- });
- }.bind(this));
- },
- delectRow() {
- if (this.state.selectedRows.length > 1) {
- return;
- };
- this.setState({
- selectedRowKeys: [],
- loading: this.state.selectedRows.length > 0
- });
- $.ajax({
- method: "POST",
- dataType: "json",
- crossDomain: false,
- url: globalConfig.context + "/api/admin/banners/delete",
- data: {
- id: this.state.selectedRows[0].id
- }
- }).done(function (data) {
- if (data.error && data.error.length) {
- message.warning(data.error[0].message);
- } else {
- message.success('删除成功!');
- };
- this.setState({
- loading: false,
- });
- this.loadData();
- }.bind(this));
- },
- reset() {
- this.state.searchKey = undefined;
- this.loadData();
- },
- render() {
- const rowSelection = {
- selectedRowKeys: this.state.selectedRowKeys,
- onChange: (selectedRowKeys, selectedRows) => {
- this.setState({
- selectedRows: selectedRows.slice(-1),
- selectedRowKeys: selectedRowKeys.slice(-1)
- });
- }
- };
- const hasSelected = this.state.selectedRowKeys.length > 0;
- return (
- <div></div>
- )
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- }
- });
- export default Lecture;
|