ai-manus/chat-client/src/store/modules/dashboard.ts

334 lines
9.4 KiB
TypeScript
Raw Normal View History

/**
* Dashboard -
*/
import { defineStore } from 'pinia'
import { ref, computed } from 'vue'
import type {
TrainInfo,
MechanicInfo,
DiagnosticCode,
TreatmentMethod,
TypicalCase,
StandardFile,
RuleRegulation,
PrecautionInfo,
RouteInfo,
FaultCause,
ModuleType,
SearchResult
} from '@/types/dashboard'
import { dashboardService } from '@/services/dashboardService'
export const useDashboardStore = defineStore('dashboard', () => {
// 状态定义
const trainInfo = ref<TrainInfo[]>([])
const mechanicInfo = ref<MechanicInfo[]>([])
const diagnosticCodes = ref<DiagnosticCode[]>([])
const treatmentMethods = ref<TreatmentMethod[]>([])
const typicalCases = ref<TypicalCase[]>([])
const standardFiles = ref<StandardFile[]>([])
const ruleRegulations = ref<RuleRegulation[]>([])
const precautions = ref<PrecautionInfo[]>([])
const routeInfo = ref<RouteInfo[]>([])
const faultCauses = ref<FaultCause[]>([])
// 搜索和UI状态
const searchQuery = ref('')
const selectedModule = ref<ModuleType | null>(null)
const isLoading = ref(false)
const lastUpdateTime = ref<Date | null>(null)
// 计算属性
const totalTrains = computed(() => trainInfo.value.length)
const runningTrains = computed(() =>
trainInfo.value.filter(train => train.status === 'running').length
)
const maintenanceTrains = computed(() =>
trainInfo.value.filter(train => train.status === 'maintenance').length
)
const activeMechanics = computed(() =>
mechanicInfo.value.filter(mechanic => mechanic.status === 'working').length
)
const highSeverityIssues = computed(() =>
diagnosticCodes.value.filter(code => code.severity === 'high').length
)
const searchResults = computed((): SearchResult[] => {
if (!searchQuery.value.trim()) return []
const query = searchQuery.value.toLowerCase()
const results: SearchResult[] = []
// 搜索车组信息
trainInfo.value.forEach(train => {
if (train.name.toLowerCase().includes(query) ||
train.location.toLowerCase().includes(query)) {
results.push({
id: train.id,
title: train.name,
content: `位置: ${train.location}, 状态: ${train.status}`,
type: 'trainInfo' as ModuleType,
relevance: 1
})
}
})
// 搜索故障信息
diagnosticCodes.value.forEach(code => {
if (code.description.toLowerCase().includes(query) ||
code.code.toLowerCase().includes(query)) {
results.push({
id: code.code,
title: code.code,
content: code.description,
type: 'faultInfo' as ModuleType,
relevance: 1
})
}
})
// 搜索典型案例
typicalCases.value.forEach(case_ => {
if (case_.title.toLowerCase().includes(query) ||
case_.description.toLowerCase().includes(query)) {
results.push({
id: case_.id,
title: case_.title,
content: case_.description,
type: 'typicalCase' as ModuleType,
relevance: 1
})
}
})
return results.slice(0, 10) // 限制搜索结果数量
})
// Actions
const loadAllData = async () => {
isLoading.value = true
try {
const data = await dashboardService.loadAllData()
trainInfo.value = data.trainInfo
mechanicInfo.value = data.mechanicInfo
diagnosticCodes.value = data.diagnosticCodes
treatmentMethods.value = data.treatmentMethods
typicalCases.value = data.typicalCases
standardFiles.value = data.standardFiles
ruleRegulations.value = data.ruleRegulations
precautions.value = data.precautions
routeInfo.value = data.routeInfo
faultCauses.value = data.faultCauses
lastUpdateTime.value = new Date()
} catch (error) {
console.error('Error loading data:', error)
} finally {
isLoading.value = false
}
}
const updateSearchQuery = (query: string) => {
searchQuery.value = query
}
const selectModule = (module: ModuleType | null) => {
selectedModule.value = module
}
const refreshData = async () => {
await loadAllData()
}
const refreshModuleData = async (moduleType: ModuleType) => {
isLoading.value = true
try {
const data = await dashboardService.refreshModuleData(moduleType)
switch (moduleType) {
case 'trainInfo':
trainInfo.value = data as TrainInfo[]
break
case 'mechanicInfo':
case 'personnelInfo':
mechanicInfo.value = data as MechanicInfo[]
break
case 'faultInfo':
diagnosticCodes.value = data as DiagnosticCode[]
break
case 'emergencyDisposal':
treatmentMethods.value = data as TreatmentMethod[]
break
case 'routeInfo':
routeInfo.value = data as RouteInfo[]
break
case 'typicalCase':
typicalCases.value = data as TypicalCase[]
break
case 'ruleRegulation':
ruleRegulations.value = data as RuleRegulation[]
break
case 'precautions':
precautions.value = data as PrecautionInfo[]
break
}
lastUpdateTime.value = new Date()
} catch (error) {
console.error('Error refreshing module data:', error)
} finally {
isLoading.value = false
}
}
// 获取特定模块的数据
const getModuleData = (moduleType: ModuleType) => {
switch (moduleType) {
case 'trainInfo':
return trainInfo.value
case 'mechanicInfo':
case 'personnelInfo':
return mechanicInfo.value
case 'faultInfo':
return diagnosticCodes.value
case 'emergencyDisposal':
return treatmentMethods.value
case 'routeInfo':
return routeInfo.value
case 'typicalCase':
return typicalCases.value
case 'ruleRegulation':
return ruleRegulations.value
case 'precautions':
return precautions.value
case 'inputCard':
return []
default:
return []
}
}
// 获取故障原因数据
const getFaultCauses = () => faultCauses.value
// 更新处置方法数据(用于 WebSocket 接收数据)
const updateTreatmentMethods = (methods: TreatmentMethod[]) => {
treatmentMethods.value = methods
lastUpdateTime.value = new Date()
console.log('处置方法数据已更新:', methods)
}
// 更新故障原因数据(用于 WebSocket 接收数据)
const updateFaultCauses = (causes: FaultCause[]) => {
faultCauses.value = causes
lastUpdateTime.value = new Date()
console.log('故障原因数据已更新:', causes)
}
// 更新车组信息数据(用于 WebSocket 接收数据)
const updateTrainInfo = (trains: TrainInfo[]) => {
trainInfo.value = trains
lastUpdateTime.value = new Date()
console.log('车组信息数据已更新:', trains)
}
// 更新机械师信息数据(用于 WebSocket 接收数据)
const updateMechanicInfo = (mechanics: MechanicInfo[]) => {
mechanicInfo.value = mechanics
lastUpdateTime.value = new Date()
console.log('机械师信息数据已更新:', mechanics)
}
// 更新诊断代码数据(用于 WebSocket 接收数据)
const updateDiagnosticCodes = (codes: DiagnosticCode[]) => {
diagnosticCodes.value = codes
lastUpdateTime.value = new Date()
console.log('诊断代码数据已更新:', codes)
}
// 更新典型案例数据(用于 WebSocket 接收数据)
const updateTypicalCases = (cases: TypicalCase[]) => {
typicalCases.value = cases
lastUpdateTime.value = new Date()
console.log('典型案例数据已更新:', cases)
}
// 更新标准文件数据(用于 WebSocket 接收数据)
const updateStandardFiles = (files: StandardFile[]) => {
standardFiles.value = files
lastUpdateTime.value = new Date()
console.log('标准文件数据已更新:', files)
}
// 更新规章制度数据(用于 WebSocket 接收数据)
const updateRuleRegulations = (rules: RuleRegulation[]) => {
ruleRegulations.value = rules
lastUpdateTime.value = new Date()
console.log('规章制度数据已更新:', rules)
}
// 更新注意事项数据(用于 WebSocket 接收数据)
const updatePrecautions = (precautionsList: PrecautionInfo[]) => {
precautions.value = precautionsList
lastUpdateTime.value = new Date()
console.log('注意事项数据已更新:', precautionsList)
}
// 更新交路信息数据(用于 WebSocket 接收数据)
const updateRouteInfo = (routes: RouteInfo[]) => {
routeInfo.value = routes
lastUpdateTime.value = new Date()
console.log('交路信息数据已更新:', routes)
}
return {
// 状态
trainInfo,
mechanicInfo,
diagnosticCodes,
treatmentMethods,
typicalCases,
standardFiles,
ruleRegulations,
precautions,
routeInfo,
faultCauses,
searchQuery,
selectedModule,
isLoading,
lastUpdateTime,
// 计算属性
totalTrains,
runningTrains,
maintenanceTrains,
activeMechanics,
highSeverityIssues,
searchResults,
// 方法
loadAllData,
updateSearchQuery,
selectModule,
refreshData,
refreshModuleData,
getModuleData,
getFaultCauses,
updateTreatmentMethods,
updateFaultCauses,
updateTrainInfo,
updateMechanicInfo,
updateDiagnosticCodes,
updateTypicalCases,
updateStandardFiles,
updateRuleRegulations,
updatePrecautions,
updateRouteInfo
}
})