VideoPlayList.js 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. import React, { PureComponent } from 'react';
  2. import moment from 'moment';
  3. import { Table, Pagination, Select, Input } from 'antd';
  4. import AXVideoPlayer from '../../../components/AXVideoPlayer/index';
  5. import styles from './VideoPlayList.less';
  6. export default class VideoPlayList extends PureComponent {
  7. constructor(props) {
  8. super(props);
  9. this.state = {
  10. currentPlayingIndex: 0,
  11. searchSelectKey: 'code',
  12. searchInputValue: '',
  13. };
  14. }
  15. componentWillReceiveProps(nextProps) {
  16. const { dataSource } = nextProps;
  17. if (dataSource && dataSource.length) {
  18. this.setState({ currentPlayingIndex: 0 });
  19. }
  20. }
  21. handleOnRowClick = (index) => {
  22. this.setState({ currentPlayingIndex: index });
  23. };
  24. handleSearchSelectChange = (value) => {
  25. this.setState({ searchSelectKey: value });
  26. };
  27. handleInputChange = (e) => {
  28. this.setState({ searchInputValue: e.target.value });
  29. };
  30. handleFilterOperation = (params) => {
  31. const { pageSize, pageNo, onFilterClick } = this.props;
  32. const { searchSelectKey, searchInputValue } = this.state;
  33. onFilterClick({
  34. pageNo,
  35. pageSize,
  36. [searchSelectKey]: searchInputValue,
  37. ...params,
  38. });
  39. };
  40. handleSearchBtnClick = () => {
  41. this.handleFilterOperation();
  42. };
  43. handleTablePageChange = (page, pageSize) => {
  44. this.handleFilterOperation({
  45. pageSize,
  46. pageNo: page,
  47. });
  48. };
  49. handleTablePageSizeChange = (current, size) => {
  50. this.handleFilterOperation({
  51. pageSize: size,
  52. pageNo: current,
  53. });
  54. };
  55. render() {
  56. const { dataSource, loading, totalSize, pageSize, pageNo } = this.props;
  57. const renderQuality = (quality) => {
  58. if (quality === 'high') {
  59. return '高清';
  60. } else {
  61. return '标清';
  62. }
  63. };
  64. const renderItem = (data) => {
  65. return (
  66. <div className={styles.meta}>
  67. <p>
  68. <span>编号: </span>
  69. <a>{`${data.code}`}</a>
  70. </p>
  71. <p>
  72. <span>名称: </span>
  73. {`${data.name}`}
  74. </p>
  75. <p>
  76. <span>格式: </span>
  77. {`${renderQuality(data.quality)}[${data.format}]`}
  78. </p>
  79. <p>
  80. <span>时间: </span>
  81. {`${moment(data.gmtModified).format('YYYY-MM-DD HH:mm:ss')}`}
  82. </p>
  83. </div>
  84. );
  85. };
  86. const renderVideoPlayer = () => {
  87. if (dataSource.length) {
  88. const videoItem = dataSource[this.state.currentPlayingIndex];
  89. return (
  90. <AXVideoPlayer
  91. width="100%"
  92. height="100%"
  93. url={videoItem.url}
  94. isM3U8={videoItem.format === 'm3u8'}
  95. />
  96. );
  97. }
  98. return null;
  99. };
  100. const columns = [{
  101. title: '名称/编号/状态/格式/质量/日期',
  102. key: 1,
  103. dataIndex: 'cn',
  104. render: (_, record) => renderItem(record),
  105. }];
  106. const paginationProps = {
  107. pageSize,
  108. total: totalSize,
  109. current: pageNo,
  110. simple: true,
  111. showTotal: total => `共 ${total} 条`,
  112. onChange: this.handleTablePageChange,
  113. onShowSizeChange: this.handleTablePageSizeChange,
  114. };
  115. const selectOptions = [{
  116. field: 'code',
  117. name: '编号',
  118. }, {
  119. field: 'name',
  120. name: '名称',
  121. }];
  122. const onRowClick = (_, index) => {
  123. return {
  124. onClick: () => this.handleOnRowClick(index),
  125. };
  126. };
  127. const renderHeader = () => {
  128. return (
  129. <Input.Search
  130. value={this.state.searchInputValue}
  131. style={{ width: '100%' }}
  132. addonBefore={
  133. <Select
  134. placeholder="请选择"
  135. value={this.state.searchSelectKey}
  136. onChange={this.handleSearchSelectChange}
  137. >
  138. {selectOptions.map(item => (
  139. <Select.Option
  140. key={item.field}
  141. value={item.field}
  142. >
  143. {item.name}
  144. </Select.Option>))}
  145. </Select>
  146. }
  147. placeholder="请输入"
  148. enterButton
  149. onChange={this.handleInputChange}
  150. onSearch={this.handleSearchBtnClick}
  151. />
  152. );
  153. };
  154. return (
  155. <div className={styles.content}>
  156. <div className={styles.left}>
  157. <Table
  158. bordered
  159. title={() => renderHeader()}
  160. footer={() => <Pagination {...paginationProps} />}
  161. columns={columns}
  162. pagination={false}
  163. onRow={onRowClick}
  164. rowKey={record => record.key}
  165. className={styles.table}
  166. rowClassName={(_, index) =>
  167. (index === this.state.currentPlayingIndex ? styles.rowChecked : null)
  168. }
  169. loading={loading}
  170. dataSource={dataSource}
  171. />
  172. </div>
  173. <div className={styles.right}>
  174. {renderVideoPlayer()}
  175. </div>
  176. </div>
  177. );
  178. }
  179. }