|
|
|
|
@ -306,9 +306,17 @@ const buildDatabaseUrl = () => {
|
|
|
|
|
case 'sqlite':
|
|
|
|
|
return `sqlite:///${systemForm.dbPath}`
|
|
|
|
|
case 'postgresql':
|
|
|
|
|
if (systemForm.dbPassword) {
|
|
|
|
|
return `postgresql://${systemForm.dbUsername}:${systemForm.dbPassword}@${systemForm.dbHost}:${systemForm.dbPort}/${systemForm.dbName}`
|
|
|
|
|
} else {
|
|
|
|
|
return `postgresql://${systemForm.dbUsername}@${systemForm.dbHost}:${systemForm.dbPort}/${systemForm.dbName}`
|
|
|
|
|
}
|
|
|
|
|
case 'mysql':
|
|
|
|
|
if (systemForm.dbPassword) {
|
|
|
|
|
return `mysql://${systemForm.dbUsername}:${systemForm.dbPassword}@${systemForm.dbHost}:${systemForm.dbPort}/${systemForm.dbName}`
|
|
|
|
|
} else {
|
|
|
|
|
return `mysql://${systemForm.dbUsername}@${systemForm.dbHost}:${systemForm.dbPort}/${systemForm.dbName}`
|
|
|
|
|
}
|
|
|
|
|
default:
|
|
|
|
|
return 'sqlite:///./amazing_data.db'
|
|
|
|
|
}
|
|
|
|
|
@ -320,19 +328,49 @@ const parseDatabaseUrl = (url: string) => {
|
|
|
|
|
systemForm.dbPath = url.replace('sqlite:///', '')
|
|
|
|
|
} else if (url.startsWith('postgresql://')) {
|
|
|
|
|
systemForm.dbType = 'postgresql'
|
|
|
|
|
try {
|
|
|
|
|
const urlPart = url.replace('postgresql://', '')
|
|
|
|
|
const parts = urlPart.split('@')
|
|
|
|
|
if (parts.length === 2) {
|
|
|
|
|
const userPass = parts[0].split(':')
|
|
|
|
|
systemForm.dbUsername = userPass[0] || 'postgres'
|
|
|
|
|
systemForm.dbPassword = userPass.length > 1 ? userPass[1] : ''
|
|
|
|
|
const hostPortDb = parts[1].split('/')
|
|
|
|
|
systemForm.dbName = hostPortDb.length > 1 ? hostPortDb[1] : 'amazing_data'
|
|
|
|
|
const hostPort = hostPortDb[0].split(':')
|
|
|
|
|
systemForm.dbHost = hostPort[0] || 'localhost'
|
|
|
|
|
systemForm.dbPort = hostPort.length > 1 ? parseInt(hostPort[1]) : 5432
|
|
|
|
|
}
|
|
|
|
|
} catch (e) {
|
|
|
|
|
systemForm.dbHost = 'localhost'
|
|
|
|
|
systemForm.dbPort = 5432
|
|
|
|
|
systemForm.dbUsername = 'postgres'
|
|
|
|
|
systemForm.dbPassword = ''
|
|
|
|
|
systemForm.dbName = 'amazing_data'
|
|
|
|
|
}
|
|
|
|
|
} else if (url.startsWith('mysql://')) {
|
|
|
|
|
systemForm.dbType = 'mysql'
|
|
|
|
|
try {
|
|
|
|
|
const urlPart = url.replace('mysql://', '')
|
|
|
|
|
const parts = urlPart.split('@')
|
|
|
|
|
if (parts.length === 2) {
|
|
|
|
|
const userPass = parts[0].split(':')
|
|
|
|
|
systemForm.dbUsername = userPass[0] || 'root'
|
|
|
|
|
systemForm.dbPassword = userPass.length > 1 ? userPass[1] : ''
|
|
|
|
|
const hostPortDb = parts[1].split('/')
|
|
|
|
|
systemForm.dbName = hostPortDb.length > 1 ? hostPortDb[1] : 'amazing_data'
|
|
|
|
|
const hostPort = hostPortDb[0].split(':')
|
|
|
|
|
systemForm.dbHost = hostPort[0] || 'localhost'
|
|
|
|
|
systemForm.dbPort = hostPort.length > 1 ? parseInt(hostPort[1]) : 3306
|
|
|
|
|
}
|
|
|
|
|
} catch (e) {
|
|
|
|
|
systemForm.dbHost = 'localhost'
|
|
|
|
|
systemForm.dbPort = 3306
|
|
|
|
|
systemForm.dbUsername = 'root'
|
|
|
|
|
systemForm.dbPassword = ''
|
|
|
|
|
systemForm.dbName = 'amazing_data'
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const fetchSystemConfigs = async () => {
|
|
|
|
|
@ -467,12 +505,16 @@ const handleTestConnection = async () => {
|
|
|
|
|
if (!valid) return
|
|
|
|
|
|
|
|
|
|
testingConnection.value = true
|
|
|
|
|
dbStructureStatus.value = null
|
|
|
|
|
showInitButton.value = false
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
const databaseUrl = buildDatabaseUrl()
|
|
|
|
|
const res: any = await testSystemConnection({
|
|
|
|
|
database: databaseUrl,
|
|
|
|
|
redis: systemForm.redis
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
if (res.data?.database) {
|
|
|
|
|
ElMessage.success('数据库连接成功')
|
|
|
|
|
const structureRes: any = await checkDatabaseStructure()
|
|
|
|
|
@ -483,20 +525,25 @@ const handleTestConnection = async () => {
|
|
|
|
|
} else {
|
|
|
|
|
dbStructureStatus.value = 'incomplete'
|
|
|
|
|
showInitButton.value = true
|
|
|
|
|
ElMessage.warning('数据结构不完整,需要初始化')
|
|
|
|
|
const missingTables = structureRes.data?.missing_tables || []
|
|
|
|
|
ElMessage.warning(`数据结构不完整,缺少表: ${missingTables.join(', ')}`)
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
ElMessage.error('数据库连接失败')
|
|
|
|
|
const dbErrorMsg = res.data?.database_error || res.message || '未知错误'
|
|
|
|
|
ElMessage.error(`数据库连接失败: ${dbErrorMsg}`)
|
|
|
|
|
dbStructureStatus.value = null
|
|
|
|
|
showInitButton.value = false
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (res.data?.redis) {
|
|
|
|
|
ElMessage.success('Redis连接成功')
|
|
|
|
|
} else {
|
|
|
|
|
ElMessage.error('Redis连接失败')
|
|
|
|
|
const redisErrorMsg = res.data?.redis_error || '请检查Redis服务是否启动'
|
|
|
|
|
ElMessage.error(`Redis连接失败: ${redisErrorMsg}`)
|
|
|
|
|
}
|
|
|
|
|
} catch (error) {
|
|
|
|
|
ElMessage.error('检测连接失败')
|
|
|
|
|
} catch (error: any) {
|
|
|
|
|
const errorMsg = error.response?.data?.message || error.message || '网络请求失败'
|
|
|
|
|
ElMessage.error(`检测连接失败: ${errorMsg}`)
|
|
|
|
|
dbStructureStatus.value = null
|
|
|
|
|
showInitButton.value = false
|
|
|
|
|
} finally {
|
|
|
|
|
|