支持大文件
This commit is contained in:
@@ -5,6 +5,7 @@ import { SettingOutlined, UploadOutlined, UserOutlined, WindowsOutlined, Loading
|
||||
import { useRouter, useRoute } from 'vue-router';
|
||||
import { Command } from '@tauri-apps/plugin-shell';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import { ErrorCode, createErrorInfo } from './utils/errorCodes';
|
||||
|
||||
const router = useRouter();
|
||||
const route = useRoute();
|
||||
@@ -82,9 +83,11 @@ async function runCoreProcess() {
|
||||
|
||||
if (portStatus === 'wrong_app') {
|
||||
// 端口被其他应用占用
|
||||
const errorInfo = createErrorInfo(ErrorCode.BACKEND_PORT_OCCUPIED);
|
||||
backendStatus.value = 'error';
|
||||
backendErrorInfo.value = t('message.backend_port_occupied');
|
||||
message.error(t('message.backend_port_occupied'));
|
||||
backendErrorInfo.value = `${errorInfo.message} (错误码: ${errorInfo.code})`;
|
||||
message.error(backendErrorInfo.value);
|
||||
router.push(`/error?e=${encodeURIComponent(backendErrorInfo.value)}&code=${errorInfo.code}`);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -105,15 +108,19 @@ async function runCoreProcess() {
|
||||
backendErrorInfo.value = '';
|
||||
message.success(t('message.backend_started'));
|
||||
} else {
|
||||
const errorInfo = createErrorInfo(ErrorCode.BACKEND_RESPONSE_ERROR, `HTTP 状态码: ${response.status}`);
|
||||
backendStatus.value = 'error';
|
||||
backendErrorInfo.value = t('common.status_error');
|
||||
router.push('/error');
|
||||
backendErrorInfo.value = `${errorInfo.message} (错误码: ${errorInfo.code})`;
|
||||
message.error(backendErrorInfo.value);
|
||||
router.push(`/error?e=${encodeURIComponent(backendErrorInfo.value)}&code=${errorInfo.code}`);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("后端连接失败:", error);
|
||||
const errorInfo = createErrorInfo(ErrorCode.BACKEND_CONNECTION_FAILED, error instanceof Error ? error.message : String(error));
|
||||
backendStatus.value = 'error';
|
||||
backendErrorInfo.value = t('common.status_error');
|
||||
router.push('/error');
|
||||
backendErrorInfo.value = `${errorInfo.message} (错误码: ${errorInfo.code})`;
|
||||
message.error(backendErrorInfo.value);
|
||||
router.push(`/error?e=${encodeURIComponent(backendErrorInfo.value)}&code=${errorInfo.code}`);
|
||||
}
|
||||
}, 3000); // 等待3秒让后端启动
|
||||
})
|
||||
@@ -127,9 +134,11 @@ async function runCoreProcess() {
|
||||
runCoreProcess();
|
||||
}, 2000);
|
||||
} else {
|
||||
const errorInfo = createErrorInfo(ErrorCode.BACKEND_START_FAILED, `已重试 ${maxRetries} 次`);
|
||||
backendStatus.value = 'error';
|
||||
backendErrorInfo.value = t('message.backend_start_failed', { count: maxRetries });
|
||||
message.error(t('message.backend_start_failed', { count: maxRetries }));
|
||||
backendErrorInfo.value = `${errorInfo.message} (错误码: ${errorInfo.code})`;
|
||||
message.error(backendErrorInfo.value);
|
||||
router.push(`/error?e=${encodeURIComponent(backendErrorInfo.value)}&code=${errorInfo.code}`);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ import { ref, inject, watch, onUnmounted } from 'vue';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import { message, notification } from 'ant-design-vue';
|
||||
import { sendNotification } from '@tauri-apps/plugin-notification';
|
||||
import { ErrorCode, createErrorInfo } from '../utils/errorCodes';
|
||||
|
||||
const { t } = useI18n();
|
||||
|
||||
@@ -239,61 +240,49 @@ onUnmounted(() => {
|
||||
function handleError(result: any) {
|
||||
if (result === 'jini') {
|
||||
javaAvailable.value = false;
|
||||
const errorInfo = createErrorInfo(ErrorCode.JAVA_NOT_FOUND);
|
||||
notification.error({
|
||||
message: t('home.java_error_title'),
|
||||
description: t('home.java_error_desc'),
|
||||
message: `${t('home.java_error_title')} (错误码: ${errorInfo.code})`,
|
||||
description: `${t('home.java_error_desc')}\n\n${t('home.suggestions')}:\n${errorInfo.suggestions?.map((s, i) => `${i + 1}. ${s}`).join('\n')}`,
|
||||
duration: 0
|
||||
});
|
||||
} else if (typeof result === 'string') {
|
||||
let errorTitle = t('home.backend_error');
|
||||
let errorDesc = t('home.backend_error_desc', { error: result });
|
||||
let suggestions: string[] = [];
|
||||
let errorInfo;
|
||||
|
||||
if (result.includes('network') || result.includes('connection') || result.includes('timeout')) {
|
||||
errorTitle = t('home.network_error_title');
|
||||
errorDesc = t('home.network_error_desc', { error: result });
|
||||
suggestions = [
|
||||
t('home.suggestion_check_network'),
|
||||
t('home.suggestion_check_firewall'),
|
||||
t('home.suggestion_retry')
|
||||
];
|
||||
errorInfo = createErrorInfo(ErrorCode.NETWORK_ERROR, result);
|
||||
} else if (result.includes('file') || result.includes('permission') || result.includes('disk')) {
|
||||
errorTitle = t('home.file_error_title');
|
||||
errorDesc = t('home.file_error_desc', { error: result });
|
||||
suggestions = [
|
||||
t('home.suggestion_check_disk_space'),
|
||||
t('home.suggestion_check_permission'),
|
||||
t('home.suggestion_check_file_format')
|
||||
];
|
||||
if (result.includes('not found')) {
|
||||
errorInfo = createErrorInfo(ErrorCode.FILE_NOT_FOUND, result);
|
||||
} else if (result.includes('permission')) {
|
||||
errorInfo = createErrorInfo(ErrorCode.FILE_PERMISSION_ERROR, result);
|
||||
} else if (result.includes('format')) {
|
||||
errorInfo = createErrorInfo(ErrorCode.FILE_FORMAT_ERROR, result);
|
||||
} else {
|
||||
errorInfo = createErrorInfo(ErrorCode.FILE_NOT_FOUND, result);
|
||||
}
|
||||
} else if (result.includes('memory') || result.includes('out of memory') || result.includes('heap')) {
|
||||
errorTitle = t('home.memory_error_title');
|
||||
errorDesc = t('home.memory_error_desc', { error: result });
|
||||
suggestions = [
|
||||
t('home.suggestion_increase_memory'),
|
||||
t('home.suggestion_close_other_apps'),
|
||||
t('home.suggestion_restart_application')
|
||||
];
|
||||
errorInfo = createErrorInfo(ErrorCode.MEMORY_INSUFFICIENT, result);
|
||||
} else if (result.includes('disk') || result.includes('space')) {
|
||||
errorInfo = createErrorInfo(ErrorCode.DISK_SPACE_INSUFFICIENT, result);
|
||||
} else {
|
||||
suggestions = [
|
||||
t('home.suggestion_check_backend'),
|
||||
t('home.suggestion_check_logs'),
|
||||
t('home.suggestion_contact_support')
|
||||
];
|
||||
errorInfo = createErrorInfo(ErrorCode.UNKNOWN_ERROR, result);
|
||||
}
|
||||
|
||||
const fullDescription = `${errorDesc}\n\n${t('home.suggestions')}:\n${suggestions.map((s, i) => `${i + 1}. ${s}`).join('\n')}`;
|
||||
const fullDescription = `${errorInfo.message}: ${errorInfo.details}\n\n${t('home.suggestions')}:\n${errorInfo.suggestions?.map((s, i) => `${i + 1}. ${s}`).join('\n')}`;
|
||||
|
||||
notification.error({
|
||||
message: errorTitle,
|
||||
message: `${errorInfo.message} (错误码: ${errorInfo.code})`,
|
||||
description: fullDescription,
|
||||
duration: 0
|
||||
});
|
||||
|
||||
resetState();
|
||||
} else {
|
||||
const errorInfo = createErrorInfo(ErrorCode.UNKNOWN_ERROR);
|
||||
notification.error({
|
||||
message: t('home.unknown_error_title'),
|
||||
description: t('home.unknown_error_desc'),
|
||||
message: `${t('home.unknown_error_title')} (错误码: ${errorInfo.code})`,
|
||||
description: `${t('home.unknown_error_desc')}\n\n${t('home.suggestions')}:\n${errorInfo.suggestions?.map((s, i) => `${i + 1}. ${s}`).join('\n')}`,
|
||||
duration: 0
|
||||
});
|
||||
resetState();
|
||||
|
||||
153
front/src/utils/errorCodes.ts
Normal file
153
front/src/utils/errorCodes.ts
Normal file
@@ -0,0 +1,153 @@
|
||||
// 错误码定义
|
||||
export enum ErrorCode {
|
||||
// 后端启动相关错误
|
||||
BACKEND_START_FAILED = 1001,
|
||||
BACKEND_PORT_OCCUPIED = 1002,
|
||||
BACKEND_CONNECTION_FAILED = 1003,
|
||||
BACKEND_RESPONSE_ERROR = 1004,
|
||||
|
||||
// 网络相关错误
|
||||
NETWORK_ERROR = 2001,
|
||||
NETWORK_TIMEOUT = 2002,
|
||||
NETWORK_CONNECTION_REFUSED = 2003,
|
||||
|
||||
// 文件相关错误
|
||||
FILE_NOT_FOUND = 3001,
|
||||
FILE_PERMISSION_ERROR = 3002,
|
||||
FILE_FORMAT_ERROR = 3003,
|
||||
FILE_SIZE_ERROR = 3004,
|
||||
|
||||
// 系统相关错误
|
||||
JAVA_NOT_FOUND = 4001,
|
||||
DISK_SPACE_INSUFFICIENT = 4002,
|
||||
MEMORY_INSUFFICIENT = 4003,
|
||||
|
||||
// 未知错误
|
||||
UNKNOWN_ERROR = 9999
|
||||
}
|
||||
|
||||
// 错误信息映射
|
||||
export const errorMessages: Record<ErrorCode, string> = {
|
||||
[ErrorCode.BACKEND_START_FAILED]: '后端服务启动失败',
|
||||
[ErrorCode.BACKEND_PORT_OCCUPIED]: '后端服务端口被占用',
|
||||
[ErrorCode.BACKEND_CONNECTION_FAILED]: '后端服务连接失败',
|
||||
[ErrorCode.BACKEND_RESPONSE_ERROR]: '后端服务响应错误',
|
||||
[ErrorCode.NETWORK_ERROR]: '网络连接错误',
|
||||
[ErrorCode.NETWORK_TIMEOUT]: '网络连接超时',
|
||||
[ErrorCode.NETWORK_CONNECTION_REFUSED]: '网络连接被拒绝',
|
||||
[ErrorCode.FILE_NOT_FOUND]: '文件未找到',
|
||||
[ErrorCode.FILE_PERMISSION_ERROR]: '文件权限错误',
|
||||
[ErrorCode.FILE_FORMAT_ERROR]: '文件格式错误',
|
||||
[ErrorCode.FILE_SIZE_ERROR]: '文件大小错误',
|
||||
[ErrorCode.JAVA_NOT_FOUND]: 'Java 未找到',
|
||||
[ErrorCode.DISK_SPACE_INSUFFICIENT]: '磁盘空间不足',
|
||||
[ErrorCode.MEMORY_INSUFFICIENT]: '内存不足',
|
||||
[ErrorCode.UNKNOWN_ERROR]: '未知错误'
|
||||
};
|
||||
|
||||
// 错误建议映射
|
||||
export const errorSuggestions: Record<ErrorCode, string[]> = {
|
||||
[ErrorCode.BACKEND_START_FAILED]: [
|
||||
'检查 37019 端口是否被占用',
|
||||
'检查后端服务是否正常',
|
||||
'重启应用程序'
|
||||
],
|
||||
[ErrorCode.BACKEND_PORT_OCCUPIED]: [
|
||||
'关闭占用 37019 端口的其他应用',
|
||||
'检查是否有其他 DeEarthX 实例在运行',
|
||||
'重启计算机后再试'
|
||||
],
|
||||
[ErrorCode.BACKEND_CONNECTION_FAILED]: [
|
||||
'检查后端服务是否正在运行',
|
||||
'检查网络连接是否正常',
|
||||
'重启应用程序'
|
||||
],
|
||||
[ErrorCode.BACKEND_RESPONSE_ERROR]: [
|
||||
'检查后端服务是否正常',
|
||||
'重启后端服务',
|
||||
'联系技术支持'
|
||||
],
|
||||
[ErrorCode.NETWORK_ERROR]: [
|
||||
'检查网络连接是否正常',
|
||||
'检查防火墙设置',
|
||||
'稍后重试'
|
||||
],
|
||||
[ErrorCode.NETWORK_TIMEOUT]: [
|
||||
'检查网络连接速度',
|
||||
'稍后重试',
|
||||
'检查目标服务器是否可访问'
|
||||
],
|
||||
[ErrorCode.NETWORK_CONNECTION_REFUSED]: [
|
||||
'检查目标服务器是否正在运行',
|
||||
'检查网络连接是否正常',
|
||||
'检查防火墙设置'
|
||||
],
|
||||
[ErrorCode.FILE_NOT_FOUND]: [
|
||||
'确认文件路径是否正确',
|
||||
'检查文件是否存在',
|
||||
'重新上传文件'
|
||||
],
|
||||
[ErrorCode.FILE_PERMISSION_ERROR]: [
|
||||
'检查文件权限设置',
|
||||
'以管理员身份运行应用程序',
|
||||
'检查文件是否被其他程序占用'
|
||||
],
|
||||
[ErrorCode.FILE_FORMAT_ERROR]: [
|
||||
'确认文件格式是否正确',
|
||||
'重新上传正确格式的文件',
|
||||
'检查文件是否损坏'
|
||||
],
|
||||
[ErrorCode.FILE_SIZE_ERROR]: [
|
||||
'检查文件大小是否符合要求',
|
||||
'压缩文件后再上传',
|
||||
'检查磁盘空间是否充足'
|
||||
],
|
||||
[ErrorCode.JAVA_NOT_FOUND]: [
|
||||
'安装 Java 17 或更高版本',
|
||||
'配置 Java 环境变量',
|
||||
'重启应用程序'
|
||||
],
|
||||
[ErrorCode.DISK_SPACE_INSUFFICIENT]: [
|
||||
'清理磁盘空间',
|
||||
'选择其他存储位置',
|
||||
'删除不必要的文件'
|
||||
],
|
||||
[ErrorCode.MEMORY_INSUFFICIENT]: [
|
||||
'增加系统内存',
|
||||
'关闭其他占用内存的应用程序',
|
||||
'减少同时处理的任务数量'
|
||||
],
|
||||
[ErrorCode.UNKNOWN_ERROR]: [
|
||||
'重启应用程序',
|
||||
'检查系统日志',
|
||||
'联系技术支持'
|
||||
]
|
||||
};
|
||||
|
||||
// 获取错误信息
|
||||
export function getErrorMessage(code: ErrorCode): string {
|
||||
return errorMessages[code] || errorMessages[ErrorCode.UNKNOWN_ERROR];
|
||||
}
|
||||
|
||||
// 获取错误建议
|
||||
export function getErrorSuggestions(code: ErrorCode): string[] {
|
||||
return errorSuggestions[code] || errorSuggestions[ErrorCode.UNKNOWN_ERROR];
|
||||
}
|
||||
|
||||
// 错误对象接口
|
||||
export interface ErrorInfo {
|
||||
code: ErrorCode;
|
||||
message: string;
|
||||
details?: string;
|
||||
suggestions?: string[];
|
||||
}
|
||||
|
||||
// 创建错误信息
|
||||
export function createErrorInfo(code: ErrorCode, details?: string): ErrorInfo {
|
||||
return {
|
||||
code,
|
||||
message: getErrorMessage(code),
|
||||
details,
|
||||
suggestions: getErrorSuggestions(code)
|
||||
};
|
||||
}
|
||||
@@ -1,22 +1,67 @@
|
||||
<template>
|
||||
<div class="tw:h-full tw:w-full tw:flex tw:flex-col tw:justify-center tw:items-center">
|
||||
<div class="tw:w-32 tw:h-32 tw:mb-25">
|
||||
<div class="tw:w-32 tw:h-32 tw:mb-8">
|
||||
<svg class="w-32 h-32 mb-4" viewBox="0 0 120 120">
|
||||
<circle cx="60" cy="60" r="50" fill="#ef4444" />
|
||||
<path d="M40,40 L80,80 M80,40 L40,80" stroke="white" stroke-width="10" stroke-linecap="round" />
|
||||
</svg>
|
||||
<p class="tw:text-2xl tw:font-bold tw:text-center tw:mb-20 tw:text-red-500">Error</p>
|
||||
<p class="tw:text-sm tw:text-center tw:text-gray-500">
|
||||
</div>
|
||||
<p class="tw:text-2xl tw:font-bold tw:text-center tw:mb-6 tw:text-red-500">Error</p>
|
||||
<div class="tw:w-1/2 tw:max-w-md tw:bg-white tw:p-6 tw:rounded-lg tw:shadow-lg">
|
||||
<p class="tw:text-sm tw:text-center tw:text-gray-500 mb-4">
|
||||
{{ errorMessage }}
|
||||
</p>
|
||||
<div v-if="errorCode" class="tw:text-sm tw:text-center tw:text-gray-500 mb-6">
|
||||
错误码:{{ errorCode }}
|
||||
</div>
|
||||
<div v-if="suggestions.length > 0" class="tw:mt-6">
|
||||
<p class="tw:text-sm tw:font-medium tw:text-gray-700 mb-2">建议解决方案:</p>
|
||||
<ul class="tw:text-xs tw:text-gray-600 tw:list-disc tw:pl-5">
|
||||
<li v-for="(suggestion, index) in suggestions" :key="index" class="tw:mb-1">
|
||||
{{ suggestion }}
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="tw:mt-6 tw:flex tw:justify-center tw:gap-4">
|
||||
<button
|
||||
class="tw:px-4 tw:py-2 tw:bg-[#67eac3] tw:text-gray-800 tw:rounded-md tw:hover:bg-[#56d9b0] tw:transition-colors"
|
||||
@click="goBack"
|
||||
>
|
||||
返回首页
|
||||
</button>
|
||||
<button
|
||||
v-if="errorCode"
|
||||
class="tw:px-4 tw:py-2 tw:bg-[#67eac3] tw:text-gray-800 tw:rounded-md tw:hover:bg-[#56d9b0] tw:transition-colors"
|
||||
@click="openErrorDoc"
|
||||
>
|
||||
文档帮助
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import { useRoute } from 'vue-router';
|
||||
import { useRoute, useRouter } from 'vue-router';
|
||||
import { ErrorCode, getErrorSuggestions } from '../utils/errorCodes';
|
||||
import { open } from '@tauri-apps/plugin-shell';
|
||||
|
||||
const route = useRoute();
|
||||
const router = useRouter();
|
||||
const errorReason = route.query.e as string;
|
||||
const errorMessage = errorReason ? `错误原因:${errorReason}` : 'DeEarthX.Core 启动失败!';
|
||||
const errorCodeStr = route.query.code as string;
|
||||
const errorCode = errorCodeStr ? parseInt(errorCodeStr) as ErrorCode : undefined;
|
||||
const errorMessage = errorReason ? errorReason : 'DeEarthX.Core 启动失败!';
|
||||
const suggestions = errorCode ? getErrorSuggestions(errorCode) : [];
|
||||
|
||||
function goBack() {
|
||||
router.push('/');
|
||||
}
|
||||
|
||||
function openErrorDoc() {
|
||||
if (errorCode) {
|
||||
const url = `https://dex.xcclyc.cn/api/error-codes.html#_${errorCode}`;
|
||||
open(url);
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
Reference in New Issue
Block a user