From 2057e1ea0f77f9fd28f47e7a373e53efd2441c25 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AE=87=E9=98=B3?= Date: Sun, 12 Jan 2025 20:31:08 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A4=A7=E6=94=B9=E5=8A=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pages/Article/index.tsx | 14 ++++--- src/pages/Cate/index.tsx | 9 +++-- src/pages/Comment/index.tsx | 6 ++- src/pages/Create/index.tsx | 15 ++++---- src/pages/CreateRecord/index.tsx | 14 +++---- .../components/NewOldVisitors/chart.d.ts | 24 ------------ .../components/VisitorsStatisChat/index.tsx | 38 +++++++++++++++---- .../components/VisitorsStatisChat/type.d.ts | 13 ------- .../Dashboard/components/Stats/index.tsx | 7 ++-- .../Dashboard/components/Stats/type.d.ts | 10 ----- src/pages/Decycle/index.tsx | 21 +++++----- src/pages/Draft/index.tsx | 10 +++-- src/pages/File/index.tsx | 32 ++++++++-------- src/pages/Footprint/index.tsx | 33 ++++++++-------- src/pages/Iterative/index.tsx | 6 ++- src/pages/Login/index.tsx | 15 ++++---- src/pages/Oss/index.tsx | 36 +++++++++--------- 17 files changed, 147 insertions(+), 156 deletions(-) delete mode 100644 src/pages/Dashboard/components/Stats/components/NewOldVisitors/chart.d.ts delete mode 100644 src/pages/Dashboard/components/Stats/components/VisitorsStatisChat/type.d.ts delete mode 100644 src/pages/Dashboard/components/Stats/type.d.ts diff --git a/src/pages/Article/index.tsx b/src/pages/Article/index.tsx index 14630e7..28b7f60 100644 --- a/src/pages/Article/index.tsx +++ b/src/pages/Article/index.tsx @@ -27,11 +27,12 @@ export default () => { const { RangePicker } = DatePicker; const getArticleList = async () => { - setLoading(true); - try { + setLoading(true); + const { data } = await getArticleListAPI(); setArticleList(data); + setLoading(false); } catch (error) { setLoading(false); @@ -39,9 +40,9 @@ export default () => { }; const delArticleData = async (id: number) => { - setLoading(true); - try { + setLoading(true); + // 普通删除:可从回收站恢复 await delArticleDataAPI(id, true); await getArticleList(); @@ -151,9 +152,9 @@ export default () => { ]; const onFilterSubmit = async (values: FilterForm) => { - setLoading(true) - try { + setLoading(true) + const query: FilterArticle = { key: values.title, cateIds: values.cateIds, @@ -166,6 +167,7 @@ export default () => { const { data } = await getArticleListAPI({ query }); setArticleList(data); + setLoading(false) } catch (error) { setLoading(false) diff --git a/src/pages/Cate/index.tsx b/src/pages/Cate/index.tsx index 6c3d5af..176a3d0 100644 --- a/src/pages/Cate/index.tsx +++ b/src/pages/Cate/index.tsx @@ -25,6 +25,7 @@ const CatePage = () => { const { data } = await getCateListAPI(); data.sort((a, b) => a.order - b.order) setList(data); + setLoading(false) } catch (error) { setLoading(false) @@ -46,14 +47,16 @@ const CatePage = () => { const editCateData = async (id: number) => { try { + setEditLoading(true) + setIsMethod("edit"); setIsModelOpen(true); - setEditLoading(true) const { data } = await getCateDataAPI(id); setIsCateShow(data.type === "cate" ? false : true); setCate(data); form.setFieldsValue(data); + setEditLoading(false) } catch (error) { setEditLoading(false) @@ -61,9 +64,9 @@ const CatePage = () => { }; const delCateData = async (id: number) => { - setLoading(true) - try { + setLoading(true) + await delCateDataAPI(id); await getCateList(); message.success('🎉 删除分类成功'); diff --git a/src/pages/Comment/index.tsx b/src/pages/Comment/index.tsx index 719cc99..6a8bab0 100644 --- a/src/pages/Comment/index.tsx +++ b/src/pages/Comment/index.tsx @@ -150,9 +150,9 @@ export default () => { const [replyInfo, setReplyInfo] = useState("") const [isReplyModalOpen, setIsReplyModalOpen] = useState(false); const handleReply = async () => { - setBtnLoading(true) - try { + setBtnLoading(true) + await addCommentDataAPI({ avatar: user.avatar, url: web.url, @@ -169,6 +169,8 @@ export default () => { message.success('🎉 回复评论成功'); setIsReplyModalOpen(false) setReplyInfo("") + + setBtnLoading(true) } catch (error) { setBtnLoading(false) } diff --git a/src/pages/Create/index.tsx b/src/pages/Create/index.tsx index d642a71..9736781 100644 --- a/src/pages/Create/index.tsx +++ b/src/pages/Create/index.tsx @@ -32,19 +32,20 @@ export default () => { // 获取文章数据 const getArticleData = async () => { try { + setLoading(true) + const { data } = await getArticleDataAPI(id) setData(data) setContent(data.content) + + setLoading(false) } catch (error) { setLoading(false) } - - setLoading(false) } // 回显数据 useEffect(() => { - setLoading(true) setPublishOpen(false) // 有Id就回显指定的数据 @@ -93,9 +94,9 @@ export default () => { // 解析接口数据 const parsingData = async (command: string) => { - setLoading(true) - try { + setLoading(true) + const res = await fetch(`/ai/v1/chat/completions`, { method: "POST", headers: { @@ -142,12 +143,12 @@ export default () => { // 保留最后一行未处理的数据 receivedText = lines[lines.length - 1]; + + setLoading(false) } } catch (error) { setLoading(false) } - - setLoading(false) } // AI功能 diff --git a/src/pages/CreateRecord/index.tsx b/src/pages/CreateRecord/index.tsx index 151327c..c235026 100644 --- a/src/pages/CreateRecord/index.tsx +++ b/src/pages/CreateRecord/index.tsx @@ -32,9 +32,9 @@ export default () => { } const onSubmit = async () => { - setLoading(true) - try { + setLoading(true) + const data = { content, images: JSON.stringify(imageList), @@ -52,29 +52,29 @@ export default () => { await addRecordDataAPI(data) } + setLoading(false) navigate("/record") } catch (error) { setLoading(false) } - - setLoading(false) } const getRecordData = async () => { try { + setLoading(true) + const { data } = await getRecordDataAPI(id) setContent(data.content) setImageList(JSON.parse(data.images as string)) + + setLoading(false) } catch (error) { setLoading(false) } - - setLoading(false) } // 回显数据 useEffect(() => { - setLoading(true) // 有Id就回显指定的数据 if (id) getRecordData() }, [id]) diff --git a/src/pages/Dashboard/components/Stats/components/NewOldVisitors/chart.d.ts b/src/pages/Dashboard/components/Stats/components/NewOldVisitors/chart.d.ts deleted file mode 100644 index 07e3ffb..0000000 --- a/src/pages/Dashboard/components/Stats/components/NewOldVisitors/chart.d.ts +++ /dev/null @@ -1,24 +0,0 @@ -export interface Result { - timeSpan: string[]; - fields: string[]; - items: [ - string[][], - number[][], - any[], - any[] - ]; -} - -export interface MonthlySums { - [key: string]: { - pv: number; - ip: number; - }; -} - -export interface ChartOneState { - series: { - name: string; - data: number[]; - }[]; -} \ No newline at end of file diff --git a/src/pages/Dashboard/components/Stats/components/VisitorsStatisChat/index.tsx b/src/pages/Dashboard/components/Stats/components/VisitorsStatisChat/index.tsx index 4b3995d..e07034b 100644 --- a/src/pages/Dashboard/components/Stats/components/VisitorsStatisChat/index.tsx +++ b/src/pages/Dashboard/components/Stats/components/VisitorsStatisChat/index.tsx @@ -2,9 +2,32 @@ import { useEffect, useState, useCallback, useMemo } from 'react'; import { Spin } from 'antd'; import { ApexOptions } from 'apexcharts'; import ReactApexChart from 'react-apexcharts'; -import { MonthlySums, ChartOneState } from './type'; import dayjs from 'dayjs'; -import { Result } from '../../type'; + +interface Result { + timeSpan: string[]; + fields: string[]; + items: [ + string[][], + number[][], + any[], + any[] + ]; +} + +interface MonthlySums { + [key: string]: { + pv: number; + ip: number; + }; +} + +interface ChartOneState { + series: { + name: string; + data: number[]; + }[]; +} export default () => { const [loading, setLoading] = useState(false); @@ -124,9 +147,9 @@ export default () => { // 获取统计数据 const getDataList = useCallback(async () => { - setLoading(true) - try { + setLoading(true) + const siteId = import.meta.env.VITE_BAIDU_TONGJI_SITE_ID; const token = import.meta.env.VITE_BAIDU_TONGJI_ACCESS_TOKEN; @@ -134,16 +157,16 @@ export default () => { const data = await response.json(); const { result } = data; setResult(result); + + setLoading(false); } catch (error) { setLoading(false) } - - setLoading(false); }, [startDate, endDate]); useEffect(() => { getDataList(); - }, [getDataList]); + }, []); // 切换不同范围的数据 const scopeData = useMemo(() => { @@ -239,6 +262,7 @@ export default () => { // 当数据发生变化时,更新图表选项和状态 useEffect(() => { setLoading(true) + setOptions((data) => ({ ...data, xaxis: { ...options.xaxis, categories: scopeData.categories || [] } diff --git a/src/pages/Dashboard/components/Stats/components/VisitorsStatisChat/type.d.ts b/src/pages/Dashboard/components/Stats/components/VisitorsStatisChat/type.d.ts deleted file mode 100644 index a269507..0000000 --- a/src/pages/Dashboard/components/Stats/components/VisitorsStatisChat/type.d.ts +++ /dev/null @@ -1,13 +0,0 @@ -export interface MonthlySums { - [key: string]: { - pv: number; - ip: number; - }; -} - -export interface ChartOneState { - series: { - name: string; - data: number[]; - }[]; -} \ No newline at end of file diff --git a/src/pages/Dashboard/components/Stats/index.tsx b/src/pages/Dashboard/components/Stats/index.tsx index cb7770a..4c28954 100644 --- a/src/pages/Dashboard/components/Stats/index.tsx +++ b/src/pages/Dashboard/components/Stats/index.tsx @@ -31,9 +31,9 @@ export default () => { // 获取统计数据 const getDataList = async () => { - setLoading(true) - try { + setLoading(true) + const siteId = import.meta.env.VITE_BAIDU_TONGJI_SITE_ID; const token = import.meta.env.VITE_BAIDU_TONGJI_ACCESS_TOKEN; @@ -78,11 +78,10 @@ export default () => { setStats({ pv, ip, bounce: (bounce / count) || 0, avgTime: formatTime(avgTime / count) || "00:00:00" }) + setLoading(false) } catch (error) { setLoading(false) } - - setLoading(false) }; useEffect(() => { diff --git a/src/pages/Dashboard/components/Stats/type.d.ts b/src/pages/Dashboard/components/Stats/type.d.ts deleted file mode 100644 index e39f696..0000000 --- a/src/pages/Dashboard/components/Stats/type.d.ts +++ /dev/null @@ -1,10 +0,0 @@ -export interface Result { - timeSpan: string[]; - fields: string[]; - items: [ - string[][], - number[][], - any[], - any[] - ]; -} \ No newline at end of file diff --git a/src/pages/Decycle/index.tsx b/src/pages/Decycle/index.tsx index 876de34..8d4e7cb 100644 --- a/src/pages/Decycle/index.tsx +++ b/src/pages/Decycle/index.tsx @@ -25,24 +25,25 @@ export default () => { const getArticleList = async () => { try { + setLoading(true); + const { data } = await getArticleListAPI({ query: { isDel: 1 } }); - setArticleList(data as Article[]); + setArticleList(data); + + setLoading(false); } catch (error) { setLoading(false); } - - setLoading(false); }; useEffect(() => { - setLoading(true); getArticleList() }, []); const delArticleData = async (id: number) => { - setLoading(true); - try { + setLoading(true); + // 严格删除:彻底从数据库删除,无法恢复 await delArticleDataAPI(id); await getArticleList(); @@ -55,12 +56,14 @@ export default () => { }; const reductionArticleData = async (id: number) => { - setLoading(true); - try { + setLoading(true); + await reductionArticleDataAPI(id) - navigate("/article") notification.success({ message: '🎉 还原文章成功' }) + navigate("/article") + + setLoading(false) } catch (error) { setLoading(false); } diff --git a/src/pages/Draft/index.tsx b/src/pages/Draft/index.tsx index a592b3d..28d78f8 100644 --- a/src/pages/Draft/index.tsx +++ b/src/pages/Draft/index.tsx @@ -23,23 +23,25 @@ export default () => { const getArticleList = async () => { try { + setLoading(true) + const { data } = await getArticleListAPI({ query: { isDraft: 1 } }); setArticleList(data as Article[]); + + setLoading(false) } catch (error) { setLoading(false); } - setLoading(false) }; useEffect(() => { - setLoading(true) getArticleList() }, []); const delArticleData = async (id: number) => { - setLoading(true); - try { + setLoading(true); + await delArticleDataAPI(id); await getArticleList(); form.resetFields() diff --git a/src/pages/File/index.tsx b/src/pages/File/index.tsx index 8edbe6d..fdbdcc5 100644 --- a/src/pages/File/index.tsx +++ b/src/pages/File/index.tsx @@ -36,56 +36,56 @@ export default () => { // 获取目录列表 const getDirList = async () => { - setLoading(true) - try { + setLoading(true) + const { data } = await getDirListAPI() setDirList(data) + + setLoading(false) } catch (error) { setLoading(false) } - - setLoading(false) } // 获取指定目录的文件列表 const getFileList = async (dir: string) => { - setLoading(true) - try { + setLoading(true) + const { data } = await getFileListAPI(dir) if (!fileList.length && !data.length) message.error("该目录中没有文件") setFileList(data) + + setLoading(false) } catch (error) { setLoading(false) } - - setLoading(false) } // 删除图片 const onDeleteImage = async (data: File) => { - setBtnLoading(true) - try { + setBtnLoading(true) + await delFileDataAPI(data.url) await getFileList(dirName) message.success("🎉 删除图片成功") setFile({} as File) setOpenFileInfoDrawer(false) setOpenFilePreviewDrawer(false) + + setBtnLoading(false) } catch (error) { setBtnLoading(false) } - - setBtnLoading(false) } // 下载图片 const onDownloadImage = (data: File) => { - setDownloadLoading(true) - try { + setDownloadLoading(true) + fetch(data.url) .then((response) => response.blob()) .then((blob) => { @@ -98,11 +98,11 @@ export default () => { URL.revokeObjectURL(url); link.remove(); }); + + setDownloadLoading(false) } catch (error) { setDownloadLoading(false) } - - setDownloadLoading(false) }; // 打开目录 diff --git a/src/pages/Footprint/index.tsx b/src/pages/Footprint/index.tsx index 155562b..3917bbb 100644 --- a/src/pages/Footprint/index.tsx +++ b/src/pages/Footprint/index.tsx @@ -129,9 +129,9 @@ export default () => { }; const editFootprintData = async (id: number) => { - setEditLoading(true); - try { + setEditLoading(true); + setIsMethod("edit"); setIsModelOpen(true); @@ -142,17 +142,17 @@ export default () => { setFootprint(data); form.setFieldsValue(data); + + setEditLoading(false); } catch (error) { setEditLoading(false); } - - setEditLoading(false); }; - + const onSubmit = async () => { - setBtnLoading(true) - try { + setBtnLoading(true) + form.validateFields().then(async (values: Footprint) => { values.createTime = values.createTime.valueOf() values.images = values.images ? (values.images as string).split("\n") : [] @@ -166,6 +166,7 @@ export default () => { } await getFootprintList(); + setBtnLoading(false) reset() }); } catch (error) { @@ -176,9 +177,9 @@ export default () => { const closeModel = () => reset(); const onFilterSubmit = async (values: FilterForm) => { - setLoading(true) - try { + setLoading(true) + const query: FilterData = { key: values.address, startDate: values.createTime && values.createTime[0].valueOf() + '', @@ -187,18 +188,18 @@ export default () => { const { data } = await getFootprintListAPI({ query }); setFootprintList(data); + + setLoading(false) } catch (error) { setLoading(false) } - - setLoading(false) } // 通过详细地址获取纬度 const getGeocode = async () => { - setEditLoading(true) - try { + setEditLoading(true) + const address = form.getFieldValue("address") const { data } = await axios.get('https://restapi.amap.com/v3/geocode/geo', { @@ -215,17 +216,15 @@ export default () => { // 立即触发校验 form.validateFields(['position']); - setEditLoading(false) - return data.geocodes[0].location; } else { message.warning('未找到该地址的经纬度'); } + + setEditLoading(false) } catch (error) { setEditLoading(false) } - - setEditLoading(false) }; return ( diff --git a/src/pages/Iterative/index.tsx b/src/pages/Iterative/index.tsx index 5651c16..d5e8a8a 100644 --- a/src/pages/Iterative/index.tsx +++ b/src/pages/Iterative/index.tsx @@ -24,6 +24,8 @@ export default () => { // 从github获取最近10次迭代记录 const getCommitData = async (project: string) => { try { + setLoading(true) + const res = await fetch(`https://api.github.com/repos/LiuYuYang01/${project}/commits?per_page=10`) const data = await res.json() const result = data?.map((item: Commit) => ( @@ -47,11 +49,11 @@ export default () => { setServer_IterativeRecording(result) break; } + + setLoading(false) } catch (error) { setLoading(false) } - - setLoading(false) } useEffect(() => { diff --git a/src/pages/Login/index.tsx b/src/pages/Login/index.tsx index 16bcd00..8e12d4f 100644 --- a/src/pages/Login/index.tsx +++ b/src/pages/Login/index.tsx @@ -7,19 +7,21 @@ import { loginDataAPI } from '@/api/User'; import { useUserStore } from '@/stores'; export default () => { + const navigate = useNavigate(); + const location = useLocation(); + const store = useUserStore(); + const [loading, setLoading] = useState(false) const [form] = useForm(); + const [isPassVisible, setIsPassVisible] = useState(false); - const store = useUserStore(); - const navigate = useNavigate(); - const location = useLocation(); const returnUrl = new URLSearchParams(location.search).get('returnUrl') || '/'; const onSubmit = async () => { - setLoading(true) - try { + setLoading(true) + const values = await form.validateFields(); const { data } = await loginDataAPI(values); @@ -33,12 +35,11 @@ export default () => { description: `Hello ${data.user.name} 欢迎回来`, }); + setLoading(false) navigate(returnUrl); } catch (error) { setLoading(false) } - - setLoading(false) }; return ( diff --git a/src/pages/Oss/index.tsx b/src/pages/Oss/index.tsx index cf5d881..61b1441 100644 --- a/src/pages/Oss/index.tsx +++ b/src/pages/Oss/index.tsx @@ -86,25 +86,26 @@ export default () => { const getOssList = async () => { try { + setLoading(true); + const { data } = await getOssListAPI(); setOssList(data); + + setLoading(false); } catch (error) { setLoading(false) } - - setLoading(false); }; useEffect(() => { - setLoading(true); getOssList(); getOssPlatformList() }, []); const enableOssData = async (id: number) => { - setLoading(true) - try { + setLoading(true) + await enableOssDataAPI(id); await getOssList(); message.success('启用成功'); @@ -114,9 +115,9 @@ export default () => { }; const disableOssData = async (id: number) => { - setLoading(true) - try { + setLoading(true) + await disableOssDataAPI(id); await getOssList(); message.success('禁用成功'); @@ -126,25 +127,25 @@ export default () => { }; const editOssData = async (record: Oss) => { - setEditLoading(true) - try { + setEditLoading(true) + setIsModalOpen(true); const { data } = await getOssDataAPI(record.id) setOss(data); form.setFieldsValue(data); + + setEditLoading(false) } catch (error) { setEditLoading(false) } - - setEditLoading(false) }; const delOssData = async (id: number) => { - setLoading(true); - try { + setLoading(true); + await delOssDataAPI(id); await getOssList(); message.success('🎉 删除存储配置成功'); @@ -166,9 +167,9 @@ export default () => { }; const onSubmit = async () => { - setBtnLoading(true); - try { + setBtnLoading(true); + const values = await form.validateFields(); if (oss.id) { @@ -179,15 +180,14 @@ export default () => { message.success('🎉 新增存储配置成功'); } + await getOssList(); setIsModalOpen(false); - getOssList(); form.resetFields(); + setBtnLoading(false); } catch (error) { setBtnLoading(false); } - - setBtnLoading(false) }; return (