App.vue 48 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292
  1. <script setup lang="ts">
  2. import { computed, onBeforeUnmount, onMounted, reactive, ref, watch } from 'vue'
  3. import { ElMessageBox } from 'element-plus'
  4. import { createAnnotation, deleteAnnotation, deletePretrain, fetchAnnotationConfig, fetchAnnotationsByIds, fetchFaults, fetchPeriodDetail, fetchPretrainStatus, fetchQueryOptions, fetchSitePoints, fetchTimePoints, fetchTspluseRuler, fetchWaveWindow, getToken, login as apiLogin, logout as apiLogout, recordPretrain } from './api'
  5. import PeriodModal from './components/PeriodModal.vue'
  6. import AlarmMonitor from './components/AlarmMonitor.vue'
  7. import { fixedAxisRange } from './utils/axis'
  8. import TimePointStrip from './components/TimePointStrip.vue'
  9. import WaveChart from './components/WaveChart.vue'
  10. import { STOPPED_COLOR, statusGradientColor } from './statusColor'
  11. import { DEVICE_POINT_TO_TYPE, DEVICE_POINTS, PRIMARY_DEVICE_POINT, type Annotation, type AnnotationLabel, type Cycle, type DevicePoint, type Fault, type MeasurementType, type PeriodDetail, type QueryOption, type SitePoint, type TimePoint, type QueryOptionsResponse, type WaveWindowFile, type WaveWindowResponse } from './types'
  12. const queryMeta = ref<QueryOptionsResponse | null>(null)
  13. const selectedDevicePart = ref('')
  14. const selectedDevicePoints = ref<DevicePoint[]>([PRIMARY_DEVICE_POINT])
  15. const fileListPoint = ref<DevicePoint | string>(PRIMARY_DEVICE_POINT)
  16. const minTime = ref('')
  17. const maxTime = ref('')
  18. const selectedTimeRangePoint = ref<DevicePoint | ''>('')
  19. const windowSize = ref(4)
  20. const maxPoints = ref(200000)
  21. const noSampling = ref(false)
  22. const includeStopped = ref(false)
  23. const abnormalOnly = ref(false)
  24. const noCycleOnly = ref(false)
  25. const minStatus = ref<number | null>(null)
  26. const firstCycleOnly = ref(false)
  27. const sitePointOptions = ref<SitePoint[]>([])
  28. const selectedSitePoints = ref<string[]>([])
  29. const pksTimeBounds = ref<{ min: string | null; max: string | null } | null>(null)
  30. const ruler = ref<{ min: number; max: number } | null>(null)
  31. const timePoints = ref<TimePoint[]>([])
  32. const referencePoints = ref<TimePoint[]>([])
  33. const faults = ref<Fault[]>([])
  34. const startIndex = ref(0)
  35. const waveData = ref<WaveWindowResponse | null>(null)
  36. const chartMode = ref<'split' | 'merge'>('split')
  37. const activeTab = ref<'model1' | 'alarm'>('model1')
  38. const chartDirty = ref(false)
  39. const queryLoading = ref(false)
  40. const timePointsLoading = ref(false)
  41. const waveLoading = ref(false)
  42. const errorMessage = ref('')
  43. const initialized = ref(false)
  44. const periodDetail = ref<PeriodDetail | null>(null)
  45. const periodVisible = ref(false)
  46. const periodLoading = ref(false)
  47. const annotationWidth = ref(10)
  48. const annotations = ref<Annotation[]>([])
  49. const annotationLoading = ref(false)
  50. const loggedIn = ref(false)
  51. const loginLoading = ref(false)
  52. const loginError = ref('')
  53. const loginForm = reactive({ username: '', password: '' })
  54. const waveChartRef = ref<InstanceType<typeof WaveChart> | null>(null)
  55. const recordedFileIds = ref<number[]>([])
  56. const recordingFileId = ref<number | null>(null)
  57. let queryDebounce: ReturnType<typeof setTimeout> | undefined
  58. let waveRequestId = 0
  59. const deviceParts = computed(() => queryMeta.value?.deviceParts ?? [])
  60. const devicePoints = computed(() => queryMeta.value?.devicePoints ?? DEVICE_POINTS)
  61. const unitNumber = computed(() => {
  62. const match = /^([789])号机组/.exec(selectedDevicePart.value)
  63. return match ? match[1] : null
  64. })
  65. const isPksMode = computed(() => firstCycleOnly.value && !!unitNumber.value)
  66. const isPksOnly = computed(() => isPksMode.value && !selectedDevicePoints.value.length && selectedSitePoints.value.length > 0)
  67. const canQueryTimePoints = computed(() => Boolean(selectedDevicePart.value) && (selectedDevicePoints.value.length > 0 || (isPksMode.value && selectedSitePoints.value.length > 0)))
  68. const pointModel = computed({
  69. get: () => (isPksMode.value
  70. ? [...selectedDevicePoints.value as unknown as string[], ...selectedSitePoints.value]
  71. : selectedDevicePoints.value as unknown as string[]),
  72. set: (value: string[]) => {
  73. const wave = value.filter((item) => (DEVICE_POINTS as readonly string[]).includes(item)) as DevicePoint[]
  74. const site = value.filter((item) => !(DEVICE_POINTS as readonly string[]).includes(item))
  75. selectedDevicePoints.value = wave
  76. selectedSitePoints.value = site
  77. },
  78. })
  79. const sitePointLabel = (point: SitePoint) => `${point.itemName} ${point.itemDescription}`.trim()
  80. const SITE_TAB_LABEL = '全场点位'
  81. const siteDescriptionMap = computed<Record<string, string>>(() => {
  82. const map: Record<string, string> = {}
  83. for (const item of sitePointOptions.value) map[item.itemName] = item.itemDescription
  84. return map
  85. })
  86. const siteDescription = (itemName: string) => siteDescriptionMap.value[itemName] || itemName
  87. const fileTabs = computed(() => {
  88. if (!isPksMode.value) return selectedDevicePoints.value as unknown as string[]
  89. return [
  90. ...selectedDevicePoints.value as unknown as string[],
  91. ...(selectedSitePoints.value.length ? [SITE_TAB_LABEL] : []),
  92. ]
  93. })
  94. const isSiteTab = computed(() => fileListPoint.value === SITE_TAB_LABEL)
  95. const windowSiteRows = computed(() => {
  96. if (!isSiteTab.value) return []
  97. return (waveData.value?.points ?? []).map((point, index) => ({
  98. index,
  99. sampleTime: point.sampleTime,
  100. values: Object.fromEntries(
  101. selectedSitePoints.value.map((itemName) => [itemName, point.siteValues?.[itemName] ?? null]),
  102. ),
  103. }))
  104. })
  105. const devicePointCounts = computed<Record<string, { pre: number | null; ab: number | null }>>(() => {
  106. const map: Record<string, { pre: number | null; ab: number | null }> = {}
  107. for (const point of devicePoints.value) {
  108. const pointName = `${selectedDevicePart.value}${point}`
  109. map[point] = {
  110. pre: queryMeta.value?.pretrainCounts?.[pointName] ?? null,
  111. ab: queryMeta.value?.abnormalCounts?.[pointName] ?? null,
  112. }
  113. }
  114. return map
  115. })
  116. function devicePointLabel(point: DevicePoint): string {
  117. const { pre, ab } = devicePointCounts.value[point] ?? { pre: null, ab: null }
  118. const inner: string[] = []
  119. if (pre != null) inner.push(String(pre))
  120. if (ab != null) inner.push(String(ab))
  121. return inner.length ? `${point} (${inner.join(' · ')})` : point
  122. }
  123. const selectedOptionRows = computed<QueryOption[]>(() => (
  124. queryMeta.value?.options.filter((row) => (
  125. row.devicePart === selectedDevicePart.value && selectedDevicePoints.value.includes(row.devicePoint)
  126. )) ?? []
  127. ))
  128. const timeRangeOptions = computed<QueryOption[]>(() => (
  129. queryMeta.value?.options.filter((row) => row.devicePart === selectedDevicePart.value) ?? []
  130. ))
  131. const selectedWindowPoints = computed(() => {
  132. const slice = timePoints.value.slice(startIndex.value, startIndex.value + stripWindowSize.value)
  133. return hasReference.value ? [...referencePoints.value, ...slice] : slice
  134. })
  135. const hasReference = computed(() => referencePoints.value.length > 0)
  136. const stripWindowSize = computed(() => Math.max(0, windowSize.value - (hasReference.value ? 1 : 0)))
  137. const maxStart = computed(() => Math.max(0, timePoints.value.length - stripWindowSize.value))
  138. const endIndex = computed(() => Math.min(timePoints.value.length, startIndex.value + stripWindowSize.value))
  139. const statusFilter = computed(() => {
  140. const list: string[] = []
  141. if (abnormalOnly.value) list.push('abnormal')
  142. if (noCycleOnly.value) list.push('no_cycle')
  143. return list
  144. })
  145. const currentCycles = computed(() => waveData.value?.cycles ?? [])
  146. const pressureAxis = computed(() => {
  147. const series = waveData.value?.series.find((item) => item.measurementType === '压力')
  148. if (!series) return null
  149. return fixedAxisRange('压力', series.min, series.max)
  150. })
  151. const currentSource = computed(() => waveData.value?.source ?? timePointsSource.value)
  152. const timePointsSource = ref<'database' | 'demo'>('demo')
  153. const availableTypeCount = computed(() => selectedOptionRows.value.reduce((total, row) => total + row.fileCount, 0))
  154. const annotatedFileIds = computed(() => [...new Set(annotations.value.map((item) => item.waveFileId))])
  155. const windowFiles = computed(() => (waveData.value?.files ?? []).filter((file) => file.devicePoint === fileListPoint.value))
  156. const primaryDevicePoint = computed(() => (
  157. waveData.value?.primaryPoint
  158. ?? (selectedDevicePoints.value.includes('压力盖侧')
  159. ? '压力盖侧'
  160. : selectedDevicePoints.value.includes('压力轴侧')
  161. ? '压力轴侧'
  162. : selectedDevicePoints.value[0])
  163. ))
  164. type PartPointSelection = { wave: DevicePoint[]; site: string[] }
  165. const PART_SELECTION_KEY = 'wave-workbench.part-selection'
  166. const partSelections = ref<Record<string, PartPointSelection>>(loadPartSelections())
  167. function loadPartSelections(): Record<string, PartPointSelection> {
  168. try {
  169. const raw = localStorage.getItem(PART_SELECTION_KEY)
  170. if (!raw) return {}
  171. const data = JSON.parse(raw) as Record<string, Partial<PartPointSelection>>
  172. const cleaned: Record<string, PartPointSelection> = {}
  173. for (const key of Object.keys(data)) {
  174. const entry = data[key]
  175. if (!entry) continue
  176. const wave = ((entry.wave ?? []).filter((point) => (DEVICE_POINTS as readonly string[]).includes(point))) as DevicePoint[]
  177. const site = (entry.site ?? []).filter((name): name is string => typeof name === 'string')
  178. cleaned[key] = { wave, site }
  179. }
  180. return cleaned
  181. } catch {
  182. return {}
  183. }
  184. }
  185. function persistPartSelections() {
  186. try {
  187. localStorage.setItem(PART_SELECTION_KEY, JSON.stringify(partSelections.value))
  188. } catch {
  189. // 忽略存储失败(如隐私模式)
  190. }
  191. }
  192. function snapshotSelection(): PartPointSelection {
  193. return { wave: [...selectedDevicePoints.value], site: [...selectedSitePoints.value] }
  194. }
  195. function rememberPart(part: string) {
  196. if (!part) return
  197. partSelections.value[part] = snapshotSelection()
  198. persistPartSelections()
  199. }
  200. function unitOfPart(part: string): string | null {
  201. const match = /^([789])号机组/.exec(part)
  202. return match ? match[1] : null
  203. }
  204. function mirrorSiteAcrossUnits(site: string[], toUnit: string, available: Set<string>): string[] {
  205. const result: string[] = []
  206. for (const item of site) {
  207. const match = /^YSJ([789])_(\d+)$/.exec(item)
  208. if (!match || match[1] === toUnit) continue
  209. const mirrored = `YSJ${toUnit}_${match[2]}`
  210. if (available.has(mirrored)) result.push(mirrored)
  211. }
  212. return result
  213. }
  214. function toInputTime(value: string) {
  215. if (!value) return ''
  216. return value.replace('T', ' ').slice(0, 19)
  217. }
  218. function toApiTime(value: string) {
  219. return value ? value.replace('T', ' ') + (value.length === 16 ? ':00' : '') : undefined
  220. }
  221. function boundsForSelection() {
  222. const rows = selectedOptionRows.value
  223. if (rows.length) {
  224. const unionRows = rows.filter((row) => row.devicePoint === PRIMARY_DEVICE_POINT || row.devicePoint === '压力轴侧')
  225. const effective = unionRows.length ? unionRows : rows
  226. const min = effective.reduce((latest, row) => (row.minTime > latest ? row.minTime : latest), effective[0].minTime)
  227. const max = effective.reduce((earliest, row) => (row.maxTime < earliest ? row.maxTime : earliest), effective[0].maxTime)
  228. return { min: toInputTime(min), max: toInputTime(max) }
  229. }
  230. if (isPksOnly.value && pksTimeBounds.value?.min && pksTimeBounds.value?.max) {
  231. return { min: toInputTime(pksTimeBounds.value.min), max: toInputTime(pksTimeBounds.value.max) }
  232. }
  233. return null
  234. }
  235. function syncTimeBounds(force = false) {
  236. const bounds = boundsForSelection()
  237. if (!bounds) return
  238. if (force || !minTime.value || minTime.value < bounds.min || minTime.value > bounds.max) minTime.value = bounds.min
  239. if (force || !maxTime.value || maxTime.value > bounds.max || maxTime.value < bounds.min) maxTime.value = bounds.max
  240. if (minTime.value > maxTime.value) {
  241. minTime.value = bounds.min
  242. maxTime.value = bounds.max
  243. }
  244. }
  245. function formatDateTime(value: string | undefined) {
  246. if (!value) return '未选择'
  247. return value.replace('T', ' ').slice(0, 16)
  248. }
  249. function statusText() {
  250. if (timePointsLoading.value) return '正在读取时间点'
  251. if (waveLoading.value) return '正在整理波形'
  252. if (!timePoints.value.length) return '等待查询'
  253. return '窗口已就绪'
  254. }
  255. async function loadOptions() {
  256. queryLoading.value = true
  257. errorMessage.value = ''
  258. try {
  259. const result = await fetchQueryOptions()
  260. queryMeta.value = result
  261. selectedDevicePart.value = result.deviceParts[0] ?? ''
  262. selectedTimeRangePoint.value = ''
  263. syncTimeBounds(true)
  264. initialized.value = true
  265. await loadTimePoints()
  266. } catch (error) {
  267. errorMessage.value = error instanceof Error ? error.message : '查询条件读取失败'
  268. } finally {
  269. queryLoading.value = false
  270. }
  271. }
  272. async function loadSitePoints() {
  273. if (!isPksMode.value || !selectedDevicePart.value) {
  274. sitePointOptions.value = []
  275. pksTimeBounds.value = null
  276. return
  277. }
  278. try {
  279. const result = await fetchSitePoints(selectedDevicePart.value)
  280. sitePointOptions.value = result.items
  281. pksTimeBounds.value = result.minTime && result.maxTime ? { min: result.minTime, max: result.maxTime } : null
  282. } catch {
  283. sitePointOptions.value = []
  284. pksTimeBounds.value = null
  285. }
  286. }
  287. async function loadTspluseRuler() {
  288. try {
  289. ruler.value = await fetchTspluseRuler()
  290. } catch {
  291. ruler.value = null
  292. }
  293. }
  294. async function loadFaults() {
  295. if (!selectedDevicePart.value) {
  296. faults.value = []
  297. return
  298. }
  299. try {
  300. const result = await fetchFaults({
  301. devicePart: selectedDevicePart.value,
  302. minTime: toApiTime(minTime.value),
  303. maxTime: toApiTime(maxTime.value),
  304. })
  305. faults.value = result.faults
  306. } catch {
  307. faults.value = []
  308. }
  309. }
  310. function firstRunningIndex(): number {
  311. const index = timePoints.value.findIndex((point) =>
  312. selectedDevicePoints.value.some((pointName) => (point.files[pointName]?.rpm ?? 0) > 0),
  313. )
  314. return index >= 0 ? index : 0
  315. }
  316. async function loadTimePoints() {
  317. if (!selectedDevicePart.value) return
  318. if (!selectedDevicePoints.value.length && !isPksOnly.value) return
  319. timePointsLoading.value = true
  320. waveData.value = null
  321. errorMessage.value = ''
  322. try {
  323. const result = await fetchTimePoints({
  324. devicePart: selectedDevicePart.value,
  325. devicePoints: selectedDevicePoints.value,
  326. minTime: toApiTime(minTime.value),
  327. maxTime: toApiTime(maxTime.value),
  328. includeStopped: includeStopped.value,
  329. minStatus: noCycleOnly.value ? null : minStatus.value,
  330. statusFilter: statusFilter.value,
  331. sitePoints: isPksMode.value ? selectedSitePoints.value : [],
  332. })
  333. timePoints.value = result.points
  334. referencePoints.value = result.referencePoints ?? []
  335. timePointsSource.value = result.source
  336. startIndex.value = Math.max(
  337. 0,
  338. Math.min(firstRunningIndex(), Math.max(0, timePoints.value.length - stripWindowSize.value)),
  339. )
  340. chartDirty.value = true
  341. void loadAnnotations()
  342. void loadFaults()
  343. } catch (error) {
  344. timePoints.value = []
  345. referencePoints.value = []
  346. errorMessage.value = error instanceof Error ? error.message : '时间点读取失败'
  347. } finally {
  348. timePointsLoading.value = false
  349. }
  350. }
  351. async function loadWaveWindowNow() {
  352. const points = selectedWindowPoints.value
  353. if (!points.length || !selectedDevicePart.value) {
  354. waveData.value = null
  355. chartDirty.value = false
  356. return
  357. }
  358. const requestId = ++waveRequestId
  359. waveLoading.value = true
  360. try {
  361. const result = await fetchWaveWindow({
  362. devicePart: selectedDevicePart.value,
  363. devicePoints: selectedDevicePoints.value,
  364. points,
  365. maxPoints: maxPoints.value,
  366. noSampling: noSampling.value,
  367. firstCycleOnly: firstCycleOnly.value,
  368. sitePoints: isPksMode.value ? selectedSitePoints.value : [],
  369. })
  370. if (requestId === waveRequestId) {
  371. waveData.value = result
  372. chartDirty.value = false
  373. }
  374. } catch (error) {
  375. if (requestId === waveRequestId) errorMessage.value = error instanceof Error ? error.message : '波形读取失败'
  376. } finally {
  377. if (requestId === waveRequestId) waveLoading.value = false
  378. }
  379. }
  380. function markChartDirty() {
  381. chartDirty.value = true
  382. }
  383. function scheduleTimePoints() {
  384. if (!initialized.value) return
  385. if (queryDebounce) clearTimeout(queryDebounce)
  386. queryDebounce = setTimeout(() => void loadTimePoints(), 180)
  387. }
  388. function formatRange(option: QueryOption) {
  389. return `${formatDateTime(option.minTime)} ~ ${formatDateTime(option.maxTime)}`
  390. }
  391. function onTimeRangeChange(value: DevicePoint | '') {
  392. if (!value) return
  393. const row = queryMeta.value?.options.find((item) => (
  394. item.devicePart === selectedDevicePart.value && item.devicePoint === value
  395. ))
  396. if (!row) return
  397. minTime.value = toInputTime(row.minTime)
  398. maxTime.value = toInputTime(row.maxTime)
  399. }
  400. let partRestoreSeq = 0
  401. async function onDevicePartChange(previous?: string) {
  402. const current = selectedDevicePart.value
  403. const seq = ++partRestoreSeq
  404. selectedTimeRangePoint.value = ''
  405. selectedSitePoints.value = []
  406. if (!current) {
  407. selectedDevicePoints.value = [PRIMARY_DEVICE_POINT]
  408. return
  409. }
  410. const currentUnit = unitOfPart(current)
  411. if (currentUnit) {
  412. try {
  413. const result = await fetchSitePoints(current)
  414. if (seq !== partRestoreSeq) return
  415. sitePointOptions.value = result.items
  416. pksTimeBounds.value = result.minTime && result.maxTime ? { min: result.minTime, max: result.maxTime } : null
  417. } catch {
  418. if (seq !== partRestoreSeq) return
  419. sitePointOptions.value = []
  420. pksTimeBounds.value = null
  421. }
  422. } else {
  423. sitePointOptions.value = []
  424. pksTimeBounds.value = null
  425. }
  426. if (seq !== partRestoreSeq) return
  427. const available = new Set(sitePointOptions.value.map((item) => item.itemName))
  428. const saved = partSelections.value[current]
  429. const source = previous && previous !== current ? partSelections.value[previous] : null
  430. let wave: DevicePoint[] = []
  431. let site: string[] = []
  432. if (saved) {
  433. wave = saved.wave
  434. site = saved.site.filter((name) => !currentUnit || available.has(name))
  435. } else if (source) {
  436. wave = source.wave
  437. if (currentUnit) site = mirrorSiteAcrossUnits(source.site, currentUnit, available)
  438. }
  439. if (!wave.length && !(currentUnit && site.length)) {
  440. wave = [PRIMARY_DEVICE_POINT]
  441. }
  442. selectedDevicePoints.value = wave
  443. selectedSitePoints.value = site
  444. if (!isPksMode.value && fileListPoint.value === SITE_TAB_LABEL) {
  445. fileListPoint.value = wave[0] ?? PRIMARY_DEVICE_POINT
  446. }
  447. syncTimeBounds(true)
  448. scheduleTimePoints()
  449. }
  450. function onDevicePointsChange() {
  451. const points = selectedDevicePoints.value
  452. if (!points.length && !isPksMode.value) {
  453. selectedDevicePoints.value = [PRIMARY_DEVICE_POINT]
  454. return
  455. }
  456. if (selectedDevicePart.value) rememberPart(selectedDevicePart.value)
  457. syncTimeBounds(true)
  458. scheduleTimePoints()
  459. }
  460. function onTimeChange() {
  461. if (minTime.value > maxTime.value) {
  462. errorMessage.value = '开始时间不能晚于结束时间'
  463. return
  464. }
  465. scheduleTimePoints()
  466. }
  467. function onStartIndexChange(value: number) {
  468. startIndex.value = Math.max(0, Math.min(value, maxStart.value))
  469. markChartDirty()
  470. }
  471. function onWindowSizeChange(value: number) {
  472. windowSize.value = Math.max(1, Math.min(200, Math.round(value || 1)))
  473. startIndex.value = Math.min(startIndex.value, maxStart.value)
  474. markChartDirty()
  475. }
  476. function resetWindow() {
  477. startIndex.value = 0
  478. markChartDirty()
  479. }
  480. function pageWindow(direction: -1 | 1) {
  481. const next = startIndex.value + direction * stripWindowSize.value
  482. startIndex.value = Math.max(0, Math.min(next, maxStart.value))
  483. markChartDirty()
  484. }
  485. function jumpToIndex(index: number) {
  486. onStartIndexChange(Number(index))
  487. }
  488. type JumpSegment = { text: string; color?: string }
  489. const jumpOptions = computed(() => timePoints.value.map((point, index) => {
  490. const text = point.sampleTime.replace('T', ' ')
  491. const segments: JumpSegment[] = [{ text }]
  492. const statuses: JumpSegment[] = []
  493. for (const devicePoint of selectedDevicePoints.value) {
  494. const file = point.files[devicePoint]
  495. if (!file || file.status === undefined) continue
  496. const color = file.rpm <= 0 ? STOPPED_COLOR : statusGradientColor(file.status, ruler.value)
  497. statuses.push({ text: String(file.status), color })
  498. }
  499. if (statuses.length) {
  500. segments.push({ text: ' (' })
  501. statuses.forEach((segment, i) => {
  502. if (i > 0) segments.push({ text: '·', color: '#8b9aa2' })
  503. segments.push(segment)
  504. })
  505. segments.push({ text: ')' })
  506. }
  507. const label = statuses.length
  508. ? `${text} (${statuses.map((segment) => segment.text).join('·')})`
  509. : text
  510. return { value: index, segments, label }
  511. }))
  512. function sampleTimeStyle(file: WaveWindowFile) {
  513. if (file.measurementType !== '压力') return undefined
  514. const color = file.rpm <= 0 ? STOPPED_COLOR : statusGradientColor(file.status, ruler.value)
  515. return { color }
  516. }
  517. function refresh() {
  518. void loadOptions()
  519. }
  520. async function openPeriod(cycle: Cycle) {
  521. periodVisible.value = true
  522. periodLoading.value = true
  523. periodDetail.value = null
  524. try {
  525. periodDetail.value = await fetchPeriodDetail(cycle.waveFileId, cycle.periodNo)
  526. } catch (error) {
  527. errorMessage.value = error instanceof Error ? error.message : '周期详情读取失败'
  528. periodVisible.value = false
  529. } finally {
  530. periodLoading.value = false
  531. }
  532. }
  533. function closePeriod() {
  534. periodVisible.value = false
  535. }
  536. async function loadAnnotationConfig() {
  537. try {
  538. const result = await fetchAnnotationConfig()
  539. annotationWidth.value = result.annotationWidth
  540. } catch {
  541. annotationWidth.value = 10
  542. }
  543. }
  544. async function loadAnnotations() {
  545. const ids = [...new Set(
  546. timePoints.value.flatMap((point) => (
  547. selectedDevicePoints.value
  548. .map((devicePoint) => point.files[devicePoint]?.id)
  549. .filter((id): id is number => id != null)
  550. )),
  551. )]
  552. if (!ids.length) {
  553. annotations.value = []
  554. return
  555. }
  556. try {
  557. const result = await fetchAnnotationsByIds(ids)
  558. annotations.value = result.annotations
  559. } catch {
  560. annotations.value = []
  561. }
  562. }
  563. type AnnotationBlock = {
  564. waveFileId: number
  565. periodStart: number
  566. periodEnd: number
  567. sampleIndexStart: number
  568. sampleIndexEnd: number
  569. }
  570. function annotationBlock(cycle: Cycle): AnnotationBlock | null {
  571. const width = Math.max(1, annotationWidth.value)
  572. const fileCycles = (waveData.value?.cycles ?? []).filter((item) => item.waveFileId === cycle.waveFileId)
  573. const maxPeriod = Math.max(1, ...fileCycles.map((item) => item.periodNo))
  574. let leftBound = 1
  575. let rightBound = maxPeriod
  576. const existing = annotations.value
  577. .filter((item) => item.waveFileId === cycle.waveFileId)
  578. .sort((a, b) => a.periodStart - b.periodStart)
  579. for (const item of existing) {
  580. if (item.periodEnd < cycle.periodNo) {
  581. leftBound = Math.max(leftBound, item.periodEnd + 1)
  582. } else if (item.periodStart > cycle.periodNo) {
  583. rightBound = Math.min(rightBound, item.periodStart - 1)
  584. } else {
  585. return null
  586. }
  587. }
  588. if (leftBound > rightBound) return null
  589. let start = Math.max(leftBound, cycle.periodNo - Math.floor((width - 1) / 2))
  590. let end = Math.min(rightBound, start + width - 1)
  591. start = Math.max(leftBound, end - width + 1)
  592. const startCycle = fileCycles.find((item) => item.periodNo === start)
  593. const endCycle = fileCycles.find((item) => item.periodNo === end)
  594. return {
  595. waveFileId: cycle.waveFileId,
  596. periodStart: start,
  597. periodEnd: end,
  598. sampleIndexStart: startCycle?.startSampleIndex ?? cycle.startSampleIndex,
  599. sampleIndexEnd: endCycle?.endSampleIndex ?? cycle.endSampleIndex,
  600. }
  601. }
  602. async function chooseLabel(block: AnnotationBlock): Promise<AnnotationLabel | null> {
  603. try {
  604. await ElMessageBox.confirm(
  605. `将在周期 ${block.periodStart} — ${block.periodEnd} 创建标注,请选择样本类型`,
  606. '创建标注',
  607. {
  608. confirmButtonText: '正常样本',
  609. cancelButtonText: '异常样本',
  610. distinguishCancelAndClose: true,
  611. type: 'info',
  612. closeOnClickModal: false,
  613. },
  614. )
  615. return '正常'
  616. } catch (action) {
  617. if (action === 'cancel') return '异常'
  618. return null
  619. }
  620. }
  621. async function onAnnotationToggle(cycle: Cycle) {
  622. if (annotationLoading.value) return
  623. const existing = annotations.value.find((item) => (
  624. item.waveFileId === cycle.waveFileId && cycle.periodNo >= item.periodStart && cycle.periodNo <= item.periodEnd
  625. ))
  626. if (existing) {
  627. try {
  628. await ElMessageBox.confirm(
  629. `取消该标注(${existing.label},周期 ${existing.periodStart} — ${existing.periodEnd})?`,
  630. '取消标注',
  631. { confirmButtonText: '取消标注', cancelButtonText: '保留', type: 'warning', closeOnClickModal: false },
  632. )
  633. } catch {
  634. return
  635. }
  636. annotationLoading.value = true
  637. try {
  638. await deleteAnnotation(existing.id)
  639. await loadAnnotations()
  640. } catch (error) {
  641. errorMessage.value = error instanceof Error ? error.message : '标注取消失败'
  642. } finally {
  643. annotationLoading.value = false
  644. }
  645. return
  646. }
  647. const block = annotationBlock(cycle)
  648. if (!block) return
  649. const label = await chooseLabel(block)
  650. if (!label) return
  651. annotationLoading.value = true
  652. try {
  653. await createAnnotation({
  654. wave_file_id: block.waveFileId,
  655. label,
  656. period_start: block.periodStart,
  657. period_end: block.periodEnd,
  658. sample_index_start: block.sampleIndexStart,
  659. sample_index_end: block.sampleIndexEnd,
  660. })
  661. await loadAnnotations()
  662. } catch (error) {
  663. errorMessage.value = error instanceof Error ? error.message : '标注创建失败'
  664. } finally {
  665. annotationLoading.value = false
  666. }
  667. }
  668. watch(selectedDevicePart, async (current, previous) => {
  669. if (!initialized.value) return
  670. if (previous && previous !== current) rememberPart(previous)
  671. await onDevicePartChange(previous)
  672. })
  673. watch(selectedDevicePoints, () => {
  674. if (initialized.value) onDevicePointsChange()
  675. }, { deep: true })
  676. watch([minTime, maxTime], () => {
  677. if (initialized.value) onTimeChange()
  678. })
  679. watch(windowSize, () => {
  680. if (initialized.value) onWindowSizeChange(windowSize.value)
  681. })
  682. watch(noSampling, () => {
  683. if (initialized.value && selectedWindowPoints.value.length) loadWaveWindowNow()
  684. })
  685. watch(includeStopped, () => {
  686. if (initialized.value) scheduleTimePoints()
  687. })
  688. watch(abnormalOnly, () => {
  689. if (initialized.value) scheduleTimePoints()
  690. })
  691. watch(noCycleOnly, () => {
  692. if (initialized.value) scheduleTimePoints()
  693. })
  694. watch(minStatus, () => {
  695. if (initialized.value) scheduleTimePoints()
  696. })
  697. watch(firstCycleOnly, () => {
  698. if (!initialized.value) return
  699. windowSize.value = firstCycleOnly.value ? 50 : 4
  700. markChartDirty()
  701. void loadWaveWindowNow()
  702. })
  703. watch([firstCycleOnly, unitNumber], async () => {
  704. if (!initialized.value) return
  705. if (isPksMode.value) {
  706. await loadSitePoints()
  707. if (selectedSitePoints.value.length) fileListPoint.value = SITE_TAB_LABEL
  708. } else {
  709. sitePointOptions.value = []
  710. pksTimeBounds.value = null
  711. if (!selectedDevicePoints.value.length) selectedDevicePoints.value = [PRIMARY_DEVICE_POINT]
  712. if (fileListPoint.value === SITE_TAB_LABEL) fileListPoint.value = selectedDevicePoints.value[0] ?? PRIMARY_DEVICE_POINT
  713. }
  714. })
  715. watch(selectedSitePoints, (points) => {
  716. if (!initialized.value) return
  717. if (selectedDevicePart.value) rememberPart(selectedDevicePart.value)
  718. if (isPksMode.value) scheduleTimePoints()
  719. if (points.length) fileListPoint.value = SITE_TAB_LABEL
  720. })
  721. watch(waveData, () => void refreshPretrainStatus(), { deep: false })
  722. async function refreshPretrainStatus() {
  723. const ids = waveData.value?.files.map((file) => file.id) ?? []
  724. if (!ids.length) {
  725. recordedFileIds.value = []
  726. return
  727. }
  728. try {
  729. const result = await fetchPretrainStatus(ids)
  730. recordedFileIds.value = result.recorded
  731. } catch {
  732. recordedFileIds.value = []
  733. }
  734. }
  735. function locateFile(file: WaveWindowFile) {
  736. waveChartRef.value?.locateFile(file.pointIndex)
  737. }
  738. async function recordFile(file: WaveWindowFile) {
  739. if (recordedFileIds.value.includes(file.id) || recordingFileId.value != null) return
  740. recordingFileId.value = file.id
  741. try {
  742. const result = await recordPretrain({
  743. id: file.id,
  744. point_name: file.pointName,
  745. measurement_type: file.measurementType,
  746. rpm: file.rpm,
  747. sample_time: file.sampleTime,
  748. file_name: file.fileName,
  749. })
  750. if (result.recorded || result.already) {
  751. recordedFileIds.value = [...new Set([...recordedFileIds.value, file.id])]
  752. }
  753. } catch (error) {
  754. errorMessage.value = error instanceof Error ? error.message : '记录失败'
  755. } finally {
  756. recordingFileId.value = null
  757. }
  758. }
  759. async function deleteRecordedFile(file: WaveWindowFile) {
  760. if (!recordedFileIds.value.includes(file.id) || recordingFileId.value != null) return
  761. recordingFileId.value = file.id
  762. try {
  763. await deletePretrain(file.id)
  764. recordedFileIds.value = recordedFileIds.value.filter((id) => id !== file.id)
  765. } catch (error) {
  766. errorMessage.value = error instanceof Error ? error.message : '删除失败'
  767. } finally {
  768. recordingFileId.value = null
  769. }
  770. }
  771. async function handleLogin() {
  772. if (!loginForm.username || !loginForm.password) {
  773. loginError.value = '请输入账号和密码'
  774. return
  775. }
  776. loginLoading.value = true
  777. loginError.value = ''
  778. try {
  779. await apiLogin(loginForm.username, loginForm.password)
  780. loggedIn.value = true
  781. loginForm.password = ''
  782. await loadOptions()
  783. void loadTspluseRuler()
  784. void loadAnnotationConfig()
  785. } catch (error) {
  786. loginError.value = error instanceof Error ? error.message : '登录失败'
  787. } finally {
  788. loginLoading.value = false
  789. }
  790. }
  791. async function handleLogout() {
  792. await apiLogout()
  793. loggedIn.value = false
  794. waveData.value = null
  795. timePoints.value = []
  796. annotations.value = []
  797. }
  798. function onAuthExpired() {
  799. loggedIn.value = false
  800. waveData.value = null
  801. timePoints.value = []
  802. annotations.value = []
  803. }
  804. onMounted(() => {
  805. window.addEventListener('auth-expired', onAuthExpired)
  806. loggedIn.value = getToken() != null
  807. if (loggedIn.value) {
  808. void loadOptions()
  809. void loadTspluseRuler()
  810. void loadAnnotationConfig()
  811. }
  812. })
  813. onBeforeUnmount(() => {
  814. window.removeEventListener('auth-expired', onAuthExpired)
  815. if (queryDebounce) clearTimeout(queryDebounce)
  816. })
  817. </script>
  818. <template>
  819. <div v-if="!loggedIn" class="login-shell">
  820. <form class="login-card" @submit.prevent="handleLogin">
  821. <div class="login-brand">
  822. <div class="brand-mark"><span></span><span></span><span></span></div>
  823. <div>
  824. <div class="brand-kicker">COMPRESSOR / WAVE LAB</div>
  825. <h1>故障预测波形工作台</h1>
  826. </div>
  827. </div>
  828. <p class="login-hint">请登录后继续使用</p>
  829. <el-input v-model="loginForm.username" class="login-input" size="large" placeholder="账号" clearable @input="loginError = ''" />
  830. <el-input v-model="loginForm.password" class="login-input" size="large" type="password" show-password placeholder="密码" @keyup.enter="handleLogin" @input="loginError = ''" />
  831. <el-alert v-if="loginError" class="login-error" type="error" :closable="false" show-icon :title="loginError" />
  832. <el-button class="login-button" type="primary" size="large" :loading="loginLoading" native-type="submit">登 录</el-button>
  833. </form>
  834. </div>
  835. <div v-else class="app-shell">
  836. <header class="app-header">
  837. <div class="brand-lockup">
  838. <div class="brand-mark"><span></span><span></span><span></span></div>
  839. <div>
  840. <div class="brand-kicker">COMPRESSOR / WAVE LAB</div>
  841. <h1>故障预测波形工作台</h1>
  842. </div>
  843. </div>
  844. <div class="header-meta">
  845. <el-button class="header-logout" plain @click="handleLogout">退出登录</el-button>
  846. </div>
  847. </header>
  848. <el-tabs v-model="activeTab" class="workspace-tabs">
  849. <el-tab-pane label="模型1" name="model1">
  850. <main class="workspace">
  851. <section class="query-panel panel">
  852. <div class="panel-heading compact-heading">
  853. <div>
  854. <h2>查询条件</h2>
  855. </div>
  856. <div class="heading-meta">
  857. <span class="live-indicator"><i></i> 浏览模式</span>
  858. <span class="header-date">{{ selectedDevicePart || '未选择机组与部位' }}</span>
  859. <el-button class="header-refresh" type="primary" plain :loading="queryLoading" @click="refresh">刷新</el-button>
  860. <el-tag class="connection-badge" :type="currentSource === 'database' ? 'success' : 'warning'" effect="plain">
  861. {{ currentSource === 'database' ? '数据库已连接' : '演示数据' }}
  862. </el-tag>
  863. </div>
  864. </div>
  865. <div class="query-grid">
  866. <label class="field field-point">
  867. <span class="field-label">机组与部位</span>
  868. <el-select
  869. v-model="selectedDevicePart"
  870. class="query-control"
  871. size="large"
  872. filterable
  873. :disabled="queryLoading"
  874. placeholder="输入机组、气缸或部位关键词"
  875. filter-placeholder="搜索机组与部位"
  876. >
  877. <el-option v-for="devicePart in deviceParts" :key="devicePart" :label="devicePart" :value="devicePart" />
  878. </el-select>
  879. </label>
  880. <div class="field field-types">
  881. <span class="field-label">测试点位</span>
  882. <el-select
  883. v-model="pointModel"
  884. class="query-control"
  885. size="large"
  886. multiple
  887. collapse-tags
  888. collapse-tags-tooltip
  889. :max-collapse-tags="2"
  890. placeholder="选择测试点位"
  891. >
  892. <template v-if="isPksMode">
  893. <el-option-group label="波形点位">
  894. <el-option
  895. v-for="point in devicePoints"
  896. :key="point"
  897. :label="devicePointLabel(point)"
  898. :value="point"
  899. >
  900. <span>{{ point }}</span>
  901. <template v-if="devicePointCounts[point]?.pre !== null || devicePointCounts[point]?.ab !== null">
  902. <span class="point-counts">
  903. (<span v-if="devicePointCounts[point]?.pre !== null">{{ devicePointCounts[point]?.pre }}</span><template v-if="devicePointCounts[point]?.pre !== null && devicePointCounts[point]?.ab !== null"> · </template><span v-if="devicePointCounts[point]?.ab !== null" class="abnormal-count">{{ devicePointCounts[point]?.ab }}</span>)
  904. </span>
  905. </template>
  906. </el-option>
  907. </el-option-group>
  908. <el-option-group label="全场点位 (PKS)">
  909. <el-option
  910. v-for="point in sitePointOptions"
  911. :key="point.itemName"
  912. :value="point.itemName"
  913. :label="sitePointLabel(point)"
  914. />
  915. </el-option-group>
  916. </template>
  917. <template v-else>
  918. <el-option
  919. v-for="point in devicePoints"
  920. :key="point"
  921. :label="devicePointLabel(point)"
  922. :value="point"
  923. >
  924. <span>{{ point }}</span>
  925. <template v-if="devicePointCounts[point]?.pre !== null || devicePointCounts[point]?.ab !== null">
  926. <span class="point-counts">
  927. (<span v-if="devicePointCounts[point]?.pre !== null">{{ devicePointCounts[point]?.pre }}</span><template v-if="devicePointCounts[point]?.pre !== null && devicePointCounts[point]?.ab !== null"> · </template><span v-if="devicePointCounts[point]?.ab !== null" class="abnormal-count">{{ devicePointCounts[point]?.ab }}</span>)
  928. </span>
  929. </template>
  930. </el-option>
  931. </template>
  932. </el-select>
  933. </div>
  934. <label class="field">
  935. <span class="field-label">开始时间</span>
  936. <el-date-picker
  937. v-model="minTime"
  938. class="query-control"
  939. size="large"
  940. type="datetime"
  941. value-format="YYYY-MM-DD HH:mm:ss"
  942. format="YYYY-MM-DD HH:mm:ss"
  943. :disabled="queryLoading"
  944. placeholder="选择开始时间"
  945. />
  946. </label>
  947. <label class="field">
  948. <span class="field-label">结束时间</span>
  949. <el-date-picker
  950. v-model="maxTime"
  951. class="query-control"
  952. size="large"
  953. type="datetime"
  954. value-format="YYYY-MM-DD HH:mm:ss"
  955. format="YYYY-MM-DD HH:mm:ss"
  956. :disabled="queryLoading"
  957. placeholder="选择结束时间"
  958. />
  959. </label>
  960. <el-button class="query-action query-button" type="primary" size="large" :loading="timePointsLoading" :disabled="!canQueryTimePoints" @click="loadTimePoints">
  961. 查询时间点
  962. </el-button>
  963. <div class="query-row-2">
  964. <label class="field field-check">
  965. <span class="field-label">运行状态</span>
  966. <el-checkbox v-model="includeStopped" class="query-checkbox" size="large">停机</el-checkbox>
  967. <el-checkbox v-model="abnormalOnly" class="query-checkbox" size="large" :disabled="queryLoading || isPksOnly">异常</el-checkbox>
  968. <el-checkbox v-model="noCycleOnly" class="query-checkbox" size="large" :disabled="queryLoading || isPksOnly">无周期</el-checkbox>
  969. </label>
  970. <div class="field-second-group">
  971. <label class="field field-status">
  972. <span class="field-label">质心距离</span>
  973. <el-input-number
  974. v-model="minStatus"
  975. class="query-control"
  976. size="large"
  977. :min="0"
  978. :max="4"
  979. :step="1"
  980. :step-strictly="true"
  981. controls-position="right"
  982. :disabled="queryLoading || noCycleOnly || isPksOnly"
  983. clearable
  984. placeholder="可空"
  985. :title="isPksOnly ? '仅 PKS 点位组合下不可用' : (noCycleOnly ? '勾选无周期时忽略质心距离' : undefined)"
  986. />
  987. </label>
  988. <label class="field field-first-cycle">
  989. <span class="field-label">首个周期</span>
  990. <el-checkbox v-model="firstCycleOnly" class="query-checkbox" size="large" :disabled="queryLoading">连续曲线</el-checkbox>
  991. </label>
  992. </div>
  993. <label class="field window-field">
  994. <span class="field-label">时间窗口 <em>{{ isPksOnly ? '时间点数量' : '文件数量' }}</em></span>
  995. <el-input-number
  996. v-model="windowSize"
  997. class="query-control window-number"
  998. size="large"
  999. :min="1"
  1000. :max="200"
  1001. controls-position="right"
  1002. :disabled="queryLoading"
  1003. />
  1004. </label>
  1005. <label class="field field-time-range">
  1006. <span class="field-label">时间段</span>
  1007. <el-select
  1008. v-model="selectedTimeRangePoint"
  1009. class="query-control"
  1010. size="large"
  1011. clearable
  1012. filterable
  1013. :disabled="queryLoading"
  1014. placeholder="选择测试点位"
  1015. filter-placeholder="搜索测试点位"
  1016. @change="onTimeRangeChange"
  1017. >
  1018. <el-option
  1019. v-for="option in timeRangeOptions"
  1020. :key="option.devicePoint"
  1021. :value="option.devicePoint"
  1022. :label="`${option.devicePoint} ${formatRange(option)}`"
  1023. />
  1024. </el-select>
  1025. </label>
  1026. </div>
  1027. </div>
  1028. <el-alert v-if="errorMessage" class="data-alert" type="error" :closable="false" show-icon :title="errorMessage" />
  1029. </section>
  1030. <section class="selection-panel panel">
  1031. <TimePointStrip
  1032. :points="timePoints"
  1033. :device-points="selectedDevicePoints"
  1034. :point-to-type="DEVICE_POINT_TO_TYPE"
  1035. :start-index="startIndex"
  1036. :window-size="stripWindowSize"
  1037. :loading="timePointsLoading"
  1038. :min-time="minTime"
  1039. :max-time="maxTime"
  1040. :annotated-file-ids="annotatedFileIds"
  1041. :faults="faults"
  1042. :ruler="ruler"
  1043. :site-points="isPksMode ? selectedSitePoints : []"
  1044. :site-descriptions="siteDescriptionMap"
  1045. @update:start-index="onStartIndexChange"
  1046. />
  1047. <div class="selection-controls">
  1048. <div class="selection-readout">
  1049. <span class="selection-accent"></span>
  1050. <span>当前窗口覆盖 <strong>{{ selectedWindowPoints.length }}</strong> 个时间点</span>
  1051. <span v-if="hasReference" class="reference-badge" title="始终保留一个 status=0 的正常数据用于对比,固定不随翻页变化">
  1052. 正常对比:{{ formatDateTime(referencePoints[0]?.sampleTime) }}
  1053. </span>
  1054. </div>
  1055. <div class="selection-actions">
  1056. <el-button class="ghost-button" plain :disabled="!startIndex" @click="resetWindow">回到起点</el-button>
  1057. <el-button class="ghost-button" plain :disabled="startIndex <= 0" @click="pageWindow(-1)">上一页</el-button>
  1058. <el-button class="ghost-button" plain :disabled="startIndex >= timePoints.length - windowSize" @click="pageWindow(1)">下一页</el-button>
  1059. <el-select-v2
  1060. class="jump-select"
  1061. :options="jumpOptions"
  1062. :model-value="startIndex"
  1063. :disabled="!timePoints.length"
  1064. size="small"
  1065. filterable
  1066. placeholder="跳转"
  1067. @update:model-value="jumpToIndex"
  1068. >
  1069. <template #default="{ item }">
  1070. <template v-for="(segment, segmentIndex) in item.segments" :key="segmentIndex">
  1071. <span v-if="segment.color" :style="{ color: segment.color }">{{ segment.text }}</span>
  1072. <span v-else>{{ segment.text }}</span>
  1073. </template>
  1074. </template>
  1075. </el-select-v2>
  1076. <el-button
  1077. class="ghost-button chart-query"
  1078. :class="{ 'is-dirty': chartDirty }"
  1079. type="primary"
  1080. plain
  1081. :loading="waveLoading"
  1082. :disabled="waveLoading || !selectedWindowPoints.length"
  1083. @click="loadWaveWindowNow"
  1084. >查询图表</el-button>
  1085. </div>
  1086. </div>
  1087. <div v-if="(waveData?.files.length || windowSiteRows.length)" class="window-files">
  1088. <div class="window-files-title">
  1089. <span>{{ isSiteTab ? '当前窗口 全场点位记录' : '当前窗口 wave_file 记录' }}</span>
  1090. <el-radio-group v-model="fileListPoint" class="file-point-radio" size="small">
  1091. <el-radio-button v-for="point in fileTabs" :key="point" :value="point">{{ point }}</el-radio-button>
  1092. </el-radio-group>
  1093. </div>
  1094. <div class="window-files-scroll">
  1095. <table v-if="isSiteTab" class="window-files-table">
  1096. <thead>
  1097. <tr>
  1098. <th>#</th>
  1099. <th>sample_time</th>
  1100. <th v-for="itemName in selectedSitePoints" :key="itemName" :title="itemName">{{ siteDescription(itemName) }}</th>
  1101. </tr>
  1102. </thead>
  1103. <tbody>
  1104. <tr v-for="row in windowSiteRows" :key="row.index">
  1105. <td class="mono">{{ row.index + 1 }}</td>
  1106. <td class="mono">{{ row.sampleTime }}</td>
  1107. <td v-for="itemName in selectedSitePoints" :key="itemName" class="mono">{{ row.values[itemName] ?? '—' }}</td>
  1108. </tr>
  1109. </tbody>
  1110. </table>
  1111. <table v-else class="window-files-table">
  1112. <thead>
  1113. <tr>
  1114. <th>id</th>
  1115. <th>point_name</th>
  1116. <th>测试点位</th>
  1117. <th>measurement_type</th>
  1118. <th>rpm</th>
  1119. <th>sample_time</th>
  1120. <th>tspluse_status</th>
  1121. <th>file_name</th>
  1122. <th>操作</th>
  1123. </tr>
  1124. </thead>
  1125. <tbody>
  1126. <tr v-for="file in windowFiles" :key="file.id">
  1127. <td class="mono">{{ file.id }}</td>
  1128. <td>{{ file.pointName }}</td>
  1129. <td>{{ file.devicePoint }}</td>
  1130. <td>{{ file.measurementType }}</td>
  1131. <td class="mono">{{ file.rpm }}</td>
  1132. <td class="mono" :style="sampleTimeStyle(file)">{{ file.sampleTime.replace('T', ' ') }}</td>
  1133. <td class="mono">{{ file.status ?? '' }}</td>
  1134. <td class="file-name" :title="file.fileName">{{ file.fileName || '—' }}</td>
  1135. <td class="actions">
  1136. <el-button class="file-action" size="small" plain :disabled="!waveData" @click="locateFile(file)">定位</el-button>
  1137. <el-button
  1138. v-if="!recordedFileIds.includes(file.id)"
  1139. class="file-action"
  1140. size="small"
  1141. type="primary"
  1142. plain
  1143. :loading="recordingFileId === file.id"
  1144. @click="recordFile(file)"
  1145. >记录</el-button>
  1146. <el-button
  1147. v-else
  1148. class="file-action"
  1149. size="small"
  1150. type="danger"
  1151. plain
  1152. :loading="recordingFileId === file.id"
  1153. @click="deleteRecordedFile(file)"
  1154. >删除</el-button>
  1155. </td>
  1156. </tr>
  1157. </tbody>
  1158. </table>
  1159. </div>
  1160. </div>
  1161. </section>
  1162. <section class="chart-panel panel">
  1163. <div class="panel-heading chart-heading">
  1164. <div>
  1165. <h2>波形预览</h2>
  1166. </div>
  1167. <div class="chart-actions">
  1168. <span class="annotation-width">标度宽度:<strong>{{ annotationWidth }}</strong></span>
  1169. <el-radio-group v-model="chartMode" class="mode-switch" size="small">
  1170. <el-radio-button label="split">分图显示</el-radio-button>
  1171. <el-radio-button label="merge">归一合并</el-radio-button>
  1172. </el-radio-group>
  1173. <el-switch
  1174. v-model="noSampling"
  1175. class="sampling-switch"
  1176. size="small"
  1177. active-text="不采样"
  1178. inactive-text="采样"
  1179. :disabled="waveLoading"
  1180. />
  1181. <div class="chart-status"><i :class="{ busy: waveLoading }"></i>{{ statusText() }}</div>
  1182. </div>
  1183. </div>
  1184. <WaveChart
  1185. ref="waveChartRef"
  1186. :data="waveData"
  1187. :points="selectedWindowPoints"
  1188. :mode="chartMode"
  1189. :loading="waveLoading"
  1190. :annotations="annotations"
  1191. :site-descriptions="siteDescriptionMap"
  1192. @period-dblclick="openPeriod"
  1193. @annotation-toggle="onAnnotationToggle"
  1194. />
  1195. </section>
  1196. <aside class="insight-panel panel">
  1197. <div class="panel-heading compact-heading">
  1198. <div><h2>当前窗口</h2></div>
  1199. <span class="readout-number">{{ String(selectedWindowPoints.length).padStart(2, '0') }}</span>
  1200. </div>
  1201. <div class="readout-grid">
  1202. <div class="readout-card">
  1203. <span>时间跨度</span>
  1204. <div class="readout-value">
  1205. <strong>{{ formatDateTime(selectedWindowPoints[0]?.sampleTime) }}</strong>
  1206. <small>至 {{ formatDateTime(selectedWindowPoints[selectedWindowPoints.length - 1]?.sampleTime) }}</small>
  1207. </div>
  1208. </div>
  1209. <div class="readout-card"><span>检测周期</span><strong>{{ currentCycles.length }}</strong></div>
  1210. <div class="readout-card"><span>选择范围</span><strong>#{{ startIndex + 1 }} — #{{ endIndex }}</strong></div>
  1211. <div class="readout-card"><span>显示策略</span><strong>MIN / MAX</strong></div>
  1212. </div>
  1213. <div class="data-footprint">
  1214. <div><span>测试点位</span><strong>{{ [...selectedDevicePoints, ...(isPksMode ? selectedSitePoints : [])].join(' / ') || '未选择' }}</strong></div>
  1215. <div><span>可用文件</span><strong>{{ availableTypeCount.toLocaleString() }}</strong></div>
  1216. <div><span>抽样上限</span><strong>{{ maxPoints.toLocaleString() }} 点</strong></div>
  1217. </div>
  1218. </aside>
  1219. </main>
  1220. </el-tab-pane>
  1221. <el-tab-pane label="告警监控" name="alarm">
  1222. <AlarmMonitor />
  1223. </el-tab-pane>
  1224. </el-tabs>
  1225. <PeriodModal :visible="periodVisible" :detail="periodDetail" :loading="periodLoading" :pressure-axis="pressureAxis" @close="closePeriod" />
  1226. </div>
  1227. </template>