|
@@ -1,7 +1,7 @@
|
|
import { useEffect, useRef, useState } from 'react'
|
|
import { useEffect, useRef, useState } from 'react'
|
|
import { ActionsButton } from 'components'
|
|
import { ActionsButton } from 'components'
|
|
import style from '../style.module.scss'
|
|
import style from '../style.module.scss'
|
|
-import { AntUploadProps, addExampleFile, deleteExampleFile } from 'api'
|
|
|
|
|
|
+import { addExampleFile, deleteExampleFile } from 'api'
|
|
import { UploadOutlined } from '@ant-design/icons'
|
|
import { UploadOutlined } from '@ant-design/icons'
|
|
import { confirm, onlyOpenWindow } from 'utils'
|
|
import { confirm, onlyOpenWindow } from 'utils'
|
|
import {
|
|
import {
|
|
@@ -108,8 +108,7 @@ export const ExampleFiles = (props: ExampleScenesProps) => {
|
|
visible={true}
|
|
visible={true}
|
|
onOk={props.onClose}
|
|
onOk={props.onClose}
|
|
onCancel={props.onClose}
|
|
onCancel={props.onClose}
|
|
- okText="确定"
|
|
|
|
- cancelText="取消"
|
|
|
|
|
|
+ footer={null}
|
|
>
|
|
>
|
|
{renderAddFile}
|
|
{renderAddFile}
|
|
<div className={style['model-header']}>
|
|
<div className={style['model-header']}>
|
|
@@ -130,6 +129,17 @@ export const ExampleFiles = (props: ExampleScenesProps) => {
|
|
)
|
|
)
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+const FileTitleInput = (props: { value?: string, onChange?: (value: string) => void;}) =>
|
|
|
|
+ <Input
|
|
|
|
+ onChange={ev => {
|
|
|
|
+ const value = ev.target.value.trim()
|
|
|
|
+ if (value.length <= 50) {
|
|
|
|
+ props.onChange && props.onChange(value)
|
|
|
|
+ }
|
|
|
|
+ }}
|
|
|
|
+ value={props.value}
|
|
|
|
+ />
|
|
|
|
+
|
|
export type AddExampleFileProps = Pick<Example, 'caseId'> & { onClose: () => void,}
|
|
export type AddExampleFileProps = Pick<Example, 'caseId'> & { onClose: () => void,}
|
|
export const AddExampleFile = (props: AddExampleFileProps) => {
|
|
export const AddExampleFile = (props: AddExampleFileProps) => {
|
|
const dispatch = useDispatch()
|
|
const dispatch = useDispatch()
|
|
@@ -144,8 +154,9 @@ export const AddExampleFile = (props: AddExampleFileProps) => {
|
|
}
|
|
}
|
|
await addExampleFile({
|
|
await addExampleFile({
|
|
...values,
|
|
...values,
|
|
|
|
+ filesUrl: void 0,
|
|
caseId: props.caseId,
|
|
caseId: props.caseId,
|
|
- filesUrl: values.filesUrl.fileList[0].response
|
|
|
|
|
|
+ file: values.filesUrl.file.originFileObj
|
|
})
|
|
})
|
|
props.onClose()
|
|
props.onClose()
|
|
dispatch(fetchExampleFiles({ caseId: props.caseId }))
|
|
dispatch(fetchExampleFiles({ caseId: props.caseId }))
|
|
@@ -153,13 +164,31 @@ export const AddExampleFile = (props: AddExampleFileProps) => {
|
|
const onSubmit = () => {
|
|
const onSubmit = () => {
|
|
from.current?.submit()
|
|
from.current?.submit()
|
|
}
|
|
}
|
|
|
|
+ const accpets = [".pdf", ".word", ".jpg"]
|
|
|
|
|
|
const uploadProps: UploadProps = {
|
|
const uploadProps: UploadProps = {
|
|
- ...AntUploadProps,
|
|
|
|
|
|
+ async customRequest(option) {
|
|
|
|
+ const file = option.file as File
|
|
|
|
+ const filename = file.name
|
|
|
|
+ const ext = filename.substring(filename.lastIndexOf('.'))
|
|
|
|
+ const isSuper = accpets.includes(ext)
|
|
|
|
+ if (!isSuper) {
|
|
|
|
+ message.error(`只能${accpets.join(',')}上传文件`)
|
|
|
|
+ option.onError && option.onError(new Error(`只能${accpets.join(',')}上传文件`))
|
|
|
|
+ return
|
|
|
|
+ } else if (file.size > 100 * 1024 * 1024) {
|
|
|
|
+ message.error(`上传文件不能超过100M`)
|
|
|
|
+ option.onError && option.onError(new Error(`上传文件不能超过100M`))
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ option.onSuccess && option.onSuccess(file.name)
|
|
|
|
+ },
|
|
listType: 'picture',
|
|
listType: 'picture',
|
|
|
|
+ multiple: false,
|
|
|
|
+ accept: accpets.join(","),
|
|
maxCount: 1,
|
|
maxCount: 1,
|
|
onPreview(file) {
|
|
onPreview(file) {
|
|
- onlyOpenWindow(file.response)
|
|
|
|
|
|
+ onlyOpenWindow(URL.createObjectURL(file.originFileObj!))
|
|
}
|
|
}
|
|
};
|
|
};
|
|
|
|
|
|
@@ -187,11 +216,11 @@ export const AddExampleFile = (props: AddExampleFileProps) => {
|
|
</Form.Item>
|
|
</Form.Item>
|
|
<Form.Item name="filesUrl" label="上传附件" rules={[{ required: true, message: '附件文件不能为空' }]}>
|
|
<Form.Item name="filesUrl" label="上传附件" rules={[{ required: true, message: '附件文件不能为空' }]}>
|
|
<Upload {...uploadProps}>
|
|
<Upload {...uploadProps}>
|
|
- <Button icon={<UploadOutlined />}>请上传pdf/word/jpg格式文件</Button>
|
|
|
|
|
|
+ <Button icon={<UploadOutlined />}>请上传{accpets.join('/')}格式文件</Button>
|
|
</Upload>
|
|
</Upload>
|
|
</Form.Item>
|
|
</Form.Item>
|
|
- <Form.Item name="filesTitle" label="附件标题" rules={[{ required: true, message: '附件标题不能为空' }]}>
|
|
|
|
- <Input />
|
|
|
|
|
|
+ <Form.Item name="filesTitle" label="附件标题" rules={[{ required: true, message: '附件标题不能为空' }]} >
|
|
|
|
+ <FileTitleInput />
|
|
</Form.Item>
|
|
</Form.Item>
|
|
</Form>
|
|
</Form>
|
|
</Modal>
|
|
</Modal>
|