import React, { useEffect, useState, useRef } from 'react'; import { clearCacheAll, clearCacheKey, clearCacheName, getCacheValue, listCacheKey, listCacheName } from '@/services/monitor/cachelist'; import { Button, Card, Col, Form, FormInstance, Input, message, Row, Table } from 'antd'; import styles from './index.less'; import { FormattedMessage } from '@umijs/max'; import { ReloadOutlined } from '@ant-design/icons'; import { ProForm } from '@ant-design/pro-components'; const { TextArea } = Input; /* * * * @author whiteshader@163.com * @datetime 2022/06/27 * * */ const CacheList: React.FC = () => { const [cacheNames, setCacheNames] = useState([]); const [currentCacheName, setCurrentCacheName] = useState([]); const [cacheKeys, setCacheKeys] = useState([]); const [form] = Form.useForm(); const getCacheNames = () => { listCacheName().then((res) => { if (res.code === 200) { setCacheNames(res.data); } }); } useEffect(() => { getCacheNames(); }, []); const getCacheKeys = (cacheName: string) => { listCacheKey(cacheName).then(res => { if (res.code === 200) { let index = 0; const keysData = res.data.map((item: any) => { return { index: index++, cacheKey: item } }) setCacheKeys(keysData); } }); }; const onClearAll = async () => { clearCacheAll().then(res => { if(res.code === 200) { message.success("清理全部缓存成功"); } }); }; const onClearAllFailed = (errorInfo: any) => { message.error('Failed:', errorInfo); }; const refreshCacheNames = () => { getCacheNames(); message.success("刷新缓存列表成功"); }; const refreshCacheKeys = () => { getCacheKeys(currentCacheName); message.success("刷新键名列表成功"); }; const columns = [ { title: '缓存名称', dataIndex: 'cacheName', key: 'cacheName', render: (_: any, record: any) => { return record.cacheName.replace(":", ""); } }, { title: '备注', dataIndex: 'remark', key: 'remark', }, { title: , dataIndex: 'option', width: '40px', valueType: 'option', render: (_: any, record: API.Monitor.CacheContent) => [ , ] } ]; const cacheKeysColumns = [ { title: '序号', dataIndex: 'index', key: 'index' }, { title: '缓存键名', dataIndex: 'cacheKey', key: 'cacheKey', render: (_: any, record: any) => { return record.cacheKey.replace(currentCacheName, ""); } }, { title: , dataIndex: 'option', width: '40px', valueType: 'option', render: (_: any, record: API.Monitor.CacheContent) => [ , ] } ]; return (
} onClick={()=>{ refreshCacheNames()}} type="link" />} className={styles.card}> { return { onClick: () => { setCurrentCacheName(record.cacheName); getCacheKeys(record.cacheName); }, }; }} /> } onClick={()=>{ refreshCacheKeys()}} type="link" />} className={styles.card}>
{ return { onClick: () => { getCacheValue(currentCacheName, record.cacheKey).then(res => { if (res.code === 200) { form.resetFields(); form.setFieldsValue({ cacheName: res.data.cacheName, cacheKey: res.data.cacheKey, cacheValue: res.data.cacheValue, remark: res.data.remark, }); } }); }, }; }} /> } onClick={()=>{ onClearAll()}} type="link" >清理全部} className={styles.card}>