AudioBookList.js 5.3 KB

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