123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703 |
- import React from 'react';
- import '../../leftTab.less';
- import ReactDom from 'react-dom';
- import ajax from 'jquery/src/ajax/xhr.js';
- import $ from 'jquery/src/ajax';
- import Editors from '../../../richTextEditors'
- import '../content.less';
- import moment from 'moment';
- import { citySelect,provinceList,areaSelect,provinceSelect,addressList} from '../../../NewDicProvinceList';
- import { Form,Radio, Icon, Button, Input, Select, Spin, Table, Switch, message, DatePicker, Modal, Upload,Popconfirm,AutoComplete,Tabs,Checkbox,Tree,Cascader} from 'antd';
- import {policy} from '../../../dataDic.js';
- import {beforeUpload, getBase64,getauditStatus} from '../../../tools.js';
- const TabPane = Tabs.TabPane;
- const TreeNodet = Tree.TreeNode;
- const CheckboxGroup = Checkbox.Group;
- const Avatar = React.createClass({
- getInitialState() {
- return {
- imageUrl: ''
- }
- },
- handleChange(info) {
- if (info.file.status === 'done') {
- // Get this url from response in real world.
- getBase64(info.file.originFileObj, imageUrl => this.setState({ imageUrl }));
- this.props.urlData(info.file.response.data);
- }
- },
- componentWillReceiveProps(nextProps) {
- if (this.props.visible && !nextProps.visible) {
- 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/news/upload"}
- data={{ 'sign': 'news_title_picture' }}
- 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 Manage=React.createClass({
- loadData(pageNo, theType) {
- this.setState({
- loading: true,
- ispage:pageNo,
- });
- $.ajax({
- method: "get",
- dataType: "json",
- crossDomain: false,
- url: globalConfig.context + '/api/admin/news/list',
- data: {
- pageNo: pageNo || 1,
- pageSize: this.state.pagination.pageSize,
- type: theType || 1, //新闻类型
- title: this.state.searchTitle,
- author: this.state.searchAuthor,
- startCreateTime: this.state.startDate, //新闻开始时间 yyyy-MM-dd
- endCreateTime: this.state.endDate, //新闻结束时间 yyyy-MM-dd
- source: this.state.searchSource,
- hot: this.state.searchHot, //是否放在首页
- },
- success: function (data) {
- let theArr = [];
- if (!data.data || !data.data.list) {
- if (data.error && data.error.length) {
- message.warning(data.error[0].message);
- };
- } else {
- for (let i = 0; i < data.data.list.length; i++) {
- let thisdata = data.data.list[i];
- theArr.push({
- key: i,
- id: thisdata.id ? thisdata.id.toString() : null,
- createTime: thisdata.createTime,
- editTime: thisdata.editTime,
- title: thisdata.title,
- titleImg: thisdata.titleImg,
- author: thisdata.author,
- type: thisdata.type,
- callnubs:thisdata.type,
- hot: thisdata.hot,
- source: thisdata.source,
- sourceUrl: thisdata.sourceUrl,
- summary: thisdata.summary,
- content: thisdata.content,
- createTimeFormattedDate: thisdata.createTimeFormattedDate,
- auditStatus:thisdata.auditStatus,
- });
- };
- 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));
- },
- loadDetailData() {
- this.setState({
- loading: true
- });
- $.ajax({
- method: "get",
- dataType: "json",
- crossDomain: false,
- url: globalConfig.context + '/api/admin/news/detail',
- data: {
- id: this.state.RowData.id //新闻主键ID(数字类型,非字符串)
- },
- success: function (data) {
- let theObj = {};
- if (!data.data) {
- if (data.error && data.error.length) {
- message.warning(data.error[0].message);
- }
- } else {
- theObj = data.data;
- if(theObj.provinceId==null||theObj.provinceId==''){
- theObj.provinceId=11
- }
- };
- this.setState({
- RowData: theObj,
- topNumber:data.data.topNumber,
- hotspot:data.data.hotspot,
- callnubs:theObj.type.toString()
- });
- }.bind(this),
- }).always(function () {
- this.setState({
- loading: false
- });
- }.bind(this));
- },
- getInitialState() {
- return {
- loading: false,
- visible: false,
- callnub:'1',
- selectedRowKeys: [],
- selectedRows: [],
- keysObj: {},
- RowData: {},
- pagination: {
- defaultCurrent: 1,
- defaultPageSize: 10,
- showQuickJumper: true,
- pageSize: 10,
- onChange: function (page) {
- this.loadData(page,this.state.callnub);
- }.bind(this),
- showTotal: function (total) {
- return '共' + total + '条数据';
- }
- },
- columns: [
- {
- title: '标题',
- dataIndex: 'title',
- key: 'title',
- width: '20%'
- }, {
- title: '发布时间',
- dataIndex: 'createTimeFormattedDate',
- key: 'createTimeFormattedDate',
- }, {
- title: '作者',
- dataIndex: 'author',
- key: 'author',
- }, {
- title: '审核状态',
- dataIndex: 'auditStatus',
- key: 'auditStatus',
- render: text => { return getauditStatus(text) }
- }, {
- title: '来源',
- dataIndex: 'source',
- key: 'source',
- }, {
- title: '简介',
- dataIndex: 'summary',
- key: 'summary',
- width: '50%'
- }
- ],
- list:provinceList,
- tableData: []
- };
- },
- tableRowClick(record, index) {
- this.state.RowData = record;
- this.loadDetailData();
- this.setState({
- visible: true
- });
- },
- componentWillMount() {
- this.loadData(1,1);
- },
- componentWillReceiveProps(nextProps) {
- if (this.props.newsType != nextProps.newsType) {
- this.state.searchTitle = undefined;
- this.state.searchAuthor = undefined;
- this.state.startDate = undefined;
- this.state.endDate = undefined;
- this.state.searchSource = undefined;
- this.state.searchHot = undefined;
- this.loadData(1, nextProps.newsType);
- };
- },
- callback(e) {
- this.setState({
- callnub: e,
- })
- if(e == 1) {
- this.setState({
- })
- this.resets();
- this.loadData(1,1);
- }
- if(e == 2) {
- this.setState({
- })
- this.resets();
- this.loadData(1,2);
- }
- if(e == 3) {
- this.setState({
- })
- this.resets();
- this.loadData(1,3);
- }
- if(e == 4) {
- this.setState({
- })
- this.resets();
- this.loadData(1,4);
- }
- if(e == 5) {
- this.setState({
- })
- this.resets();
- this.loadData(1,5);
- }
- },
- submit() {
- if (!this.state.RowData.title) {
- message.warning('必须填写一个标题!');
- return;
- };
- if (!this.state.RowData.createTimeFormattedDate) {
- message.warning('必须选择一个发布时间!');
- return;
- };
- if (!this.state.RowData.author) {
- message.warning('必须填写一个作者!');
- return;
- };
- // if(this.state.topNumber){
- // let topStr = this.state.topNumber.toString();
- // let stateReg = topStr.match(/^[0-9]*$/g);
- // if(!stateReg){
- // message.warning('置顶请输入数字!')
- // return false
- // };
- // }
- this.setState({
- loading: true
- });
- $.ajax({
- method: "post",
- dataType: "json",
- crossDomain: false,
- url: globalConfig.context + (this.state.RowData.id ? '/api/admin/news/update' : '/api/admin/news/add'),
- data: {
- id: this.state.RowData.id || null, //主键,如果不填主键则为新增记录,填主键则为更新
- title: this.state.RowData.title,
- auditStatus:0,
- titleImg: this.state.RowData.titleImg,
- author: this.state.RowData.author,
- type: this.state.callnubs,
- hot: this.state.RowData.hot || 0,
- source: this.state.RowData.source,
- sourceUrl: this.state.RowData.sourceUrl,
- summary: this.state.RowData.summary,
- releaseStatus: this.state.RowData.releaseStatus,
- content: this.state.RowData.content,
- createTimeFormattedDate: this.state.RowData.createTimeFormattedDate,
- provinceId: this.state.RowData.provinceId,
- topNumber:this.state.topNumber,
- hotspot :this.state.hotspot
- },
- success: function (data) {
- if (data.error && data.error.length) {
- message.warning(data.error[0].message);
- } else {
- message.success('保存成功!');
- this.setState({ visible: false });
- this.loadData(this.state.ispage,this.state.callnub);
- };
- }.bind(this),
- }).always(function () {
- this.setState({
- loading: false
- });
- }.bind(this));
- },
- submits() {
- if (!this.state.RowData.title) {
- message.warning('必须填写一个标题!');
- return;
- };
- if (!this.state.RowData.createTimeFormattedDate) {
- message.warning('必须选择一个发布时间!');
- return;
- };
- if (!this.state.RowData.author) {
- message.warning('必须填写一个作者!');
- return;
- };
- this.setState({
- loading: true
- });
- $.ajax({
- method: "post",
- dataType: "json",
- crossDomain: false,
- url: globalConfig.context + (this.state.RowData.id ? '/api/admin/news/update' : '/api/admin/news/add'),
- data: {
- id: this.state.RowData.id || null, //主键,如果不填主键则为新增记录,填主键则为更新
- title: this.state.RowData.title,
- auditStatus:1,
- titleImg: this.state.RowData.titleImg,
- author: this.state.RowData.author,
- type: this.state.callnubs,
- hot: this.state.RowData.hot || 0,
- source: this.state.RowData.source,
- sourceUrl: this.state.RowData.sourceUrl,
- summary: this.state.RowData.summary,
- releaseStatus: this.state.RowData.releaseStatus,
- content: this.state.RowData.content,
- createTimeFormattedDate: this.state.RowData.createTimeFormattedDate,
- provinceId: this.state.RowData.provinceId,
- },
- success: function (data) {
- if (data.error && data.error.length) {
- message.warning(data.error[0].message);
- } else {
- message.success('保存成功!');
- this.setState({ visible: false });
- this.loadData(this.state.ispage,this.state.callnub);
- };
- }.bind(this),
- }).always(function () {
- this.setState({
- loading: false
- });
- }.bind(this));
- },
- delectRow() {
- let deletedIds = [];
- for (let idx = 0; idx < this.state.selectedRows.length; idx++) {
- let rowItem = this.state.selectedRows[idx];
- if (rowItem.id) {
- deletedIds.push(rowItem.id)
- };
- };
- this.setState({
- selectedRowKeys: [],
- loading: deletedIds.length > 0
- });
- $.ajax({
- method: "POST",
- dataType: "json",
- crossDomain: false,
- url: globalConfig.context + "/api/admin/news/delete",
- data: {
- ids: deletedIds
- }
- }).done(function (data) {
- if (data.error && data.error.length) {
- message.warning(data.error[0].message);
- } else {
- message.success('删除成功!');
- };
- this.setState({
- loading: false,
- });
- this.loadData(this.state.ispage,this.state.callnub);
- }.bind(this));
- },
- reset() {
- this.state.searchTitle = undefined;
- this.state.searchAuthor = undefined;
- this.state.startDate = undefined;
- this.state.endDate = undefined;
- this.state.searchSource = undefined;
- this.state.searchHot = undefined;
- this.loadData(1,this.state.callnub);
- },
- resets() {
- this.state.searchTitle = undefined;
- this.state.searchAuthor = undefined;
- this.state.startDate = undefined;
- this.state.endDate = undefined;
- this.state.searchSource = undefined;
- this.state.searchHot = undefined;
- },
- cleanCache(sign) {
- this.setState({
- loading: true
- });
- $.ajax({
- method: "post",
- dataType: "json",
- crossDomain: false,
- url: globalConfig.context + '/api/admin/news/cleanCache',
- data: {
- 'cacheKey': sign
- },
- success: function (data) {
- if (data.error && data.error.length) {
- message.warning(data.error[0].message);
- } else {
- message.success('清除缓存成功!');
- };
- }.bind(this),
- }).always(function () {
- this.setState({
- loading: false
- });
- }.bind(this));
- },
- 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 className="admin-content" >
- <div className="admin-content-search">
- <Button type="primary" style={{ float: 'right' }}
- onClick={() => { this.setState({ RowData: {}, visible: true ,topNumber :'',hotspot :1}) }}>
- 添加<Icon type="plus" />
- </Button>
- <Input placeholder="标题" style={{ width: 200 ,marginBottom:'10px',marginRight:'10px'}}
- value={this.state.searchTitle}
- onChange={(e) => { this.setState({ searchTitle: e.target.value }); }} />
- <Input placeholder="作者" style={{ width: 100 ,marginRight:'10px'}}
- value={this.state.searchAuthor}
- onChange={(e) => { this.setState({ searchAuthor: e.target.value }); }} />
- <Input placeholder="来源" style={{ width: 100 ,marginRight:'10px'}}
- value={this.state.searchSource}
- onChange={(e) => { this.setState({ searchSource: e.target.value }); }} />
- {this.props.newsType == 2 || this.props.newsType == 3 ? <Select placeholder="显示在首页"
- style={{ width: 100,marginRight:'10px' }}
- value={this.state.searchHot}
- onChange={(e) => { this.setState({ searchHot: e }) }}>
- <Select.Option value="0" >不显示</Select.Option>
- <Select.Option value="1" >显示</Select.Option>
- </Select> : <span></span>}
- <span style={{marginRight:'10px'}}>发布时间</span>
- <DatePicker style={{ width: 110,marginRight:'10px' }}
- format="YYYY-MM-DD"
- placeholder="选择开始时间"
- value={this.state.startDate ? moment(this.state.startDate, "YYYY-MM-DD") : undefined}
- onChange={(t, str) => {
- this.setState({ startDate: str });
- }} />
- <span style={{marginRight:'10px'}}>到</span>
- <DatePicker style={{ width: 110 ,marginRight:'10px'}}
- format="YYYY-MM-DD"
- placeholder="选择结束时间"
- value={this.state.endDate ? moment(this.state.endDate, "YYYY-MM-DD") : undefined}
- onChange={(t, str) => {
- this.setState({ endDate: str });
- }} />
- <Button type="primary" onClick={() => { this.loadData(1,this.state.callnub) }} style={{marginRight:'10px'}}>搜索</Button>
- <Button onClick={this.reset} style={{marginRight:'10px'}}>重置</Button>
- <Button type='danger' disabled={!hasSelected} onClick={this.delectRow} style={{marginRight:'10px'}}>
- 删除<Icon type="minus" />
- </Button>
- <Button type="primary" onClick={() => { this.cleanCache('news_list_cache_key'); }}>清除策源地缓存</Button>
- <Button type="primary" onClick={() => { this.cleanCache('news_portal_list_cache_key'); }}>清除列表页缓存</Button>
- <Button type="primary" onClick={() => { this.cleanCache('news_index_list_cache_key'); }}>清除首页缓存</Button>
- </div>
- <div className="clearfix" style={{marginLeft:'20px'}}>
- <Tabs onChange={this.callback} type="card" activeKey={this.state.callnub} style={{paddingLeft:'15px',paddingRight:'15px',marginRight:'20px'}}>
- <TabPane tab="科技快讯" key="1" ></TabPane>
- <TabPane tab="交易问题" key="2"></TabPane>
- <TabPane tab="技淘动态" key="3"></TabPane>
- <TabPane tab="国家政策" key="4"></TabPane>
- <TabPane tab="地方政策" key="5"></TabPane>
- </Tabs>
- </div>
- <Spin spinning={this.state.loading}>
- <Table size="middle" className="no-all-select" columns={this.state.columns}
- dataSource={this.state.tableData}
- pagination={this.state.pagination}
- rowSelection={rowSelection}
- style={{
- cursor: 'pointer',
- }}
- onRowClick={this.tableRowClick} />
- </Spin>
- <Modal title="新闻详情" width={1000} className="news-modal"
- visible={this.state.visible}
- maskClosable={false}
- footer={null}
- afterClose={() => { this.state.RowData = {}; }}
- onCancel={() => { this.setState({ visible: false }) }} >
- <Spin spinning={this.state.loading}>
- <div className="clearfix">
- <div className="modal-box">
- <span className="modal-box-title">新闻标题</span>
- <div className="modal-box-detail">
- <Input value={this.state.RowData.title}
- onChange={(e) => {
- this.state.RowData.title = e.target.value;
- this.setState({ RowData: this.state.RowData });
- }} />
- </div>
- </div>
- <div className="modal-box">
- <span className="modal-box-title">简介</span>
- <div className="modal-box-detail">
- <Input type="textarea" rows={3} value={this.state.RowData.summary}
- onChange={(e) => {
- this.state.RowData.summary = e.target.value;
- this.setState({ RowData: this.state.RowData });
- }} />
- </div>
- </div>
- <div className="modal-box">
- <span className="modal-box-title">来源</span>
- <div className="modal-box-detail">
- <Input value={this.state.RowData.source}
- onChange={(e) => {
- this.state.RowData.source = e.target.value;
- this.setState({ RowData: this.state.RowData });
- }} />
- </div>
- </div>
- <div className="modal-box">
- <span className="modal-box-title">来源链接</span>
- <div className="modal-box-detail">
- <Input value={this.state.RowData.sourceUrl}
- onChange={(e) => {
- this.state.RowData.sourceUrl = e.target.value;
- this.setState({ RowData: this.state.RowData });
- }} />
- </div>
- </div>
- <div className="modal-box">
- <span className="modal-box-title">政策类别</span>
- <div className="modal-box-detail">
- <Select placeholder="政策类别" value={this.state.callnubs} style={{width:'40%'}}
- onChange={(e)=>{this.setState({callnubs:e})}}>
- {
- policy.map(function (item) {
- return <Select.Option key={item.value} >{item.key}</Select.Option>
- })
- }
- </Select>
- </div>
- </div>
- <div className="modal-box" style={{ position: 'absolute', right: '0', width: '480px' }}>
- <span className="modal-box-title">标题图片</span>
- <div className="modal-box-detail clearfix" style={{ width: '360px' }}>
- <Avatar sign={'news_title_picture'} visible={this.state.visible}
- imageUrl={this.state.RowData.titleImg ? (globalConfig.avatarHost + "/upload" + this.state.RowData.titleImg) : null}
- urlData={(url) => { this.state.RowData.titleImg = url }} />
- </div>
- </div>
- </div>
- <div className="clearfix">
- <div className="modal-box news-box">
- <span className="modal-box-title">作者</span>
- <div className="modal-box-detail">
- <Input value={this.state.RowData.author}
- onChange={(e) => {
- this.state.RowData.author = e.target.value;
- this.setState({ RowData: this.state.RowData });
- }} />
- </div>
- </div>
- <div className="modal-box news-box">
- <span className="modal-box-title">发布时间</span>
- <div className="modal-box-detail">
- <DatePicker style={{ width: '120px' }}
- format="YYYY-MM-DD"
- placeholder="选择发布时间"
- value={this.state.RowData.createTimeFormattedDate ? moment(this.state.RowData.createTimeFormattedDate, "YYYY-MM-DD") : undefined}
- onChange={(t, str) => {
- this.state.RowData.createTimeFormattedDate = str;
- this.setState({ RowData: this.state.RowData});
- }} />
- </div>
- </div>
- {this.props.newsType == 2 || this.props.newsType == 3 ? <div className="modal-box news-box">
- <span className="modal-box-title">发布在首页</span>
- <div className="modal-box-detail">
- <Radio.Group value={this.state.RowData.hot} onChange={(e) => {
- this.state.RowData.hot = e.target.value;
- this.setState({ RowData: this.state.RowData });
- }} >
- <Radio value={0}>否</Radio>
- <Radio value={1}>是</Radio>
- </Radio.Group>
- </div>
- </div> : <div></div>}
- </div>
- <div className="modal-box">
- <span className="modal-box-title">选择省份</span>
- <select value={this.state.RowData.provinceId} onChange={(e) => {
- this.state.RowData.provinceId = e.target.value;
- this.setState({RowData: this.state.RowData});
- }} className="provin">
- {
- this.state.list.map(function(name){
- return (
- <option value={name.id} key={name.id} >{name.name}</option>
- )
- })
- }
- </select>
- </div>
- <div className="clearfix">
- <div className="modal-box news-box">
- <span className="modal-box-title">置顶序号:</span>
- <div className="modal-box-detail">
- <Input value={this.state.topNumber } placeholder="请输入数字"
- onChange={(e) => {
- this.setState({ topNumber:e.target.value});
- }} />
- </div>
- </div>
- <div className="modal-box news-box">
- <span className="modal-box-title">热门:</span>
- <div className="modal-box-detail">
- <Radio.Group value={this.state.hotspot} onChange={(e) => {
- this.setState({ hotspot : e.target.value });
- }} >
- <Radio value={1}>否</Radio>
- <Radio value={0}>是</Radio>
- </Radio.Group>
- </div>
- </div>
- </div>
- <Editors textContent={this.state.RowData.content}
- uploadUrl={'/api/admin/news/upload'}
- uploadSign={'news_content_picture'}
- handleRichText={(value) => { this.state.RowData.content = value; }}
- visible={this.state.visible} />
- <div className="modal-box">
- <Button type="primary" onClick={this.submit}>保存草稿</Button>
- <Button type="primary" onClick={this.submits}>提交审核</Button>
- <Button type="ghost" onClick={() => { this.setState({ visible: false }) }}>取消</Button>
- </div>
- </Spin>
- </Modal>
- </div>
- )
- }
- })
- export default Manage;
|