完成开户方式的修改

This commit is contained in:
Lrd
2026-06-26 14:52:13 +08:00
parent 157e7e5bba
commit 7e2a44c0a1
9 changed files with 260 additions and 213 deletions
+12
View File
@@ -470,6 +470,18 @@ export async function deleteOpenType(id: string): Promise<void> {
await api.delete(`/open-type/delete/${id}`);
}
export interface OpenTypeItem {
id: string;
openType: number;
typeName: string;
description: string;
thumb?: string;
}
export async function getOpenTypeAll(): Promise<{ data: OpenTypeItem[] }> {
return api.get('/open-type/open_type_all');
}
// ── Generation Records (Admin) ─────────────────────────────
export async function getAdminGenerationRecords(params?: {
+24 -33
View File
@@ -2,20 +2,7 @@ import React, { useEffect, useState } from 'react';
import { Link } from 'react-router-dom';
import { Button, Card, Space, Table, Tag, Modal, Select, App, Input, Typography } from 'antd';
import { PlusOutlined, LockOutlined } from '@ant-design/icons';
import { getOAuthList, requestOAuth } from '../api';
const OPEN_TYPE_MAP: Record<number, string> = {
1: '千川',
2: '广告',
3: '本地推',
4: '星图',
5: '快手代理商',
6: '巨量星图',
7: '巨量服务单',
8: '腾讯服务单',
9: '腾讯营销K2',
10: '腾讯营销K3',
};
import { getOAuthList, requestOAuth, getOpenTypeAll } from '../api';
const PORT_TYPE_MAP: Record<number, string> = {
1: '巨量',
@@ -62,11 +49,31 @@ const AuthorizationPage: React.FC = () => {
open_type: undefined as number | undefined,
account_id: '',
});
const [openTypeMap, setOpenTypeMap] = useState<Record<number, string>>({});
const [openTypeOptions, setOpenTypeOptions] = useState<{ value: number; label: 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);
setOpenTypeOptions(options);
} catch (error) {
console.error('加载开户方式列表失败:', error);
}
};
const loadOAuthList = async (page = 1, pageSize = 10, params = searchParams) => {
setListLoading(true);
try {
@@ -197,7 +204,7 @@ const AuthorizationPage: React.FC = () => {
title: '开户方式',
dataIndex: 'openType',
key: 'openType',
render: (text: number) => <span style={{ color: '#1e293b' }}>{OPEN_TYPE_MAP[text] || text}</span>,
render: (text: number) => <span style={{ color: '#1e293b' }}>{openTypeMap[text] || text}</span>,
},
{
title: '平台端口',
@@ -225,16 +232,6 @@ const AuthorizationPage: React.FC = () => {
width: 160,
render: (text: string) => <span style={{ color: '#64748b' }}>{formatDateTime(text)}</span>,
},
{
title: '操作',
key: 'action',
width: 120,
render: (_: unknown, record: AuthorizationData) => (
<Link to={`/consume?accountId=${record.id}`} style={{ color: '#6366f1' }}>
</Link>
),
},
];
const tableData = authorizations.map((item, index) => ({
@@ -279,10 +276,7 @@ const AuthorizationPage: React.FC = () => {
value={searchParams.open_type}
onChange={(value) => setSearchParams(prev => ({ ...prev, open_type: value }))}
style={{ width: 140 }}
options={Object.entries(OPEN_TYPE_MAP).map(([key, value]) => ({
value: Number(key),
label: value,
}))}
options={openTypeOptions}
/>
<Input
placeholder="账号ID"
@@ -349,10 +343,7 @@ const AuthorizationPage: React.FC = () => {
value={selectedOpenType}
onChange={(value) => setSelectedOpenType(value)}
style={{ width: '100%' }}
options={Object.entries(OPEN_TYPE_MAP).map(([key, value]) => ({
value: Number(key),
label: value,
}))}
options={openTypeOptions}
/>
</Modal>
</div>
+19 -8
View File
@@ -78,11 +78,13 @@ const AdminPlatform: React.FC = () => {
const handleCreate = async () => {
try {
const values = await createForm.validateFields();
const thumbUrl = createThumbUrl;
const thumbPath = thumbUrl.startsWith('http') ? thumbUrl.replace(/^https?:\/\/[^/]+/, '') : thumbUrl;
await createOpenType({
open_type: values.open_type,
type_name: values.type_name,
description: values.description,
thumb: createThumbUrl,
thumb: thumbPath,
});
message.success('创建成功');
setCreateModalVisible(false);
@@ -107,8 +109,11 @@ const AdminPlatform: React.FC = () => {
const handleUpdate = async (id: string) => {
try {
const openType = await getOpenType(id);
const thumb = openType.data?.thumb || '';
const baseUrl = import.meta.env.VITE_API_BASE || 'http://localhost:8000';
const fullThumbUrl = thumb.startsWith('http') ? thumb : `${baseUrl}${thumb}`;
setCurrentOpenType(openType.data || {});
setUpdateThumbUrl(openType.thumb || '');
setUpdateThumbUrl(fullThumbUrl);
setUpdateModalVisible(true);
} catch (e: any) {
message.error(e?.message || '获取详情失败');
@@ -119,11 +124,13 @@ const AdminPlatform: React.FC = () => {
if (!currentOpenType) return;
try {
const values = await updateForm.validateFields();
const thumbUrl = updateThumbUrl;
const thumbPath = thumbUrl.startsWith('http') ? thumbUrl.replace(/^https?:\/\/[^/]+/, '') : thumbUrl;
await updateOpenType(currentOpenType.id, {
open_type: values.open_type,
type_name: values.type_name,
description: values.description,
thumb: updateThumbUrl,
thumb: thumbPath,
});
message.success('更新成功');
setUpdateModalVisible(false);
@@ -218,7 +225,7 @@ const AdminPlatform: React.FC = () => {
},
{
title: '操作',
width: 200,
width: 240,
render: (_: any, record: OpenType) => (
<Space>
<Button
@@ -337,8 +344,10 @@ const AdminPlatform: React.FC = () => {
try {
const uploadFile = assertUploadFile(file);
const res = await uploadImage(uploadFile);
setCreateThumbUrl(res.url);
onSuccess?.({ url: res.url });
const baseUrl = import.meta.env.VITE_API_BASE || 'http://localhost:8000';
const fullUrl = res.url.startsWith('http') ? res.url : `${baseUrl}${res.url}`;
setCreateThumbUrl(fullUrl);
onSuccess?.({ url: fullUrl });
} catch (e) {
onError?.(normalizeUploadError(e));
}
@@ -481,8 +490,10 @@ const AdminPlatform: React.FC = () => {
try {
const uploadFile = assertUploadFile(file);
const res = await uploadImage(uploadFile);
setUpdateThumbUrl(res.url);
onSuccess?.({ url: res.url });
const baseUrl = import.meta.env.VITE_API_BASE || 'http://localhost:8000';
const fullUrl = res.url.startsWith('http') ? res.url : `${baseUrl}${res.url}`;
setUpdateThumbUrl(fullUrl);
onSuccess?.({ url: fullUrl });
} catch (e) {
onError?.(normalizeUploadError(e));
}