您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

createModal.tsx 3.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. import React, { useEffect, useState } from 'react'
  2. import { connect, Dispatch } from 'umi';
  3. import i18n from 'i18next';
  4. import { useTranslation, Trans } from 'react-i18next'
  5. import { Input, Modal, Form } from 'antd'
  6. import styles from './index.less';
  7. import type { chunkModelState } from './model'
  8. import EditTag from './editTag'
  9. type FieldType = {
  10. content_ltks?: string;
  11. };
  12. interface kFProps {
  13. dispatch: Dispatch;
  14. chunkModel: chunkModelState;
  15. getChunkList: () => void;
  16. doc_id: string
  17. }
  18. const Index: React.FC<kFProps> = ({ chunkModel, dispatch, getChunkList, doc_id }) => {
  19. const { isShowCreateModal, chunk_id, chunkInfo } = chunkModel
  20. const [important_kwd, setImportantKwd] = useState(['Unremovable', 'Tag 2', 'Tag 3']);
  21. const { t } = useTranslation()
  22. const handleCancel = () => {
  23. dispatch({
  24. type: 'chunkModel/updateState',
  25. payload: {
  26. isShowCreateModal: false
  27. }
  28. });
  29. };
  30. useEffect(() => {
  31. if (chunk_id && isShowCreateModal) {
  32. dispatch({
  33. type: 'chunkModel/get_chunk',
  34. payload: {
  35. chunk_id
  36. },
  37. callback(info: any) {
  38. console.log(info)
  39. const { content_ltks, important_kwd = [] } = info
  40. form.setFieldsValue({ content_ltks })
  41. setImportantKwd(important_kwd)
  42. }
  43. });
  44. }
  45. }, [chunk_id, isShowCreateModal])
  46. const [form] = Form.useForm()
  47. const handleOk = async () => {
  48. try {
  49. const values = await form.validateFields();
  50. dispatch({
  51. type: 'chunkModel/create_hunk',
  52. payload: {
  53. content_ltks: values.content_ltks,
  54. doc_id,
  55. chunk_id,
  56. important_kwd
  57. },
  58. callback: () => {
  59. dispatch({
  60. type: 'chunkModel/updateState',
  61. payload: {
  62. isShowCreateModal: false
  63. }
  64. });
  65. getChunkList && getChunkList()
  66. }
  67. });
  68. } catch (errorInfo) {
  69. console.log('Failed:', errorInfo);
  70. }
  71. };
  72. return (
  73. <Modal title="Basic Modal" open={isShowCreateModal} onOk={handleOk} onCancel={handleCancel}>
  74. <Form
  75. form={form}
  76. name="validateOnly"
  77. labelCol={{ span: 5 }}
  78. wrapperCol={{ span: 19 }}
  79. style={{ maxWidth: 600 }}
  80. autoComplete="off"
  81. >
  82. <Form.Item<FieldType>
  83. label="chunk 内容"
  84. name="content_ltks"
  85. rules={[{ required: true, message: 'Please input name!' }]}
  86. >
  87. <Input.TextArea />
  88. </Form.Item>
  89. <EditTag tags={important_kwd} setTags={setImportantKwd} />
  90. </Form>
  91. </Modal >
  92. );
  93. }
  94. export default connect(({ chunkModel, loading }) => ({ chunkModel, loading }))(Index);