feat: pg引入

This commit is contained in:
archer
2023-04-18 22:35:55 +08:00
parent a540ee944a
commit 9e951fbc15
17 changed files with 260 additions and 150 deletions

View File

@@ -16,14 +16,14 @@ import { useToast } from '@/hooks/useToast';
import { customAlphabet } from 'nanoid';
const nanoid = customAlphabet('abcdefghijklmnopqrstuvwxyz1234567890', 12);
export type FormData = { dataId?: string; text: string; q: string };
export type FormData = { dataId?: string; a: string; q: string };
const InputDataModal = ({
onClose,
onSuccess,
modelId,
defaultValues = {
text: '',
a: '',
q: ''
}
}: {
@@ -51,11 +51,8 @@ const InputDataModal = ({
modelId: modelId,
data: [
{
text: e.text,
q: {
id: nanoid(),
text: e.q
}
a: e.a,
q: e.q
}
]
});
@@ -65,7 +62,7 @@ const InputDataModal = ({
status: res === 0 ? 'success' : 'warning'
});
reset({
text: '',
a: '',
q: ''
});
onSuccess();
@@ -81,10 +78,10 @@ const InputDataModal = ({
async (e: FormData) => {
if (!e.dataId) return;
if (e.text !== defaultValues.text || e.q !== defaultValues.q) {
if (e.a !== defaultValues.a || e.q !== defaultValues.q) {
await putModelDataById({
dataId: e.dataId,
text: e.text,
a: e.a,
q: e.q === defaultValues.q ? '' : e.q
});
onSuccess();
@@ -144,7 +141,7 @@ const InputDataModal = ({
maxLength={1000}
resize={'none'}
h={'calc(100% - 30px)'}
{...register(`text`, {
{...register(`a`, {
required: '知识点'
})}
/>

View File

@@ -19,7 +19,7 @@ import {
Input
} from '@chakra-ui/react';
import type { ModelSchema } from '@/types/mongoSchema';
import type { RedisModelDataItemType } from '@/types/redis';
import type { ModelDataItemType } from '@/types/model';
import { ModelDataStatusMap } from '@/constants/model';
import { usePagination } from '@/hooks/usePagination';
import {
@@ -53,9 +53,9 @@ const ModelDataCard = ({ model }: { model: ModelSchema }) => {
total,
getData,
pageNum
} = usePagination<RedisModelDataItemType>({
} = usePagination<ModelDataItemType>({
api: getModelDataList,
pageSize: 8,
pageSize: 10,
params: {
modelId: model._id,
searchText
@@ -149,7 +149,7 @@ const ModelDataCard = ({ model }: { model: ModelSchema }) => {
<MenuItem
onClick={() =>
setEditInputData({
text: '',
a: '',
q: ''
})
}
@@ -216,7 +216,7 @@ const ModelDataCard = ({ model }: { model: ModelSchema }) => {
maxH={'250px'}
overflowY={'auto'}
>
{item.text}
{item.a}
</Box>
</Td>
<Td>{ModelDataStatusMap[item.status]}</Td>
@@ -231,7 +231,7 @@ const ModelDataCard = ({ model }: { model: ModelSchema }) => {
setEditInputData({
dataId: item.id,
q: item.q,
text: item.text
a: item.a
})
}
/>