|
@@ -1,143 +1,99 @@
|
|
|
-import React, { useState } from 'react';
|
|
|
-import { Button, Form, Input, message, Modal, Radio, Upload } from 'antd';
|
|
|
-import { TableListItem } from '../data.d';
|
|
|
-import { UploadOutlined } from '@ant-design/icons';
|
|
|
+import React from 'react';
|
|
|
+import {Button, message, Modal} from 'antd';
|
|
|
+import {TableListItem} from '../../MemoryList/data.d';
|
|
|
+import Quill from "@/pages/Memory/components/Quill";
|
|
|
+import service from "@/pages/Memory/service";
|
|
|
+import {useSingleState} from "nice-hooks";
|
|
|
|
|
|
// 表单特殊字段
|
|
|
-export interface FormValueType extends Partial<TableListItem> {}
|
|
|
+export interface FormValueType extends Partial<TableListItem> {
|
|
|
+}
|
|
|
|
|
|
export interface UpdateFormProps {
|
|
|
- onCancel: (flag?: boolean, formVals?: FormValueType) => void;
|
|
|
- onSubmit: (values: FormValueType) => void;
|
|
|
- updateModalVisible: boolean;
|
|
|
+ onCancel: (fresh?:boolean) => void;
|
|
|
+ modalVisible: boolean;
|
|
|
values: Partial<TableListItem>;
|
|
|
}
|
|
|
|
|
|
-const FormItem = Form.Item;
|
|
|
-
|
|
|
-const formLayout = {
|
|
|
- labelCol: { span: 7 },
|
|
|
- wrapperCol: { span: 13 },
|
|
|
-};
|
|
|
|
|
|
const UpdateForm: React.FC<UpdateFormProps> = (props) => {
|
|
|
- const [formVals, setFormVals] = useState<FormValueType>(props.values);
|
|
|
|
|
|
- const [form] = Form.useForm();
|
|
|
+ const [formValues, setFormValues] = useSingleState<TableListItem>({
|
|
|
+ back: "",
|
|
|
+ front: "",
|
|
|
+ id: undefined,
|
|
|
+ period: 0,
|
|
|
+ remindTime: new Date(),
|
|
|
+ tag: "",
|
|
|
+ updateTime: "",
|
|
|
+ userId: 0,...props.values});
|
|
|
|
|
|
const {
|
|
|
- onSubmit: handleUpdate,
|
|
|
- onCancel: handleUpdateModalVisible,
|
|
|
- updateModalVisible,
|
|
|
- values,
|
|
|
+ onCancel: hideModal,
|
|
|
+ modalVisible,
|
|
|
} = props;
|
|
|
|
|
|
- const submit = async () => {
|
|
|
- const fieldsValue = await form.validateFields();
|
|
|
- const newValue = { ...formVals, ...fieldsValue };
|
|
|
- setFormVals(newValue);
|
|
|
- handleUpdate(newValue);
|
|
|
- };
|
|
|
-
|
|
|
- const modelFileProps = {
|
|
|
- action: 'https://www.mocky.io/v2/5cc8019d300000980a055e76',
|
|
|
- // @ts-ignore
|
|
|
- onChange(info) {
|
|
|
- if (info.file.status === 'done') {
|
|
|
- setFormVals({ ...formVals, ...{ modelFile: info.file.response.url } });
|
|
|
- message.success(`file uploaded successfully`);
|
|
|
- } else if (info.file.status === 'error') {
|
|
|
- message.error(`file upload failed.`);
|
|
|
- }
|
|
|
- },
|
|
|
- };
|
|
|
- const vocabFileProps = {
|
|
|
- action: 'https://www.mocky.io/v2/5cc8019d300000980a055e76',
|
|
|
- // @ts-ignore
|
|
|
- onChange(info) {
|
|
|
- if (info.file.status === 'done') {
|
|
|
- setFormVals({ ...formVals, ...{ vocabFile: info.file.response.url } });
|
|
|
- message.success(`file uploaded successfully`);
|
|
|
- } else if (info.file.status === 'error') {
|
|
|
- message.error(`file upload failed.`);
|
|
|
- }
|
|
|
- },
|
|
|
- };
|
|
|
- const labelFileProps = {
|
|
|
- action: 'https://www.mocky.io/v2/5cc8019d300000980a055e76',
|
|
|
- // @ts-ignore
|
|
|
- onChange(info) {
|
|
|
- if (info.file.status === 'done') {
|
|
|
- setFormVals({ ...formVals, ...{ labelFile: info.file.response.url } });
|
|
|
- message.success(`file uploaded successfully`);
|
|
|
- } else if (info.file.status === 'error') {
|
|
|
- message.error(`file upload failed.`);
|
|
|
- }
|
|
|
- },
|
|
|
- };
|
|
|
-
|
|
|
- const renderFooter = () => {
|
|
|
- return (
|
|
|
- <>
|
|
|
- <Button onClick={() => handleUpdateModalVisible(false, values)}>取消</Button>
|
|
|
- <Button type="primary" onClick={() => submit()}>
|
|
|
- 提交
|
|
|
- </Button>
|
|
|
- </>
|
|
|
- );
|
|
|
- };
|
|
|
|
|
|
return (
|
|
|
<Modal
|
|
|
width={640}
|
|
|
- bodyStyle={{ padding: '32px 40px 48px' }}
|
|
|
+ bodyStyle={{padding: '15px 15px 15px'}}
|
|
|
destroyOnClose
|
|
|
title="配置模型"
|
|
|
- visible={updateModalVisible}
|
|
|
- footer={renderFooter()}
|
|
|
- onCancel={() => handleUpdateModalVisible()}
|
|
|
+ visible={modalVisible}
|
|
|
+ onCancel={() => hideModal(false)}
|
|
|
+ footer={null}
|
|
|
>
|
|
|
- <Form {...formLayout} form={form} initialValues={formVals}>
|
|
|
- <FormItem
|
|
|
- name="modelName"
|
|
|
- label="模型名称"
|
|
|
- rules={[{ required: true, message: '请输入规则名称!' }]}
|
|
|
- >
|
|
|
- <Input placeholder="请输入" />
|
|
|
- </FormItem>
|
|
|
+ <div>
|
|
|
+ <h4>正面</h4>
|
|
|
+ <Quill
|
|
|
+ readonly={false}
|
|
|
+ onChange={(value) => {
|
|
|
+ setFormValues({front: value});
|
|
|
+ }}
|
|
|
+ value={formValues.front}/>
|
|
|
|
|
|
- <FormItem
|
|
|
- name="modelType"
|
|
|
- label="模型类型"
|
|
|
- rules={[{ required: true, message: '请选择模型类型!' }]}
|
|
|
+ <p/>
|
|
|
+ <h4>反面</h4>
|
|
|
+ <Quill
|
|
|
+ readonly={false}
|
|
|
+ onChange={(value) => {
|
|
|
+ setFormValues({back: value});
|
|
|
+ }}
|
|
|
+ value={formValues.back}
|
|
|
+ />
|
|
|
+ <p/>
|
|
|
+ <Button
|
|
|
+ type="primary"
|
|
|
+ onClick={async () => {
|
|
|
+ let res;
|
|
|
+ if (formValues.id != undefined) {
|
|
|
+ res = await service.update(formValues);
|
|
|
+ } else {
|
|
|
+ res = await service.insert(formValues);
|
|
|
+ }
|
|
|
+ if (res.success) {
|
|
|
+ message.info('操作成功');
|
|
|
+ if (formValues.id != undefined) {
|
|
|
+ hideModal(true);
|
|
|
+ } else {
|
|
|
+ setFormValues({front:'',back:''})
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ message.info(`操作失败: ${res.message}`);
|
|
|
+ }
|
|
|
+ }}
|
|
|
>
|
|
|
- <Radio.Group>
|
|
|
- <Radio.Button value="0">aubert</Radio.Button>
|
|
|
- <Radio.Button value="1">blstm</Radio.Button>
|
|
|
- </Radio.Group>
|
|
|
- </FormItem>
|
|
|
- <FormItem label="模型文件">
|
|
|
- <Upload {...modelFileProps}>
|
|
|
- <Button>
|
|
|
- <UploadOutlined /> Upload
|
|
|
- </Button>
|
|
|
- </Upload>
|
|
|
- </FormItem>
|
|
|
- <FormItem label="词向量文件">
|
|
|
- <Upload {...vocabFileProps}>
|
|
|
- <Button>
|
|
|
- <UploadOutlined /> Upload
|
|
|
- </Button>
|
|
|
- </Upload>
|
|
|
- </FormItem>
|
|
|
- <FormItem label="标签文件">
|
|
|
- <Upload {...labelFileProps}>
|
|
|
- <Button>
|
|
|
- <UploadOutlined /> Upload
|
|
|
- </Button>
|
|
|
- </Upload>
|
|
|
- </FormItem>
|
|
|
- </Form>
|
|
|
+ 确定
|
|
|
+ </Button>
|
|
|
+ <span> </span>
|
|
|
+ <Button
|
|
|
+ type="primary"
|
|
|
+ onClick={() => {
|
|
|
+ hideModal(false)
|
|
|
+ }}
|
|
|
+ >关闭</Button>
|
|
|
+ </div>
|
|
|
</Modal>
|
|
|
);
|
|
|
};
|