新增:连接管理、数据查询等功能
This commit is contained in:
81
web/src/views/db-cli/composables/useStructureStoreLegacy.ts
Normal file
81
web/src/views/db-cli/composables/useStructureStoreLegacy.ts
Normal file
@@ -0,0 +1,81 @@
|
||||
/**
|
||||
* @deprecated 请使用 useStructureStore
|
||||
*/
|
||||
import { ref } from 'vue'
|
||||
import { Message } from '@arco-design/web-vue'
|
||||
import { GetTableStructure } from '../../wailsjs/wailsjs/go/main/App'
|
||||
|
||||
export function useStructureState() {
|
||||
const structureLoading = ref(false)
|
||||
const structureError = ref('')
|
||||
const structureData = ref<any>(null)
|
||||
const structureInfo = ref<{
|
||||
connectionId: number
|
||||
database: string
|
||||
tableName: string
|
||||
dbType: 'mysql' | 'mongo' | 'redis'
|
||||
nodeType: string
|
||||
} | null>(null)
|
||||
|
||||
const loadStructure = async (
|
||||
connectionId: number,
|
||||
database: string,
|
||||
tableName: string,
|
||||
dbType: 'mysql' | 'mongo' | 'redis',
|
||||
nodeType: string
|
||||
) => {
|
||||
if (nodeType === 'connection' || nodeType === 'database' || !tableName) {
|
||||
structureInfo.value = { connectionId, database, tableName: '', dbType, nodeType }
|
||||
structureData.value = null
|
||||
return
|
||||
}
|
||||
|
||||
try {
|
||||
structureLoading.value = true
|
||||
structureError.value = ''
|
||||
|
||||
if (!window.go?.main?.App?.GetTableStructure) {
|
||||
throw new Error('Go 后端未就绪')
|
||||
}
|
||||
|
||||
const result = await window.go.main.App.GetTableStructure(connectionId, database, tableName)
|
||||
structureData.value = result
|
||||
structureInfo.value = { connectionId, database, tableName, dbType, nodeType }
|
||||
} catch (error: unknown) {
|
||||
const errorMessage = error instanceof Error ? error.message : '加载表结构失败'
|
||||
structureError.value = errorMessage
|
||||
Message.error('加载表结构失败: ' + errorMessage)
|
||||
structureData.value = null
|
||||
structureInfo.value = null
|
||||
} finally {
|
||||
structureLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
const clearStructure = () => {
|
||||
structureData.value = null
|
||||
structureInfo.value = null
|
||||
structureError.value = ''
|
||||
}
|
||||
|
||||
const refreshStructure = async () => {
|
||||
if (!structureInfo.value) return
|
||||
await loadStructure(
|
||||
structureInfo.value.connectionId,
|
||||
structureInfo.value.database,
|
||||
structureInfo.value.tableName,
|
||||
structureInfo.value.dbType,
|
||||
structureInfo.value.nodeType
|
||||
)
|
||||
}
|
||||
|
||||
return {
|
||||
structureLoading,
|
||||
structureError,
|
||||
structureData,
|
||||
structureInfo,
|
||||
loadStructure,
|
||||
clearStructure,
|
||||
refreshStructure
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user