From aea85076fb87428e662ac7017e42c9454778c01c Mon Sep 17 00:00:00 2001 From: Sinclair Date: Sat, 17 Feb 2024 20:34:45 +0800 Subject: [PATCH] add cache --- src/pages/setting/sensitive.tsx | 14 +++- src/pages/tool/cache.tsx | 115 +++++++++++++++++++++++++++++--- src/services/setting.ts | 8 +++ 3 files changed, 123 insertions(+), 14 deletions(-) diff --git a/src/pages/setting/sensitive.tsx b/src/pages/setting/sensitive.tsx index b047ea7..6425bcf 100644 --- a/src/pages/setting/sensitive.tsx +++ b/src/pages/setting/sensitive.tsx @@ -1,5 +1,5 @@ import React, { useEffect, useState } from 'react'; -import ProForm, { ProFormTextArea } from '@ant-design/pro-form'; +import ProForm, { ProFormInstance, ProFormTextArea } from '@ant-design/pro-form'; import { PageHeaderWrapper } from '@ant-design/pro-layout'; import { Button, Card, message, Space, Modal } from 'antd'; import { @@ -9,6 +9,7 @@ import { } from '@/services/setting'; const SettingSensitiveFrom: React.FC = (props) => { + const formRef = React.createRef(); const [setting, setSetting] = useState([]); const [fetched, setFetched] = useState(false); useEffect(() => { @@ -42,8 +43,11 @@ const SettingSensitiveFrom: React.FC = (props) => { title: '确定要同步敏感词列表吗?该操作会从安企CMS官网同步最新的敏感词到本地,并替换', onOk: () => { syncSettingSensitiveWords({}) - .then((res) => { + .then(async (res) => { message.success(res.msg); + const res2 = await getSettingSensitiveWords(); + let setting = res2.data || []; + formRef.current?.setFieldsValue({ words: setting.join('\n') }); }) .catch((err) => { message.success(err.msg || '同步失败'); @@ -63,7 +67,11 @@ const SettingSensitiveFrom: React.FC = (props) => { } > {fetched && ( - + = (props) => { }) .catch((err) => { console.log(err); - }).finally(() => { + }) + .finally(() => { hide(); }); }; + const onSubmitUpdate = async (values: any) => { + const hide = message.loading('正在提交中', 0); + values.update = true; + saveSettingCache(values) + .then((res) => { + message.success(res.msg); + getSetting(); + }) + .catch((err) => { + console.log(err); + }) + .finally(() => { + hide(); + }); + }; + + const onSubmitMigrate = () => { + Modal.confirm({ + title: '确认更新数据库表结构吗?', + okText: '确认更新', + okType: 'primary', + cancelText: '取消', + onOk: () => { + const hide = message.loading('正在提交中', 0); + saveSettingMigrateDB({}) + .then((res) => { + message.success(res.msg); + }) + .catch((err) => { + console.log(err); + }) + .finally(() => { + hide(); + }); + }, + }); + }; + return ( - + {setting && ( - - 0 ? moment(setting.last_update * 1000).format('YYYY-MM-DD HH:mm') : '未曾更新' - }} label="上次更新时间" width="lg" readonly /> + + 0 + ? moment(setting.last_update * 1000).format('YYYY-MM-DD HH:mm') + : '未曾更新', + }} + label="上次更新时间" + width="lg" + readonly + /> + + + )} +
+ + {setting && ( + + + + )} + +
+
+ + + + + + + + +
); }; diff --git a/src/services/setting.ts b/src/services/setting.ts index 77f6618..e06545e 100644 --- a/src/services/setting.ts +++ b/src/services/setting.ts @@ -144,6 +144,14 @@ export async function saveSettingCache(body: any, options?: { [key: string]: any }); } +export async function saveSettingMigrateDB(body: any, options?: { [key: string]: any }) { + return post({ + url: '/setting/migratedb', + body, + options, + }); +} + export async function convertImagetoWebp(body: any, options?: { [key: string]: any }) { return post({ url: '/setting/convert/webp',