|
|
|
|
@ -2,30 +2,61 @@ import { getMonitorInfoTree } from '@/api/ems/base/baseMonitorInfo';
|
|
|
|
|
import type { VibrationBoardQuery } from '@/api/ems/types';
|
|
|
|
|
import { createDefaultTimeRange } from './vibrationBoardShared';
|
|
|
|
|
|
|
|
|
|
type VibrationBoardQueryForm = {
|
|
|
|
|
compareScope: string;
|
|
|
|
|
monitorId: string;
|
|
|
|
|
monitorIds: string[];
|
|
|
|
|
selectionLabel: string;
|
|
|
|
|
samplingInterval: number;
|
|
|
|
|
vibrationParam: string;
|
|
|
|
|
highThreshold: number | undefined;
|
|
|
|
|
warningThreshold: number | undefined;
|
|
|
|
|
minContinuousSamples: number | undefined;
|
|
|
|
|
rapidRiseThreshold: number | undefined;
|
|
|
|
|
stddevThreshold: number | undefined;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
type BuildQueryOptions = {
|
|
|
|
|
includeVibrationParam?: boolean;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const createDefaultQueryForm = (defaultMetric = 'vibrationSpeed'): VibrationBoardQueryForm => ({
|
|
|
|
|
compareScope: 'all',
|
|
|
|
|
monitorId: '',
|
|
|
|
|
monitorIds: [],
|
|
|
|
|
selectionLabel: '全部振动设备',
|
|
|
|
|
samplingInterval: 5,
|
|
|
|
|
vibrationParam: defaultMetric,
|
|
|
|
|
highThreshold: undefined,
|
|
|
|
|
warningThreshold: undefined,
|
|
|
|
|
minContinuousSamples: undefined,
|
|
|
|
|
rapidRiseThreshold: undefined,
|
|
|
|
|
stddevThreshold: undefined
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// 模块级缓存:同一浏览器会话内 7 个页面共享设备树与查询状态,避免重复请求和切页丢筛选。
|
|
|
|
|
const sharedState = reactive({
|
|
|
|
|
treeLoaded: false,
|
|
|
|
|
monitorTreeOptions: [] as any[],
|
|
|
|
|
deviceDisplayMap: {} as Record<string, string>,
|
|
|
|
|
daterangeRecordTime: createDefaultTimeRange() as string[],
|
|
|
|
|
queryForm: createDefaultQueryForm()
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
export function useVibrationBoardQueryState(defaultMetric = 'vibrationSpeed') {
|
|
|
|
|
const state = reactive({
|
|
|
|
|
const localState = reactive({
|
|
|
|
|
loading: false,
|
|
|
|
|
treeLoading: false,
|
|
|
|
|
monitorTreeOptions: [] as any[],
|
|
|
|
|
treeProps: { label: 'label', children: 'children' },
|
|
|
|
|
deviceDisplayMap: {} as Record<string, string>,
|
|
|
|
|
daterangeRecordTime: createDefaultTimeRange() as string[],
|
|
|
|
|
queryForm: {
|
|
|
|
|
compareScope: 'all',
|
|
|
|
|
monitorId: '',
|
|
|
|
|
monitorIds: [] as string[],
|
|
|
|
|
selectionLabel: '全部振动设备',
|
|
|
|
|
samplingInterval: 5,
|
|
|
|
|
vibrationParam: defaultMetric,
|
|
|
|
|
highThreshold: undefined as number | undefined,
|
|
|
|
|
warningThreshold: undefined as number | undefined,
|
|
|
|
|
minContinuousSamples: undefined as number | undefined,
|
|
|
|
|
rapidRiseThreshold: undefined as number | undefined,
|
|
|
|
|
stddevThreshold: undefined as number | undefined
|
|
|
|
|
}
|
|
|
|
|
treeProps: { label: 'label', children: 'children' }
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const { loading, treeLoading, monitorTreeOptions, treeProps, deviceDisplayMap, daterangeRecordTime, queryForm } = toRefs(state);
|
|
|
|
|
// 仅在首次进入页面时应用默认主看指标,后续页面切换沿用用户最新选择。
|
|
|
|
|
if (!sharedState.queryForm.vibrationParam) {
|
|
|
|
|
sharedState.queryForm.vibrationParam = defaultMetric;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const { loading, treeLoading, treeProps } = toRefs(localState);
|
|
|
|
|
const { monitorTreeOptions, deviceDisplayMap, daterangeRecordTime, queryForm } = toRefs(sharedState);
|
|
|
|
|
const deviceCount = computed(() => queryForm.value.monitorIds?.length || (queryForm.value.monitorId ? 1 : 0));
|
|
|
|
|
const hasMultiDevice = computed(() => deviceCount.value > 1 || ['group', 'all'].includes(queryForm.value.compareScope));
|
|
|
|
|
|
|
|
|
|
@ -68,12 +99,27 @@ export function useVibrationBoardQueryState(defaultMetric = 'vibrationSpeed') {
|
|
|
|
|
queryForm.value.vibrationParam = value;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const resetAnomalyThresholds = () => {
|
|
|
|
|
// 主看指标切换后必须回到“未覆盖”状态,让后端按新指标重新下发默认阈值,
|
|
|
|
|
// 否则会把上一指标的阈值误当成当前指标的用户自定义值。
|
|
|
|
|
queryForm.value.highThreshold = undefined;
|
|
|
|
|
queryForm.value.warningThreshold = undefined;
|
|
|
|
|
queryForm.value.minContinuousSamples = undefined;
|
|
|
|
|
queryForm.value.rapidRiseThreshold = undefined;
|
|
|
|
|
queryForm.value.stddevThreshold = undefined;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const loadTree = async () => {
|
|
|
|
|
// 已加载且有缓存时直接复用,避免 7 个页面重复打同一个树接口。
|
|
|
|
|
if (sharedState.treeLoaded) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
treeLoading.value = true;
|
|
|
|
|
try {
|
|
|
|
|
const response = await getMonitorInfoTree({ monitorType: 10 });
|
|
|
|
|
monitorTreeOptions.value = response.data || [];
|
|
|
|
|
deviceDisplayMap.value = buildDeviceDisplayMap(monitorTreeOptions.value);
|
|
|
|
|
sharedState.treeLoaded = true;
|
|
|
|
|
if (!queryForm.value.monitorIds.length && !queryForm.value.monitorId) {
|
|
|
|
|
applySelection(buildSelection(getLeafNodes(monitorTreeOptions.value), '全部振动设备', 'all'));
|
|
|
|
|
}
|
|
|
|
|
@ -91,9 +137,11 @@ export function useVibrationBoardQueryState(defaultMetric = 'vibrationSpeed') {
|
|
|
|
|
applySelection(buildSelection([data], data.label, 'single'));
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const buildQuery = (): VibrationBoardQuery => ({
|
|
|
|
|
const buildQuery = (options?: BuildQueryOptions): VibrationBoardQuery => ({
|
|
|
|
|
samplingInterval: queryForm.value.samplingInterval,
|
|
|
|
|
vibrationParam: queryForm.value.vibrationParam,
|
|
|
|
|
// 质量页不展示主看指标时,必须禁掉这个隐藏筛选条件,
|
|
|
|
|
// 否则会继承其它页面的指标选择,悄悄改变质量统计口径。
|
|
|
|
|
vibrationParam: options?.includeVibrationParam === false ? undefined : queryForm.value.vibrationParam,
|
|
|
|
|
beginRecordTime: daterangeRecordTime.value[0],
|
|
|
|
|
endRecordTime: daterangeRecordTime.value[1],
|
|
|
|
|
highThreshold: queryForm.value.highThreshold,
|
|
|
|
|
@ -125,6 +173,7 @@ export function useVibrationBoardQueryState(defaultMetric = 'vibrationSpeed') {
|
|
|
|
|
setTimeRange,
|
|
|
|
|
setSamplingInterval,
|
|
|
|
|
setVibrationParam,
|
|
|
|
|
resetAnomalyThresholds,
|
|
|
|
|
buildQuery,
|
|
|
|
|
getMonitorDisplayName
|
|
|
|
|
};
|
|
|
|
|
|