flash.jsx 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396
  1. import React from 'react';
  2. import { Icon, Button, Spin, message, Table, Input, Modal, DatePicker, Upload, Select } from 'antd';
  3. import { beforeUpload, getBase64 } from '../../../tools';
  4. import moment from 'moment';
  5. import ajax from 'jquery/src/ajax/xhr.js';
  6. import $ from 'jquery/src/ajax';
  7. const Avatar = React.createClass({
  8. getInitialState() {
  9. return {
  10. imageUrl: ''
  11. }
  12. },
  13. handleChange(info) {
  14. if (info.file.status === 'done') {
  15. // Get this url from response in real world.
  16. getBase64(info.file.originFileObj, imageUrl => this.setState({ imageUrl }));
  17. this.props.urlData(info.file.response.data);
  18. }
  19. },
  20. componentWillReceiveProps(nextProps) {
  21. if (this.props.id != nextProps.id) {
  22. this.state.imageUrl = null;
  23. };
  24. },
  25. render() {
  26. const imageUrl = this.state.imageUrl;
  27. return (
  28. <Upload
  29. className="avatar-uploader"
  30. name={this.props.name}
  31. showUploadList={false}
  32. action={globalConfig.context + "/api/admin/banners/upload"}
  33. data={{ 'sign': this.props.sign }}
  34. beforeUpload={beforeUpload}
  35. onChange={this.handleChange} >
  36. {
  37. (imageUrl || this.props.imageUrl) ?
  38. <img src={imageUrl || this.props.imageUrl} role="presentation" id={this.props.name} /> :
  39. <Icon type="plus" className="avatar-uploader-trigger" />
  40. }
  41. </Upload>
  42. );
  43. }
  44. });
  45. const Lecture = React.createClass({
  46. loadData(pageNo) {
  47. this.setState({
  48. loading: true
  49. });
  50. $.ajax({
  51. method: "get",
  52. dataType: "json",
  53. crossDomain: false,
  54. url: globalConfig.context + '/api/admin/banners/list',
  55. data: {
  56. pageNo: pageNo || 1,
  57. pageSize: this.state.pagination.pageSize,
  58. key: this.state.searchKey
  59. },
  60. success: function (data) {
  61. let theArr = [];
  62. if (!data.data) {
  63. if (data.error && data.error.length) {
  64. message.warning(data.error[0].message);
  65. };
  66. } else {
  67. for (let i = 0; i < data.data.length; i++) {
  68. let thisdata = data.data[i];
  69. theArr.push({
  70. key: i,
  71. id: thisdata.id, //主键
  72. sign: thisdata.sign, // 位置标示
  73. text: thisdata.text, //广告图描述
  74. imgurl: thisdata.imgurl, //广告图url
  75. url: thisdata.url, //跳转链接
  76. width: thisdata.width, //宽度
  77. height: thisdata.height, //高度
  78. startDate: thisdata.startDate, //广告图开始时间
  79. endDate: thisdata.endDate //广告图结束时间
  80. });
  81. };
  82. this.state.pagination.current = data.data.pageNo;
  83. this.state.pagination.total = data.data.totalCount;
  84. };
  85. this.setState({
  86. tableData: theArr,
  87. pagination: this.state.pagination
  88. });
  89. }.bind(this),
  90. }).always(function () {
  91. this.setState({
  92. loading: false
  93. });
  94. }.bind(this));
  95. },
  96. getInitialState() {
  97. return {
  98. loading: false,
  99. visible: false,
  100. selectedRowKeys: [],
  101. selectedRows: [],
  102. keysObj: {},
  103. RowData: {},
  104. pagination: {
  105. defaultCurrent: 1,
  106. defaultPageSize: 10,
  107. showQuickJumper: true,
  108. pageSize: 10,
  109. onChange: function (page) {
  110. this.loadData(page);
  111. }.bind(this),
  112. showTotal: function (total) {
  113. return '共' + total + '条数据';
  114. }
  115. },
  116. columns: [
  117. {
  118. title: '位置',
  119. dataIndex: 'sign',
  120. key: 'sign',
  121. render: text => { return this.state.keysObj[text] }
  122. }, {
  123. title: '广告图描述',
  124. dataIndex: 'text',
  125. key: 'text',
  126. }, {
  127. title: '广告图url',
  128. dataIndex: 'imgurl',
  129. key: 'imgurl',
  130. }, {
  131. title: '跳转链接',
  132. dataIndex: 'url',
  133. key: 'url',
  134. }, {
  135. title: '宽度',
  136. dataIndex: 'width',
  137. key: 'width',
  138. }, {
  139. title: '高度',
  140. dataIndex: 'height',
  141. key: 'height',
  142. }, {
  143. title: '开始时间',
  144. dataIndex: 'startDate',
  145. key: 'startDate',
  146. }, {
  147. title: '结束时间',
  148. dataIndex: 'endDate',
  149. key: 'endDate',
  150. }
  151. ],
  152. tableData: []
  153. };
  154. },
  155. tableRowClick(record, index) {
  156. this.state.RowData = record;
  157. this.setState({
  158. visible: true
  159. });
  160. },
  161. componentWillMount() {
  162. this.loadData();
  163. },
  164. submit() {
  165. if (!this.state.RowData.sign) {
  166. message.warning('必须选择一个位置!');
  167. return;
  168. };
  169. if (!this.state.RowData.imgurl) {
  170. message.warning('必须上传一张广告图!');
  171. return;
  172. };
  173. if (!this.state.RowData.url) {
  174. message.warning('必须填写跳转链接!');
  175. return;
  176. };
  177. this.setState({
  178. loading: true
  179. });
  180. $.ajax({
  181. method: "post",
  182. dataType: "json",
  183. crossDomain: false,
  184. url: globalConfig.context + '/api/admin/banners/save',
  185. data: {
  186. id: this.state.RowData.id || null, //主键,如果不填主键则为新增记录,填主键则为更新
  187. sign: this.state.RowData.sign, // 位置标示,必填
  188. text: this.state.RowData.text, //广告图描述,长度 255
  189. imgurl: this.state.RowData.imgurl, //广告图url,必填,长度 255
  190. url: this.state.RowData.url, //跳转链接,必填,长度255
  191. width: this.state.RowData.width, //宽度,非必填,最大99999
  192. height: this.state.RowData.height, //高度,非必填,最大99999
  193. startDate: this.state.RowData.startDate, //广告图开始时间,非必填
  194. endDate: this.state.RowData.endDate //广告图结束时间,非必填
  195. },
  196. success: function (data) {
  197. if (data.error && data.error.length) {
  198. message.warning(data.error[0].message);
  199. } else {
  200. message.success('保存成功!');
  201. this.setState({ visible: false });
  202. this.loadData();
  203. };
  204. }.bind(this),
  205. }).always(function () {
  206. this.setState({
  207. loading: false
  208. });
  209. }.bind(this));
  210. },
  211. delectRow() {
  212. if (this.state.selectedRows.length > 1) {
  213. return;
  214. };
  215. this.setState({
  216. selectedRowKeys: [],
  217. loading: this.state.selectedRows.length > 0
  218. });
  219. $.ajax({
  220. method: "POST",
  221. dataType: "json",
  222. crossDomain: false,
  223. url: globalConfig.context + "/api/admin/banners/delete",
  224. data: {
  225. id: this.state.selectedRows[0].id
  226. }
  227. }).done(function (data) {
  228. if (data.error && data.error.length) {
  229. message.warning(data.error[0].message);
  230. } else {
  231. message.success('删除成功!');
  232. };
  233. this.setState({
  234. loading: false,
  235. });
  236. this.loadData();
  237. }.bind(this));
  238. },
  239. reset() {
  240. this.state.searchKey = undefined;
  241. this.loadData();
  242. },
  243. render() {
  244. const rowSelection = {
  245. selectedRowKeys: this.state.selectedRowKeys,
  246. onChange: (selectedRowKeys, selectedRows) => {
  247. this.setState({
  248. selectedRows: selectedRows.slice(-1),
  249. selectedRowKeys: selectedRowKeys.slice(-1)
  250. });
  251. }
  252. };
  253. const hasSelected = this.state.selectedRowKeys.length > 0;
  254. return (
  255. <div></div>
  256. )
  257. // return (
  258. // <div className="admin-content" >
  259. // <div className="admin-content-title">广告图管理</div>
  260. // <div className="admin-content-warp">
  261. // <div className="admin-content-header">广告图列表</div>
  262. // <div className="admin-content-search">
  263. // <Select placeholder="选择广告图位置"
  264. // style={{ width: 200 }}
  265. // value={this.state.searchKey}
  266. // onChange={(e) => { this.setState({ searchKey: e }) }}>
  267. // {this.state.keysOption}
  268. // </Select>
  269. // <Button type="primary" onClick={this.loadData}>搜索</Button>
  270. // <Button type="ghost" onClick={this.clearCache}>清除缓存</Button>
  271. // <Button onClick={this.reset}>重置</Button>
  272. // <Button type='danger' disabled={!hasSelected} onClick={this.delectRow}>
  273. // 删除<Icon type="minus" />
  274. // </Button>
  275. // <Button type="primary" style={{ float: 'right' }}
  276. // onClick={() => { this.setState({ RowData: {}, visible: true }) }}>
  277. // 添加<Icon type="plus" />
  278. // </Button>
  279. // </div>
  280. // <Spin spinning={this.state.loading}>
  281. // <Table className="no-all-select" columns={this.state.columns}
  282. // dataSource={this.state.tableData}
  283. // pagination={this.state.pagination}
  284. // rowSelection={rowSelection}
  285. // onRowClick={this.tableRowClick} />
  286. // </Spin>
  287. // </div>
  288. // <Modal title="广告图详情" width={1000}
  289. // visible={this.state.visible}
  290. // maskClosable={false}
  291. // footer={null}
  292. // afterClose={() => { this.state.RowData = {} }}
  293. // onCancel={() => { this.setState({ visible: false }) }} >
  294. // <Spin spinning={this.state.loading}>
  295. // <div className="modal-box">
  296. // <span className="modal-box-title">广告图位置</span>
  297. // {this.state.RowData.id ? <div className="modal-box-detail">
  298. // {this.state.keysObj[this.state.RowData.sign]}
  299. // </div> : <div className="modal-box-detail">
  300. // <Select placeholder="选择广告图位置"
  301. // style={{ width: 200 }}
  302. // value={this.state.RowData.sign}
  303. // onChange={(e) => {
  304. // this.state.RowData.sign = e;
  305. // this.setState({ RowData: this.state.RowData })
  306. // }}>
  307. // {this.state.keysOption}
  308. // </Select>
  309. // </div>}
  310. // </div>
  311. // <div className="modal-box">
  312. // <span className="modal-box-title">广告图描述</span>
  313. // <div className="modal-box-detail">
  314. // <Input value={this.state.RowData.text}
  315. // onChange={(e) => {
  316. // this.state.RowData.text = e.target.value;
  317. // this.setState({ RowData: this.state.RowData });
  318. // }} />
  319. // </div>
  320. // </div>
  321. // <div className="modal-box">
  322. // <span className="modal-box-title">跳转链接</span>
  323. // <div className="modal-box-detail">
  324. // <Input value={this.state.RowData.url}
  325. // onChange={(e) => {
  326. // this.state.RowData.url = e.target.value;
  327. // this.setState({ RowData: this.state.RowData });
  328. // }} />
  329. // </div>
  330. // </div>
  331. // <div className="modal-box">
  332. // <span className="modal-box-title">图片宽度</span>
  333. // <div className="modal-box-detail">
  334. // <Input value={this.state.RowData.width}
  335. // onChange={(e) => {
  336. // this.state.RowData.width = e.target.value;
  337. // this.setState({ RowData: this.state.RowData });
  338. // }} />
  339. // </div>
  340. // </div>
  341. // <div className="modal-box">
  342. // <span className="modal-box-title">图片高度</span>
  343. // <div className="modal-box-detail">
  344. // <Input value={this.state.RowData.height}
  345. // onChange={(e) => {
  346. // this.state.RowData.height = e.target.value;
  347. // this.setState({ RowData: this.state.RowData });
  348. // }} />
  349. // </div>
  350. // </div>
  351. // <div className="modal-box">
  352. // <span className="modal-box-title">广告图播放时间</span>
  353. // <div className="modal-box-detail">
  354. // <DatePicker
  355. // showTime
  356. // format="YYYY-MM-DD HH:mm:ss"
  357. // placeholder="选择开始时间"
  358. // value={this.state.RowData.startDate ? moment(this.state.RowData.startDate, "YYYY-MM-DD HH:mm:ss") : undefined}
  359. // onChange={(t, str) => {
  360. // this.state.RowData.startDate = str;
  361. // this.setState({ RowData: this.state.RowData });
  362. // }} />
  363. // <span>到</span>
  364. // <DatePicker
  365. // showTime
  366. // format="YYYY-MM-DD HH:mm:ss"
  367. // placeholder="选择结束时间"
  368. // value={this.state.RowData.endDate ? moment(this.state.RowData.endDate, "YYYY-MM-DD HH:mm:ss") : undefined}
  369. // onChange={(t, str) => {
  370. // this.state.RowData.endDate = str;
  371. // this.setState({ RowData: this.state.RowData });
  372. // }} />
  373. // </div>
  374. // </div>
  375. // <div className="modal-box">
  376. // <span className="modal-box-title">上传图片</span>
  377. // <div className="modal-box-detail clearfix">
  378. // <Avatar sign={this.state.RowData.sign} id={this.state.RowData.id}
  379. // imageUrl={this.state.RowData.imgurl ? (globalConfig.avatarHost + "/upload" + this.state.RowData.imgurl) : null}
  380. // urlData={(url) => { this.state.RowData.imgurl = url }} />
  381. // </div>
  382. // </div>
  383. // <div className="modal-box">
  384. // <Button type="primary" onClick={this.submit}>提交</Button>
  385. // <Button type="ghost" onClick={() => { this.setState({ visible: false }) }}>取消</Button>
  386. // </div>
  387. // </Spin>
  388. // </Modal>
  389. // </div>
  390. // );
  391. }
  392. });
  393. export default Lecture;