|
|
@ -4,10 +4,12 @@ import { customizeHttp } from '@/api/http' |
|
|
|
import { useChartDataPondFetch } from '@/hooks/' |
|
|
|
import { useChartDataPondFetch } from '@/hooks/' |
|
|
|
import { CreateComponentType, ChartFrameEnum } from '@/packages/index.d' |
|
|
|
import { CreateComponentType, ChartFrameEnum } from '@/packages/index.d' |
|
|
|
import { useChartEditStore } from '@/store/modules/chartEditStore/chartEditStore' |
|
|
|
import { useChartEditStore } from '@/store/modules/chartEditStore/chartEditStore' |
|
|
|
import { RequestDataTypeEnum } from '@/enums/httpEnum' |
|
|
|
import { RequestAJAXTypes, RequestDataTypeEnum } from '@/enums/httpEnum' |
|
|
|
import { isPreview, newFunctionHandle, intervalUnitHandle } from '@/utils' |
|
|
|
import { isPreview, newFunctionHandle, intervalUnitHandle } from '@/utils' |
|
|
|
import { setOption } from '@/packages/public/chart' |
|
|
|
import { setOption } from '@/packages/public/chart' |
|
|
|
import { isNil } from 'lodash' |
|
|
|
import { isNil } from 'lodash' |
|
|
|
|
|
|
|
import dayjs from "dayjs"; |
|
|
|
|
|
|
|
import { debounce } from "lodash"; |
|
|
|
|
|
|
|
|
|
|
|
// 获取类型
|
|
|
|
// 获取类型
|
|
|
|
type ChartEditStoreType = typeof useChartEditStore |
|
|
|
type ChartEditStoreType = typeof useChartEditStore |
|
|
@ -41,26 +43,46 @@ export const useChartDataFetch = ( |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const requestIntervalFn = () => { |
|
|
|
watch(() => targetComponent.request, () => { |
|
|
|
const chartEditStore = useChartEditStore() |
|
|
|
if (isPreview()) return |
|
|
|
|
|
|
|
console.log("监听到 request 更改:", targetComponent.request) |
|
|
|
|
|
|
|
requestIntervalFn() |
|
|
|
|
|
|
|
}, { deep: true }) |
|
|
|
|
|
|
|
|
|
|
|
// 全局数据
|
|
|
|
|
|
|
|
const { |
|
|
|
|
|
|
|
requestOriginUrl, |
|
|
|
|
|
|
|
requestIntervalUnit: globalUnit, |
|
|
|
|
|
|
|
requestInterval: globalRequestInterval |
|
|
|
|
|
|
|
} = toRefs(chartEditStore.getRequestGlobalConfig) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function requestIntervalFn() { |
|
|
|
// 目标组件
|
|
|
|
// 目标组件
|
|
|
|
|
|
|
|
const { requestDataType, } = toRefs(targetComponent.request) |
|
|
|
|
|
|
|
clearInterval(fetchInterval) |
|
|
|
|
|
|
|
// 非请求类型
|
|
|
|
|
|
|
|
if (!RequestAJAXTypes.includes(requestDataType.value)) return; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
switch (requestDataType.value) { |
|
|
|
|
|
|
|
case RequestDataTypeEnum.AJAX: |
|
|
|
|
|
|
|
AJAXRequestIntervalFn() |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
case RequestDataTypeEnum.Source: |
|
|
|
|
|
|
|
SourceRequestIntervalFn() |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
default: |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function AJAXRequestIntervalFn() { |
|
|
|
|
|
|
|
const chartEditStore = useChartEditStore() |
|
|
|
const { |
|
|
|
const { |
|
|
|
requestDataType, |
|
|
|
|
|
|
|
requestUrl, |
|
|
|
requestUrl, |
|
|
|
requestIntervalUnit: targetUnit, |
|
|
|
requestIntervalUnit: targetUnit, |
|
|
|
requestInterval: targetInterval |
|
|
|
requestInterval: targetInterval |
|
|
|
} = toRefs(targetComponent.request) |
|
|
|
} = toRefs(targetComponent.request) |
|
|
|
|
|
|
|
|
|
|
|
// 非请求类型
|
|
|
|
// 全局数据
|
|
|
|
if (requestDataType.value !== RequestDataTypeEnum.AJAX) return |
|
|
|
const { |
|
|
|
|
|
|
|
requestOriginUrl, |
|
|
|
|
|
|
|
requestIntervalUnit: globalUnit, |
|
|
|
|
|
|
|
requestInterval: globalRequestInterval |
|
|
|
|
|
|
|
} = toRefs(chartEditStore.getRequestGlobalConfig) |
|
|
|
|
|
|
|
|
|
|
|
try { |
|
|
|
try { |
|
|
|
// 处理地址
|
|
|
|
// 处理地址
|
|
|
@ -70,10 +92,8 @@ export const useChartDataFetch = ( |
|
|
|
const completePath = requestOriginUrl && requestOriginUrl.value + requestUrl.value |
|
|
|
const completePath = requestOriginUrl && requestOriginUrl.value + requestUrl.value |
|
|
|
if (!completePath) return |
|
|
|
if (!completePath) return |
|
|
|
|
|
|
|
|
|
|
|
clearInterval(fetchInterval) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const fetchFn = async () => { |
|
|
|
const fetchFn = async () => { |
|
|
|
console.log("监听到更改") |
|
|
|
console.log("监听到更改", dayjs().format('YYYY-MM-DD HH:mm:ss')) |
|
|
|
const res = await customizeHttp(toRaw(targetComponent.request), toRaw(chartEditStore.getRequestGlobalConfig)) |
|
|
|
const res = await customizeHttp(toRaw(targetComponent.request), toRaw(chartEditStore.getRequestGlobalConfig)) |
|
|
|
if (res) { |
|
|
|
if (res) { |
|
|
|
try { |
|
|
|
try { |
|
|
@ -91,34 +111,74 @@ 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 后触发,可以按需调整
|
|
|
|
|
|
|
|
|
|
|
|
watch( |
|
|
|
watch( |
|
|
|
() => targetComponent.request.requestParams, |
|
|
|
() => targetComponent.request.requestParams, |
|
|
|
() => { |
|
|
|
() => { |
|
|
|
fetchFn() |
|
|
|
debouncedFetch() |
|
|
|
}, |
|
|
|
}, |
|
|
|
{ |
|
|
|
{ |
|
|
|
immediate: true, |
|
|
|
immediate: true, |
|
|
|
deep: true |
|
|
|
deep: true |
|
|
|
} |
|
|
|
} |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
// eslint-disable-next-line no-empty
|
|
|
|
|
|
|
|
} catch (error) { |
|
|
|
|
|
|
|
console.log('AJAXRequestIntervalFn Error:', error) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 定时时间
|
|
|
|
function SourceRequestIntervalFn() { |
|
|
|
const time = targetInterval && !isNil(targetInterval.value) ? targetInterval.value : globalRequestInterval.value |
|
|
|
const chartEditStore = useChartEditStore() |
|
|
|
// 单位
|
|
|
|
const { |
|
|
|
const unit = targetInterval && !isNil(targetInterval.value) ? targetUnit.value : globalUnit.value |
|
|
|
station, |
|
|
|
// 开启轮询
|
|
|
|
devices, |
|
|
|
if (time) { |
|
|
|
points, |
|
|
|
fetchInterval = setInterval(fetchFn, intervalUnitHandle(time, unit)) |
|
|
|
requestIntervalUnit: targetUnit, |
|
|
|
|
|
|
|
requestInterval: targetInterval |
|
|
|
|
|
|
|
} = toRefs(targetComponent.requestSource) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try { |
|
|
|
|
|
|
|
function fetchFn() { |
|
|
|
|
|
|
|
clearInterval(fetchInterval) |
|
|
|
|
|
|
|
console.log(station, devices, points, targetUnit, targetInterval) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
watch( |
|
|
|
|
|
|
|
() => targetComponent.requestSource, |
|
|
|
|
|
|
|
() => { |
|
|
|
|
|
|
|
fetchFn() |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
immediate: true, |
|
|
|
|
|
|
|
deep: true |
|
|
|
} |
|
|
|
} |
|
|
|
// eslint-disable-next-line no-empty
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
} catch (error) { |
|
|
|
} catch (error) { |
|
|
|
console.log(error) |
|
|
|
console.log('SourceRequestIntervalFn Error:', error) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (isPreview()) { |
|
|
|
if (isPreview()) { |
|
|
|
console.log("是否是数据池:",targetComponent.request.requestDataType === RequestDataTypeEnum.Pond) |
|
|
|
|
|
|
|
console.log(targetComponent) |
|
|
|
console.log(targetComponent) |
|
|
|
targetComponent.request.requestDataType === RequestDataTypeEnum.Pond |
|
|
|
targetComponent.request.requestDataType === RequestDataTypeEnum.Pond |
|
|
|
? addGlobalDataInterface(targetComponent, useChartEditStore, (newData: any) => { |
|
|
|
? addGlobalDataInterface(targetComponent, useChartEditStore, (newData: any) => { |
|
|
|