82 lines
2.2 KiB
TypeScript
82 lines
2.2 KiB
TypeScript
/**
|
|
* @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
|
|
}
|
|
}
|