import React, { useEffect, useState } from 'react'; import { Button, Card, Space, Table, Tag, Typography, message, Modal, Form, Input, Select, InputNumber, } from 'antd'; import { MenuOutlined, ReloadOutlined, PlusOutlined, EyeOutlined, EditOutlined, DeleteOutlined, } from '@ant-design/icons'; import { getOauthAppList, createOauthApp, getOauthApp, updateOauthApp, deleteOauthApp } from '../api'; import { formatDate } from '../utils/formatDate'; interface OAuthApp { id: string; appId: string; secret: string; status: number; count: number; openType: number; authUrl?: string; company?: string; createBy: string; createdAt: string; updatedAt: string; } const AdminOauthAppList: React.FC = () => { const [apps, setApps] = useState([]); const [total, setTotal] = useState(0); const [loading, setLoading] = useState(false); const [page, setPage] = useState(1); const [createModalVisible, setCreateModalVisible] = useState(false); const [detailModalVisible, setDetailModalVisible] = useState(false); const [updateModalVisible, setUpdateModalVisible] = useState(false); const [currentApp, setCurrentApp] = useState(null); const [form] = Form.useForm(); const [updateForm] = Form.useForm(); const load = async (p?: number) => { setLoading(true); try { const res = await getOauthAppList(p || page); setApps(res.items || []); setTotal(res.total || 0); } catch { message.error('加载应用管理列表失败'); } finally { setLoading(false); } }; const handleCreate = async () => { try { const values = await form.validateFields(); await createOauthApp({ app_id: values.app_id, secret: values.secret, open_type: values.open_type, count: values.count, auth_url: values.auth_url, company: values.company, }); message.success('创建成功'); setCreateModalVisible(false); form.resetFields(); load(); } catch (e: any) { message.error(e?.message || '创建失败'); } }; const handleDetail = async (id: string) => { try { const app = await getOauthApp(id); setCurrentApp(app); setDetailModalVisible(true); } catch (e: any) { message.error(e?.message || '获取详情失败'); } }; const handleUpdate = async (id: string) => { try { const app = await getOauthApp(id); setCurrentApp(app); updateForm.setFieldsValue({ app_id: app.appId, secret: app.secret, open_type: app.openType, count: app.count, auth_url: app.authUrl, company: app.company, }); setUpdateModalVisible(true); } catch (e: any) { message.error(e?.message || '获取详情失败'); } }; const handleSaveUpdate = async () => { if (!currentApp) return; try { const values = await updateForm.validateFields(); await updateOauthApp(currentApp.id, { app_id: values.app_id, secret: values.secret, open_type: values.open_type, count: values.count, auth_url: values.auth_url, company: values.company, }); message.success('更新成功'); setUpdateModalVisible(false); updateForm.resetFields(); load(); } catch (e: any) { message.error(e?.message || '更新失败'); } }; const handleDelete = (id: string) => { Modal.confirm({ title: '确认删除', content: '确定要删除这个应用管理吗?', okText: '删除', okType: 'danger', cancelText: '取消', onOk: async () => { try { await deleteOauthApp(id); message.success('删除成功'); load(); } catch (e: any) { message.error(e?.message || '删除失败'); } }, }); }; useEffect(() => { load(); }, []); const columns = [ { title: 'ID', dataIndex: 'id', render: (v: string) => {v}, }, { title: '应用ID', dataIndex: 'appId', render: (v: string) => {v}, }, { title: '应用密钥', dataIndex: 'secret', render: (v: string) => {v}, }, { title: '开户方式', dataIndex: 'openType', render: (v: number) => { const typeMap: Record = { 1: '千川', 2: '广告', 3: '本地推', 4: '星图', 5: '快手代理商', 6: '巨量星图', 7: '巨量服务单', 8: '腾讯服务单', 9: '腾讯营销K2', 10: '腾讯营销K3' }; return {typeMap[v] || v}; }, }, { title: '归属公司', dataIndex: 'company', render: (v: string) => {v}, }, { title: '授权次数', dataIndex: 'count', render: (v: number) => {v}, }, { title: '状态', dataIndex: 'status', render: (v: number) => {v === 1 ? '正常' : '禁用'}, }, { title: '授权URL', dataIndex: 'authUrl', render: (v: string) => {v}, }, { title: '创建人', dataIndex: 'createBy', render: (v: string) => {v}, }, { title: '创建时间', dataIndex: 'createdAt', render: (v: string) => {formatDate(v)}, }, { title: '更新时间', dataIndex: 'updatedAt', render: (v: string) => {formatDate(v)}, }, { title: '操作', render: (_: any, record: OAuthApp) => ( ), }, ]; return (
应用管理列表
`共 ${t} 条记录`, onChange: (p) => { setPage(p); load(p); }, }} scroll={{ x: 800 }} /> { setCreateModalVisible(false); form.resetFields(); }} okText="创建" cancelText="取消" width={600} >
{ setDetailModalVisible(false); setCurrentApp(null); }} okText="关闭" cancelText="取消" width={600} > {currentApp && (

ID: {currentApp.id}

应用ID: {currentApp.appId}

应用密钥: {currentApp.secret}

开户方式: {(() => { const typeMap: Record = { 1: '千川', 2: '广告', 3: '本地推', 4: '星图', 5: '快手代理商', 6: '巨量星图', 7: '巨量服务单', 8: '腾讯服务单', 9: '腾讯营销K2', 10: '腾讯营销K3' }; return typeMap[currentApp.openType] || currentApp.openType; })()}

归属公司: {currentApp.company || '-'}

授权次数: {currentApp.count}

状态: {currentApp.status === 1 ? '正常' : '禁用'}

授权URL: {currentApp.authUrl || '-'}

创建人: {currentApp.createBy}

创建时间: {formatDate(currentApp.createdAt)}

更新时间: {formatDate(currentApp.updatedAt)}

)}
{ setUpdateModalVisible(false); updateForm.resetFields(); setCurrentApp(null); }} okText="更新" cancelText="取消" width={600} >
); }; export default AdminOauthAppList;