From c493779a8504fe1eb548c865ff268a7f7436ec01 Mon Sep 17 00:00:00 2001
From: wanshenmean <cathay_xy@163.com>
Date: 星期四, 19 三月 2026 11:43:36 +0800
Subject: [PATCH] feat: 集成机械手客户端并重构模拟器前端工作台

---
 Code/WCS/WIDESEAWCS_S7Simulator/WIDESEAWCS_S7Simulator.Web/src/api/index.ts |   93 ++++++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 89 insertions(+), 4 deletions(-)

diff --git a/Code/WCS/WIDESEAWCS_S7Simulator/WIDESEAWCS_S7Simulator.Web/src/api/index.ts b/Code/WCS/WIDESEAWCS_S7Simulator/WIDESEAWCS_S7Simulator.Web/src/api/index.ts
index 4847b83..c45b917 100644
--- a/Code/WCS/WIDESEAWCS_S7Simulator/WIDESEAWCS_S7Simulator.Web/src/api/index.ts
+++ b/Code/WCS/WIDESEAWCS_S7Simulator/WIDESEAWCS_S7Simulator.Web/src/api/index.ts
@@ -1,8 +1,12 @@
-import axios from 'axios'
+锘縤mport axios from 'axios'
 import type {
   InstanceListItem,
   InstanceState,
-  InstanceConfig
+  InstanceConfig,
+  ProtocolTemplate,
+  RobotClientStartRequest,
+  RobotClientSendRequest,
+  RobotClientStatusResponse
 } from '../types'
 
 const api = axios.create({
@@ -18,7 +22,7 @@
   return response.data
 }
 
-// 鑾峰彇鎸囧畾瀹炰緥鐘舵��
+// 鑾峰彇瀹炰緥鐘舵��
 export async function getInstance(id: string): Promise<InstanceState | null> {
   try {
     const response = await api.get<InstanceState>('/SimulatorInstances/GetInstance', {
@@ -51,7 +55,7 @@
 // 鍒涘缓瀹炰緥
 export async function createInstance(config: InstanceConfig): Promise<InstanceState | null> {
   try {
-    const response = await api.post<InstanceState>('/SimulatorInstances/Create',  config )
+    const response = await api.post<InstanceState>('/SimulatorInstances/Create', config)
     return response.data
   } catch (error) {
     console.error('鍒涘缓瀹炰緥澶辫触:', error)
@@ -124,4 +128,85 @@
   }
 }
 
+export async function getProtocolTemplates(): Promise<ProtocolTemplate[]> {
+  const response = await api.get<ProtocolTemplate[]>('/ProtocolTemplates')
+  return response.data
+}
+
+export async function getProtocolTemplate(id: string): Promise<ProtocolTemplate | null> {
+  try {
+    const response = await api.get<ProtocolTemplate>(`/ProtocolTemplates/${id}`)
+    return response.data
+  } catch (error) {
+    if (axios.isAxiosError(error) && error.response?.status === 404) {
+      return null
+    }
+    throw error
+  }
+}
+
+export async function createProtocolTemplate(template: ProtocolTemplate): Promise<ProtocolTemplate> {
+  const response = await api.post<ProtocolTemplate>('/ProtocolTemplates', template)
+  return response.data
+}
+
+export async function updateProtocolTemplate(id: string, template: ProtocolTemplate): Promise<ProtocolTemplate> {
+  const response = await api.put<ProtocolTemplate>(`/ProtocolTemplates/${id}`, template)
+  return response.data
+}
+
+export async function deleteProtocolTemplate(id: string): Promise<void> {
+  await api.delete(`/ProtocolTemplates/${id}`)
+}
+
+export async function readMemory(id: string): Promise<Record<string, string>> {
+  const response = await api.get<Record<string, string>>('/Memory/ReadMemory', {
+    params: { id }
+  })
+  return response.data
+}
+
+export async function writeMemory(id: string, data: Record<string, string>): Promise<boolean> {
+  try {
+    await api.post('/Memory/WriteMemory', data, {
+      params: { id }
+    })
+    return true
+  } catch (error) {
+    console.error('鍐欏叆鍐呭瓨澶辫触:', error)
+    return false
+  }
+}
+
+// 鑾峰彇鏈烘鎵嬫湇鍔$杩愯鐘舵�侊紙鍖呭惈澶氬疄渚嬪拰鎺ユ敹娑堟伅鏃ュ織锛�
+export async function getRobotClientStatus(): Promise<RobotClientStatusResponse> {
+  const response = await api.get<RobotClientStatusResponse>('/RobotClients/status')
+  return response.data
+}
+
+// 鍚姩涓�涓満姊版墜鏈嶅姟绔疄渚�
+export async function startRobotClients(request: RobotClientStartRequest): Promise<RobotClientStatusResponse> {
+  const response = await api.post<RobotClientStatusResponse>('/RobotClients/start', request)
+  return response.data
+}
+
+// 鍋滄鏈烘鎵嬫湇鍔$锛宻erverId 涓虹┖鏃跺仠姝㈠叏閮�
+export async function stopRobotClients(serverId?: string): Promise<void> {
+  await api.post('/RobotClients/stop', null, {
+    params: { serverId }
+  })
+}
+
+// 鍙戦�佹満姊版墜娑堟伅锛堟寜鏈嶅姟绔疄渚嬪箍鎾垨鍗曞彂锛�
+export async function sendRobotClientMessage(request: RobotClientSendRequest): Promise<void> {
+  await api.post('/RobotClients/send', request)
+}
+
+// 娓呯┖鎸囧畾鏈嶅姟绔疄渚嬬殑鎺ユ敹娑堟伅鏃ュ織
+export async function clearRobotClientReceivedMessages(serverId: string): Promise<void> {
+  await api.post('/RobotClients/clear-received', null, {
+    params: { serverId }
+  })
+}
+
 export default api

--
Gitblit v1.9.3