feat(testInstance): 添加测试实例链接功能

master
钟良源 2 weeks ago
parent d0a872511f
commit 0e68a74e70

@ -9,10 +9,11 @@ import {
deleteTestCase, deleteTestCase,
exportTemplate, exportTemplate,
exportTestCases, exportTestCases,
importTestCases importTestCases, startTestCase
} from '@/api/componentTestCase'; } from '@/api/componentTestCase';
import TestCaseModal from './testCaseModal'; import TestCaseModal from './testCaseModal';
import useWebSocket from '@/hooks/useWebSocket'; import useWebSocket from '@/hooks/useWebSocket';
import { getToken } from '@/utils/auth';
const CollapseItem = Collapse.Item; const CollapseItem = Collapse.Item;
@ -99,24 +100,27 @@ const TestInstance = ({ instance, parentId, onBack }: { instance: any; parentId:
}; };
// 链接实例 // 链接实例
const handleLinkInstance = () => { const handleLinkInstance = async () => {
if (isSocketConnected) { if (isSocketConnected) {
disconnect(); disconnect();
Message.info('已断开连接'); Message.info('已断开连接');
} }
else { else {
// WebSocket连接前置
const res: any = await startTestCase(instance.id);
console.log('res:', res);
// 构建WebSocket URL根据你的实际后端配置调整 // 构建WebSocket URL根据你的实际后端配置调整
const protocol = window.location.protocol === 'https:' ? 'wss:' : 'ws:'; const protocol = window.location.protocol === 'https:' ? 'wss:' : 'ws:';
const host = window.location.host; const host = window.location.host;
let wsUrl = ''; let wsUrl = '';
if (window.location.host.includes('localhost')) { if (window.location.host.includes('localhost')) {
wsUrl = `${process.env.NEXT_PUBLIC_DEV_SOCKET_HOST}/ws/v1/bpms-workbench/test-case/${instance.id}/${cryptoRandom()}`; wsUrl = `${process.env.NEXT_PUBLIC_DEV_SOCKET_HOST}/ws/v1/bpms-workbench/test-case/${instance.id}/${cryptoRandom()}?Authorization=Bearer ${getToken()}`;
} }
else { else {
wsUrl = `${protocol}//${host}/ws/v1/bpms-workbench/test-case/${instance.id}/${cryptoRandom()}`; wsUrl = `${protocol}//${host}/ws/v1/bpms-workbench/test-case/${instance.id}/${cryptoRandom()}?Authorization=Bearer ${getToken()}`;
} }
connect(wsUrl); connect(wsUrl);
addLog('正在连接测试实例...'); addLog('正在连接测试实例...');
} }
@ -311,6 +315,7 @@ const TestInstance = ({ instance, parentId, onBack }: { instance: any; parentId:
<div className={styles['tab-left']}> <div className={styles['tab-left']}>
<Button <Button
type="primary" type="primary"
status={isSocketConnected ?'danger' : 'default'}
icon={<IconLink />} icon={<IconLink />}
onClick={handleLinkInstance} onClick={handleLinkInstance}
style={{ minWidth: 250 }} style={{ minWidth: 250 }}

Loading…
Cancel
Save