videoList.jsx 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312
  1. import React from 'react';
  2. import { Icon, Button, Input, Select, Spin, Table, Switch, message, DatePicker } from 'antd';
  3. import $ from 'jquery/src/ajax';
  4. import moment from 'moment';
  5. import '@/account/demand/techDemand.less';
  6. import NewDesc from '@/administration/video/videoDesc';
  7. import { videoType ,videoStatus} from '@/dataDic.js';
  8. import {getVideoType,getVideoStatus } from '@/tools.js';
  9. const PolicyList = React.createClass({
  10. loadData(pageNo) {
  11. this.state.data = [];
  12. this.setState({
  13. page:pageNo,
  14. loading: true
  15. });
  16. $.ajax({
  17. method: "get",
  18. dataType: "json",
  19. crossDomain: false,
  20. url: globalConfig.context + "/api/admin/video/getVideoList",
  21. data: {
  22. pageNo: pageNo || 1,
  23. pageSize: this.state.pagination.pageSize,
  24. name: this.state.videoName,
  25. type: this.state.videoType,
  26. status:this.state.videoState,
  27. },
  28. success: function (data) {
  29. let theArr = [];
  30. if (!data.data || !data.data.list) {
  31. if (data.error && data.error.length) {
  32. message.warning(data.error[0].message);
  33. };
  34. } else {
  35. for (let i = 0; i < data.data.list.length; i++) {
  36. let thisdata = data.data.list[i];
  37. theArr.push({
  38. key: i,
  39. id: thisdata.id,
  40. name: thisdata.name,
  41. url:'http://118.190.205.7:8000'+thisdata.url,
  42. type: thisdata.type,
  43. owner: thisdata.owner, //审核状态
  44. status:thisdata.status,
  45. transcoding:thisdata.transcoding,
  46. summary:thisdata.summary,
  47. createTime:thisdata.createTime?(new Date(thisdata.createTime)).toLocaleString():'',
  48. releaseTime:thisdata.releaseTime?(new Date(thisdata.releaseTime)).toLocaleString():''
  49. });
  50. };
  51. };
  52. this.state.selectedRowKeys=[];
  53. this.state.pagination.current = data.data.pageNo;
  54. this.state.pagination.total = data.data.totalCount;
  55. if(data.data&&data.data.list&&!data.data.list.length){
  56. this.state.pagination.current=0
  57. this.state.pagination.total=0
  58. };
  59. this.setState({
  60. dataSource: theArr,
  61. pagination: this.state.pagination
  62. });
  63. }.bind(this),
  64. }).always(function () {
  65. this.setState({
  66. loading: false
  67. });
  68. }.bind(this));
  69. },
  70. getInitialState() {
  71. return {
  72. searchMore: true,
  73. releaseDate: [],
  74. selectedRowKeys: [],
  75. selectedRows: [],
  76. loading: false,
  77. pagination: {
  78. defaultCurrent: 1,
  79. defaultPageSize: 10,
  80. showQuickJumper: true,
  81. pageSize: 10,
  82. onChange: function (page) {
  83. this.loadData(page);
  84. }.bind(this),
  85. showTotal: function (total) {
  86. return '共' + total + '条数据';
  87. }
  88. },
  89. columns: [
  90. {
  91. title: '视频名称',
  92. dataIndex: 'name',
  93. key: 'name',
  94. }, {
  95. title: '视频地址',
  96. dataIndex: 'url',
  97. key: 'url',
  98. },
  99. {
  100. title: '视频类型',
  101. dataIndex: 'type',
  102. key: 'type',
  103. render: text => { return getVideoType(text) }
  104. },
  105. {
  106. title: '上传者',
  107. dataIndex: 'owner',
  108. key: 'owner',
  109. },
  110. {
  111. title: '转码状态',
  112. dataIndex: 'transcoding',
  113. key: 'transcoding',
  114. render:text=>{
  115. return text==2?'已转码':'正在转码'
  116. }
  117. },
  118. {
  119. title: '发布时间',
  120. dataIndex: 'releaseTime',
  121. key: 'releaseTime'
  122. },
  123. {
  124. title: '创建时间',
  125. dataIndex: 'createTime',
  126. key: 'createTime'
  127. },
  128. {
  129. title: '状态',
  130. dataIndex: 'status',
  131. key: 'status',
  132. render: text => { return getVideoStatus(text) }
  133. },
  134. {
  135. title: '操作',
  136. dataIndex: 'caozuo',
  137. key: 'caozuo',
  138. render:(text,recard) => {
  139. return <div className="btnRight">
  140. {((recard.status=='0'||recard.status=='2')&&recard.transcoding=='2')&&<Button type="primary" style={{ background: "#3fcf9e", border: "none", color: "#fff" }} onClick={(e)=>{e.stopPropagation(),this.submission(recard,1)}}>发布</Button>}
  141. {recard.status=='1'&&<Button type="danger" onClick={(e)=>{e.stopPropagation(),this.submission(recard,2)}}>撤销发布</Button>}
  142. </div>
  143. }
  144. }
  145. ],
  146. dataSource: [],
  147. searchTime: [,]
  148. };
  149. },
  150. //发布
  151. submission(record,nub){
  152. this.setState({
  153. showDesc:false,
  154. loading:true
  155. });
  156. $.ajax({
  157. method: "POST",
  158. dataType: "json",
  159. crossDomain: false,
  160. url: globalConfig.context + "/api/admin/video/updateVideo",
  161. data: {
  162. id:record.id,
  163. status:nub
  164. }
  165. }).done(function (data) {
  166. if (!data.error.length) {
  167. message.success(nub=='1'?'发布成功.':'撤销发布');
  168. this.setState({
  169. loading: false,
  170. });
  171. this.loadData(this.state.page)
  172. } else {
  173. message.warning(data.error[0].message);
  174. };
  175. }.bind(this));
  176. },
  177. componentWillMount() {
  178. this.loadData();
  179. },
  180. tableRowClick(record, index) {
  181. this.state.RowData = record;
  182. this.setState({
  183. showDesc: true
  184. });
  185. },
  186. delectRow() {
  187. this.setState({
  188. loading:true
  189. })
  190. let deletedIds =[];
  191. let rowItem = this.state.selectedRowKeys[0];
  192. let data = this.state.dataSource ||[];
  193. if (data.length) {
  194. deletedIds.push(data[rowItem].id);
  195. }
  196. $.ajax({
  197. method: "POST",
  198. dataType: "json",
  199. crossDomain: false,
  200. url: globalConfig.context + "/api/admin/video/updateVideo",
  201. data: {
  202. id: deletedIds[0],
  203. status:3
  204. }
  205. }).done(function (data) {
  206. if (!data.error.length) {
  207. message.success('删除成功!');
  208. this.setState({
  209. loading: false
  210. });
  211. if(this.state.pagination.total%10==1){
  212. this.loadData((this.state.page)-1);
  213. }else{
  214. this.loadData(this.state.page);
  215. }
  216. } else {
  217. message.warning(data.error[0].message);
  218. };
  219. }.bind(this));
  220. },
  221. addClick() {
  222. this.state.RowData = {};
  223. this.setState({
  224. showDesc: true
  225. });
  226. },
  227. closeDesc(e, s) {
  228. this.state.showDesc = e;
  229. if (s) {
  230. this.loadData(this.state.page);
  231. };
  232. },
  233. search() {
  234. this.loadData();
  235. },
  236. reset() {
  237. this.state.videoName = '';
  238. this.state.releaseDate = [];
  239. this.state.videoType = undefined;
  240. this.state.videoState = undefined;
  241. this.loadData();
  242. },
  243. searchSwitch() {
  244. this.setState({
  245. searchMore: !this.state.searchMore
  246. });
  247. },
  248. render() {
  249. const rowSelection = {
  250. selectedRowKeys: this.state.selectedRowKeys,
  251. onChange: (selectedRowKeys, selectedRows) => {
  252. this.setState({
  253. selectedRows: selectedRows.slice(-1),
  254. selectedRowKeys: selectedRowKeys.slice(-1)
  255. });
  256. }
  257. };
  258. const { RangePicker } = DatePicker;
  259. const hasSelect = this.state.selectedRowKeys.length;
  260. return (
  261. <div className="user-content" >
  262. <div className="content-title">
  263. <span>视频管理</span>
  264. <div className="patent-addNew">
  265. <Button type="primary" onClick={this.addClick}>新建视频<Icon type="plus" /></Button>
  266. </div>
  267. </div>
  268. <div className="user-search">
  269. <Input placeholder="视频名称"
  270. value={this.state.videoName}
  271. onChange={(e) => { this.setState({ videoName: e.target.value }); }} />
  272. <Select placeholder="视频类型" style={{ width: 120 }}
  273. value={this.state.videoType}
  274. onChange={(e) => { this.setState({ videoType: e }) }}>
  275. {videoType.map(item=>{
  276. return <Select.Option value={item.value}>{item.key}</Select.Option>
  277. })}
  278. </Select>
  279. <Select placeholder="视频状态" style={{ width: 120 }}
  280. value={this.state.videoState}
  281. onChange={(e) => { this.setState({ videoState: e }) }}>
  282. {videoStatus.map(item=>{
  283. return <Select.Option value={item.value}>{item.key}</Select.Option>
  284. })}
  285. </Select>
  286. <Button type="primary" onClick={this.search}>搜索</Button>
  287. <Button onClick={this.reset}>重置</Button>
  288. <Button type="danger" disabled={!hasSelect} onClick={(e)=>{this.delectRow()}}>删除</Button>
  289. </div>
  290. <div className="patent-table">
  291. <Spin spinning={this.state.loading}>
  292. <Table columns={this.state.columns}
  293. dataSource={this.state.dataSource}
  294. rowSelection={rowSelection}
  295. pagination={this.state.pagination}
  296. onRowClick={this.tableRowClick} />
  297. </Spin>
  298. </div>
  299. <NewDesc
  300. data={this.state.RowData}
  301. showDesc={this.state.showDesc}
  302. closeDesc={this.closeDesc} />
  303. </div >
  304. );
  305. }
  306. });
  307. export default PolicyList;