mirror of
https://github.com/suyiiyii/nonebot-bison.git
synced 2025-06-04 02:26:11 +08:00
✨ 添加 Cookie 增删查 功能
This commit is contained in:
parent
db4b848e3f
commit
4c20e47399
@ -1,5 +1,6 @@
|
|||||||
import React, { useState } from 'react';
|
import React, { useState } from 'react';
|
||||||
import { Form, Input, Modal } from '@arco-design/web-react';
|
import { Form, Input, Modal } from '@arco-design/web-react';
|
||||||
|
import { useNewCookieMutation } from './cookieConfigSlice';
|
||||||
|
|
||||||
interface CookieModalProps {
|
interface CookieModalProps {
|
||||||
visible: boolean;
|
visible: boolean;
|
||||||
@ -10,15 +11,26 @@ interface CookieModalProps {
|
|||||||
function CookieModal({ visible, setVisible, siteName }: CookieModalProps) {
|
function CookieModal({ visible, setVisible, siteName }: CookieModalProps) {
|
||||||
const FormItem = Form.Item;
|
const FormItem = Form.Item;
|
||||||
const [content, setContent] = useState<string>('');
|
const [content, setContent] = useState<string>('');
|
||||||
// const [confirmLoading, setConfirmLoading] = useState(false);
|
const [confirmLoading, setConfirmLoading] = useState(false);
|
||||||
const [confirmLoading] = useState(false);
|
const [newCoookie] = useNewCookieMutation();
|
||||||
|
|
||||||
|
const onSubmit = () => {
|
||||||
|
const postPromise: ReturnType<typeof newCoookie> = newCoookie({ siteName, content });
|
||||||
|
setConfirmLoading(true);
|
||||||
|
postPromise.then(() => {
|
||||||
|
setConfirmLoading(false);
|
||||||
|
setVisible(false);
|
||||||
|
setContent('');
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Modal
|
<Modal
|
||||||
title="添加 Cookie"
|
title="添加 Cookie"
|
||||||
visible={visible}
|
visible={visible}
|
||||||
onCancel={() => setVisible(false)}
|
onCancel={() => setVisible(false)}
|
||||||
confirmLoading={confirmLoading}
|
confirmLoading={confirmLoading}
|
||||||
onOk={() => setVisible(false)}
|
onOk={onSubmit}
|
||||||
style={{ maxWidth: '90vw' }}
|
style={{ maxWidth: '90vw' }}
|
||||||
>
|
>
|
||||||
|
|
||||||
|
@ -21,9 +21,9 @@ export const cookieApi = createApi({
|
|||||||
invalidatesTags: ['Cookie'],
|
invalidatesTags: ['Cookie'],
|
||||||
}),
|
}),
|
||||||
deleteCookie: builder.mutation<StatusResp, DelCookieParam>({
|
deleteCookie: builder.mutation<StatusResp, DelCookieParam>({
|
||||||
query: ({ siteName, cookieId }) => ({
|
query: ({ cookieId }) => ({
|
||||||
method: 'DELETE',
|
method: 'DELETE',
|
||||||
url: `/cookie/${cookieId}?site_name=${siteName}`,
|
url: `/cookie/${cookieId}`,
|
||||||
}),
|
}),
|
||||||
invalidatesTags: ['Cookie'],
|
invalidatesTags: ['Cookie'],
|
||||||
}),
|
}),
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
import React, { useState } from 'react';
|
import React, { useState } from 'react';
|
||||||
import {
|
import {
|
||||||
Button,
|
Button,
|
||||||
Card, Descriptions, Grid, List, Popover, Typography,
|
Card, Descriptions, Grid, List, Popconfirm, Popover, Typography,
|
||||||
} from '@arco-design/web-react';
|
} from '@arco-design/web-react';
|
||||||
import { selectSiteConf } from '../globalConf/globalConfSlice';
|
import { selectSiteConf } from '../globalConf/globalConfSlice';
|
||||||
import { useAppSelector } from '../../app/hooks';
|
import { useAppSelector } from '../../app/hooks';
|
||||||
import { Cookie, SiteConfig } from '../../utils/type';
|
import { Cookie, SiteConfig } from '../../utils/type';
|
||||||
import { useGetCookiesQuery } from './cookieConfigSlice';
|
import { useGetCookiesQuery, useDeleteCookieMutation } from './cookieConfigSlice';
|
||||||
import CookieModal from './CookieModal';
|
import CookieModal from './CookieModal';
|
||||||
|
|
||||||
interface CookieSite {
|
interface CookieSite {
|
||||||
@ -25,12 +25,19 @@ export default function CookieManager() {
|
|||||||
}));
|
}));
|
||||||
const [showModal, setShowModal] = useState(false);
|
const [showModal, setShowModal] = useState(false);
|
||||||
const [siteName, setSiteName] = useState('');
|
const [siteName, setSiteName] = useState('');
|
||||||
|
const [deleteCookie] = useDeleteCookieMutation();
|
||||||
|
|
||||||
const handleAddCookie = (newSiteName: string) => () => {
|
const handleAddCookie = (newSiteName: string) => () => {
|
||||||
console.log(newSiteName);
|
console.log(newSiteName);
|
||||||
setSiteName(newSiteName);
|
setSiteName(newSiteName);
|
||||||
setShowModal(true);
|
setShowModal(true);
|
||||||
};
|
};
|
||||||
|
const handleDelCookie = (cookieId: string) => () => {
|
||||||
|
console.log(cookieId);
|
||||||
|
deleteCookie({
|
||||||
|
cookieId,
|
||||||
|
});
|
||||||
|
};
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<Typography.Title heading={4} style={{ margin: '15px' }}>Cookie 管理</Typography.Title>
|
<Typography.Title heading={4} style={{ margin: '15px' }}>Cookie 管理</Typography.Title>
|
||||||
@ -53,27 +60,34 @@ export default function CookieManager() {
|
|||||||
{cookies.map((cookie) => (
|
{cookies.map((cookie) => (
|
||||||
<List>
|
<List>
|
||||||
|
|
||||||
<Popover
|
<List.Item key={cookie.id}>
|
||||||
key={cookie.id}
|
<div style={{ display: 'flex', justifyContent: 'space-between' }}>
|
||||||
title={cookie.friendly_name}
|
|
||||||
content={(
|
<Popover
|
||||||
<Descriptions
|
key={cookie.id}
|
||||||
column={1}
|
title={cookie.friendly_name}
|
||||||
title="Cookie 详情"
|
content={(
|
||||||
data={Object.entries(cookie).map((entry) => ({
|
<Descriptions
|
||||||
label: entry[0].toString(),
|
column={1}
|
||||||
value: entry[1].toString(),
|
title="Cookie 详情"
|
||||||
}))}
|
data={Object.entries(cookie).map((entry) => ({
|
||||||
/>
|
label: entry[0].toString(),
|
||||||
)}
|
value: typeof (entry[1]) === 'object' ? JSON.stringify(entry[1]) : entry[1].toString(),
|
||||||
>
|
}))}
|
||||||
<List.Item key={cookie.id}>
|
/>
|
||||||
<div style={{ display: 'flex', justifyContent: 'space-between' }}>
|
)}
|
||||||
|
>
|
||||||
{cookie.friendly_name}
|
{cookie.friendly_name}
|
||||||
|
</Popover>
|
||||||
|
<Popconfirm
|
||||||
|
title={`确定删除 Cookie ${cookie.friendly_name} ?`}
|
||||||
|
onOk={handleDelCookie(cookie.id.toString())}
|
||||||
|
>
|
||||||
|
|
||||||
<Button type="primary" status="danger">删除</Button>
|
<Button type="primary" status="danger">删除</Button>
|
||||||
</div>
|
</Popconfirm>
|
||||||
</List.Item>
|
</div>
|
||||||
</Popover>
|
</List.Item>
|
||||||
</List>
|
</List>
|
||||||
))}
|
))}
|
||||||
</Card>
|
</Card>
|
||||||
|
@ -109,6 +109,5 @@ export interface NewCookieParam {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export interface DelCookieParam {
|
export interface DelCookieParam {
|
||||||
siteName: string
|
|
||||||
cookieId: string
|
cookieId: string
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user