227 lines
6.1 KiB
TypeScript
227 lines
6.1 KiB
TypeScript
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;
|
||
}
|
||
|
||
// 流量池类型
|
||
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;
|
||
}
|
||
|
||
// 流量分发规则类型
|
||
export interface DistributionRule {
|
||
id: number;
|
||
name: string;
|
||
type: number;
|
||
status: number;
|
||
autoStart: number;
|
||
createTime: string;
|
||
updateTime: string;
|
||
companyId: number;
|
||
config?: {
|
||
id: number;
|
||
workbenchId: number;
|
||
distributeType: number; // 1-均分配, 2-优先级分配, 3-比例分配
|
||
maxPerDay: number; // 每日最大分配量
|
||
timeType: number; // 1-全天, 2-自定义时间段
|
||
startTime: string; // 开始时间
|
||
endTime: string; // 结束时间
|
||
account: string[]; // 账号列表
|
||
devices: string[]; // 设备列表
|
||
pools: string[]; // 流量池列表
|
||
createTime: string;
|
||
updateTime: string;
|
||
lastUpdated: string;
|
||
total: {
|
||
dailyAverage: number; // 日均分发量
|
||
totalAccounts: number; // 分发账户总数
|
||
deviceCount: number; // 分发设备数量
|
||
poolCount: number; // 流量池数量
|
||
totalUsers: number; // 总用户数
|
||
};
|
||
};
|
||
auto_like?: any;
|
||
moments_sync?: any;
|
||
group_push?: any;
|
||
}
|
||
|
||
// 流量分发列表响应类型
|
||
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()}`);
|
||
};
|
||
|
||
/**
|
||
* 获取设备标签(流量池)列表
|
||
* @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()}`);
|
||
};
|
||
|
||
/**
|
||
* 获取流量分发规则列表
|
||
* @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=${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 post<ApiResponse<any>>(`/v1/workbench/update`, {
|
||
id: 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=${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 });
|
||
};
|