App.vue 48 KB

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