授权列表新增过期时间和重新授权按钮
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import React, { useEffect, useState } from 'react';
|
||||
import { Button, Table, Modal, App, Input, Pagination, Typography, Space } from 'antd';
|
||||
import { LockOutlined } from '@ant-design/icons';
|
||||
import { LockOutlined, ArrowLeftOutlined } from '@ant-design/icons';
|
||||
import { useNavigate } from 'react-router-dom';
|
||||
import { getOAuthAccountList, deleteOAuthAccount, getOpenTypeAll } from '../api';
|
||||
|
||||
const formatDateTime = (dateStr: string) => {
|
||||
@@ -25,6 +26,7 @@ interface AuthorizationData {
|
||||
}
|
||||
|
||||
const AuthAccountPage: React.FC = () => {
|
||||
const navigate = useNavigate();
|
||||
const { message } = App.useApp();
|
||||
const [authorizations, setAuthorizations] = useState<AuthorizationData[]>([]);
|
||||
const [listLoading, setListLoading] = useState(false);
|
||||
@@ -213,6 +215,15 @@ const AuthAccountPage: React.FC = () => {
|
||||
},
|
||||
];
|
||||
|
||||
const handleBack = () => {
|
||||
const referrer = document.referrer;
|
||||
if (referrer.includes(window.location.origin)) {
|
||||
navigate(-1);
|
||||
} else {
|
||||
navigate('/authorization');
|
||||
}
|
||||
};
|
||||
|
||||
const tableData = authorizations.map((item, index) => ({
|
||||
...item,
|
||||
index: index + 1,
|
||||
@@ -222,6 +233,7 @@ const AuthAccountPage: React.FC = () => {
|
||||
return (
|
||||
<div style={{ minHeight: '94vh' }}>
|
||||
<div style={{ display: 'flex', alignItems: 'center', gap: 8, marginBottom: 12 }}>
|
||||
<Button type="text" icon={<ArrowLeftOutlined />} onClick={handleBack} />
|
||||
<LockOutlined style={{ color: '#6366f1', fontSize: 16 }} />
|
||||
<Typography.Text strong style={{ fontSize: 16 }}>授权管理</Typography.Text>
|
||||
</div>
|
||||
|
||||
@@ -154,6 +154,19 @@ const AuthorizationPage: React.FC = () => {
|
||||
}
|
||||
};
|
||||
|
||||
const handleReauthorize = async (record: AuthorizationData) => {
|
||||
try {
|
||||
const response = await requestOAuth({ open_type: record.openType });
|
||||
if (response.authUrl) {
|
||||
window.open(response.authUrl, '_blank');
|
||||
} else {
|
||||
message.error('获取授权链接失败');
|
||||
}
|
||||
} catch (error) {
|
||||
message.error('重新授权失败');
|
||||
}
|
||||
};
|
||||
|
||||
const columns = [
|
||||
{
|
||||
title: 'ID',
|
||||
@@ -162,13 +175,12 @@ const AuthorizationPage: React.FC = () => {
|
||||
},
|
||||
{
|
||||
title: '授权账户ID',
|
||||
dataIndex: 'advertiserId',
|
||||
key: 'advertiserId',
|
||||
width: 160,
|
||||
dataIndex: 'accountId',
|
||||
key: 'accountId',
|
||||
},
|
||||
{
|
||||
title: '授权账户名称',
|
||||
dataIndex: 'advertiserName',
|
||||
dataIndex: 'accountName',
|
||||
key: 'accountName',
|
||||
},
|
||||
{
|
||||
@@ -211,9 +223,10 @@ const AuthorizationPage: React.FC = () => {
|
||||
key: 'accountUsername',
|
||||
},
|
||||
{
|
||||
title: '授权应用ID',
|
||||
dataIndex: 'appid',
|
||||
key: 'appid',
|
||||
title: '开户方式',
|
||||
dataIndex: 'openType',
|
||||
key: 'openType',
|
||||
render: (text: number) => <span style={{ color: '#1e293b' }}>{openTypeMap[text] || text}</span>,
|
||||
},
|
||||
{
|
||||
title: '是否敏感物料授权',
|
||||
@@ -227,27 +240,9 @@ const AuthorizationPage: React.FC = () => {
|
||||
),
|
||||
},
|
||||
{
|
||||
title: '开户方式',
|
||||
dataIndex: 'openType',
|
||||
key: 'openType',
|
||||
render: (text: number) => <span style={{ color: '#1e293b' }}>{openTypeMap[text] || text}</span>,
|
||||
},
|
||||
{
|
||||
title: '平台端口',
|
||||
dataIndex: 'portType',
|
||||
key: 'portType',
|
||||
ellipsis: true,
|
||||
render: (text: number) => <span style={{ color: '#1e293b' }}>{PORT_TYPE_MAP[text] || text}</span>,
|
||||
},
|
||||
{
|
||||
title: '用户id',
|
||||
dataIndex: 'userId',
|
||||
key: 'userId',
|
||||
},
|
||||
{
|
||||
title: '创建时间',
|
||||
dataIndex: 'createdAt',
|
||||
key: 'createdAt',
|
||||
title: '授权过期时间',
|
||||
dataIndex: 'accessTokenExpired',
|
||||
key: 'accessTokenExpired',
|
||||
width: 160,
|
||||
render: (text: string) => <span style={{ color: '#64748b' }}>{formatDateTime(text)}</span>,
|
||||
},
|
||||
@@ -263,15 +258,24 @@ const AuthorizationPage: React.FC = () => {
|
||||
dataIndex: 'action',
|
||||
fixed: 'right' as const,
|
||||
key: 'action',
|
||||
width: 140,
|
||||
width: 190,
|
||||
render: (_: unknown, record) => (
|
||||
<Button
|
||||
type="link"
|
||||
onClick={() => navigate(`/consume?advertiserId=${record.advertiserId}`)}
|
||||
style={{ color: '#6366f1', padding: 0 }}
|
||||
>
|
||||
查看授权账户
|
||||
</Button>
|
||||
<>
|
||||
<Button
|
||||
type="link"
|
||||
onClick={() => navigate(`/authacc?advertiserId=${record.advertiserId}`)}
|
||||
style={{ color: '#6366f1', padding: 0 }}
|
||||
>
|
||||
查看授权账户
|
||||
</Button>
|
||||
<Button
|
||||
type="link"
|
||||
onClick={() => handleReauthorize(record)}
|
||||
style={{ color: '#00c49f', padding: 0, marginLeft: 8 }}
|
||||
>
|
||||
重新授权
|
||||
</Button>
|
||||
</>
|
||||
),
|
||||
},
|
||||
];
|
||||
|
||||
@@ -92,7 +92,7 @@ const ConsumePage: React.FC = () => {
|
||||
if (referrer.includes(window.location.origin)) {
|
||||
navigate(-1);
|
||||
} else {
|
||||
navigate('/authorization');
|
||||
navigate('/materials');
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user