Skip to content

Commit

Permalink
add cache
Browse files Browse the repository at this point in the history
  • Loading branch information
fesiong committed Feb 17, 2024
1 parent 392aabd commit aea8507
Show file tree
Hide file tree
Showing 3 changed files with 123 additions and 14 deletions.
14 changes: 11 additions & 3 deletions src/pages/setting/sensitive.tsx
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -9,6 +9,7 @@ import {
} from '@/services/setting';

const SettingSensitiveFrom: React.FC<any> = (props) => {
const formRef = React.createRef<ProFormInstance>();
const [setting, setSetting] = useState<any>([]);
const [fetched, setFetched] = useState<boolean>(false);
useEffect(() => {
Expand Down Expand Up @@ -42,8 +43,11 @@ const SettingSensitiveFrom: React.FC<any> = (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 || '同步失败');
Expand All @@ -63,7 +67,11 @@ const SettingSensitiveFrom: React.FC<any> = (props) => {
}
>
{fetched && (
<ProForm initialValues={{ words: setting.join('\n') }} onFinish={onSubmit}>
<ProForm
formRef={formRef}
initialValues={{ words: setting.join('\n') }}
onFinish={onSubmit}
>
<ProFormTextArea
fieldProps={{ rows: 20 }}
name="words"
Expand Down
115 changes: 104 additions & 11 deletions src/pages/tool/cache.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import React, { useEffect, useState } from 'react';
import ProForm, {
ProFormText,
} from '@ant-design/pro-form';
import ProForm, { ProFormRadio, ProFormText } from '@ant-design/pro-form';
import { PageHeaderWrapper } from '@ant-design/pro-layout';
import { Card, message } from 'antd';
import { getSettingCache, saveSettingCache } from '@/services/setting';
import { Alert, Button, Card, Modal, message } from 'antd';
import { getSettingCache, saveSettingCache, saveSettingMigrateDB } from '@/services/setting';
import moment from 'moment';
import { removeStore } from '@/utils/store';

Expand All @@ -30,22 +28,117 @@ const ToolCacheForm: React.FC<any> = (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 (
<PageHeaderWrapper>
<Card>
<Card title="更新临时缓存">
{setting && (
<ProForm onFinish={onSubmit} title="更新缓存">
<ProFormText name='last_update' fieldProps={{
value: setting.last_update > 0 ? moment(setting.last_update * 1000).format('YYYY-MM-DD HH:mm') : '未曾更新'
}} label="上次更新时间" width="lg" readonly />
<ProForm submitter={false}>
<ProFormText
name="last_update"
fieldProps={{
value:
setting.last_update > 0
? moment(setting.last_update * 1000).format('YYYY-MM-DD HH:mm')
: '未曾更新',
}}
label="上次更新时间"
width="lg"
readonly
/>
<ProFormText>
<Button onClick={() => onSubmit({})} type="primary">
更新缓存
</Button>
</ProFormText>
</ProForm>
)}
</Card>
<div className="mt-normal">
<Card title="临时缓存方式设置">
{setting && (
<ProForm onFinish={onSubmitUpdate} initialValues={setting}>
<ProFormRadio.Group
name="cache_type"
label="临时缓存方式"
options={[
{
value: '',
label: '自动处理',
},
{
value: 'file',
label: '文件缓存',
},
{
value: 'memory',
label: '内存缓存',
},
]}
extra="默认自动处理,服务器内存小于2G的采用文件缓存,大于等于2G的采用内存缓存"
/>
</ProForm>
)}
</Card>
</div>
<div className="mt-normal">
<Card title="更新数据库表">
<ProForm submitter={false}>
<Alert
className="mb-normal"
message="如果你发现缺少某个表或表字段不正确的时候,则可能需要点击下方的更新数据库表结构按钮来更正"
/>
<ProFormText>
<Button onClick={() => onSubmitMigrate()} type="primary">
更新数据库表结构
</Button>
</ProFormText>
</ProForm>
</Card>
</div>
</PageHeaderWrapper>
);
};
Expand Down
8 changes: 8 additions & 0 deletions src/services/setting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down

0 comments on commit aea8507

Please sign in to comment.