import React, { PureComponent } from 'react'; import pathToRegexp from 'path-to-regexp'; import { Card, Form, Radio, Input, Button } from 'antd'; import { connect } from 'dva'; import { routerRedux } from 'dva/router'; import PageHeaderLayout from '../../../layouts/PageHeaderLayout'; import { resourceTypes, resourceQuality } from '../../../utils/utils'; import { Hotax } from '../../../utils/config'; const formItemLayout = { labelCol: { xs: { span: 24 }, sm: { span: 6 }, }, wrapperCol: { xs: { span: 24 }, sm: { span: 14 }, md: { span: 12 }, }, }; const submitFormLayout = { wrapperCol: { xs: { span: 24, offset: 0 }, sm: { span: 12, offset: 6 }, }, }; @Form.create() @connect(({ loading }) => ({ submitting: loading.models.resource, })) export default class VideoCreatePage extends PureComponent { isEdit = () => { const { location } = this.props; const match = pathToRegexp('/resource/video-edit/:id').exec(location.pathname); if (match) { return match[1]; } return false; }; handlePageBack = () => { const { UIParams, Queryers } = this.props.location.state || {}; this.props.dispatch( routerRedux.push({ pathname: '/resource/video', state: { UIParams, Queryers }, }) ); }; handlePageSubmit = (e) => { e.preventDefault(); this.props.form.validateFieldsAndScroll((err, values) => { if (!err) { const { UIParams, Queryers } = this.props.location.state || {}; const matchId = this.isEdit(); if (matchId) { this.props.dispatch({ type: 'resource/updateVideo', payload: { id: matchId, status: Hotax.STATUS_NORMAL, ...values }, states: { UIParams, Queryers }, }); return; } this.props.dispatch({ type: 'resource/createVideo', payload: { status: Hotax.STATUS_NORMAL, ...values }, states: { UIParams, Queryers }, }); } }); }; render() { const { form, submitting, location } = this.props; const { getFieldDecorator } = form; const { state = {} } = location; const { code, name, size, type, path, rate, quality, format } = state; return (
{getFieldDecorator('code', { rules: [ { required: true, message: '视频编号不能为空', }, { pattern: /^[a-zA-Z0-9|-]+$/g, message: '编号包含非法字符', }, ], initialValue: code, })( )} {getFieldDecorator('name', { rules: [{ required: true, message: '视频名称不能为空' }], initialValue: name, })( )} {getFieldDecorator('path', { rules: [{ required: true, message: '资源路径为必填项' }], initialValue: path, })( )} {getFieldDecorator('type', { rules: [{ required: true, message: '资源类型不能为空' }], initialValue: type || Hotax.RESOURCE_VIDEO, })( { Object.keys(resourceTypes).map(key => ( {resourceTypes[key]} ) ) } )} {getFieldDecorator('quality', { rules: [{ required: true, message: '清晰度为必选项' }], initialValue: quality || Hotax.QUALITY_HIGH, })( { Object.keys(resourceQuality).map(key => ( {resourceQuality[key]} ) ) } )} {getFieldDecorator('format', { rules: [{ required: true, message: '视频格式不能为空' }], initialValue: format || 'm3u8', })( )} {getFieldDecorator('rate', { initialValue: rate, })( )} {getFieldDecorator('size', { initialValue: size, })( )}
); } }