|
@@ -0,0 +1,141 @@
|
|
|
+import React, { PureComponent } from 'react';
|
|
|
+import PropTypes from 'prop-types';
|
|
|
+import queryString from 'query-string';
|
|
|
+import { connect } from 'dva';
|
|
|
+import { routerRedux } from 'dva/router';
|
|
|
+import { Card } from 'antd';
|
|
|
+import TableList from './table';
|
|
|
+import Search from './search';
|
|
|
+import ModalForm from './modal';
|
|
|
+import PageHeaderLayout from '../../../layouts/PageHeaderLayout';
|
|
|
+
|
|
|
+@connect(state => ({ resource: state.resource }))
|
|
|
+export default class Video extends PureComponent {
|
|
|
+ static propTypes = {
|
|
|
+ resource: PropTypes.object,
|
|
|
+ location: PropTypes.object,
|
|
|
+ dispatch: PropTypes.func,
|
|
|
+ };
|
|
|
+
|
|
|
+ render() {
|
|
|
+ const { location, dispatch, resource } = this.props;
|
|
|
+
|
|
|
+ location.query = queryString.parse(location.search);
|
|
|
+ const { query, pathname } = location;
|
|
|
+ const { field, keyword, ...filters } = query;
|
|
|
+ const { list, listLoading, pagination, currentItem, itemLoading, modalVisible, isPaused, modalType } = resource // 把携带的参数中空值项删除
|
|
|
+
|
|
|
+ Object.keys(filters).map(key => { filters[key] ? null : delete filters[key] });
|
|
|
+ // 如果搜索内容不为空则添加进filters中
|
|
|
+ if (field && keyword) {
|
|
|
+ filters[field] = keyword;
|
|
|
+ }
|
|
|
+
|
|
|
+ const searchProps = {
|
|
|
+ field,
|
|
|
+ keyword,
|
|
|
+ onSearch: (payload) => {
|
|
|
+ if (!payload.keyword.length) {
|
|
|
+ delete payload.field;
|
|
|
+ delete payload.keyword;
|
|
|
+ }
|
|
|
+ dispatch(routerRedux.push({
|
|
|
+ pathname,
|
|
|
+ search: queryString.stringify({
|
|
|
+ ...payload
|
|
|
+ })
|
|
|
+ }));
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
+ const listProps = {
|
|
|
+ pagination,
|
|
|
+ location,
|
|
|
+ curStatus: filters.status,
|
|
|
+ dataSource: list,
|
|
|
+ loading: listLoading,
|
|
|
+ onChange: (pagination, filterArgs) => {
|
|
|
+ const getValue = obj => Object.keys(obj).map(key => obj[key]).join(',');
|
|
|
+ const tableFilters = Object.keys(filterArgs).reduce((obj, key) => {
|
|
|
+ const newObj = { ...obj };
|
|
|
+ newObj[key] = getValue(filterArgs[key]);
|
|
|
+ return newObj;
|
|
|
+ }, {});
|
|
|
+ const data = { ...filters, ...tableFilters };
|
|
|
+ Object.keys(data).map(key => data[key] ? null : delete data[key]);
|
|
|
+ dispatch(routerRedux.push({
|
|
|
+ pathname,
|
|
|
+ search: queryString.stringify({
|
|
|
+ ...data,
|
|
|
+ pageNo: pagination.current,
|
|
|
+ pageSize: pagination.pageSize,
|
|
|
+ }),
|
|
|
+ }));
|
|
|
+ },
|
|
|
+ onPlayVideo: (item) => {
|
|
|
+ dispatch({
|
|
|
+ type: 'resource/showModal',
|
|
|
+ payload: {
|
|
|
+ modalType: 'update',
|
|
|
+ currentItem: item,
|
|
|
+ },
|
|
|
+ })
|
|
|
+ },
|
|
|
+ // 删除一条数据后,刷新页面保持筛选数据不变
|
|
|
+ onDeleteItem: (id) => {
|
|
|
+ dispatch({
|
|
|
+ type: 'resource/delete',
|
|
|
+ payload: id,
|
|
|
+ callback: () => {
|
|
|
+ dispatch(
|
|
|
+ routerRedux.push({
|
|
|
+ pathname,
|
|
|
+ search: queryString.stringify(filters),
|
|
|
+ })
|
|
|
+ );
|
|
|
+ }
|
|
|
+ });
|
|
|
+ },
|
|
|
+ // 恢复一条数据后,刷新页面并保持筛选数据不变
|
|
|
+ onRecoverItem: (payload) => {
|
|
|
+ dispatch({
|
|
|
+ type: 'resource/recover',
|
|
|
+ payload,
|
|
|
+ callback: () => {
|
|
|
+ dispatch(
|
|
|
+ routerRedux.push({
|
|
|
+ pathname,
|
|
|
+ search: queryString.stringify(filters),
|
|
|
+ })
|
|
|
+ );
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
+ const modalProps = {
|
|
|
+ item: currentItem,
|
|
|
+ visible: modalVisible,
|
|
|
+ footer: null,
|
|
|
+ maskClosable: false,
|
|
|
+ isPaused,
|
|
|
+ title: currentItem.name || '观看视频',
|
|
|
+ wrapClassName: 'vertical-center-modal',
|
|
|
+ onCancel () {
|
|
|
+ dispatch({
|
|
|
+ type: 'resource/closeVideo',
|
|
|
+ })
|
|
|
+ },
|
|
|
+ };
|
|
|
+
|
|
|
+ return (
|
|
|
+ <PageHeaderLayout>
|
|
|
+ <Card>
|
|
|
+ <Search { ...searchProps } />
|
|
|
+ <TableList { ...listProps } />
|
|
|
+ <ModalForm { ...modalProps } />
|
|
|
+ </Card>
|
|
|
+ </PageHeaderLayout>
|
|
|
+ );
|
|
|
+ }
|
|
|
+}
|