mirror of
https://github.com/suyiiyii/nonebot-bison.git
synced 2025-06-04 02:26:11 +08:00
✨ (admin) 支持添加cookieTarget
This commit is contained in:
parent
8174ec895d
commit
6d8de1b59e
@ -1,7 +1,10 @@
|
|||||||
import React, { useState } from 'react';
|
import React, { useState } from 'react';
|
||||||
import { Form, Input, Modal } from '@arco-design/web-react';
|
import {
|
||||||
import { useNewCookieMutation } from './cookieConfigSlice';
|
Button, Empty, Form, Input, Modal, Space, Table,
|
||||||
import { Cookie } from '../../utils/type';
|
} from '@arco-design/web-react';
|
||||||
|
import { useDeleteCookieTargetMutation, useGetCookieTargetsQuery } from './cookieConfigSlice';
|
||||||
|
import { Cookie, CookieTarget } from '../../utils/type';
|
||||||
|
import CookieTargetModal from '../cookieTargetManager/CookieTargetModal';
|
||||||
|
|
||||||
interface CookieEditModalProps {
|
interface CookieEditModalProps {
|
||||||
visible: boolean;
|
visible: boolean;
|
||||||
@ -10,51 +13,109 @@ interface CookieEditModalProps {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function CookieEditModal({ visible, setVisible, cookie }: CookieEditModalProps) {
|
function CookieEditModal({ visible, setVisible, cookie }: CookieEditModalProps) {
|
||||||
|
if (!cookie) {
|
||||||
|
return <Empty />;
|
||||||
|
}
|
||||||
const FormItem = Form.Item;
|
const FormItem = Form.Item;
|
||||||
const [confirmLoading, setConfirmLoading] = useState(false);
|
// const [confirmLoading, setConfirmLoading] = useState(false);
|
||||||
|
const [deleteCookieTarget] = useDeleteCookieTargetMutation();
|
||||||
|
// 获取 Cookie Target
|
||||||
|
const { data: cookieTargets } = useGetCookieTargetsQuery({ cookieId: cookie.id });
|
||||||
|
|
||||||
|
// 添加 Cookie Target
|
||||||
|
const [showAddCookieTargetModal, setShowAddCookieTargetModal] = useState(false);
|
||||||
|
const handleAddCookieTarget = () => () => {
|
||||||
|
setShowAddCookieTargetModal(true);
|
||||||
|
};
|
||||||
|
|
||||||
|
// 删除 Cookie Target
|
||||||
|
const handleDelete = (record: CookieTarget) => () => {
|
||||||
|
deleteCookieTarget({
|
||||||
|
cookieId: record.cookieId,
|
||||||
|
target: record.target.target,
|
||||||
|
platformName: record.target.platform_name,
|
||||||
|
});
|
||||||
|
};
|
||||||
|
const columns = [
|
||||||
|
{
|
||||||
|
title: '平台名称',
|
||||||
|
dataIndex: 'target.platform_name',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '订阅名称',
|
||||||
|
dataIndex: 'target.target_name',
|
||||||
|
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: 'Cookie ID',
|
||||||
|
dataIndex: 'cookie_id',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '操作',
|
||||||
|
dataIndex: 'op',
|
||||||
|
render: (_: null, record: CookieTarget) => (
|
||||||
|
<Space size="small">
|
||||||
|
<Button type="text" status="danger" onClick={handleDelete(record)}>删除</Button>
|
||||||
|
</Space>
|
||||||
|
),
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Modal
|
<>
|
||||||
title="编辑 Cookie"
|
<Modal
|
||||||
visible={visible}
|
title="编辑 Cookie"
|
||||||
onCancel={() => setVisible(false)}
|
visible={visible}
|
||||||
confirmLoading={confirmLoading}
|
onCancel={() => setVisible(false)}
|
||||||
|
// confirmLoading={confirmLoading}
|
||||||
// onOk={onSubmit}
|
// onOk={onSubmit}
|
||||||
style={{ maxWidth: '90vw', minWidth: '50vw' }}
|
style={{ maxWidth: '90vw', minWidth: '50vw' }}
|
||||||
>
|
>
|
||||||
{cookie
|
<Form autoComplete="off">
|
||||||
&& (
|
<FormItem label="Cookie ID">
|
||||||
<Form autoComplete="off">
|
<Input disabled value={cookie.id.toString()} />
|
||||||
<FormItem label="Cookie ID">
|
</FormItem>
|
||||||
<Input disabled value={cookie.id.toString()} />
|
<FormItem label="Cookie 名称">
|
||||||
</FormItem>
|
<Input value={cookie.friendly_name} disabled />
|
||||||
<FormItem label="Cookie 名称">
|
</FormItem>
|
||||||
<Input value={cookie.friendly_name} disabled />
|
<FormItem label="所属站点">
|
||||||
</FormItem>
|
<Input value={cookie.site_name} disabled />
|
||||||
<FormItem label="所属站点">
|
</FormItem>
|
||||||
<Input value={cookie.site_name} disabled />
|
|
||||||
</FormItem>
|
|
||||||
|
|
||||||
<FormItem label="标签">
|
<FormItem label="标签">
|
||||||
<Input.TextArea
|
<Input.TextArea
|
||||||
value={JSON.stringify(cookie.tags)}
|
value={JSON.stringify(cookie.tags)}
|
||||||
disabled
|
disabled
|
||||||
/>
|
/>
|
||||||
</FormItem>
|
</FormItem>
|
||||||
|
|
||||||
<FormItem label="最后使用时间">
|
<FormItem label="最后使用时间">
|
||||||
<Input value={cookie.last_usage.toString()} disabled />
|
<Input value={cookie.last_usage.toString()} disabled />
|
||||||
</FormItem>
|
</FormItem>
|
||||||
<FormItem label="状态">
|
<FormItem label="状态">
|
||||||
<Input value={cookie.status} disabled />
|
<Input value={cookie.status} disabled />
|
||||||
</FormItem>
|
</FormItem>
|
||||||
<FormItem label="冷却时间(毫秒)">
|
<FormItem label="冷却时间(毫秒)">
|
||||||
<Input value={cookie.cd_milliseconds.toString()} disabled />
|
<Input value={cookie.cd_milliseconds.toString()} disabled />
|
||||||
</FormItem>
|
</FormItem>
|
||||||
|
|
||||||
</Form>
|
</Form>
|
||||||
)}
|
|
||||||
</Modal>
|
<Button type="primary" onClick={handleAddCookieTarget()}>关联 Cookie</Button>
|
||||||
|
<Table
|
||||||
|
columns={columns}
|
||||||
|
data={cookieTargets}
|
||||||
|
rowKey={(record: CookieTarget) => `${record.target.platform_name}-${record.target.target}`}
|
||||||
|
scroll={{ x: true }}
|
||||||
|
/>
|
||||||
|
</Modal>
|
||||||
|
|
||||||
|
<CookieTargetModal
|
||||||
|
cookie={cookie}
|
||||||
|
visible={showAddCookieTargetModal}
|
||||||
|
setVisible={setShowAddCookieTargetModal}
|
||||||
|
/>
|
||||||
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4,20 +4,14 @@ import {
|
|||||||
Table, TableColumnProps, Typography, Space, Popconfirm,
|
Table, TableColumnProps, Typography, Space, Popconfirm,
|
||||||
} from '@arco-design/web-react';
|
} from '@arco-design/web-react';
|
||||||
import { useParams } from 'react-router-dom';
|
import { useParams } from 'react-router-dom';
|
||||||
import { IconDelete, IconEdit } from '@arco-design/web-react/icon';
|
|
||||||
import { useAppSelector } from '../../app/hooks';
|
|
||||||
import { useGetCookiesQuery, useDeleteCookieMutation } from './cookieConfigSlice';
|
import { useGetCookiesQuery, useDeleteCookieMutation } from './cookieConfigSlice';
|
||||||
import './CookieManager.css';
|
import './CookieManager.css';
|
||||||
import { selectPlatformConf, selectSiteConf } from '../globalConf/globalConfSlice';
|
import { Cookie } from '../../utils/type';
|
||||||
import { Cookie, PlatformConfig } from '../../utils/type';
|
|
||||||
import CookieTargetModal from '../cookieTargetManager/CookieTargetModal';
|
|
||||||
import CookieAddModal from './CookieAddModal';
|
import CookieAddModal from './CookieAddModal';
|
||||||
import CookieEditModal from './CookieEditModal';
|
import CookieEditModal from './CookieEditModal';
|
||||||
|
|
||||||
export default function CookieManager() {
|
export default function CookieManager() {
|
||||||
const { siteName } = useParams();
|
const { siteName } = useParams();
|
||||||
const siteConf = useAppSelector(selectSiteConf);
|
|
||||||
const platformConf = useAppSelector(selectPlatformConf);
|
|
||||||
const { data: cookieDict } = useGetCookiesQuery();
|
const { data: cookieDict } = useGetCookiesQuery();
|
||||||
const cookiesList = cookieDict ? Object.values(cookieDict) : [];
|
const cookiesList = cookieDict ? Object.values(cookieDict) : [];
|
||||||
|
|
||||||
@ -59,10 +53,7 @@ export default function CookieManager() {
|
|||||||
if (siteName) {
|
if (siteName) {
|
||||||
data = cookiesList.filter((tSite) => tSite.site_name === siteName);
|
data = cookiesList.filter((tSite) => tSite.site_name === siteName);
|
||||||
}
|
}
|
||||||
const platformThatSiteSupport: Record<string, string> = Object.values(platformConf).reduce((p, c) => {
|
|
||||||
p[c.siteName] = c.platformName;
|
|
||||||
return p;
|
|
||||||
}, {} as Record<string, string>);
|
|
||||||
const columns: TableColumnProps[] = [
|
const columns: TableColumnProps[] = [
|
||||||
{
|
{
|
||||||
title: 'ID',
|
title: 'ID',
|
||||||
|
@ -41,7 +41,7 @@ export const cookieTargetApi = createApi({
|
|||||||
tagTypes: ['CookieTarget'],
|
tagTypes: ['CookieTarget'],
|
||||||
endpoints: (builder) => ({
|
endpoints: (builder) => ({
|
||||||
getCookieTargets: builder.query<CookieTarget[], {cookieId: number }>({
|
getCookieTargets: builder.query<CookieTarget[], {cookieId: number }>({
|
||||||
query: (cookieId) => `/cookie_target?cookie_id=${cookieId}`,
|
query: ({ cookieId }) => `/cookie_target?cookie_id=${cookieId}`,
|
||||||
providesTags: ['CookieTarget'],
|
providesTags: ['CookieTarget'],
|
||||||
}),
|
}),
|
||||||
newCookieTarget: builder.mutation<StatusResp, NewCookieTargetParam>({
|
newCookieTarget: builder.mutation<StatusResp, NewCookieTargetParam>({
|
||||||
|
@ -1,18 +1,40 @@
|
|||||||
import React
|
import React
|
||||||
from 'react';
|
from 'react';
|
||||||
import { Modal, Select } from '@arco-design/web-react';
|
import {
|
||||||
import { SubscribeConfig, SubscribeGroupDetail } from '../../utils/type';
|
Empty, Form, Modal, Select,
|
||||||
|
} from '@arco-design/web-react';
|
||||||
|
import { Cookie, SubscribeConfig, SubscribeGroupDetail } from '../../utils/type';
|
||||||
import { useNewCookieTargetMutation } from '../cookieManager/cookieConfigSlice';
|
import { useNewCookieTargetMutation } from '../cookieManager/cookieConfigSlice';
|
||||||
import { useGetSubsQuery } from '../subsribeConfigManager/subscribeConfigSlice';
|
import { useGetSubsQuery } from '../subsribeConfigManager/subscribeConfigSlice';
|
||||||
|
import { useAppSelector } from '../../app/hooks';
|
||||||
|
import { selectPlatformConf } from '../globalConf/globalConfSlice';
|
||||||
|
|
||||||
interface SubscribeModalProp {
|
interface SubscribeModalProp {
|
||||||
cookieId: number;
|
cookie:Cookie| null
|
||||||
visible: boolean;
|
visible: boolean;
|
||||||
setVisible: (arg0: boolean) => void;
|
setVisible: (arg0: boolean) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function CookieTargetModal({ cookieId, visible, setVisible }: SubscribeModalProp) {
|
export default function CookieTargetModal({
|
||||||
|
cookie, visible, setVisible,
|
||||||
|
}: SubscribeModalProp) {
|
||||||
|
if (!cookie) {
|
||||||
|
return <Empty />;
|
||||||
|
}
|
||||||
const [newCookieTarget] = useNewCookieTargetMutation();
|
const [newCookieTarget] = useNewCookieTargetMutation();
|
||||||
|
const FormItem = Form.Item;
|
||||||
|
|
||||||
|
// 筛选出当前Cookie支持的平台
|
||||||
|
const platformConf = useAppSelector(selectPlatformConf);
|
||||||
|
const platformThatSiteSupport = Object.values(platformConf).reduce((p, c) => {
|
||||||
|
if (c.siteName in p) {
|
||||||
|
p[c.siteName].push(c.platformName);
|
||||||
|
} else {
|
||||||
|
p[c.siteName] = [c.platformName];
|
||||||
|
}
|
||||||
|
return p;
|
||||||
|
}, {} as Record<string, string[]>);
|
||||||
|
const supportedPlatform = platformThatSiteSupport[cookie.site_name];
|
||||||
|
|
||||||
const { data: subs } = useGetSubsQuery();
|
const { data: subs } = useGetSubsQuery();
|
||||||
const pureSubs:SubscribeConfig[] = subs ? Object.values(subs)
|
const pureSubs:SubscribeConfig[] = subs ? Object.values(subs)
|
||||||
@ -20,18 +42,21 @@ export default function CookieTargetModal({ cookieId, visible, setVisible }: Sub
|
|||||||
pv:Array<SubscribeConfig>,
|
pv:Array<SubscribeConfig>,
|
||||||
cv:SubscribeGroupDetail,
|
cv:SubscribeGroupDetail,
|
||||||
) => pv.concat(cv.subscribes), []) : [];
|
) => pv.concat(cv.subscribes), []) : [];
|
||||||
|
const filteredSubs = pureSubs.filter((sub) => supportedPlatform.includes(sub.platformName));
|
||||||
const [index, setIndex] = React.useState(-1);
|
const [index, setIndex] = React.useState(-1);
|
||||||
|
|
||||||
const handleSubmit = (idx:number) => {
|
const handleSubmit = (idx:number) => {
|
||||||
const postPromise: ReturnType<typeof newCookieTarget> = newCookieTarget({
|
const postPromise: ReturnType<typeof newCookieTarget> = newCookieTarget({
|
||||||
cookieId,
|
cookieId: cookie.id,
|
||||||
platformName: pureSubs[idx].platformName,
|
platformName: filteredSubs[idx].platformName,
|
||||||
target: pureSubs[idx].target,
|
target: filteredSubs[idx].target,
|
||||||
});
|
});
|
||||||
postPromise.then(() => {
|
postPromise.then(() => {
|
||||||
setVisible(false);
|
setVisible(false);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
const { Option } = Select;
|
const { Option } = Select;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Modal
|
<Modal
|
||||||
title="关联 Cookie"
|
title="关联 Cookie"
|
||||||
@ -39,22 +64,46 @@ export default function CookieTargetModal({ cookieId, visible, setVisible }: Sub
|
|||||||
onCancel={() => setVisible(false)}
|
onCancel={() => setVisible(false)}
|
||||||
onOk={() => handleSubmit(index)}
|
onOk={() => handleSubmit(index)}
|
||||||
>
|
>
|
||||||
<Select
|
|
||||||
placeholder="选择要关联的 target"
|
<Form>
|
||||||
style={{ width: '100%' }}
|
<FormItem label="平台" required>
|
||||||
onChange={setIndex}
|
|
||||||
>
|
<Select
|
||||||
{pureSubs.length
|
placeholder="选择要关联的平台"
|
||||||
&& pureSubs.map((sub, idx) => (
|
style={{ width: '100%' }}
|
||||||
|
onChange={setIndex}
|
||||||
|
>
|
||||||
|
{supportedPlatform.length
|
||||||
|
&& supportedPlatform.map((sub, idx) => (
|
||||||
<Option
|
<Option
|
||||||
key={JSON.stringify(sub)}
|
key={JSON.stringify(sub)}
|
||||||
value={idx}
|
value={idx}
|
||||||
>
|
>
|
||||||
{JSON.stringify(sub)}
|
{sub}
|
||||||
</Option>
|
</Option>
|
||||||
))}
|
))}
|
||||||
</Select>
|
</Select>
|
||||||
|
|
||||||
|
</FormItem>
|
||||||
|
<FormItem label="订阅目标" required>
|
||||||
|
<Select
|
||||||
|
placeholder="选择要关联的订阅目标"
|
||||||
|
style={{ width: '100%' }}
|
||||||
|
onChange={setIndex}
|
||||||
|
>
|
||||||
|
{filteredSubs.length
|
||||||
|
&& filteredSubs.map((sub, idx) => (
|
||||||
|
<Option
|
||||||
|
key={JSON.stringify(sub)}
|
||||||
|
value={idx}
|
||||||
|
>
|
||||||
|
{sub.targetName}
|
||||||
|
</Option>
|
||||||
|
))}
|
||||||
|
</Select>
|
||||||
|
</FormItem>
|
||||||
|
|
||||||
|
</Form>
|
||||||
</Modal>
|
</Modal>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user