videoList.jsx 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325
  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:globalConfig.videoServer+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. render:text=>{
  95. return (text&&text.length>10)?text.substr(0,10)+'...':text;
  96. }
  97. }, {
  98. title: '视频地址',
  99. dataIndex: 'url',
  100. key: 'url',
  101. },
  102. {
  103. title: '视频类型',
  104. dataIndex: 'type',
  105. key: 'type',
  106. render: text => { return getVideoType(text) }
  107. },
  108. {
  109. title: '上传者',
  110. dataIndex: 'owner',
  111. key: 'owner',
  112. render:text=>{
  113. return text==1?'管理员':text
  114. }
  115. },
  116. {
  117. title: '转码状态',
  118. dataIndex: 'transcoding',
  119. key: 'transcoding',
  120. render:text=>{
  121. return text==2?'已转码':'正在转码'
  122. }
  123. },
  124. {
  125. title: '发布时间',
  126. dataIndex: 'releaseTime',
  127. key: 'releaseTime'
  128. },
  129. {
  130. title: '创建时间',
  131. dataIndex: 'createTime',
  132. key: 'createTime'
  133. },
  134. {
  135. title: '状态',
  136. dataIndex: 'status',
  137. key: 'status',
  138. render: text => { return getVideoStatus(text) }
  139. },
  140. {
  141. title: '操作',
  142. dataIndex: 'caozuo',
  143. key: 'caozuo',
  144. render:(text,recard) => {
  145. return <div className="btnRight">
  146. {((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>}
  147. {recard.status=='1'&&<Button type="danger" onClick={(e)=>{e.stopPropagation(),this.submission(recard,2)}}>撤销发布</Button>}
  148. </div>
  149. }
  150. }
  151. ],
  152. dataSource: [],
  153. searchTime: [,]
  154. };
  155. },
  156. //发布
  157. submission(record,nub){
  158. this.setState({
  159. showDesc:false,
  160. loading:true
  161. });
  162. $.ajax({
  163. method: "POST",
  164. dataType: "json",
  165. crossDomain: false,
  166. url: globalConfig.context + "/api/admin/video/updateVideo",
  167. data: {
  168. id:record.id,
  169. status:nub
  170. }
  171. }).done(function (data) {
  172. if (!data.error.length) {
  173. message.success(nub=='1'?'发布成功.':'撤销发布');
  174. this.setState({
  175. loading: false,
  176. });
  177. this.loadData(this.state.page)
  178. } else {
  179. message.warning(data.error[0].message);
  180. };
  181. }.bind(this));
  182. },
  183. componentWillMount() {
  184. this.loadData();
  185. },
  186. tableRowClick(record, index) {
  187. this.state.RowData = record;
  188. this.setState({
  189. showDesc: true
  190. });
  191. },
  192. delectRow() {
  193. let deletedIds =[];
  194. let rowItem = this.state.selectedRowKeys[0];
  195. let data = this.state.dataSource ||[];
  196. if (data.length) {
  197. deletedIds.push(data[rowItem].id);
  198. }
  199. if(data[rowItem].status=='1'){
  200. message.warning('不能删除已发布的视频.')
  201. return false ;
  202. }
  203. this.setState({
  204. loading:true
  205. })
  206. $.ajax({
  207. method: "POST",
  208. dataType: "json",
  209. crossDomain: false,
  210. url: globalConfig.context + "/api/admin/video/updateVideo",
  211. data: {
  212. id: deletedIds[0],
  213. status:3
  214. }
  215. }).done(function (data) {
  216. if (!data.error.length) {
  217. message.success('删除成功!');
  218. this.setState({
  219. loading: false
  220. });
  221. if(this.state.pagination.total%10==1){
  222. this.loadData((this.state.page)-1);
  223. }else{
  224. this.loadData(this.state.page);
  225. }
  226. } else {
  227. message.warning(data.error[0].message);
  228. this.setState({
  229. loading: false
  230. });
  231. };
  232. }.bind(this));
  233. },
  234. addClick() {
  235. this.state.RowData = {};
  236. this.setState({
  237. showDesc: true
  238. });
  239. },
  240. closeDesc(e, s) {
  241. this.state.showDesc = e;
  242. if (s) {
  243. this.loadData(this.state.page);
  244. };
  245. },
  246. search() {
  247. this.loadData();
  248. },
  249. reset() {
  250. this.state.videoName = '';
  251. this.state.releaseDate = [];
  252. this.state.videoType = undefined;
  253. this.state.videoState = undefined;
  254. this.loadData();
  255. },
  256. searchSwitch() {
  257. this.setState({
  258. searchMore: !this.state.searchMore
  259. });
  260. },
  261. render() {
  262. const rowSelection = {
  263. selectedRowKeys: this.state.selectedRowKeys,
  264. onChange: (selectedRowKeys, selectedRows) => {
  265. this.setState({
  266. selectedRows: selectedRows.slice(-1),
  267. selectedRowKeys: selectedRowKeys.slice(-1)
  268. });
  269. }
  270. };
  271. const { RangePicker } = DatePicker;
  272. const hasSelect = this.state.selectedRowKeys.length;
  273. return (
  274. <div className="user-content" >
  275. <div className="content-title">
  276. <span>视频管理</span>
  277. <div className="patent-addNew">
  278. <Button type="primary" onClick={this.addClick}>新建视频<Icon type="plus" /></Button>
  279. </div>
  280. </div>
  281. <div className="user-search">
  282. <Input placeholder="视频名称"
  283. value={this.state.videoName}
  284. onChange={(e) => { this.setState({ videoName: e.target.value }); }} />
  285. <Select placeholder="视频类型" style={{ width: 120 }}
  286. value={this.state.videoType}
  287. onChange={(e) => { this.setState({ videoType: e }) }}>
  288. {videoType.map(item=>{
  289. return <Select.Option value={item.value}>{item.key}</Select.Option>
  290. })}
  291. </Select>
  292. <Select placeholder="视频状态" style={{ width: 120 }}
  293. value={this.state.videoState}
  294. onChange={(e) => { this.setState({ videoState: e }) }}>
  295. {videoStatus.map(item=>{
  296. return <Select.Option value={item.value}>{item.key}</Select.Option>
  297. })}
  298. </Select>
  299. <Button type="primary" onClick={this.search}>搜索</Button>
  300. <Button onClick={this.reset}>重置</Button>
  301. <Button type="danger" disabled={!hasSelect} onClick={(e)=>{this.delectRow()}}>删除</Button>
  302. </div>
  303. <div className="patent-table">
  304. <Spin spinning={this.state.loading}>
  305. <Table columns={this.state.columns}
  306. dataSource={this.state.dataSource}
  307. rowSelection={rowSelection}
  308. pagination={this.state.pagination}
  309. onRowClick={this.tableRowClick} />
  310. </Spin>
  311. </div>
  312. <NewDesc
  313. data={this.state.RowData}
  314. showDesc={this.state.showDesc}
  315. closeDesc={this.closeDesc} />
  316. </div >
  317. );
  318. }
  319. });
  320. export default PolicyList;