|
@@ -23,6 +23,15 @@ const submitFormLayout = {
|
|
|
},
|
|
|
};
|
|
|
|
|
|
+function picNameFormat(name) {
|
|
|
+ if (!name) return name;
|
|
|
+ const separatorIndex = name.lastIndexOf('.');
|
|
|
+ if (separatorIndex !== -1) {
|
|
|
+ return name.substring(0, separatorIndex);
|
|
|
+ }
|
|
|
+ return name;
|
|
|
+}
|
|
|
+
|
|
|
@Form.create()
|
|
|
@connect(({ loading }) => ({
|
|
|
submitting: loading.models.resource,
|
|
@@ -31,14 +40,10 @@ export default class PictureSingleUpload extends PureComponent {
|
|
|
state = {
|
|
|
fileList: [],
|
|
|
code: null,
|
|
|
- name: null,
|
|
|
};
|
|
|
handleCodeInputChange = (e) => {
|
|
|
this.setState({ code: e.target.value });
|
|
|
};
|
|
|
- handleNameInputChange = (e) => {
|
|
|
- this.setState({ name: e.target.value });
|
|
|
- };
|
|
|
handleOnChangeEvent = (fileList) => {
|
|
|
this.setState({ fileList });
|
|
|
return fileList;
|
|
@@ -76,9 +81,9 @@ export default class PictureSingleUpload extends PureComponent {
|
|
|
render() {
|
|
|
const { form, submitting } = this.props;
|
|
|
const { getFieldDecorator } = form;
|
|
|
- const { fileList, code, name } = this.state;
|
|
|
+ const { fileList, code } = this.state;
|
|
|
const firstPicture = fileList[0] || {};
|
|
|
- const { type, size, path } = firstPicture;
|
|
|
+ const { type, size, path, name } = firstPicture;
|
|
|
|
|
|
return (
|
|
|
<Form onSubmit={this.handlePageSubmit}>
|
|
@@ -88,9 +93,8 @@ export default class PictureSingleUpload extends PureComponent {
|
|
|
type="warning"
|
|
|
message={
|
|
|
<Fragment>
|
|
|
- <p>1.上传图片前应先填写符合规范的图片编号和名称,否则不能上传图片;</p>
|
|
|
- <p>2.上传成功后会自动生成图片大小、格式、路径等信息,无需手动填写;</p>
|
|
|
- <p>3.图片一旦创建完成,再次编辑时,图片编号不可修改。</p>
|
|
|
+ <p>1.上传图片前应先填写符合规范的图片编号,否则不能上传图片;</p>
|
|
|
+ <p>2.上传成功后会自动生成图片名称、大小、格式、路径等信息,无需手动填写;</p>
|
|
|
</Fragment>
|
|
|
}
|
|
|
/>
|
|
@@ -106,20 +110,13 @@ export default class PictureSingleUpload extends PureComponent {
|
|
|
<Input onChange={this.handleCodeInputChange} />
|
|
|
)}
|
|
|
</Form.Item>
|
|
|
- <Form.Item label="图片名称" hasFeedback {...formItemLayout}>
|
|
|
- {getFieldDecorator('name', {
|
|
|
- rules: [{ required: true, message: '名称不能为空!' }],
|
|
|
- })(
|
|
|
- <Input onChange={this.handleNameInputChange} />
|
|
|
- )}
|
|
|
- </Form.Item>
|
|
|
<Form.Item label="图片上传" {...formItemLayout}>
|
|
|
{getFieldDecorator('fileList', {
|
|
|
getValueFromEvent: this.handleOnChangeEvent,
|
|
|
})(
|
|
|
<Uploader
|
|
|
forbidden={
|
|
|
- !((code && /^[a-zA-Z0-9|-]+$/ig.test(code) && name))
|
|
|
+ !((code && /^[a-zA-Z0-9|-]+$/ig.test(code)))
|
|
|
}
|
|
|
fileCode={code}
|
|
|
fileList={fileList}
|
|
@@ -129,6 +126,14 @@ export default class PictureSingleUpload extends PureComponent {
|
|
|
/>
|
|
|
)}
|
|
|
</Form.Item>
|
|
|
+ <Form.Item label="图片名称" hasFeedback {...formItemLayout}>
|
|
|
+ {getFieldDecorator('name', {
|
|
|
+ rules: [{ required: true, message: '名称不能为空!' }],
|
|
|
+ initialValue: picNameFormat(name),
|
|
|
+ })(
|
|
|
+ <Input />
|
|
|
+ )}
|
|
|
+ </Form.Item>
|
|
|
<Form.Item label="图片路径" {...formItemLayout}>
|
|
|
{getFieldDecorator('path', {
|
|
|
initialValue: path,
|