Compare commits

..

No commits in common. 'e142113ab8b7a5e174aef0e184efffa6102b3a54' and 'bc1daf868fae39a05c7b05a114060ab3117cf1fd' have entirely different histories.

  1. 4
      .env
  2. 49
      src/hooks/useChartDataFetch.hook.ts

4
.env

@ -3,10 +3,10 @@ VITE_DEV_PORT = '3000' @@ -3,10 +3,10 @@ VITE_DEV_PORT = '3000'
# development path
# VITE_DEV_PATH = 'https://demo.mtruning.club'
VITE_DEV_PATH = 'http://43.140.245.32:48081'
VITE_DEV_PATH = 'http://127.0.0.1:48080'
# production path
VITE_PRO_PATH = 'http://127.0.0.1:48080'
VITE_PRO_PATH = 'https://demo.mtruning.club'
# 租户开关
VITE_APP_TENANT_ENABLE=true

49
src/hooks/useChartDataFetch.hook.ts

@ -1,4 +1,4 @@ @@ -1,4 +1,4 @@
import { ref, toRaw, toRefs, watch } from 'vue'
import { ref, toRefs, toRaw, watch } from 'vue'
import type VChart from 'vue-echarts'
import { customizeHttp } from '@/api/http'
import { useChartDataPondFetch } from '@/hooks/'
@ -6,13 +6,14 @@ import { @@ -6,13 +6,14 @@ import {
RequestConfigType,
RequestDataSourceConfig
} from '@/store/modules/chartEditStore/chartEditStore.d'
import { ChartFrameEnum, CreateComponentType } from '@/packages/index.d'
import { CreateComponentType, ChartFrameEnum } from '@/packages/index.d'
import { useChartEditStore } from '@/store/modules/chartEditStore/chartEditStore'
import { RequestAJAXTypes, RequestDataTypeEnum } from '@/enums/httpEnum'
import { intervalUnitHandle, isPreview, newFunctionHandle } from '@/utils'
import { isPreview, newFunctionHandle, intervalUnitHandle } from '@/utils'
import { setOption } from '@/packages/public/chart'
import { isNil } from 'lodash'
import dayjs from "dayjs";
import { debounce } from "lodash";
// 获取类型
type ChartEditStoreType = typeof useChartEditStore
@ -30,6 +31,7 @@ export const useChartDataFetch = ( @@ -30,6 +31,7 @@ export const useChartDataFetch = (
) => {
const vChartRef = ref<typeof VChart | null>(null)
let fetchInterval: any = 0
console.log("vChartRef:", vChartRef)
// 数据池
const { addGlobalDataInterface } = useChartDataPondFetch()
@ -45,8 +47,9 @@ export const useChartDataFetch = ( @@ -45,8 +47,9 @@ export const useChartDataFetch = (
}
}
watch(() => targetComponent.request.requestContentType, () => {
watch(() => targetComponent.request, () => {
if (isPreview()) return
console.log("监听到 request 更改:", targetComponent.request)
requestIntervalFn()
}, { deep: true })
@ -111,7 +114,17 @@ export const useChartDataFetch = ( @@ -111,7 +114,17 @@ export const useChartDataFetch = (
}
}
createFetchInterval(fetchFn, targetComponent.request)
const debouncedFetch = createDebouncedFetch(fetchFn, targetComponent.requestSource)
watch(
() => targetComponent.request.requestParams,
() => {
debouncedFetch()
},
{
immediate: true,
deep: true
}
)
}
// eslint-disable-next-line no-empty
} catch (error) {
@ -133,14 +146,24 @@ export const useChartDataFetch = ( @@ -133,14 +146,24 @@ export const useChartDataFetch = (
console.log(station.value)
}
createFetchInterval(fetchFn, targetComponent.requestSource)
const debouncedFetch = createDebouncedFetch(fetchFn, targetComponent.requestSource)
watch(
() => targetComponent.requestSource,
() => {
debouncedFetch()
},
{
immediate: true,
deep: true
}
)
} catch (error) {
console.log('SourceRequestIntervalFn Error:', error)
}
}
function createFetchInterval(fetchFn: () => void, targetComponentRequest: RequestConfigType | RequestDataSourceConfig) {
function createDebouncedFetch(fetchFn: () => void, targetComponentRequest: RequestConfigType | RequestDataSourceConfig) {
const chartEditStore = useChartEditStore()
const {
requestIntervalUnit: targetUnit,
@ -153,15 +176,16 @@ export const useChartDataFetch = ( @@ -153,15 +176,16 @@ export const useChartDataFetch = (
requestIntervalUnit: globalUnit,
requestInterval: globalRequestInterval
} = toRefs(chartEditStore.getRequestGlobalConfig)
fetchFn()
// 定时时间
return debounce(() => {
const time = targetInterval && !isNil(targetInterval.value) ? targetInterval.value : globalRequestInterval.value
// 单位
// // 单位
const unit = targetInterval && !isNil(targetInterval.value) ? targetUnit.value : globalUnit.value
// 开启轮询
if (time && isPreview()) {
// // 开启轮询
if (time) {
fetchInterval = setInterval(fetchFn, intervalUnitHandle(time, unit))
}
fetchFn()
}, 500)
}
if (isPreview()) {
@ -175,5 +199,6 @@ export const useChartDataFetch = ( @@ -175,5 +199,6 @@ export const useChartDataFetch = (
} else {
requestIntervalFn()
}
console.log("vChartRef:", vChartRef)
return { vChartRef }
}
Loading…
Cancel
Save