App.vue 48 KB

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