|
|
@@ -120,6 +120,7 @@ import { ref, reactive, onMounted, computed, watch } from 'vue';
|
|
|
import { useRouter } from 'vue-router';
|
|
|
import { Setting, Link } from '@element-plus/icons-vue';
|
|
|
import { ElMessage, type FormInstance, type FormRules } from 'element-plus';
|
|
|
+import axios from 'axios';
|
|
|
import { useServerStore } from '@/stores/server';
|
|
|
import { useAuthStore } from '@/stores/auth';
|
|
|
import request from '@/api/request';
|
|
|
@@ -236,26 +237,38 @@ async function checkPythonService() {
|
|
|
ElMessage.warning('请先填写服务器地址');
|
|
|
return;
|
|
|
}
|
|
|
- if (!apiBaseUrl.value) {
|
|
|
- ElMessage.warning('请先填写服务器地址');
|
|
|
+ const url = pythonService.url ? normalizeBaseUrl(pythonService.url) : '';
|
|
|
+ if (!url) {
|
|
|
+ ElMessage.warning('请先填写 Python 服务地址');
|
|
|
return;
|
|
|
}
|
|
|
checkingPython.value = true;
|
|
|
pythonCheckResult.value = null;
|
|
|
try {
|
|
|
- const result = await request.post(
|
|
|
- '/api/system/python-service/check',
|
|
|
- { url: pythonService.url ? normalizeBaseUrl(pythonService.url) : undefined },
|
|
|
- { baseURL: apiBaseUrl.value }
|
|
|
- );
|
|
|
- pythonCheckResult.value = result;
|
|
|
- if (result.ok) {
|
|
|
- ElMessage.success('连接成功');
|
|
|
+ const electronApi = (window as any)?.electronAPI;
|
|
|
+ if (electronApi?.testPythonServiceConnection) {
|
|
|
+ const result = await electronApi.testPythonServiceConnection(url);
|
|
|
+ pythonCheckResult.value = { ok: result?.ok ?? false, error: result?.error };
|
|
|
+ if (result?.ok) {
|
|
|
+ ElMessage.success('连接成功');
|
|
|
+ } else {
|
|
|
+ ElMessage.error('连接失败');
|
|
|
+ }
|
|
|
} else {
|
|
|
- ElMessage.error('连接失败');
|
|
|
+ const healthUrl = `${url.replace(/\/$/, '')}/health`;
|
|
|
+ const res = await axios.get(healthUrl, { timeout: 5000 });
|
|
|
+ const ok = res.status >= 200 && res.status < 300;
|
|
|
+ pythonCheckResult.value = { ok, error: ok ? undefined : `HTTP ${res.status}` };
|
|
|
+ if (ok) {
|
|
|
+ ElMessage.success('连接成功');
|
|
|
+ } else {
|
|
|
+ ElMessage.error('连接失败');
|
|
|
+ }
|
|
|
}
|
|
|
- } catch {
|
|
|
- pythonCheckResult.value = { ok: false, error: '请求失败' };
|
|
|
+ } catch (e: unknown) {
|
|
|
+ const err = e as { message?: string };
|
|
|
+ const error = err?.message || '请求失败';
|
|
|
+ pythonCheckResult.value = { ok: false, error };
|
|
|
ElMessage.error('连接失败');
|
|
|
} finally {
|
|
|
checkingPython.value = false;
|