feat: 本次提交更新内容如下
暂时构建完成,
This commit is contained in:
@@ -117,9 +117,9 @@ export const deleteDistributionRule = async (id: string): Promise<ApiResponse<an
|
||||
/**
|
||||
* 启动/暂停流量分发规则
|
||||
* @param id 规则ID
|
||||
* @param status 状态:1-启动,2-暂停
|
||||
* @param status 状态:1-启动,0-暂停
|
||||
* @returns 操作结果
|
||||
*/
|
||||
export const toggleDistributionRuleStatus = async (id: string, status: WorkbenchTaskStatus.RUNNING | WorkbenchTaskStatus.PAUSED): Promise<ApiResponse<any>> => {
|
||||
return put<ApiResponse<any>>(`/v1/workbench/status/${id}`, { status });
|
||||
export const toggleDistributionRuleStatus = async (id: string, status: 0 | 1): Promise<ApiResponse<any>> => {
|
||||
return post<ApiResponse<any>>('/v1/workbench/update-status', { id, status });
|
||||
};
|
||||
@@ -89,23 +89,25 @@ export default function TrafficDistribution() {
|
||||
if (!rule) return;
|
||||
|
||||
try {
|
||||
setIsLoading(true);
|
||||
const newStatus = rule.status === WorkbenchTaskStatus.RUNNING
|
||||
? WorkbenchTaskStatus.PAUSED
|
||||
: WorkbenchTaskStatus.RUNNING;
|
||||
|
||||
// 根据当前状态决定新状态:1表示开启,0表示关闭
|
||||
const newStatus = rule.status === WorkbenchTaskStatus.RUNNING ? 0 : 1;
|
||||
|
||||
const response = await toggleDistributionRuleStatus(ruleId, newStatus);
|
||||
const response = await toggleDistributionRuleStatus(ruleId, newStatus as 0 | 1);
|
||||
|
||||
if (response.code === 200) {
|
||||
// 更新本地状态:1对应RUNNING,0对应PAUSED
|
||||
const updatedStatus = newStatus === 1 ? WorkbenchTaskStatus.RUNNING : WorkbenchTaskStatus.PAUSED;
|
||||
|
||||
setTasks(
|
||||
tasks.map((task) =>
|
||||
task.id === ruleId ? { ...task, status: newStatus } : task
|
||||
task.id === ruleId ? { ...task, status: updatedStatus } : task
|
||||
)
|
||||
);
|
||||
|
||||
toast({
|
||||
title: newStatus === WorkbenchTaskStatus.RUNNING ? '已启动' : '已暂停',
|
||||
description: `${rule.name}规则${newStatus === WorkbenchTaskStatus.RUNNING ? '已启动' : '已暂停'}`,
|
||||
title: newStatus === 1 ? '已启动' : '已暂停',
|
||||
description: `${rule.name}规则${newStatus === 1 ? '已启动' : '已暂停'}`,
|
||||
});
|
||||
} else {
|
||||
toast({
|
||||
@@ -121,9 +123,7 @@ export default function TrafficDistribution() {
|
||||
description: '操作失败,请稍后重试',
|
||||
variant: 'destructive',
|
||||
});
|
||||
} finally {
|
||||
setIsLoading(false);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const handleCreateNew = () => {
|
||||
@@ -316,7 +316,7 @@ export default function TrafficDistribution() {
|
||||
<Card key={rule.id} className="overflow-hidden">
|
||||
<div className="p-4">
|
||||
<div className="flex justify-between items-center">
|
||||
<h3 className="font-medium text-lg">流量分发</h3>
|
||||
<h3 className="font-medium text-lg">{rule.name || '未命名计划'}</h3>
|
||||
<div className="flex items-center space-x-2">
|
||||
<Badge className={rule.status === WorkbenchTaskStatus.RUNNING ? "bg-blue-100 text-blue-800" : "bg-gray-100 text-gray-800"}>
|
||||
{getStatusText(rule.status)}
|
||||
|
||||
Reference in New Issue
Block a user