|
@@ -1,9 +1,13 @@
|
|
|
import React, { PureComponent } from 'react';
|
|
|
-import { Card, Form, Select, Input, Button, Switch } from 'antd';
|
|
|
+import pathToRegexp from 'path-to-regexp';
|
|
|
+import { Card, Form, Radio, Input, Button, Switch } from 'antd';
|
|
|
import { connect } from 'dva';
|
|
|
import { routerRedux } from 'dva/router';
|
|
|
import PageHeaderLayout from '../../../layouts/PageHeaderLayout';
|
|
|
-import { boolToStatus, statusToBool } from '../../../utils/utils';
|
|
|
+import {
|
|
|
+ resourceTypes, resourceQuality, boolToStatus, statusToBool,
|
|
|
+} from '../../../utils/utils';
|
|
|
+import { Hotax } from '../../../utils/config';
|
|
|
|
|
|
const formItemLayout = {
|
|
|
labelCol: {
|
|
@@ -27,7 +31,15 @@ const submitFormLayout = {
|
|
|
@connect(({ loading }) => ({
|
|
|
submitting: loading.models.resource,
|
|
|
}))
|
|
|
-export default class VideoEditPage extends PureComponent {
|
|
|
+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(
|
|
@@ -41,17 +53,20 @@ export default class VideoEditPage extends PureComponent {
|
|
|
e.preventDefault();
|
|
|
this.props.form.validateFieldsAndScroll((err, values) => {
|
|
|
if (!err) {
|
|
|
- const { id, type, UIParams, Queryers } = this.props.location.state || {};
|
|
|
- const { fileList, status, ...params } = values;
|
|
|
- if (Array.isArray(fileList) && fileList.length) {
|
|
|
- params.url = fileList[0].url;
|
|
|
+ const { UIParams, Queryers } = this.props.location.state || {};
|
|
|
+ const { status, ...params } = values;
|
|
|
+ const matchId = this.isEdit();
|
|
|
+ if (matchId) {
|
|
|
+ this.props.dispatch({
|
|
|
+ type: 'resource/updateVideo',
|
|
|
+ payload: { id: matchId, status: boolToStatus(status), ...params },
|
|
|
+ states: { UIParams, Queryers },
|
|
|
+ });
|
|
|
+ return;
|
|
|
}
|
|
|
- params.id = id;
|
|
|
- params.type = type;
|
|
|
- params.status = boolToStatus(status);
|
|
|
this.props.dispatch({
|
|
|
- type: 'resource/updateVideo',
|
|
|
- payload: params,
|
|
|
+ type: 'resource/createVideo',
|
|
|
+ payload: { status: boolToStatus(status), ...params },
|
|
|
states: { UIParams, Queryers },
|
|
|
});
|
|
|
}
|
|
@@ -61,7 +76,7 @@ export default class VideoEditPage extends PureComponent {
|
|
|
const { form, submitting, location } = this.props;
|
|
|
const { getFieldDecorator } = form;
|
|
|
const { state = {} } = location;
|
|
|
- const { code, name, size, type, path, rate, quality, status } = state;
|
|
|
+ const { code, name, size, type, path, rate, quality, status, format } = state;
|
|
|
|
|
|
return (
|
|
|
<PageHeaderLayout>
|
|
@@ -69,10 +84,16 @@ export default class VideoEditPage extends PureComponent {
|
|
|
<Form onSubmit={this.handlePageSubmit}>
|
|
|
<Form.Item label="视频编号" {...formItemLayout}>
|
|
|
{getFieldDecorator('code', {
|
|
|
- rules: [{ required: true, message: '视频编号不能为空' }],
|
|
|
+ rules: [
|
|
|
+ {
|
|
|
+ required: true, message: '视频编号不能为空',
|
|
|
+ }, {
|
|
|
+ pattern: /^[a-zA-Z0-9|-]+$/g, message: '编号包含非法字符',
|
|
|
+ },
|
|
|
+ ],
|
|
|
initialValue: code,
|
|
|
})(
|
|
|
- <Input />
|
|
|
+ <Input placeholder="请填写" />
|
|
|
)}
|
|
|
</Form.Item>
|
|
|
<Form.Item label="视频名称" {...formItemLayout}>
|
|
@@ -80,46 +101,80 @@ export default class VideoEditPage extends PureComponent {
|
|
|
rules: [{ required: true, message: '视频名称不能为空' }],
|
|
|
initialValue: name,
|
|
|
})(
|
|
|
- <Input />
|
|
|
+ <Input placeholder="请填写" />
|
|
|
+ )}
|
|
|
+ </Form.Item>
|
|
|
+ <Form.Item label="视频路径" {...formItemLayout}>
|
|
|
+ {getFieldDecorator('path', {
|
|
|
+ rules: [{ required: true, message: '资源路径为必填项' }],
|
|
|
+ initialValue: path,
|
|
|
+ })(
|
|
|
+ <Input placeholder="请填写" />
|
|
|
)}
|
|
|
</Form.Item>
|
|
|
<Form.Item label="资源类型" {...formItemLayout}>
|
|
|
{getFieldDecorator('type', {
|
|
|
rules: [{ required: true, message: '资源类型不能为空' }],
|
|
|
- initialValue: type,
|
|
|
+ initialValue: type || Hotax.RESOURCE_VIDEO,
|
|
|
})(
|
|
|
- <Input />
|
|
|
+ <Radio.Group>
|
|
|
+ {
|
|
|
+ Object.keys(resourceTypes).map(key =>
|
|
|
+ (
|
|
|
+ <Radio.Button
|
|
|
+ key={key}
|
|
|
+ value={parseInt(key, 10)}
|
|
|
+ >{resourceTypes[key]}
|
|
|
+ </Radio.Button>
|
|
|
+ )
|
|
|
+ )
|
|
|
+ }
|
|
|
+ </Radio.Group>
|
|
|
)}
|
|
|
</Form.Item>
|
|
|
- <Form.Item label="资源路径" {...formItemLayout}>
|
|
|
- {getFieldDecorator('path', {
|
|
|
- initialValue: path,
|
|
|
+ <Form.Item label="清晰度" {...formItemLayout}>
|
|
|
+ {getFieldDecorator('quality', {
|
|
|
+ rules: [{ required: true, message: '清晰度为必选项' }],
|
|
|
+ initialValue: quality || Hotax.QUALITY_HIGH,
|
|
|
})(
|
|
|
- <Input />
|
|
|
+ <Radio.Group>
|
|
|
+ {
|
|
|
+ Object.keys(resourceQuality).map(key =>
|
|
|
+ (
|
|
|
+ <Radio.Button
|
|
|
+ key={key}
|
|
|
+ value={key}
|
|
|
+ >{resourceQuality[key]}
|
|
|
+ </Radio.Button>
|
|
|
+ )
|
|
|
+ )
|
|
|
+ }
|
|
|
+ </Radio.Group>
|
|
|
)}
|
|
|
</Form.Item>
|
|
|
- <Form.Item label="清晰度" {...formItemLayout}>
|
|
|
- {getFieldDecorator('quality', {
|
|
|
- initialValue: quality,
|
|
|
+ <Form.Item label="视频格式" {...formItemLayout}>
|
|
|
+ {getFieldDecorator('format', {
|
|
|
+ rules: [{ required: true, message: '视频格式不能为空' }],
|
|
|
+ initialValue: format || 'm3u8',
|
|
|
})(
|
|
|
- <Input />
|
|
|
+ <Input placeholder="请填写" />
|
|
|
)}
|
|
|
</Form.Item>
|
|
|
- <Form.Item label="资源码流" {...formItemLayout}>
|
|
|
+ <Form.Item label="视频码流" {...formItemLayout}>
|
|
|
{getFieldDecorator('rate', {
|
|
|
initialValue: rate,
|
|
|
})(
|
|
|
- <Input />
|
|
|
+ <Input placeholder="请填写" />
|
|
|
)}
|
|
|
</Form.Item>
|
|
|
- <Form.Item label="资源大小" {...formItemLayout}>
|
|
|
+ <Form.Item label="视频大小" {...formItemLayout}>
|
|
|
{getFieldDecorator('size', {
|
|
|
initialValue: size,
|
|
|
})(
|
|
|
- <Input />
|
|
|
+ <Input placeholder="请填写" addonAfter="字节" />
|
|
|
)}
|
|
|
</Form.Item>
|
|
|
- <Form.Item label="资源状态" {...formItemLayout}>
|
|
|
+ <Form.Item label="视频状态" {...formItemLayout}>
|
|
|
{getFieldDecorator('status', {
|
|
|
valuePropName: 'checked',
|
|
|
initialValue: statusToBool(status),
|