|
|
|
@ -2,6 +2,10 @@ import { ref, toRefs, toRaw, watch } from 'vue'
@@ -2,6 +2,10 @@ import { ref, toRefs, toRaw, watch } from 'vue'
|
|
|
|
|
import type VChart from 'vue-echarts' |
|
|
|
|
import { customizeHttp } from '@/api/http' |
|
|
|
|
import { useChartDataPondFetch } from '@/hooks/' |
|
|
|
|
import { |
|
|
|
|
RequestConfigType, |
|
|
|
|
RequestDataSourceConfig |
|
|
|
|
} from '@/store/modules/chartEditStore/chartEditStore.d' |
|
|
|
|
import { CreateComponentType, ChartFrameEnum } from '@/packages/index.d' |
|
|
|
|
import { useChartEditStore } from '@/store/modules/chartEditStore/chartEditStore' |
|
|
|
|
import { RequestAJAXTypes, RequestDataTypeEnum } from '@/enums/httpEnum' |
|
|
|
@ -110,21 +114,7 @@ export const useChartDataFetch = (
@@ -110,21 +114,7 @@ export const useChartDataFetch = (
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 普通初始化与组件交互处理监听
|
|
|
|
|
// 定义一个防抖的函数
|
|
|
|
|
const debouncedFetch = debounce(() => { |
|
|
|
|
clearInterval(fetchInterval) |
|
|
|
|
// 定时时间
|
|
|
|
|
const time = targetInterval && !isNil(targetInterval.value) ? targetInterval.value : globalRequestInterval.value |
|
|
|
|
// 单位
|
|
|
|
|
const unit = targetInterval && !isNil(targetInterval.value) ? targetUnit.value : globalUnit.value |
|
|
|
|
// 开启轮询
|
|
|
|
|
if (time) { |
|
|
|
|
fetchInterval = setInterval(fetchFn, intervalUnitHandle(time, unit)) |
|
|
|
|
} |
|
|
|
|
fetchFn() |
|
|
|
|
}, 500) // 500ms 后触发,可以按需调整
|
|
|
|
|
|
|
|
|
|
const debouncedFetch = createDebouncedFetch(fetchFn, targetComponent.requestSource) |
|
|
|
|
watch( |
|
|
|
|
() => targetComponent.request.requestParams, |
|
|
|
|
() => { |
|
|
|
@ -151,31 +141,51 @@ export const useChartDataFetch = (
@@ -151,31 +141,51 @@ export const useChartDataFetch = (
|
|
|
|
|
requestIntervalUnit: targetUnit, |
|
|
|
|
requestInterval: targetInterval |
|
|
|
|
} = toRefs(targetComponent.requestSource) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try { |
|
|
|
|
function fetchFn() { |
|
|
|
|
clearInterval(fetchInterval) |
|
|
|
|
console.log(station, devices, points, targetUnit, targetInterval) |
|
|
|
|
console.log(station.value) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const debouncedFetch = createDebouncedFetch(fetchFn, targetComponent.requestSource) |
|
|
|
|
watch( |
|
|
|
|
() => targetComponent.requestSource, |
|
|
|
|
() => { |
|
|
|
|
fetchFn() |
|
|
|
|
debouncedFetch() |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
immediate: true, |
|
|
|
|
deep: true |
|
|
|
|
} |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
} catch (error) { |
|
|
|
|
console.log('SourceRequestIntervalFn Error:', error) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function createDebouncedFetch(fetchFn: () => void, targetComponentRequest: RequestConfigType | RequestDataSourceConfig) { |
|
|
|
|
const chartEditStore = useChartEditStore() |
|
|
|
|
const { |
|
|
|
|
requestIntervalUnit: targetUnit, |
|
|
|
|
requestInterval: targetInterval |
|
|
|
|
} = toRefs(targetComponentRequest) |
|
|
|
|
|
|
|
|
|
// 全局数据
|
|
|
|
|
const { |
|
|
|
|
requestOriginUrl, |
|
|
|
|
requestIntervalUnit: globalUnit, |
|
|
|
|
requestInterval: globalRequestInterval |
|
|
|
|
} = toRefs(chartEditStore.getRequestGlobalConfig) |
|
|
|
|
return debounce(() => { |
|
|
|
|
const time = targetInterval && !isNil(targetInterval.value) ? targetInterval.value : globalRequestInterval.value |
|
|
|
|
// // 单位
|
|
|
|
|
const unit = targetInterval && !isNil(targetInterval.value) ? targetUnit.value : globalUnit.value |
|
|
|
|
// // 开启轮询
|
|
|
|
|
if (time) { |
|
|
|
|
fetchInterval = setInterval(fetchFn, intervalUnitHandle(time, unit)) |
|
|
|
|
} |
|
|
|
|
fetchFn() |
|
|
|
|
}, 500) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (isPreview()) { |
|
|
|
|