优化类型问题

This commit is contained in:
宇阳
2024-10-12 14:25:13 +08:00
parent ab92ceb396
commit c54324a3f9
9 changed files with 35 additions and 56 deletions

View File

@@ -9,8 +9,7 @@ import { getTagListAPI } from '@/api/Tag'
import { delArticleDataAPI, getArticleListAPI } from '@/api/Article';
import type { Tag as ArticleTag } from '@/types/app/tag';
import type { Cate } from '@/types/app/cate';
import type { Article } from '@/types/app/article';
import { FilterArticle, FilterForm } from './type'
import type { Article, FilterArticle, FilterForm } from '@/types/app/article';
import dayjs from 'dayjs';
@@ -127,10 +126,10 @@ const ArticlePage = () => {
const onSubmit = async (values: FilterForm) => {
const query: FilterArticle = {
key: values.title,
startDate: values.createTime ? values.createTime[0].valueOf() + '' : undefined,
endDate: values.createTime ? values.createTime[1].valueOf() + '' : undefined,
cateIds: values.cateIds,
tagId: values.tagId,
startDate: values?.createTime[0].valueOf() + '',
endDate: values?.createTime[1].valueOf() + '',
}
const { data } = await getArticleListAPI({ query });
@@ -142,7 +141,7 @@ const ArticlePage = () => {
const getCateList = async () => {
const { data } = await getCateListAPI()
setCateList(data as Cate[])
setCateList(data.filter(item => item.type === "cate") as Cate[])
}
const getTagList = async () => {

View File

@@ -1,11 +0,0 @@
export interface FilterForm {
title: string,
cateIds?: number[],
tagId?: number,
createTime: Date[]
}
export interface FilterArticle extends FilterData {
cateIds?: number[],
tagId?: number,
}

View File

@@ -1,11 +1,11 @@
import { useState, useEffect } from 'react';
import { Card, message, Table, Popconfirm, Button, Tag, Modal, Form, Input, DatePicker } from 'antd';
import { Card, message, Table, Popconfirm, Button, Modal, Form, Input, DatePicker } from 'antd';
import { getCommentListAPI } from '@/api/Comment';
import { delCommentDataAPI } from '@/api/Comment';
import { ColumnsType } from 'antd/es/table';
import { titleSty } from '@/styles/sty';
import Title from '@/components/Title';
import { Comment } from '@/types/app/comment'
import { Comment, FilterForm } from '@/types/app/comment'
import dayjs from 'dayjs';
const CommentPage = () => {
@@ -18,8 +18,6 @@ const CommentPage = () => {
const getCommentList = async () => {
const { data } = await getCommentListAPI();
// 根据时间排序:最新时间在前
// const sortedData = (data as Comment[]).sort((a, b) => +b.createTime - +a.createTime);
setList(data)
setLoading(false)
}
@@ -43,15 +41,6 @@ const CommentPage = () => {
key: 'id',
align: "center"
},
// {
// title: '状态',
// dataIndex: 'auditStatus',
// key: 'auditStatus',
// fixed: 'left',
// render: (status: number) => status ?
// <Tag bordered={false} color="processing">通过</Tag>
// : <Tag bordered={false} color="error">待审核</Tag>
// },
{
title: '名称',
dataIndex: 'name',
@@ -116,14 +105,13 @@ const CommentPage = () => {
const onSubmit = async (values: FilterForm) => {
const query: FilterData = {
key: values.title ? values.title : undefined,
content: values.content ? values.content : undefined,
startDate: values.createTime ? values.createTime[0].valueOf() + '' : undefined,
endDate: values.createTime ? values.createTime[1].valueOf() + '' : undefined,
key: values?.title,
content: values?.content,
startDate: values?.createTime[0].valueOf() + '',
endDate: values?.createTime[1].valueOf() + '',
}
const { data } = await getCommentListAPI({ query });
console.log(data);
setList(data)
}

View File

@@ -79,9 +79,6 @@ const PublishForm = ({ data, closeModel }: { data: Article, closeModel: () => vo
};
const onSubmit: FormProps<FieldType>['onFinish'] = async (values) => {
console.log(values, 777);
values.createTime = values.createTime.valueOf()
values.cateIds = [...new Set(values.cateIds?.flat())]
@@ -135,7 +132,6 @@ const PublishForm = ({ data, closeModel }: { data: Article, closeModel: () => vo
multiple
fieldNames={{ label: "name", value: "id" }}
placeholder="请选择文章分类"
onChange={(value) => { console.log(value) }}
className="w-full"
/>
</Form.Item>

View File

@@ -3,7 +3,7 @@ import { Table, Button, Tag, notification, Card, Popconfirm, Form, Input, DatePi
import { titleSty } from '@/styles/sty';
import Title from '@/components/Title';
import { delFootprintDataAPI, getFootprintListAPI, addFootprintDataAPI, editFootprintDataAPI, getFootprintDataAPI } from '@/api/Footprint';
import type { Footprint, FilterFootprint, FilterForm } from '@/types/app/footprint';
import type { Footprint, FilterForm } from '@/types/app/footprint';
import dayjs from 'dayjs';
const FootprintPage = () => {
@@ -129,7 +129,7 @@ const FootprintPage = () => {
const onSubmit = async () => {
form.validateFields().then(async (values: Footprint) => {
values.createTime = values.createTime.valueOf()
values.images = values.images?(values.images as string).split("\n"):[]
values.images = values.images ? (values.images as string).split("\n") : []
if (isMethod === "edit") {
await editFootprintDataAPI({ ...footprint, ...values });
@@ -147,10 +147,10 @@ const FootprintPage = () => {
const closeModel = () => reset();
const onFilterSubmit = async (values: FilterForm) => {
const query: FilterFootprint = {
key: values.address ? values.address : null,
startDate: values.createTime ? values.createTime[0].valueOf() + '' : null,
endDate: values.createTime ? values.createTime[1].valueOf() + '' : null,
const query: FilterData = {
key: values.address,
startDate: values?.createTime[0].valueOf() + '',
endDate: values?.createTime[1].valueOf() + '',
}
const { data } = await getFootprintListAPI({ query });

View File

@@ -1,5 +0,0 @@
export interface FilterForm {
content?: string;
cateId?: number;
createTime?: [moment.Moment, moment.Moment];
}

View File

@@ -15,3 +15,15 @@ export interface Article {
count?: number,
createTime?: string,
}
export interface FilterForm {
title?: string,
cateIds?: number[],
tagId?: number,
createTime: Date[]
}
export interface FilterArticle extends FilterData {
cateIds?: number[],
tagId?: number,
}

View File

@@ -18,3 +18,9 @@ export interface Info {
list: Comment[],
paginate: Page
}
export interface FilterForm {
title?: string,
content?: string,
createTime: Date[]
}

View File

@@ -8,13 +8,7 @@ export interface Footprint {
createTime?: string | Dayjs;
}
export interface FilterFootprint {
key?: string | null;
startDate?: string | null;
endDate?: string | null;
}
export interface FilterForm {
address?: string;
createTime?: [moment.Moment, moment.Moment];
createTime: Date[]
}