AudioBookList.js 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. /* eslint-disable no-prototype-builtins,jsx-a11y/media-has-caption */
  2. import React, { Component } from 'react';
  3. import moment from 'moment';
  4. import { connect } from 'dva';
  5. import { routerRedux } from 'dva/router';
  6. import { Card, Button, message } from 'antd';
  7. import Ellipsis from '../../../components/Ellipsis';
  8. import PageHeaderLayout from '../../../layouts/PageHeaderLayout';
  9. import { StandardTableList } from '../../../components/AXList';
  10. import { addRowKey, genAbsolutePicUrl } from '../../../utils/utils';
  11. import styles from './AudioBookList.less';
  12. const Message = message;
  13. function deleteBlankKey(obj) {
  14. if (!(typeof obj === 'object')) {
  15. return;
  16. }
  17. const newObj = { ...obj };
  18. for (const key in newObj) {
  19. if (newObj.hasOwnProperty(key) && !newObj[key]) {
  20. delete newObj[key];
  21. }
  22. }
  23. return newObj;
  24. }
  25. function genAudioBook(obj = {}) {
  26. const { id, code, name, status } = obj;
  27. let { img, audio } = obj;
  28. img = img || {};
  29. audio = audio || {};
  30. return {
  31. id,
  32. code,
  33. name,
  34. status,
  35. imgUrl: img.url,
  36. imgPath: img.path,
  37. imgFormat: img.format,
  38. imgQuality: img.quality,
  39. audioUrl: audio.url,
  40. audioPath: audio.path,
  41. audioFormat: audio.format,
  42. audioQuality: audio.quality,
  43. };
  44. }
  45. @connect(({ loading, resource }) => ({
  46. resource,
  47. loading: loading.models.resource,
  48. }))
  49. export default class AudioBookListPage extends Component {
  50. constructor(props) {
  51. super(props);
  52. const { state } = props.location;
  53. this.state = {
  54. UIParams: (state || {}).UIParams, // 组件的状态参数
  55. Queryers: (state || {}).Queryers, // 查询的条件参数
  56. };
  57. }
  58. componentWillMount() {
  59. this.props.dispatch({
  60. type: 'resource/clearState',
  61. });
  62. }
  63. componentDidMount() {
  64. this.props.dispatch({
  65. type: 'resource/fetchAudioBookList',
  66. payload: { ...this.state.Queryers },
  67. });
  68. }
  69. // 创建有声读物(增)
  70. handleCreateOperation = () => {
  71. const { UIParams, Queryers } = this.state;
  72. this.props.dispatch(
  73. routerRedux.push({
  74. pathname: '/resource/audiobook-create',
  75. state: { UIParams, Queryers },
  76. })
  77. );
  78. };
  79. // 修改有声读物(改)
  80. handleUpdateOperation = (item) => {
  81. const { UIParams, Queryers } = this.state;
  82. this.props.dispatch(
  83. routerRedux.push({
  84. pathname: `/resource/audiobook-edit/${item.id}`,
  85. state: { UIParams, Queryers, audioBookItem: genAudioBook(item) },
  86. })
  87. );
  88. };
  89. // 查询有声读物(查)
  90. handleFilterOperation = (params, states) => {
  91. const newParams = deleteBlankKey(params);
  92. this.props.dispatch({
  93. type: 'resource/fetchAudioBookList',
  94. payload: newParams,
  95. });
  96. this.setState({
  97. UIParams: states,
  98. Queryers: newParams,
  99. });
  100. };
  101. // TODO: 批量操作
  102. handleBatchOperation = () => {
  103. Message.info('暂不支持批量操作!');
  104. };
  105. render() {
  106. const { loading, resource } = this.props;
  107. const { list, totalSize, pageSize, pageNo } = resource;
  108. const pagination = {
  109. pageNo,
  110. pageSize,
  111. totalSize,
  112. };
  113. const batchActions = [{
  114. key: 'delete',
  115. name: '批量删除',
  116. }, {
  117. key: 'edit',
  118. name: '批量编辑',
  119. }];
  120. const basicSearch = {
  121. keys: [{
  122. name: '有声读物名称',
  123. field: 'name',
  124. }, {
  125. name: '有声读物编号',
  126. field: 'code',
  127. }],
  128. };
  129. const columns = [{
  130. title: '有声读物编号',
  131. key: 1,
  132. dataIndex: 'code',
  133. width: '18%',
  134. render: text => (
  135. <Ellipsis tooltip lines={1}>{text}</Ellipsis>
  136. ),
  137. }, {
  138. title: '有声读物名称',
  139. key: 2,
  140. dataIndex: 'name',
  141. width: '20%',
  142. render: text => (
  143. <Ellipsis tooltip lines={1}>{text}</Ellipsis>
  144. ),
  145. }, {
  146. title: '有声读物配图',
  147. key: 3,
  148. dataIndex: 'img',
  149. width: '20%',
  150. render: (text) => {
  151. const { path } = text || {};
  152. return (
  153. <div className={styles.picWrapper}>
  154. <img src={genAbsolutePicUrl(path)} alt="thumb" />
  155. </div>
  156. );
  157. },
  158. }, {
  159. title: '有声读物音频',
  160. key: 4,
  161. dataIndex: 'audio',
  162. width: '20%',
  163. render: (text) => {
  164. const { url } = text || {};
  165. return (
  166. <div className={styles.audioWrapper}>
  167. <audio controls src={url}>浏览器暂不支持播放</audio>
  168. </div>
  169. );
  170. },
  171. }, {
  172. title: '修改时间',
  173. key: 5,
  174. dataIndex: 'gmtModified',
  175. render: text => moment(text).format('YYYY-MM-DD HH:mm:ss'),
  176. width: '17%',
  177. }, {
  178. title: '操作',
  179. key: 6,
  180. dataIndex: 'operation',
  181. render: (_, record) => (
  182. <Button
  183. size="small"
  184. type="primary"
  185. className="editBtn"
  186. onClick={() => this.handleUpdateOperation(record)}
  187. >编辑
  188. </Button>
  189. ),
  190. width: '5%',
  191. align: 'right',
  192. }];
  193. return (
  194. <PageHeaderLayout>
  195. <Card bordered={false}>
  196. <StandardTableList
  197. columns={columns}
  198. loading={loading}
  199. dataSource={addRowKey(list)}
  200. header={{
  201. basicSearch,
  202. onFilterClick: this.handleFilterOperation,
  203. onCreateClick: this.handleCreateOperation,
  204. }}
  205. footer={{
  206. pagination,
  207. batchActions,
  208. onBatchClick: this.handleBatchOperation,
  209. }}
  210. keepUIState={{ ...this.state.UIParams }}
  211. showStatusSelect={false}
  212. />
  213. </Card>
  214. </PageHeaderLayout>
  215. );
  216. }
  217. }