2025-07-10 15:05:10 +08:00
|
|
|
|
import { get, post, put, del } from './request';
|
|
|
|
|
|
import type { ApiResponse } from '@/types/common';
|
|
|
|
|
|
|
|
|
|
|
|
// 工作台任务类型
|
|
|
|
|
|
export enum WorkbenchTaskType {
|
|
|
|
|
|
MOMENTS_SYNC = 1, // 朋友圈同步
|
|
|
|
|
|
GROUP_PUSH = 2, // 社群推送
|
|
|
|
|
|
AUTO_LIKE = 3, // 自动点赞
|
|
|
|
|
|
AUTO_GROUP = 4, // 自动建群
|
|
|
|
|
|
TRAFFIC_DISTRIBUTION = 5, // 流量分发
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 工作台任务状态
|
|
|
|
|
|
export enum WorkbenchTaskStatus {
|
|
|
|
|
|
PENDING = 0, // 待处理
|
|
|
|
|
|
RUNNING = 1, // 运行中
|
|
|
|
|
|
PAUSED = 2, // 已暂停
|
|
|
|
|
|
COMPLETED = 3, // 已完成
|
|
|
|
|
|
FAILED = 4, // 失败
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 账号类型
|
|
|
|
|
|
export interface Account {
|
|
|
|
|
|
id: string;
|
|
|
|
|
|
userName: string;
|
|
|
|
|
|
realName: string;
|
|
|
|
|
|
nickname: string;
|
|
|
|
|
|
memo: string;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 账号列表响应类型
|
|
|
|
|
|
export interface AccountListResponse {
|
|
|
|
|
|
list: Account[];
|
|
|
|
|
|
total: number;
|
|
|
|
|
|
page: number;
|
|
|
|
|
|
limit: number;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-07-10 16:36:51 +08:00
|
|
|
|
// 流量池类型
|
|
|
|
|
|
export interface TrafficPool {
|
|
|
|
|
|
id: string;
|
|
|
|
|
|
name: string;
|
|
|
|
|
|
count: number;
|
|
|
|
|
|
description?: string;
|
|
|
|
|
|
deviceIds: string[];
|
|
|
|
|
|
createTime?: string;
|
|
|
|
|
|
updateTime?: string;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 流量池列表响应类型
|
|
|
|
|
|
export interface TrafficPoolListResponse {
|
|
|
|
|
|
list: TrafficPool[];
|
|
|
|
|
|
total: number;
|
|
|
|
|
|
page: number;
|
|
|
|
|
|
pageSize: number;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-07-10 15:05:10 +08:00
|
|
|
|
// 流量分发规则类型
|
|
|
|
|
|
export interface DistributionRule {
|
|
|
|
|
|
id: string;
|
|
|
|
|
|
name: string;
|
|
|
|
|
|
status: number;
|
|
|
|
|
|
deviceCount: number;
|
|
|
|
|
|
totalTraffic: number;
|
|
|
|
|
|
distributedTraffic: number;
|
|
|
|
|
|
lastDistributionTime: string;
|
|
|
|
|
|
createTime: string;
|
|
|
|
|
|
creator: string;
|
|
|
|
|
|
distributionInterval: number;
|
|
|
|
|
|
maxDistributionPerDay: number;
|
|
|
|
|
|
timeRange: { start: string; end: string };
|
|
|
|
|
|
targetChannels?: string[];
|
|
|
|
|
|
distributionRatio?: Record<string, number>;
|
|
|
|
|
|
priority?: 'high' | 'medium' | 'low';
|
|
|
|
|
|
filterConditions?: string[];
|
|
|
|
|
|
config?: {
|
|
|
|
|
|
total?: {
|
|
|
|
|
|
dailyAverage: number; // 日均分发量
|
|
|
|
|
|
deviceCount: number; // 分发设备
|
|
|
|
|
|
poolCount: string; // 流量池
|
|
|
|
|
|
totalAccounts: number; // 分发账户
|
|
|
|
|
|
totalUsers: number; // 总用户数
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 流量分发列表响应类型
|
|
|
|
|
|
export interface TrafficDistributionListResponse {
|
|
|
|
|
|
list: DistributionRule[];
|
|
|
|
|
|
total: number;
|
|
|
|
|
|
page: number;
|
|
|
|
|
|
limit: number;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 获取账号列表
|
|
|
|
|
|
* @param params 查询参数
|
|
|
|
|
|
* @returns 账号列表
|
|
|
|
|
|
*/
|
|
|
|
|
|
export const fetchAccountList = async (params: {
|
|
|
|
|
|
page?: number; // 页码
|
|
|
|
|
|
limit?: number; // 每页数量
|
|
|
|
|
|
keyword?: string; // 搜索关键词
|
|
|
|
|
|
} = {}): Promise<ApiResponse<AccountListResponse>> => {
|
|
|
|
|
|
const { page = 1, limit = 10, keyword = "" } = params;
|
|
|
|
|
|
|
|
|
|
|
|
const queryParams = new URLSearchParams();
|
|
|
|
|
|
queryParams.append('page', page.toString());
|
|
|
|
|
|
queryParams.append('limit', limit.toString());
|
|
|
|
|
|
|
|
|
|
|
|
if (keyword) {
|
|
|
|
|
|
queryParams.append('keyword', keyword);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return get<ApiResponse<AccountListResponse>>(`/v1/workbench/account-list?${queryParams.toString()}`);
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2025-07-10 16:36:51 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* 获取设备标签(流量池)列表
|
|
|
|
|
|
* @param params 查询参数
|
|
|
|
|
|
* @returns 流量池列表
|
|
|
|
|
|
*/
|
|
|
|
|
|
export const fetchDeviceLabels = async (params: {
|
|
|
|
|
|
deviceIds: string[]; // 设备ID列表
|
|
|
|
|
|
page?: number; // 页码
|
|
|
|
|
|
pageSize?: number; // 每页数量
|
|
|
|
|
|
keyword?: string; // 搜索关键词
|
|
|
|
|
|
}): Promise<ApiResponse<TrafficPoolListResponse>> => {
|
|
|
|
|
|
const { deviceIds, page = 1, pageSize = 10, keyword = "" } = params;
|
|
|
|
|
|
|
|
|
|
|
|
const queryParams = new URLSearchParams();
|
|
|
|
|
|
queryParams.append('deviceIds', deviceIds.join(','));
|
|
|
|
|
|
queryParams.append('page', page.toString());
|
|
|
|
|
|
queryParams.append('pageSize', pageSize.toString());
|
|
|
|
|
|
|
|
|
|
|
|
if (keyword) {
|
|
|
|
|
|
queryParams.append('keyword', keyword);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return get<ApiResponse<TrafficPoolListResponse>>(`/v1/workbench/device-labels?${queryParams.toString()}`);
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2025-07-10 15:05:10 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* 获取流量分发规则列表
|
|
|
|
|
|
* @param params 查询参数
|
|
|
|
|
|
* @returns 流量分发规则列表
|
|
|
|
|
|
*/
|
|
|
|
|
|
export const fetchDistributionRules = async (params: {
|
|
|
|
|
|
page?: number;
|
|
|
|
|
|
limit?: number;
|
|
|
|
|
|
keyword?: string;
|
|
|
|
|
|
} = {}): Promise<ApiResponse<TrafficDistributionListResponse>> => {
|
|
|
|
|
|
const { page = 1, limit = 10, keyword = "" } = params;
|
|
|
|
|
|
|
|
|
|
|
|
const queryParams = new URLSearchParams();
|
|
|
|
|
|
queryParams.append('type', WorkbenchTaskType.TRAFFIC_DISTRIBUTION.toString());
|
|
|
|
|
|
queryParams.append('page', page.toString());
|
|
|
|
|
|
queryParams.append('limit', limit.toString());
|
|
|
|
|
|
|
|
|
|
|
|
if (keyword) {
|
|
|
|
|
|
queryParams.append('keyword', keyword);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return get<ApiResponse<TrafficDistributionListResponse>>(`/v1/workbench/list?${queryParams.toString()}`);
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 获取流量分发规则详情
|
|
|
|
|
|
* @param id 规则ID
|
|
|
|
|
|
* @returns 流量分发规则详情
|
|
|
|
|
|
*/
|
|
|
|
|
|
export const fetchDistributionRuleDetail = async (id: string): Promise<ApiResponse<DistributionRule>> => {
|
|
|
|
|
|
return get<ApiResponse<DistributionRule>>(`/v1/workbench/detail/${id}`);
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 创建流量分发规则
|
|
|
|
|
|
* @param params 创建参数
|
|
|
|
|
|
* @returns 创建结果
|
|
|
|
|
|
*/
|
|
|
|
|
|
export const createDistributionRule = async (params: any): Promise<ApiResponse<{ id: string }>> => {
|
|
|
|
|
|
return post<ApiResponse<{ id: string }>>('/v1/workbench/create', {
|
|
|
|
|
|
...params,
|
|
|
|
|
|
type: WorkbenchTaskType.TRAFFIC_DISTRIBUTION
|
|
|
|
|
|
});
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 更新流量分发规则
|
|
|
|
|
|
* @param id 规则ID
|
|
|
|
|
|
* @param params 更新参数
|
|
|
|
|
|
* @returns 更新结果
|
|
|
|
|
|
*/
|
|
|
|
|
|
export const updateDistributionRule = async (id: string, params: any): Promise<ApiResponse<any>> => {
|
|
|
|
|
|
return put<ApiResponse<any>>(`/v1/workbench/update/${id}`, {
|
|
|
|
|
|
...params,
|
|
|
|
|
|
type: WorkbenchTaskType.TRAFFIC_DISTRIBUTION
|
|
|
|
|
|
});
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 删除流量分发规则
|
|
|
|
|
|
* @param id 规则ID
|
|
|
|
|
|
* @returns 删除结果
|
|
|
|
|
|
*/
|
|
|
|
|
|
export const deleteDistributionRule = async (id: string): Promise<ApiResponse<any>> => {
|
|
|
|
|
|
return del<ApiResponse<any>>(`/v1/workbench/delete/${id}`);
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 启动/暂停流量分发规则
|
|
|
|
|
|
* @param id 规则ID
|
|
|
|
|
|
* @param status 状态:1-启动,0-暂停
|
|
|
|
|
|
* @returns 操作结果
|
|
|
|
|
|
*/
|
|
|
|
|
|
export const toggleDistributionRuleStatus = async (id: string, status: 0 | 1): Promise<ApiResponse<any>> => {
|
|
|
|
|
|
return post<ApiResponse<any>>('/v1/workbench/update-status', { id, status });
|
2025-07-10 10:57:26 +08:00
|
|
|
|
};
|