314 lines
9.8 KiB
TypeScript
314 lines
9.8 KiB
TypeScript
import React, { useEffect, useState } from 'react';
|
|
import { Button, Table, Modal, App, Input, Pagination, Typography, Space } from 'antd';
|
|
import { LockOutlined, ArrowLeftOutlined } from '@ant-design/icons';
|
|
import { useNavigate } from 'react-router-dom';
|
|
import { getOAuthAccountList, deleteOAuthAccount, getOpenTypeAll } from '../api';
|
|
|
|
const formatDateTime = (dateStr: string) => {
|
|
if (!dateStr) return '';
|
|
const date = new Date(dateStr);
|
|
const year = date.getFullYear();
|
|
const month = String(date.getMonth() + 1).padStart(2, '0');
|
|
const day = String(date.getDate()).padStart(2, '0');
|
|
const hours = String(date.getHours()).padStart(2, '0');
|
|
const minutes = String(date.getMinutes()).padStart(2, '0');
|
|
const seconds = String(date.getSeconds()).padStart(2, '0');
|
|
return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
|
|
};
|
|
|
|
interface AuthorizationData {
|
|
id: string;
|
|
status: string;
|
|
description: string;
|
|
account_userid?: string;
|
|
open_type?: number;
|
|
account_id?: string;
|
|
}
|
|
|
|
const AuthAccountPage: React.FC = () => {
|
|
const navigate = useNavigate();
|
|
const { message } = App.useApp();
|
|
const [authorizations, setAuthorizations] = useState<AuthorizationData[]>([]);
|
|
const [listLoading, setListLoading] = useState(false);
|
|
const [currentPage, setCurrentPage] = useState(1);
|
|
const [pageSize, setPageSize] = useState(10);
|
|
const [total, setTotal] = useState(0);
|
|
const [searchParams, setSearchParams] = useState({
|
|
advertiser_id: '',
|
|
oauth_id: '',
|
|
advertiser_name: '',
|
|
});
|
|
const [openTypeMap, setOpenTypeMap] = useState<Record<number, string>>({});
|
|
|
|
useEffect(() => {
|
|
loadOAuthList();
|
|
loadOpenTypeList();
|
|
}, []);
|
|
|
|
const loadOpenTypeList = async () => {
|
|
try {
|
|
const res = await getOpenTypeAll();
|
|
const data = res.data || [];
|
|
const map: Record<number, string> = {};
|
|
const options: { value: number; label: string }[] = [];
|
|
data.forEach(item => {
|
|
map[item.openType] = item.typeName;
|
|
options.push({ value: item.openType, label: item.typeName });
|
|
});
|
|
setOpenTypeMap(map);
|
|
} catch (error) {
|
|
console.error('加载开户方式列表失败:', error);
|
|
}
|
|
};
|
|
|
|
const loadOAuthList = async (page = 1, pageSize = 10, params = searchParams) => {
|
|
setListLoading(true);
|
|
try {
|
|
const response = await getOAuthAccountList({
|
|
advertiser_id: params.advertiser_id || '',
|
|
oauth_id: params.oauth_id || '',
|
|
advertiser_name: params.advertiser_name || '',
|
|
page,
|
|
page_size: pageSize,
|
|
});
|
|
if (response) {
|
|
if (response.data) {
|
|
setAuthorizations(response.data.data || response.data);
|
|
}
|
|
if (response.pagination) {
|
|
setTotal(response.pagination.total || 0);
|
|
setCurrentPage(response.pagination.page || 1);
|
|
setPageSize(response.pagination.pageSize || 10);
|
|
}
|
|
} else {
|
|
setAuthorizations(response || []);
|
|
}
|
|
} catch (error) {
|
|
message.error('获取授权列表失败');
|
|
} finally {
|
|
setListLoading(false);
|
|
}
|
|
};
|
|
|
|
const columns = [
|
|
{
|
|
title: 'ID',
|
|
dataIndex: 'id',
|
|
key: 'id',
|
|
},
|
|
{
|
|
title: '广告主账户ID',
|
|
dataIndex: 'advertiserId',
|
|
key: 'advertiserId',
|
|
width: 160,
|
|
},
|
|
{
|
|
title: '广告主账户名称',
|
|
dataIndex: 'advertiserName',
|
|
key: 'advertiserName',
|
|
},
|
|
{
|
|
title: '广告主账户角色',
|
|
dataIndex: 'advertiserRole',
|
|
key: 'advertiserRole',
|
|
},
|
|
{
|
|
title: '授权账户ID',
|
|
dataIndex: 'accountId',
|
|
key: 'accountId',
|
|
width: 160,
|
|
},
|
|
{
|
|
title: '授权账户名称',
|
|
dataIndex: 'accountName',
|
|
key: 'accountName',
|
|
},
|
|
|
|
{
|
|
title: '授权账户角色',
|
|
dataIndex: 'accountRole',
|
|
key: 'accountRole',
|
|
render: (role: string) => {
|
|
const roleMap: Record<string, string> = {
|
|
ADVERTISER: '客户',
|
|
CUSTOMER_ADMIN: '普通版工作台-管理员',
|
|
CUSTOMER_OPERATOR: '普通版工作台-协作者',
|
|
AGENT: '代理商',
|
|
CHILD_AGENT: '二级代理商',
|
|
PLATFORM_ROLE_STAR: '星图账户',
|
|
PLATFORM_ROLE_SHOP_ACCOUNT: '抖音店铺账户',
|
|
PLATFORM_ROLE_QIANCHUAN_AGENT: '千川代理商',
|
|
PLATFORM_ROLE_STAR_AGENT: '星图代理商',
|
|
PLATFORM_ROLE_AWEME: '抖音号',
|
|
PLATFORM_ROLE_STAR_MCN: '星图MCN机构',
|
|
PLATFORM_ROLE_STAR_ISV: '星图服务商',
|
|
AGENT_SYSTEM_ACCOUNT: '代理商系统账户',
|
|
PLATFORM_ROLE_LOCAL_AGENT: '本地推代理商',
|
|
PLATFORM_ROLE_YUNTU_BRAND_ISV_ADMIN: '云图品牌服务商管理员',
|
|
PLATFORM_ROLE_LIFE: '抖音来客账户',
|
|
PLATFORM_ROLE_ENTERPRISE_BP_ADMIN: '升级版工作台管理员',
|
|
PLATFORM_ROLE_ENTERPRISE_BP_OPERATOR: '升级版工作台协作者',
|
|
};
|
|
return roleMap[role] || role;
|
|
},
|
|
},
|
|
{
|
|
title: '授权账户登录账号ID',
|
|
dataIndex: 'accountUserid',
|
|
key: 'accountUserid',
|
|
},
|
|
{
|
|
title: '授权账户登录账号名称',
|
|
dataIndex: 'accountUsername',
|
|
key: 'accountUsername',
|
|
},
|
|
{
|
|
title: '授权ID',
|
|
dataIndex: 'oauthId',
|
|
key: 'oauthId',
|
|
},
|
|
{
|
|
title: '开户方式',
|
|
dataIndex: 'openType',
|
|
key: 'openType',
|
|
render: (text: number) => <span style={{ color: '#1e293b' }}>{openTypeMap[text] || text}</span>,
|
|
},
|
|
{
|
|
title: '创建时间',
|
|
dataIndex: 'createdAt',
|
|
key: 'createdAt',
|
|
width: 160,
|
|
render: (text: string) => <span style={{ color: '#64748b' }}>{formatDateTime(text)}</span>,
|
|
},
|
|
{
|
|
title: '操作',
|
|
fixed: 'right' as const,
|
|
dataIndex: 'action',
|
|
key: 'action',
|
|
render: (_: string, record: AuthorizationData) => (
|
|
<Space>
|
|
<Button
|
|
size="small"
|
|
danger
|
|
onClick={() => {
|
|
Modal.confirm({
|
|
title: '确认删除',
|
|
content: '确定要删除该授权账户吗?',
|
|
okText: '确定',
|
|
cancelText: '取消',
|
|
onOk: async () => {
|
|
try {
|
|
await deleteOAuthAccount({ id: record.id });
|
|
message.success('删除成功');
|
|
loadOAuthList(currentPage, pageSize);
|
|
} catch (error) {
|
|
message.error('删除失败');
|
|
}
|
|
},
|
|
});
|
|
}}
|
|
>
|
|
删除
|
|
</Button>
|
|
</Space>
|
|
),
|
|
},
|
|
];
|
|
|
|
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,
|
|
key: item.id,
|
|
}));
|
|
|
|
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>
|
|
|
|
<div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center', gap: 12, marginBottom: 16 }}>
|
|
<div style={{ display: 'flex', gap: 12 }}>
|
|
<Input
|
|
placeholder="广告主账户ID"
|
|
value={searchParams.advertiser_id}
|
|
onChange={(e) => setSearchParams(prev => ({ ...prev, advertiser_id: e.target.value }))}
|
|
style={{ width: 180 }}
|
|
onPressEnter={() => { setCurrentPage(1); loadOAuthList(1, pageSize); }}
|
|
/>
|
|
<Input
|
|
placeholder="授权ID"
|
|
value={searchParams.oauth_id}
|
|
onChange={(e) => setSearchParams(prev => ({ ...prev, oauth_id: e.target.value }))}
|
|
style={{ width: 180 }}
|
|
onPressEnter={() => { setCurrentPage(1); loadOAuthList(1, pageSize); }}
|
|
/>
|
|
<Input
|
|
placeholder="广告主账户名称"
|
|
value={searchParams.advertiser_name}
|
|
onChange={(e) => setSearchParams(prev => ({ ...prev, advertiser_name: e.target.value }))}
|
|
style={{ width: 180 }}
|
|
onPressEnter={() => { setCurrentPage(1); loadOAuthList(1, pageSize); }}
|
|
/>
|
|
<Button
|
|
type="primary"
|
|
size="medium"
|
|
onClick={() => { setCurrentPage(1); loadOAuthList(1, pageSize); }}
|
|
>
|
|
搜索
|
|
</Button>
|
|
<Button
|
|
size="medium"
|
|
onClick={() => {
|
|
setSearchParams({ advertiser_id: '', oauth_id: '', advertiser_name: '' });
|
|
setCurrentPage(1);
|
|
loadOAuthList(1, pageSize);
|
|
}}
|
|
>
|
|
重置
|
|
</Button>
|
|
</div>
|
|
</div>
|
|
|
|
<div style={{ background: '#fff', borderRadius: 12, boxShadow: '0 1px 3px rgba(0,0,0,0.05)' }}>
|
|
<Table
|
|
dataSource={tableData}
|
|
columns={columns}
|
|
loading={listLoading}
|
|
pagination={false}
|
|
rowKey="id"
|
|
bordered={false}
|
|
scroll={{ x: 'max-content' }}
|
|
/>
|
|
<div style={{ padding: '16px', textAlign: 'right' }}>
|
|
<Pagination
|
|
current={currentPage}
|
|
pageSize={pageSize}
|
|
total={total}
|
|
showSizeChanger
|
|
showTotal={(total) => `共 ${total} 条记录`}
|
|
onChange={(page, size) => {
|
|
setCurrentPage(page);
|
|
setPageSize(size);
|
|
loadOAuthList(page, size);
|
|
}}
|
|
size="small"
|
|
/>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
);
|
|
};
|
|
|
|
export default AuthAccountPage; |