| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330 |
- "use client";
- import {useEffect, useState} from "react";
- import {useRouter} from "next/navigation";
- import {ClearOutlined, DeleteOutlined, ReloadOutlined} from "@ant-design/icons";
- import {Button, Col, Flex, Form, Input, Row, Table, Tooltip,} from "antd";
- import {PageContainer, ProCard} from "@ant-design/pro-components";
- import {faFileLines, faFloppyDisk, faKey,} from "@fortawesome/free-solid-svg-icons";
- import {FontAwesomeIcon} from "@fortawesome/react-fontawesome";
- import {fetchApi} from "@/app/_modules/func";
- const { TextArea } = Input;
- //查询缓存API
- const queryCacheAPI = "/api/monitor/cache/getNames";
- //删除指定的缓存API
- const deleteCacheAPI = "/api/monitor/cache/clearCacheName";
- //查询缓存Key API
- const queryCacheKeyAPI = "/api/monitor/cache/getKeys";
- //查询缓存值API
- const queryValueAPI = "/api/monitor/cache/getValue";
- //删除指定的Key API
- const deleteKeyAPI = "/api/monitor/cache/clearCacheKey";
- //清空所有缓存API
- const clearAPI = "/api/monitor/cache/clearCacheAll";
- export default function CacheList() {
- const { push } = useRouter();
- //缓存列表加载状态
- const [isCacheLoading, setIsCacheLoading] = useState(false);
- //缓存数据
- const [cacheData, setCacheData] = useState([]);
- //查询缓存
- const queryCache = async () => {
- setIsCacheLoading(true);
- const body = await fetchApi(queryCacheAPI, push);
- if (body !== undefined) {
- if (body.code == 200) {
- setCacheData(body.data);
- }
- }
- setIsCacheLoading(false);
- };
- useEffect(() => {
- queryCache();
- }, []);
- //缓存列定义
- const cacheColumns = [
- {
- title: "序号",
- key: "index",
- width: "60px",
- render: (text: any, record: any, index: number) => `${index + 1}`,
- },
- {
- title: "缓存名称",
- dataIndex: "cacheName",
- ellipsis: true,
- },
- {
- title: "备注",
- dataIndex: "remark",
- },
- {
- title: "操作",
- key: "action",
- render: (text: any, record: any) => [
- <Button
- key="deleteBtn"
- type="link"
- danger
- icon={<DeleteOutlined />}
- onClick={() => deleteCache(record.cacheName)}
- ></Button>,
- ],
- },
- ];
- //缓存列表行点击
- const cacheRowClick = (record: any, index: any) => {
- return {
- onMouseDown: (event: any) => {
- setSelectedCache(record.cacheName);
- queryKeys(record.cacheName);
- },
- };
- };
- //删除指定的缓存
- const deleteCache = async (cacheName: string) => {
- const body = await fetchApi(`${deleteCacheAPI}/${cacheName}}`, push, {
- method: "DELETE",
- });
- if (body != undefined) {
- if (body.code == 200) {
- App.useApp().message.success(`清理缓存[${cacheName}]成功`);
- queryCache();
- } else {
- App.useApp().message.error(body.msg);
- }
- }
- };
- //选中的缓存
- const [selectedCache, setSelectedCache] = useState("");
- //key列表加载状态
- const [isKeyLoading, setIsKeyLoading] = useState(false);
- //key 数据
- const [keyData, setKeyData] = useState([]);
- //查询缓存对应的key
- const queryKeys = async (cacheName?: string) => {
- if (cacheName === undefined) {
- if (selectedCache === "") {
- return;
- }
- cacheName = selectedCache;
- }
- setIsKeyLoading(true);
- const body = await fetchApi(`${queryCacheKeyAPI}/${cacheName}`, push);
- if (body !== undefined) {
- if (body.code == 200) {
- setKeyData(body.data);
- }
- }
- setIsKeyLoading(false);
- };
- //key列定义
- const keyColumns = [
- {
- title: "序号",
- key: "index",
- width: "60px",
- render: (text: any, record: any, index: number) => `${index + 1}`,
- },
- {
- title: "缓存键名",
- key: "key",
- ellipsis: true,
- render: (text: any, record: string) => record.split(":")[1],
- },
- {
- title: "操作",
- key: "action",
- render: (text: any, record: any) => [
- <Button
- key="deleteBtn"
- type="link"
- danger
- icon={<DeleteOutlined />}
- onClick={() => deleteKey(record)}
- ></Button>,
- ],
- },
- ];
- //key列表行点击
- const keyRowClick = (record: any, index: any) => {
- return {
- onClick: (event: any) => {
- queryValue(record);
- },
- };
- };
- //删除指定的key
- const deleteKey = async (key: string) => {
- const body = await fetchApi(`${deleteKeyAPI}/${key}`, push, {
- method: "DELETE",
- });
- if (body != undefined) {
- if (body.code == 200) {
- App.useApp().message.success(`清理缓存键名[${key}]成功`);
- queryKeys();
- } else {
- App.useApp().message.error(body.msg);
- }
- }
- };
- //缓存值展示表单
- const [valueForm] = Form.useForm();
- //查询值
- const queryValue = async (key: any) => {
- const body = await fetchApi(
- `${queryValueAPI}/${selectedCache}/${key}`,
- push
- );
- if (body !== undefined) {
- if (body.code == 200) {
- valueForm?.setFieldsValue({
- cacheName: body.data.cacheName,
- cacheKey: body.data.cacheKey,
- cacheValue: body.data.cacheValue,
- });
- }
- }
- };
- //清空全部缓存
- const clearCache = async () => {
- const body = await fetchApi(clearAPI, push, {
- method: "DELETE",
- });
- if (body !== undefined) {
- if (body.code == 200) {
- App.useApp().message.success("清空全部缓存成功");
- } else {
- App.useApp().message.error(body.msg);
- }
- } else {
- App.useApp().message.error("清空全部缓存异常");
- }
- };
- return (
- <PageContainer title={false}>
- <Flex justify="flex-end" style={{ marginBottom: 16 }}>
- <Tooltip title="清空全部缓存">
- <Button
- icon={<ClearOutlined />}
- type="primary"
- onClick={clearCache}
- />
- </Tooltip>
- </Flex>
- <Row gutter={8}>
- <Col span={8}>
- <ProCard
- title={
- <>
- <FontAwesomeIcon icon={faFloppyDisk} />
- <span style={{ marginLeft: 6 }}>缓存列表</span>
- </>
- }
- extra={
- <Tooltip title="刷新">
- <a onClick={queryCache}>
- <ReloadOutlined />
- </a>
- </Tooltip>
- }
- style={{ height: "100%" }}
- headerBordered
- bordered
- hoverable
- >
- <div style={{ overflowX: "auto" }}>
- <Table
- dataSource={cacheData}
- columns={cacheColumns}
- loading={isCacheLoading}
- onRow={cacheRowClick}
- />
- </div>
- </ProCard>
- </Col>
- <Col span={8}>
- <ProCard
- title={
- <>
- <FontAwesomeIcon icon={faKey} />
- <span style={{ marginLeft: 6 }}>键名列表</span>
- </>
- }
- extra={
- <Tooltip title="刷新">
- <a onClick={() => queryKeys()}>
- <ReloadOutlined />
- </a>
- </Tooltip>
- }
- style={{ height: "100%" }}
- headerBordered
- bordered
- hoverable
- >
- <div style={{ overflowX: "auto" }}>
- <Table
- dataSource={keyData}
- columns={keyColumns}
- loading={isKeyLoading}
- onRow={keyRowClick}
- />
- </div>
- </ProCard>
- </Col>
- <Col span={8}>
- <ProCard
- title={
- <>
- <FontAwesomeIcon icon={faFileLines} />
- <span style={{ marginLeft: 6 }}>缓存内容</span>
- </>
- }
- style={{ height: "100%" }}
- headerBordered
- bordered
- hoverable
- >
- <Form layout="vertical" form={valueForm}>
- <Form.Item label="缓存名称" name="cacheName">
- <Input readOnly />
- </Form.Item>
- <Form.Item label="缓存键名" name="cacheKey">
- <Input readOnly />
- </Form.Item>
- <Form.Item label="缓存内容" name="cacheValue">
- <TextArea readOnly rows={8} />
- </Form.Item>
- </Form>
- </ProCard>
- </Col>
- </Row>
- </PageContainer>
- );
- }
|